[Bf-blender-cvs] [2fb92853710] master: Fix T70039, T68707: issues when opening .blend file from Finder on macOS

Yevgeny Makarov noreply at git.blender.org
Tue Feb 11 17:45:18 CET 2020


Commit: 2fb928537104ec5a5060c29a6bc253906ff8a3dc
Author: Yevgeny Makarov
Date:   Tue Feb 11 17:40:43 2020 +0100
Branches: master
https://developer.blender.org/rB2fb928537104ec5a5060c29a6bc253906ff8a3dc

Fix T70039, T68707: issues when opening .blend file from Finder on macOS

* Missing close dialog displayed to warn about unsaved changes.
* No reaction when the file was opened on a different desktop.

Differential Revision: https://developer.blender.org/D6765

===================================================================

M	intern/ghost/intern/GHOST_SystemCocoa.mm
M	source/blender/windowmanager/intern/wm_window.c

===================================================================

diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm
index 297b73f8b14..b65404cf9b1 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemCocoa.mm
@@ -1366,10 +1366,17 @@ void GHOST_SystemCocoa::handleQuitRequest()
 bool GHOST_SystemCocoa::handleOpenDocumentRequest(void *filepathStr)
 {
   NSString *filepath = (NSString *)filepathStr;
-  bool confirmOpen = true;
   NSArray *windowsList;
   char *temp_buff;
   size_t filenameTextSize;
+
+  /* Check for blender opened windows and make the frontmost key. In case blender
+   * is minimized, opened on another desktop space, or in full-screen mode. */
+  windowsList = [NSApp orderedWindows];
+  if ([windowsList count]) {
+    [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
+  }
+
   GHOST_Window *window = (GHOST_Window *)m_windowManager->getActiveWindow();
 
   if (!window) {
@@ -1377,51 +1384,25 @@ 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())
+   * it'll lead to "stuck cursor" situation if the alert panel is raised. */
+  if (window && window->getCursorGrabModeIsWarp()) {
     return NO;
-
-  // Check open windows if some changes are not saved
-  if (m_windowManager->getAnyModifiedState()) {
-    @autoreleasepool {
-      NSAlert *alert = [[NSAlert alloc] init];
-      NSString *title = [NSString stringWithFormat:@"Opening %@", [filepath lastPathComponent]];
-      NSString *text = @"Current document has not been saved.\nDo you really want to proceed?";
-      [alert addButtonWithTitle:@"Open"];
-      [alert addButtonWithTitle:@"Cancel"];
-      [alert setMessageText:title];
-      [alert setInformativeText:text];
-      [alert setAlertStyle:NSAlertStyleInformational];
-      confirmOpen = [alert runModal] == NSAlertFirstButtonReturn;
-    }
-  }
-
-  // Give back focus to the blender window
-  windowsList = [NSApp orderedWindows];
-  if ([windowsList count]) {
-    [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
   }
 
-  if (confirmOpen) {
-    filenameTextSize = [filepath lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
-
-    temp_buff = (char *)malloc(filenameTextSize + 1);
-
-    if (temp_buff == NULL) {
-      return GHOST_kFailure;
-    }
+  filenameTextSize = [filepath lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+  temp_buff = (char *)malloc(filenameTextSize + 1);
 
-    strncpy(temp_buff, [filepath cStringUsingEncoding:NSUTF8StringEncoding], filenameTextSize);
+  if (temp_buff == NULL) {
+    return GHOST_kFailure;
+  }
 
-    temp_buff[filenameTextSize] = '\0';
+  strncpy(temp_buff, [filepath cStringUsingEncoding:NSUTF8StringEncoding], filenameTextSize);
+  temp_buff[filenameTextSize] = '\0';
 
-    pushEvent(new GHOST_EventString(
-        getMilliSeconds(), GHOST_kEventOpenMainFile, window, (GHOST_TEventDataPtr)temp_buff));
+  pushEvent(new GHOST_EventString(
+      getMilliSeconds(), GHOST_kEventOpenMainFile, window, (GHOST_TEventDataPtr)temp_buff));
 
-    return YES;
-  }
-  else
-    return NO;
+  return YES;
 }
 
 GHOST_TSuccess GHOST_SystemCocoa::handleTabletEvent(void *eventPtr, short eventType)
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index 4f70eeefb76..148195df372 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -1450,7 +1450,8 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
 
           WM_operator_properties_create_ptr(&props_ptr, ot);
           RNA_string_set(&props_ptr, "filepath", path);
-          WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &props_ptr);
+          RNA_boolean_set(&props_ptr, "display_file_selector", false);
+          WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr);
           WM_operator_properties_free(&props_ptr);
 
           CTX_wm_window_set(C, NULL);



More information about the Bf-blender-cvs mailing list