diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-18 01:12:21 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-05-18 11:31:10 +0300 |
commit | 14f00e11fe4289c7ce16810faa7c5806869cd988 (patch) | |
tree | 0973cf788112a2648fad7c0512d386f572842dcd /intern/ghost | |
parent | 47189985781ec9dfc4c9899bc2c08482fddc8ef3 (diff) |
macOS: always use the Blender quit dialog, like other platforms
The same was done for Windows, but some extra changes were needed to make it
work on macOS. This is required because the Blender quit dialog now contains
additional settings for image saving.
Diffstat (limited to 'intern/ghost')
-rw-r--r-- | intern/ghost/GHOST_Types.h | 5 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_EventPrinter.cpp | 4 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemCocoa.h | 2 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemCocoa.mm | 47 | ||||
-rw-r--r-- | intern/ghost/intern/GHOST_SystemSDL.cpp | 7 |
5 files changed, 17 insertions, 48 deletions
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h index faba5bb996a..f38154cbf94 100644 --- a/intern/ghost/GHOST_Types.h +++ b/intern/ghost/GHOST_Types.h @@ -125,9 +125,6 @@ typedef enum { // GHOST_kWindowStateUnModified, } GHOST_TWindowState; -/** Constants for the answer to the blender exit request */ -typedef enum { GHOST_kExitCancel = 0, GHOST_kExitNow } GHOST_TExitRequestResponse; - typedef enum { GHOST_kWindowOrderTop = 0, GHOST_kWindowOrderBottom } GHOST_TWindowOrder; typedef enum { @@ -165,7 +162,7 @@ typedef enum { GHOST_kEventKeyUp, // GHOST_kEventKeyAuto, - GHOST_kEventQuit, + GHOST_kEventQuitRequest, GHOST_kEventWindowClose, GHOST_kEventWindowActivate, diff --git a/intern/ghost/intern/GHOST_EventPrinter.cpp b/intern/ghost/intern/GHOST_EventPrinter.cpp index 3c5f613e11f..ba9ed6e3037 100644 --- a/intern/ghost/intern/GHOST_EventPrinter.cpp +++ b/intern/ghost/intern/GHOST_EventPrinter.cpp @@ -139,8 +139,8 @@ bool GHOST_EventPrinter::processEvent(GHOST_IEvent *event) std::cout << "GHOST_kEventOpenMainFile with no path specified!!"; } break; - case GHOST_kEventQuit: - std::cout << "GHOST_kEventQuit"; + case GHOST_kEventQuitRequest: + std::cout << "GHOST_kEventQuitRequest"; break; case GHOST_kEventWindowClose: std::cout << "GHOST_kEventWindowClose"; diff --git a/intern/ghost/intern/GHOST_SystemCocoa.h b/intern/ghost/intern/GHOST_SystemCocoa.h index 749139fee76..1201b5c4a14 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.h +++ b/intern/ghost/intern/GHOST_SystemCocoa.h @@ -140,7 +140,7 @@ class GHOST_SystemCocoa : public GHOST_System { * Handle User request to quit, from Menu bar Quit, and Cmd+Q * Display alert panel if changes performed since last save */ - GHOST_TUns8 handleQuitRequest(); + void handleQuitRequest(); /** * Handle Cocoa openFile event diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 1fd0914eb73..9afc882955c 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -427,10 +427,8 @@ extern "C" int GHOST_HACK_getFirstFile(char buf[FIRSTFILEBUFLG]) /* TODO: implement graceful termination through Cocoa mechanism * to avoid session log off to be canceled. */ /* Note that Cmd+Q is already handled by keyhandler. */ - if (systemCocoa->handleQuitRequest() == GHOST_kExitNow) - return NSTerminateCancel; //NSTerminateNow; - else - return NSTerminateCancel; + systemCocoa->handleQuitRequest(); + return NSTerminateCancel; } // To avoid canceling a log off process, we must use Cocoa termination process @@ -1342,46 +1340,17 @@ GHOST_TSuccess GHOST_SystemCocoa::handleDraggingEvent(GHOST_TEventType eventType return GHOST_kSuccess; } -GHOST_TUns8 GHOST_SystemCocoa::handleQuitRequest() +void GHOST_SystemCocoa::handleQuitRequest() { GHOST_Window *window = (GHOST_Window *)m_windowManager->getActiveWindow(); // Discard quit event if we are in cursor grab sequence if (window && window->getCursorGrabModeIsWarp()) - return GHOST_kExitCancel; - - // Check open windows if some changes are not saved - if (m_windowManager->getAnyModifiedState()) { - int shouldQuit = NSRunAlertPanel( - @"Exit Blender", - @"Some changes have not been saved.\nDo you really want to quit?", - @"Cancel", - @"Quit Anyway", - nil); - if (shouldQuit == NSAlertAlternateReturn) { - pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventQuit, NULL)); - return GHOST_kExitNow; - } - else { - // Give back focus to the blender window if user selected cancel quit - NSArray *windowsList = [NSApp orderedWindows]; - if ([windowsList count]) { - [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil]; - // Handle the modifiers keyes changed state issue - // as recovering from the quit dialog is like application - // gaining focus back. - // Main issue fixed is Cmd modifier not being cleared - handleApplicationBecomeActiveEvent(); - } - } - } - else { - pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventQuit, NULL)); - m_outsideLoopEventProcessed = true; - return GHOST_kExitNow; - } + return; - return GHOST_kExitCancel; + // Push the event to Blender so it can open a dialog if needed + pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventQuitRequest, window)); + m_outsideLoopEventProcessed = true; } bool GHOST_SystemCocoa::handleOpenDocumentRequest(void *filepathStr) @@ -1400,7 +1369,7 @@ bool GHOST_SystemCocoa::handleOpenDocumentRequest(void *filepathStr) /* Discard event if we are in cursor grab sequence, * it'll lead to "stuck cursor" situation if the alert panel is raised */ if (window && window->getCursorGrabModeIsWarp()) - return GHOST_kExitCancel; + return NO; // Check open windows if some changes are not saved if (m_windowManager->getAnyModifiedState()) { diff --git a/intern/ghost/intern/GHOST_SystemSDL.cpp b/intern/ghost/intern/GHOST_SystemSDL.cpp index 7b0407c6c4c..18163882cec 100644 --- a/intern/ghost/intern/GHOST_SystemSDL.cpp +++ b/intern/ghost/intern/GHOST_SystemSDL.cpp @@ -338,9 +338,12 @@ void GHOST_SystemSDL::processEvent(SDL_Event *sdl_event) break; } - case SDL_QUIT: - g_event = new GHOST_Event(getMilliSeconds(), GHOST_kEventQuit, NULL); + + case SDL_QUIT: { + GHOST_IWindow *window = m_windowManager->getActiveWindow(); + g_event = new GHOST_Event(getMilliSeconds(), GHOST_kEventQuitRequest, window); break; + } case SDL_MOUSEMOTION: { SDL_MouseMotionEvent &sdl_sub_evt = sdl_event->motion; |