[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25464] trunk/blender/intern/ghost/intern: Cocoa : add confirmation request before opening a .blend file ( dropped on Blender icon or dbl-clicked in Finder)

Damien Plisson damien.plisson at yahoo.fr
Fri Dec 18 14:13:15 CET 2009


Revision: 25464
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25464
Author:   damien78
Date:     2009-12-18 14:13:14 +0100 (Fri, 18 Dec 2009)

Log Message:
-----------
Cocoa : add confirmation request before opening a .blend file (dropped on Blender icon or dbl-clicked in Finder)

Modified Paths:
--------------
    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h
    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h	2009-12-18 13:08:11 UTC (rev 25463)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h	2009-12-18 13:13:14 UTC (rev 25464)
@@ -140,6 +140,24 @@
 	 */
 	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 @@
     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.

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2009-12-18 13:08:11 UTC (rev 25463)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2009-12-18 13:13:14 UTC (rev 25464)
@@ -436,9 +436,7 @@
 
 - (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,7 +1084,34 @@
 	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)
 {
 	NSEvent *event = (NSEvent *)eventPtr;





More information about the Bf-blender-cvs mailing list