Workspaces: remove separate workspaces.blend config file.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 20 Aug 2018 13:37:19 +0000 (15:37 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 20 Aug 2018 14:23:22 +0000 (16:23 +0200)
This is quite confusing in the current UI, with both startup.blend and
workspaces.blend containing a list of workspaces. In practice you'd usually
want to save workspaces to both files.

The downside of having a single file may be that you then can't disable
certain workspaces by default, but we could add a setting for that.

release/scripts/startup/bl_ui/space_userpref.py
source/blender/blenkernel/BKE_appdir.h
source/blender/editors/screen/workspace_edit.c
source/blender/windowmanager/intern/wm_files.c
source/blender/windowmanager/intern/wm_operators.c
source/blender/windowmanager/wm_files.h

index e8fdfc71ae851bea64a46c2accfb9d81c261b826..ddcc19a37817bba2e3897d8ea90f679aeba8dd0d 100644 (file)
@@ -44,9 +44,7 @@ class USERPREF_HT_header(Header):
 
         layout.operator_context = 'INVOKE_DEFAULT'
 
-        if userpref.active_section == 'INTERFACE':
-            layout.operator("wm.save_workspace_file")
-        elif userpref.active_section == 'INPUT':
+        if userpref.active_section == 'INPUT':
             layout.operator("wm.keyconfig_import")
             layout.operator("wm.keyconfig_export")
         elif userpref.active_section == 'ADDONS':
index ffbdc6972f4b1efb3f3873fd4dc2ca9fc452b1d9..ac8f861fa561584827a5b0453962123173b9a855 100644 (file)
@@ -82,7 +82,6 @@ enum {
 
 #define BLENDER_STARTUP_FILE    "startup.blend"
 #define BLENDER_USERPREF_FILE   "userpref.blend"
-#define BLENDER_WORKSPACES_FILE "workspaces.blend"
 #define BLENDER_QUIT_FILE       "quit.blend"
 #define BLENDER_BOOKMARK_FILE   "bookmarks.txt"
 #define BLENDER_HISTORY_FILE    "recent-files.txt"
index 267dce87e26150d27edb16d0ba381ba161fa2f4d..4f8389d9f7de32038a4655b8b13e8e4a6c5a7eca 100644 (file)
@@ -64,6 +64,8 @@
 #include "UI_interface.h"
 #include "UI_resources.h"
 
+#include "BLT_translation.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 #include "WM_toolsystem.h"
@@ -371,7 +373,7 @@ static void workspace_config_file_path_from_folder_id(
        const char * const cfgdir = BKE_appdir_folder_id(folder_id, app_template);
 
        if (cfgdir) {
-               BLI_make_file_string(bmain->name, r_path, cfgdir, BLENDER_WORKSPACES_FILE);
+               BLI_make_file_string(bmain->name, r_path, cfgdir, BLENDER_STARTUP_FILE);
        }
        else {
                r_path[0] = '\0';
@@ -390,12 +392,7 @@ static WorkspaceConfigFileData *workspace_config_file_read(
                has_path = true;
        }
 
-       if (has_path) {
-               return BKE_blendfile_workspace_config_read(workspace_config_path, NULL, 0, reports);
-       }
-       else {
-               return BKE_blendfile_workspace_config_read(NULL, datatoc_startup_blend, datatoc_startup_blend_size, reports);
-       }
+       return (has_path) ? BKE_blendfile_workspace_config_read(workspace_config_path, NULL, 0, reports) : NULL;
 }
 
 static void workspace_append_button(
@@ -425,18 +422,56 @@ ATTR_NONNULL(1, 2)
 static void workspace_config_file_append_buttons(
         uiLayout *layout, const Main *bmain, ReportList *reports)
 {
-       WorkspaceConfigFileData *workspace_config = workspace_config_file_read(bmain, reports);
+       wmOperatorType *ot_append = WM_operatortype_find("WORKSPACE_OT_append_activate", true);
+       WorkspaceConfigFileData *startup_config = workspace_config_file_read(bmain, reports);
+       WorkspaceConfigFileData *builtin_config = BKE_blendfile_workspace_config_read(NULL, datatoc_startup_blend, datatoc_startup_blend_size, reports);
+
+       if (startup_config) {
+               bool has_title = false;
 
-       if (workspace_config) {
-               wmOperatorType *ot_append = WM_operatortype_find("WORKSPACE_OT_append_activate", true);
+               for (WorkSpace *workspace = startup_config->workspaces.first; workspace; workspace = workspace->id.next) {
+                       if (BLI_findstring(&bmain->workspaces, workspace->id.name, offsetof(ID, name))) {
+                               continue;
+                       }
+
+                       if (!has_title) {
+                               uiItemS(layout);
+                               uiItemL(layout, IFACE_("Startup File"), ICON_NONE);
+                               has_title = true;
+                       }
+
+                       workspace_append_button(layout, ot_append, workspace, startup_config->main);
+               }
+       }
+
+       if (builtin_config) {
+               bool has_title = false;
+
+               for (WorkSpace *workspace = builtin_config->workspaces.first; workspace; workspace = workspace->id.next) {
+                       if (BLI_findstring(&bmain->workspaces, workspace->id.name, offsetof(ID, name))) {
+                               continue;
+                       }
+                       if (startup_config && BLI_findstring(&startup_config->workspaces, workspace->id.name, offsetof(ID, name))) {
+                               continue;
+                       }
+
+                       if (!has_title) {
+                               uiItemS(layout);
+                               uiItemL(layout, IFACE_("Builtin"), ICON_NONE);
+                               has_title = true;
+                       }
 
-               for (WorkSpace *workspace = workspace_config->workspaces.first; workspace; workspace = workspace->id.next) {
                        if (BLI_findstring(&bmain->workspaces, workspace->id.name, offsetof(ID, name)) == NULL) {
-                               workspace_append_button(layout, ot_append, workspace, workspace_config->main);
+                               workspace_append_button(layout, ot_append, workspace, builtin_config->main);
                        }
                }
+       }
 
-               BKE_blendfile_workspace_config_data_free(workspace_config);
+       if (startup_config) {
+               BKE_blendfile_workspace_config_data_free(startup_config);
+       }
+       if (builtin_config) {
+               BKE_blendfile_workspace_config_data_free(builtin_config);
        }
 }
 
@@ -448,7 +483,6 @@ static int workspace_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
        uiLayout *layout = UI_popup_menu_layout(pup);
 
        uiItemO(layout, "Duplicate Current", ICON_NONE, "WORKSPACE_OT_workspace_duplicate");
-       uiItemS(layout);
        workspace_config_file_append_buttons(layout, bmain, op->reports);
 
        UI_popup_menu_end(C, pup);
index 196e6cfa5ce4b75d2d0fe15a1511b170ef124e9e..65f4823464a1d7c81c4b15b9f739694e87a13993 100644 (file)
@@ -1603,42 +1603,6 @@ void WM_OT_save_userpref(wmOperatorType *ot)
        ot->exec = wm_userpref_write_exec;
 }
 
-static int wm_workspace_configuration_file_write_exec(bContext *C, wmOperator *op)
-{
-       Main *bmain = CTX_data_main(C);
-       char filepath[FILE_MAX];
-
-       const char *app_template = U.app_template[0] ? U.app_template : NULL;
-       const char * const cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, app_template);
-       if (cfgdir == NULL) {
-               BKE_report(op->reports, RPT_ERROR, "Unable to create workspace configuration file path");
-               return OPERATOR_CANCELLED;
-       }
-
-       BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_WORKSPACES_FILE, NULL);
-       printf("trying to save workspace configuration file at %s ", filepath);
-
-       if (BKE_blendfile_workspace_config_write(bmain, filepath, op->reports) != 0) {
-               printf("ok\n");
-               return OPERATOR_FINISHED;
-       }
-       else {
-               printf("fail\n");
-       }
-
-       return OPERATOR_CANCELLED;
-}
-
-void WM_OT_save_workspace_file(wmOperatorType *ot)
-{
-       ot->name = "Save Workspace Configuration";
-       ot->idname = "WM_OT_save_workspace_file";
-       ot->description = "Save workspaces of the current file as part of the user configuration";
-
-       ot->invoke = WM_operator_confirm;
-       ot->exec = wm_workspace_configuration_file_write_exec;
-}
-
 static int wm_history_file_read_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
 {
        ED_file_read_bookmarks();
index 299624bc50b5381cf223f7e0d05c2074c2950e68..4f39d2131b90a8ccc1294a18e9377e58802a8f86 100644 (file)
@@ -3211,7 +3211,6 @@ void wm_operatortypes_register(void)
        WM_operatortype_append(WM_OT_read_factory_settings);
        WM_operatortype_append(WM_OT_save_homefile);
        WM_operatortype_append(WM_OT_save_userpref);
-       WM_operatortype_append(WM_OT_save_workspace_file);
        WM_operatortype_append(WM_OT_userpref_autoexec_path_add);
        WM_operatortype_append(WM_OT_userpref_autoexec_path_remove);
        WM_operatortype_append(WM_OT_window_fullscreen_toggle);
index e17251560129823c7481afe2dc60bd294f529bba..147ed88296664a7cbed8907893724d36493cd88a 100644 (file)
@@ -46,7 +46,6 @@ void        WM_OT_save_homefile(struct wmOperatorType *ot);
 void        WM_OT_userpref_autoexec_path_add(struct wmOperatorType *ot);
 void        WM_OT_userpref_autoexec_path_remove(struct wmOperatorType *ot);
 void        WM_OT_save_userpref(struct wmOperatorType *ot);
-void        WM_OT_save_workspace_file(struct wmOperatorType *ot);
 void        WM_OT_read_history(struct wmOperatorType *ot);
 void        WM_OT_read_homefile(struct wmOperatorType *ot);
 void        WM_OT_read_factory_settings(struct wmOperatorType *ot);