Cocoa : add confirmation request before opening a .blend file (dropped on Blender...
authorDamien Plisson <damien.plisson@yahoo.fr>
Fri, 18 Dec 2009 13:13:14 +0000 (13:13 +0000)
committerDamien Plisson <damien.plisson@yahoo.fr>
Fri, 18 Dec 2009 13:13:14 +0000 (13:13 +0000)
intern/ghost/intern/GHOST_SystemCocoa.h
intern/ghost/intern/GHOST_SystemCocoa.mm

index bcc5da72b2ef3894fc223f2266370838dcd9cef1..81eb8978588890b23ad9a664604e03b3e47392fa 100644 (file)
@@ -140,6 +140,24 @@ public:
         */
        GHOST_TUns8 handleQuitRequest();
        
+       /**
+        * Handle Cocoa openFile event
+        * Display confirmation request panel if changes performed since last save
+        */
+       bool handleOpenDocumentRequest(void *filepathStr);      
+       
+       /**
+     * Handles a drag'n'drop destination event. Called by GHOST_WindowCocoa window subclass
+     * @param eventType The type of drag'n'drop event
+        * @param draggedObjectType The type object concerned (currently array of file names, string, TIFF image)
+        * @param mouseX x mouse coordinate (in cocoa base window coordinates)
+        * @param mouseY y mouse coordinate
+        * @param window The window on which the event occured
+     * @return Indication whether the event was handled. 
+     */
+       GHOST_TSuccess handleDraggingEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType,
+                                                                          GHOST_WindowCocoa* window, int mouseX, int mouseY, void* data);
+       
        /***************************************************************************************
         ** Cursor management functionality
         ***************************************************************************************/
@@ -207,18 +225,6 @@ public:
     GHOST_TSuccess handleApplicationBecomeActiveEvent();
        
        
-       /**
-     * Handles a drag'n'drop destination event. Called by GHOST_WindowCocoa window subclass
-     * @param eventType The type of drag'n'drop event
-        * @param draggedObjectType The type object concerned (currently array of file names, string, TIFF image)
-        * @param mouseX x mouse coordinate (in cocoa base window coordinates)
-        * @param mouseY y mouse coordinate
-        * @param window The window on which the event occured
-     * @return Indication whether the event was handled. 
-     */
-       GHOST_TSuccess handleDraggingEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType,
-                                                                          GHOST_WindowCocoa* window, int mouseX, int mouseY, void* data);
-       
 protected:
        /**
         * Initializes the system.
index 41601cd1c49d0a88643060c67b4d05ce67473009..71465822bee51fd6d21e5ff9dab8b062a0399a7f 100644 (file)
@@ -436,9 +436,7 @@ int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op)
 
 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
 {
-       NSLog(@"\nGet open file event from cocoa : %@",filename);
-       systemCocoa->handleDraggingEvent(GHOST_kEventDraggingDropOnIcon, GHOST_kDragnDropTypeFilenames, nil, 0, 0, [NSArray arrayWithObject:filename]);
-       return YES;
+       return systemCocoa->handleOpenDocumentRequest(filename);
 }
 
 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
@@ -1086,6 +1084,33 @@ GHOST_TUns8 GHOST_SystemCocoa::handleQuitRequest()
        return GHOST_kExitCancel;
 }
 
+bool GHOST_SystemCocoa::handleOpenDocumentRequest(void *filepathStr)
+{
+       NSString *filepath = (NSString*)filepathStr;
+       int confirmOpen = NSAlertAlternateReturn;
+       NSArray *windowsList;
+       
+       //Check open windows if some changes are not saved
+       if (m_windowManager->getAnyModifiedState())
+       {
+               confirmOpen = NSRunAlertPanel([NSString stringWithFormat:@"Opening %@",[filepath lastPathComponent]],
+                                                                                @"Current document has not been saved.\nDo you really want to proceed?",
+                                                                                @"Cancel", @"Open", nil);
+       }
+
+       //Give back focus to the blender window
+       windowsList = [NSApp orderedWindows];
+       if ([windowsList count]) {
+               [[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
+       }
+
+       if (confirmOpen == NSAlertAlternateReturn)
+       {
+               handleDraggingEvent(GHOST_kEventDraggingDropOnIcon,GHOST_kDragnDropTypeFilenames,NULL,0,0, [NSArray arrayWithObject:filepath]);
+               return YES;
+       }
+       else return NO;
+}
 
 GHOST_TSuccess GHOST_SystemCocoa::handleTabletEvent(void *eventPtr, short eventType)
 {