Cleanup: move theme reset into it's own operator file
authorCampbell Barton <ideasman42@gmail.com>
Fri, 1 Mar 2019 13:52:00 +0000 (00:52 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 1 Mar 2019 13:53:39 +0000 (00:53 +1100)
release/scripts/startup/bl_ui/space_userpref.py
source/blender/editors/include/ED_userpref.h [new file with mode: 0644]
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface_intern.h
source/blender/editors/interface/interface_ops.c
source/blender/editors/interface/resources.c
source/blender/editors/space_api/spacetypes.c
source/blender/editors/space_userpref/userpref_ops.c

index 0697d79..811bf7e 100644 (file)
@@ -694,7 +694,7 @@ class USERPREF_MT_interface_theme_presets(Menu):
     draw = Menu.draw_preset
 
     def reset_cb(context):
-        bpy.ops.ui.reset_default_theme()
+        bpy.ops.preferences.reset_default_theme()
 
 
 class USERPREF_PT_theme(Panel):
@@ -720,7 +720,7 @@ class USERPREF_PT_theme(Panel):
 
         row = split.row(align=True)
         row.operator("preferences.theme_install", text="Install...", icon='IMPORT')
-        row.operator("ui.reset_default_theme", text="Reset", icon='LOOP_BACK')
+        row.operator("preferences.reset_default_theme", text="Reset", icon='LOOP_BACK')
 
 
 class USERPREF_PT_theme_user_interface(PreferencePanel):
diff --git a/source/blender/editors/include/ED_userpref.h b/source/blender/editors/include/ED_userpref.h
new file mode 100644 (file)
index 0000000..2947060
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup editors
+ */
+
+#ifndef __ED_USERPREF_H__
+#define __ED_USERPREF_H__
+
+void ED_operatortypes_userpref(void);
+
+#endif  /* __ED_USERPREF_H__ */
index 79f80c6..9c77199 100644 (file)
@@ -1402,6 +1402,10 @@ void UI_widgetbase_draw_cache_begin(void);
 void UI_widgetbase_draw_cache_flush(void);
 void UI_widgetbase_draw_cache_end(void);
 
+/* Use for resetting the theme. */
+void UI_theme_init_default(void);
+void UI_style_init_default(void);
+
 /* Special drawing for toolbar, mainly workarounds for inflexible icon sizing. */
 #define USE_UI_TOOLBAR_HACK
 
index 656e727..19390a6 100644 (file)
@@ -818,8 +818,6 @@ void icon_draw_rect_input(
 
 /* resources.c */
 void init_userdef_do_versions(struct Main *bmain);
-void ui_theme_init_default(void);
-void ui_style_init_default(void);
 void ui_resources_init(void);
 void ui_resources_free(void);
 
index fdf6665..6152590 100644 (file)
 #include "BKE_main.h"
 #include "BLI_ghash.h"
 
-/* Reset Default Theme ------------------------ */
-
-static int reset_default_theme_exec(bContext *C, wmOperator *UNUSED(op))
-{
-       ui_theme_init_default();
-       ui_style_init_default();
-       WM_event_add_notifier(C, NC_WINDOW, NULL);
-
-       return OPERATOR_FINISHED;
-}
-
-static void UI_OT_reset_default_theme(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name = "Reset to Default Theme";
-       ot->idname = "UI_OT_reset_default_theme";
-       ot->description = "Reset to the default theme colors";
-
-       /* callbacks */
-       ot->exec = reset_default_theme_exec;
-
-       /* flags */
-       ot->flag = OPTYPE_REGISTER;
-}
-
 /* Copy Data Path Operator ------------------------ */
 
 static bool copy_data_path_button_poll(bContext *C)
@@ -1603,7 +1578,6 @@ static void UI_OT_drop_color(wmOperatorType *ot)
 
 void ED_operatortypes_ui(void)
 {
-       WM_operatortype_append(UI_OT_reset_default_theme);
        WM_operatortype_append(UI_OT_copy_data_path_button);
        WM_operatortype_append(UI_OT_copy_python_command_button);
        WM_operatortype_append(UI_OT_reset_default_button);
index eaa3da8..48b24da 100644 (file)
@@ -744,9 +744,8 @@ const uchar *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
  * \note: when you add new colors, created & saved themes need initialized
  * use function below, init_userdef_do_versions()
  */
-void ui_theme_init_default(void)
+void UI_theme_init_default(void)
 {
-
        /* we search for the theme with name Default */
        bTheme *btheme = BLI_findstring(&U.themes, "Default", offsetof(bTheme, name));
        if (btheme == NULL) {
@@ -761,7 +760,7 @@ void ui_theme_init_default(void)
        btheme->active_theme_area = active_theme_area;
 }
 
-void ui_style_init_default(void)
+void UI_style_init_default(void)
 {
        BLI_freelistN(&U.uistyles);
        /* gets automatically re-allocated */
index 60094c4..0288d78 100644 (file)
@@ -57,6 +57,7 @@
 #include "ED_space_api.h"
 #include "ED_sound.h"
 #include "ED_uvedit.h"
+#include "ED_userpref.h"
 #include "ED_lattice.h"
 #include "ED_mball.h"
 #include "ED_logic.h"
@@ -99,6 +100,7 @@ void ED_spacetypes_init(void)
 //     ...
 
        /* register operator types for screen and all spaces */
+       ED_operatortypes_userpref();
        ED_operatortypes_workspace();
        ED_operatortypes_scene();
        ED_operatortypes_screen();
index 4ba3c98..f6aaf01 100644 (file)
@@ -13,7 +13,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * The Original Code is Copyright (C) 2009 Blender Foundation.
  * All rights reserved.
  */
 
  * \ingroup spuserpref
  */
 
-
 #include <string.h>
-#include <stdio.h>
+
+#include "DNA_screen_types.h"
+
+#include "BKE_context.h"
+#include "BKE_report.h"
+
+#include "RNA_types.h"
+
+#include "UI_interface.h"
+
+#include "../interface/interface_intern.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_userpref.h"
+
+/* -------------------------------------------------------------------- */
+/** \name Reset Default Theme
+ * \{ */
+
+static int reset_default_theme_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       UI_theme_init_default();
+       UI_style_init_default();
+       WM_event_add_notifier(C, NC_WINDOW, NULL);
+
+       return OPERATOR_FINISHED;
+}
+
+static void PREFERENCES_OT_reset_default_theme(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Reset to Default Theme";
+       ot->idname = "PREFERENCES_OT_reset_default_theme";
+       ot->description = "Reset to the default theme colors";
+
+       /* callbacks */
+       ot->exec = reset_default_theme_exec;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER;
+}
+
+/** \} */
+
+void ED_operatortypes_userpref(void)
+{
+       WM_operatortype_append(PREFERENCES_OT_reset_default_theme);
+}