Add operator to close a window
authorCampbell Barton <ideasman42@gmail.com>
Tue, 20 Oct 2015 04:41:13 +0000 (15:41 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 20 Oct 2015 04:42:30 +0000 (15:42 +1100)
Useful for Python scripts, which could duplicate but not close windows.

source/blender/windowmanager/intern/wm_operators.c
source/blender/windowmanager/intern/wm_window.c
source/blender/windowmanager/wm_window.h

index 2e039d815f6472126a08508a25eaed4be931806e..eabc8614c8003d2f2571ffe263e667f3756d164d 100644 (file)
@@ -2247,6 +2247,17 @@ static int wm_operator_winactive_normal(bContext *C)
        return 1;
 }
 
+/* included for script-access */
+static void WM_OT_window_close(wmOperatorType *ot)
+{
+       ot->name = "Close Window";
+       ot->idname = "WM_OT_window_close";
+       ot->description = "Close the current Blender window";
+
+       ot->exec = wm_window_close_exec;
+       ot->poll = WM_operator_winactive;
+}
+
 static void WM_OT_window_duplicate(wmOperatorType *ot)
 {
        ot->name = "Duplicate Window";
@@ -5250,6 +5261,7 @@ void wm_operatortype_init(void)
        /* reserve size is set based on blender default setup */
        global_ops_hash = BLI_ghash_str_new_ex("wm_operatortype_init gh", 2048);
 
+       WM_operatortype_append(WM_OT_window_close);
        WM_operatortype_append(WM_OT_window_duplicate);
        WM_operatortype_append(WM_OT_read_history);
        WM_operatortype_append(WM_OT_read_homefile);
index 51feea55654c3e24f3994cce24f83753206eefb8..d8e6671afdab0c0d3db1582b755da6631d6af22b 100644 (file)
@@ -712,6 +712,14 @@ wmWindow *WM_window_open_temp(bContext *C, const rcti *rect_init, int type)
 
 /* ****************** Operators ****************** */
 
+int wm_window_close_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       wmWindowManager *wm = CTX_wm_manager(C);
+       wmWindow *win = CTX_wm_window(C);
+       wm_window_close(C, wm, win);
+       return OPERATOR_FINISHED;
+}
+
 /* operator callback */
 int wm_window_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
 {
index 75ccca1a5ecd7c98696c0ecc39c4de5afd6e29d4..c106f9d785172db8398c56ebedcd15083c4cbf20 100644 (file)
@@ -77,6 +77,7 @@ void          wm_window_IME_end       (wmWindow *win);
 #endif
 
 /* *************** window operators ************** */
+int                    wm_window_close_exec(bContext *C, struct wmOperator *op);
 int                    wm_window_duplicate_exec(bContext *C, struct wmOperator *op);
 int                    wm_window_fullscreen_toggle_exec(bContext *C, struct wmOperator *op);