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.
This commit is contained in:
parent
4718998578
commit
14f00e11fe
|
@ -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,
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
return;
|
||||
|
||||
// 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 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()) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1063,7 +1063,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
|
|||
|
||||
break;
|
||||
}
|
||||
case GHOST_kEventQuit:
|
||||
case GHOST_kEventQuitRequest:
|
||||
case GHOST_kEventWindowClose: {
|
||||
ps->go = false;
|
||||
break;
|
||||
|
|
|
@ -1117,8 +1117,25 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
|
|||
GHOST_TEventType type = GHOST_GetEventType(evt);
|
||||
int time = GHOST_GetEventTime(evt);
|
||||
|
||||
if (type == GHOST_kEventQuit) {
|
||||
WM_exit(C);
|
||||
if (type == GHOST_kEventQuitRequest) {
|
||||
/* Find an active window to display quit dialog in. */
|
||||
GHOST_WindowHandle ghostwin = GHOST_GetEventWindow(evt);
|
||||
wmWindow *win;
|
||||
|
||||
if (ghostwin && GHOST_ValidWindow(g_system, ghostwin)) {
|
||||
win = GHOST_GetWindowUserData(ghostwin);
|
||||
}
|
||||
else {
|
||||
win = wm->winactive;
|
||||
}
|
||||
|
||||
/* Display quit dialog or quit immediately. */
|
||||
if (win) {
|
||||
wm_quit_with_optional_confirmation_prompt(C, win);
|
||||
}
|
||||
else {
|
||||
wm_exit_schedule_delayed(C);
|
||||
}
|
||||
}
|
||||
else {
|
||||
GHOST_WindowHandle ghostwin = GHOST_GetEventWindow(evt);
|
||||
|
|
Loading…
Reference in New Issue