Patch by Psy-Fi + my minor changes
authorAlexander Kuznetsov <kuzsasha@gmail.com>
Fri, 16 Mar 2012 17:37:45 +0000 (17:37 +0000)
committerAlexander Kuznetsov <kuzsasha@gmail.com>
Fri, 16 Mar 2012 17:37:45 +0000 (17:37 +0000)
Adds conformation on exit for windows. Needs to be enabled in user perf.

Tried to edit blender.exe.manifest for more modern dialog look, but didn't work out.

intern/ghost/GHOST_C-api.h
intern/ghost/GHOST_ISystem.h
intern/ghost/intern/GHOST_C-api.cpp
intern/ghost/intern/GHOST_System.cpp
intern/ghost/intern/GHOST_System.h
intern/ghost/intern/GHOST_SystemWin32.cpp
intern/ghost/intern/GHOST_SystemWin32.h
release/scripts/startup/bl_ui/space_userpref.py
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/intern/rna_userdef.c
source/blender/windowmanager/intern/wm_window.c

index a22b6bc371cb0673c8c76990cbdfd3c4259a83ee..3add5ccb60a5c181efbb0bdde3dd3024172d38f1 100644 (file)
@@ -842,6 +842,14 @@ extern void GHOST_putClipboard(GHOST_TInt8 *buffer, int selection);
  */
 extern int GHOST_toggleConsole(int action);
 
+
+/**
+ * Confirms quitting he program when there is just one window left open
+ * in the application
+ */
+extern int GHOST_confirmQuit(GHOST_WindowHandle windowhandle);
+
+
 #ifdef __cplusplus
 }
 #endif
index eeee8c0477bec0787047b345de8927b279c5565c..890917f98222f6fded04fa71753cc0599259302b 100644 (file)
@@ -392,7 +392,11 @@ public:
         */
        virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0;
 
-       
+       /**
+        * Confirms quitting he program when there is just one window left open
+        * in the application
+        */
+       virtual int confirmQuit(GHOST_IWindow * window) const = 0;
 protected:
        /**
         * Initialize the system.
index 6edfc4287aebd7142073b01b03ba987966e9de2f..8442f82d88666754a6afb6e720c5e43371d9d026 100644 (file)
@@ -865,3 +865,9 @@ int GHOST_toggleConsole(int action)
        GHOST_ISystem* system = GHOST_ISystem::getSystem();
        return system->toggleConsole(action);
 }
+
+
+int GHOST_confirmQuit(GHOST_WindowHandle windowhandle){
+       GHOST_ISystem* system = GHOST_ISystem::getSystem();
+       return system->confirmQuit((GHOST_IWindow*) windowhandle);
+}
index 944ade3f22b1e819504fc5bc2c0dd49f3153fd00..974f66c666a73c033ded1751cc07d9929edfd33a 100644 (file)
@@ -366,3 +366,9 @@ GHOST_TSuccess GHOST_System::createFullScreenWindow(GHOST_Window** window, const
        }
        return success;
 }
+
+
+int GHOST_System::confirmQuit(GHOST_IWindow * window) const
+{
+       return 1;
+}
index de474fe07a50dd0495e371e40c211a672c118a55..15a7cf1fdd946032bcf7ecce6c14f8fae488513e 100644 (file)
@@ -297,6 +297,13 @@ public:
           */
          virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const = 0;
 
+        /**
+        * Confirms quitting he program when there is just one window left open
+        * in the application
+        */
+       virtual int confirmQuit(GHOST_IWindow * window) const;
+
+
        
 protected:
        /**
index f4b39d01d9e82e1774b48a9ed10cc0c4d2ff5bad..1ccca4bc6bac368d8310757fffcdc9faeba2f12d 100644 (file)
@@ -1356,3 +1356,9 @@ int GHOST_SystemWin32::toggleConsole(int action)
 
        return m_consoleStatus;
 }
+
+int GHOST_SystemWin32::confirmQuit(GHOST_IWindow * window) const
+{
+       return (MessageBox(window ? ((GHOST_WindowWin32*)window)->getHWND() : 0, "Some changes have not been saved.\nDo you really want to quit ?",
+                       "Exit Blender", MB_OKCANCEL | MB_ICONWARNING | MB_TOPMOST) == IDOK);
+}
\ No newline at end of file
index 43387f68349846ad1485fa0da01f1cf4a5a81c59..bc2044e549d16518260cff321b814d70bd4e40a4 100644 (file)
@@ -200,7 +200,13 @@ public:
         * @return Indication whether the event was handled. 
         */
        static GHOST_TSuccess pushDragDropEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType,GHOST_IWindow* window, int mouseX, int mouseY, void* data);
-        
+       
+/**
+ * Confirms quitting he program when there is just one window left open
+ * in the application
+ */
+       virtual int confirmQuit(GHOST_IWindow * window) const;
+
 protected:
        /**
         * Initializes the system.
index 9d947f6fb406bc43d898b83c352ace92248dbe1b..81f67bffd6287586f4f605c01fd23b77b39d8972 100644 (file)
@@ -244,6 +244,9 @@ class USERPREF_PT_interface(Panel):
 
         col.prop(view, "show_splash")
 
+        if os.name == 'nt':
+            col.prop(view, "quit_dialog")
+
 
 class USERPREF_PT_edit(Panel):
     bl_space_type = 'USER_PREFERENCES'
index 2243eb357fc55b90b8e7e88bbdaa2c927b0befca..e014e18d07bc4371647a3c58fa6cdb3a8181dc36 100644 (file)
@@ -510,6 +510,7 @@ extern UserDef U; /* from blenkernel blender.c */
 #define USER_SPLASH_DISABLE            (1 << 27)
 #define USER_HIDE_RECENT               (1 << 28)
 #define USER_SHOW_THUMBNAILS   (1 << 29)
+#define USER_QUIT_PROMPT               (1 << 30)
 
 /* Auto-Keying mode */
        /* AUTOKEY_ON is a bitflag */
index 3673d21a9e61464455c515a7f4a1a8594268fa49..7af1dfa9da950d0fb027905e0457822817e7b050 100644 (file)
@@ -2369,6 +2369,11 @@ static void rna_def_userdef_view(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Sub Level Menu Open Delay",
                                 "Time delay in 1/10 seconds before automatically opening sub level menus");
 
+       prop = RNA_def_property(srna, "quit_dialog", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "uiflag", USER_QUIT_PROMPT);
+       RNA_def_property_ui_text(prop, "Prompt Quit",
+                                "Asks for confirmation when quitting through the window close button");
+
        /* Toolbox click-hold delay */
        prop = RNA_def_property(srna, "open_left_mouse_delay", PROP_INT, PROP_NONE);
        RNA_def_property_int_sdna(prop, NULL, "tb_leftmouse");
index 7893ac2f639ec7ad46122457999c4dc11fdcfab0..4ccebf7a4ff884040b2bd0da15386373b052497d 100644 (file)
@@ -250,8 +250,25 @@ wmWindow *wm_window_copy(bContext *C, wmWindow *winorig)
 /* this is event from ghost, or exit-blender op */
 void wm_window_close(bContext *C, wmWindowManager *wm, wmWindow *win)
 {
+       wmWindow *tmpwin;
        bScreen *screen= win->screen;
        
+       /* first check if we have any non-temp remaining windows */
+       if((U.uiflag & USER_QUIT_PROMPT) && !wm->file_saved){
+               if(wm->windows.first) {
+                       for(tmpwin = wm->windows.first; tmpwin; tmpwin = tmpwin->next){
+                               if(tmpwin == win)
+                                       continue;
+                               if(tmpwin->screen->temp == 0)
+                                       break;
+                       }
+                       if(tmpwin == NULL){
+                               if(!GHOST_confirmQuit(win->ghostwin))
+                                       return;
+                       }
+               }
+       }
+
        BLI_remlink(&wm->windows, win);
        
        wm_draw_window_clear(win);