[Bf-blender-cvs] [b9d1d90] workspaces: Add/use worksace API functions for adding/changing/deleting
Julian Eisel
noreply at git.blender.org
Fri Dec 2 17:42:53 CET 2016
Commit: b9d1d90b9084419c2e35b9c7273f90846604d68a
Author: Julian Eisel
Date: Fri Dec 2 17:40:31 2016 +0100
Branches: workspaces
https://developer.blender.org/rBb9d1d90b9084419c2e35b9c7273f90846604d68a
Add/use worksace API functions for adding/changing/deleting
Also removed anything that influences workspace user count, from now on it's simply *always* 1.
===================================================================
M source/blender/editors/include/ED_screen.h
M source/blender/editors/screen/CMakeLists.txt
M source/blender/editors/screen/screen_ops.c
A source/blender/editors/screen/workspace_edit.c
M source/blender/editors/space_api/spacetypes.c
M source/blender/makesrna/intern/rna_wm.c
M source/blenderplayer/bad_level_call_stubs/stubs.c
===================================================================
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index f5f66a0..96d8e5a 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -123,6 +123,10 @@ void ED_screens_header_tools_menu_create(struct bContext *C, struct uiLayout
bool ED_screen_stereo3d_required(struct bScreen *screen);
void ED_screen_preview_render(const struct bScreen *screen, int size_x, int size_y, unsigned int *r_rect) ATTR_NONNULL();
+/* workspaces */
+void ED_workspace_change(struct wmWindow *win, WorkSpace *ws_new);
+bool ED_workspace_delete(struct Main *bmain, struct wmWindow *win, WorkSpace *ws);
+
/* anim */
void ED_update_for_newframe(struct Main *bmain, struct Scene *scene, int mute);
@@ -134,6 +138,8 @@ bScreen *ED_screen_animation_no_scrub(const struct wmWindowManager *wm);
/* screen keymaps */
void ED_operatortypes_screen(void);
void ED_keymap_screen(struct wmKeyConfig *keyconf);
+/* workspace keymaps */
+void ED_operatortypes_workspace(void);
/* operators; context poll callbacks */
int ED_operator_screenactive(struct bContext *C);
diff --git a/source/blender/editors/screen/CMakeLists.txt b/source/blender/editors/screen/CMakeLists.txt
index 43e044b..816c0ca 100644
--- a/source/blender/editors/screen/CMakeLists.txt
+++ b/source/blender/editors/screen/CMakeLists.txt
@@ -46,6 +46,7 @@ set(SRC
screen_edit.c
screen_ops.c
screendump.c
+ workspace_edit.c
screen_intern.h
)
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 5a8b122..a4be057 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -4282,58 +4282,6 @@ static void SCREEN_OT_space_context_cycle(wmOperatorType *ot)
/* **** Workspaces **** */
/* For now here, should later get its own module */
-static int workspace_new_exec(bContext *C, wmOperator *UNUSED(op))
-{
- wmWindow *win = CTX_wm_window(C);
- WorkSpace *old_ws = win->workspace;
-
- /* TODO API function to activate workspace */
- id_us_min(&old_ws->id);
- id_us_ensure_real(&old_ws->id);
- win->workspace = BKE_workspace_duplicate(CTX_data_main(C), old_ws);
-// WM_event_add_notifier(C, NC_SCREEN | ND_SCREENBROWSE, sc); /* TODO own notifier */
-
- return OPERATOR_FINISHED;
-}
-
-static void WORKSPACE_OT_workspace_new(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "New Workspace";
- ot->description = "Add a new workspace";
- ot->idname = "WORKSPACE_OT_workspace_new";
-
- /* api callbacks */
- ot->exec = workspace_new_exec;
- ot->poll = WM_operator_winactive;
-}
-
-static int workspace_delete_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Main *bmain = CTX_data_main(C);
- wmWindow *win = CTX_wm_window(C);
-
- /* TODO API function to remove workspace */
- if (!BLI_listbase_is_single(&bmain->workspaces)) {
- WorkSpace *ws_next = win->workspace->id.next;
- BKE_libblock_free(bmain, win->workspace);
- win->workspace = ws_next ? ws_next : bmain->workspaces.first;
- id_us_plus(&win->workspace->id);
- }
-
- return OPERATOR_FINISHED;
-}
-
-static void WORKSPACE_OT_workspace_delete(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Delete Workspace";
- ot->description = "Delete the active workspace";
- ot->idname = "WORKSPACE_OT_workspace_delete";
-
- /* api callbacks */
- ot->exec = workspace_delete_exec;
-}
/* **************** Assigning operatortypes to global list, adding handlers **************** */
@@ -4386,8 +4334,6 @@ void ED_operatortypes_screen(void)
WM_operatortype_append(SCREEN_OT_delete);
WM_operatortype_append(SCENE_OT_new);
WM_operatortype_append(SCENE_OT_delete);
- WM_operatortype_append(WORKSPACE_OT_workspace_new);
- WM_operatortype_append(WORKSPACE_OT_workspace_delete);
/* tools shared by more space types */
WM_operatortype_append(ED_OT_undo);
diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c
new file mode 100644
index 0000000..df447be
--- /dev/null
+++ b/source/blender/editors/screen/workspace_edit.c
@@ -0,0 +1,143 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/screen/workspace_edit.c
+ * \ingroup edscr
+ */
+
+#include "BKE_context.h"
+#include "BKE_main.h"
+#include "BKE_library.h"
+#include "BKE_workspace.h"
+
+#include "BLI_listbase.h"
+
+#include "DNA_screen_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "ED_screen.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+
+/** \name Workspace API
+ *
+ * \brief API for managing workspaces and their data.
+ * \{ */
+
+static void workspace_unassign_window_workspace(wmWindow *win)
+{
+ win->workspace = NULL; /* just for safty, should always be set */
+}
+
+/**
+ * \note Should either be called to initially assign workspace or after calling #workspace_unassign_window_workspace.
+ */
+static void workspace_assign_to_window(wmWindow *win, WorkSpace *ws)
+{
+ BLI_assert(win->workspace == NULL);
+ win->workspace = ws;
+}
+
+void ED_workspace_change(wmWindow *win, WorkSpace *ws_new)
+{
+ workspace_unassign_window_workspace(win);
+ workspace_assign_to_window(win, ws_new);
+// WM_event_add_notifier(C, NC_SCREEN | ND_SCREENBROWSE, sc); /* TODO own notifier */
+}
+
+/**
+ * \return if succeeded.
+ */
+bool ED_workspace_delete(Main *bmain, wmWindow *win, WorkSpace *ws)
+{
+ if (BLI_listbase_is_single(&bmain->workspaces)) {
+ return false;
+ }
+
+ if (win->workspace == ws) {
+ WorkSpace *fallback_ws = ws->id.prev ? ws->id.prev : ws->id.next;
+ ED_workspace_change(win, fallback_ws);
+ }
+ BKE_libblock_free(bmain, &ws->id);
+
+ return true;
+}
+
+/** \} Workspace API */
+
+
+/** \name Workspace Operators
+ *
+ * \{ */
+
+static int workspace_new_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Main *bmain = CTX_data_main(C);
+ wmWindow *win = CTX_wm_window(C);
+ WorkSpace *old_ws = win->workspace;
+ WorkSpace *new_ws = BKE_workspace_duplicate(bmain, old_ws);
+
+ ED_workspace_change(win, new_ws);
+
+ return OPERATOR_FINISHED;
+}
+
+static void WORKSPACE_OT_workspace_new(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "New Workspace";
+ ot->description = "Add a new workspace";
+ ot->idname = "WORKSPACE_OT_workspace_new";
+
+ /* api callbacks */
+ ot->exec = workspace_new_exec;
+ ot->poll = WM_operator_winactive;
+}
+
+static int workspace_delete_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Main *bmain = CTX_data_main(C);
+ wmWindow *win = CTX_wm_window(C);
+
+ ED_workspace_delete(bmain, win, win->workspace);
+
+ return OPERATOR_FINISHED;
+}
+
+static void WORKSPACE_OT_workspace_delete(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Delete Workspace";
+ ot->description = "Delete the active workspace";
+ ot->idname = "WORKSPACE_OT_workspace_delete";
+
+ /* api callbacks */
+ ot->exec = workspace_delete_exec;
+}
+
+void ED_operatortypes_workspace(void)
+{
+ WM_operatortype_append(WORKSPACE_OT_workspace_new);
+ WM_operatortype_append(WORKSPACE_OT_workspace_delete);
+}
+
+/** \} Workspace Operators */
diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c
index 5ff1d75..3c9153c 100644
--- a/source/blender/editors/space_api/spacetypes.c
+++ b/source/blender/editors/space_api/spacetypes.c
@@ -99,6 +99,7 @@ void ED_spacetypes_init(void)
// ...
/* register operator types for screen and all spaces */
+ ED_operatortypes_workspace();
ED_operatortypes_screen();
ED_operatortypes_anim();
ED_operatortypes_animchannels();
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index b250593..485effc 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -461,6 +461,8 @@ EnumPropertyItem rna_enum_wm_report_items[] = {
#include "WM_api.h"
+#include "ED_screen.h"
+
#include "UI_interface.h"
#include "BKE_idprop.h"
@@ -621,6 +623,13 @@ static PointerRNA rna_PieMenu_layout_get(PointerRNA *ptr)
return rptr;
}
+static void rna_Window_workspace_set(PointerRNA *ptr, PointerRNA value)
+{
+ wmWindow *win = (wmWindow *)ptr->data;
+ WorkSpace *ws_new = value.data;
+ ED_workspace_change(win, ws_new);
+}
+
static void rna_Window_screen_set(PointerRNA *ptr, PointerRNA value)
{
wmWindow *win = (wmWindow *)ptr->data;
@@ -1914,7 +1923,7 @@ static void rna_def_window(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "WorkSpace");
RNA_def_property_ui_text(prop, "Workspace", "Active workspace showing in the window");
RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_pointer_funcs(prop, NULL, "rna_Window_workspace_set", NULL, NULL);
// RNA_def_property_update(prop, 0, NULL); /* TODO own notifier? */
prop = RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE);
diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c
index 15d230f..f43f9ea 100644
--- a/source/blenderplayer/bad_level_call_stubs/stubs.c
+++ b/source/blenderplayer/bad_level_call_stubs/stubs.c
@@ -394,6 +394,7 @@ struct MovieClip *ED_space_clip_get_clip(struct SpaceClip *sc) RET_NULL
void ED_space_clip_set_clip(struct bContext *C, struct bScreen *screen, struct SpaceClip *sc, struct MovieClip *clip) RET_NONE
void ED_space_clip_set_mask(struct bContext *C, struct SpaceClip *sc, struct Mask *mask) RET_NONE
void ED_s
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list