Переглянути джерело

Polycode will now ask you if you want to save unsaved files on quitting. Mac only for now

Ivan Safrin 12 роки тому
батько
коміт
3156a86afe

+ 6 - 9
IDE/Build/Mac OS X/English.lproj/MainMenu.xib

@@ -680,7 +680,7 @@
 				<string key="NSName">_NSMainMenu</string>
 			</object>
 			<object class="NSWindowTemplate" id="972006081">
-				<int key="NSWindowStyleMask">15</int>
+				<int key="NSWindowStyleMask">13</int>
 				<int key="NSWindowBacking">2</int>
 				<string key="NSWindowRect">{{335, 390}, {800, 600}}</string>
 				<int key="NSWTFlags">1954021376</int>
@@ -690,7 +690,7 @@
 				<nil key="NSUserInterfaceItemIdentifier"/>
 				<string key="NSWindowContentMinSize">{400, 200}</string>
 				<object class="NSView" key="NSWindowView" id="439893737">
-					<nil key="NSNextResponder"/>
+					<reference key="NSNextResponder"/>
 					<int key="NSvFlags">256</int>
 					<object class="NSMutableArray" key="NSSubviews">
 						<bool key="EncodedWithXMLCoder">YES</bool>
@@ -700,6 +700,8 @@
 							<object class="NSPSMatrix" key="NSDrawMatrix"/>
 							<string key="NSFrameSize">{800, 600}</string>
 							<reference key="NSSuperview" ref="439893737"/>
+							<reference key="NSWindow"/>
+							<reference key="NSNextKeyView"/>
 							<object class="NSOpenGLPixelFormat" key="NSPixelFormat">
 								<object class="NSMutableData" key="NSPixelAttributes">
 									<bytes key="NS.bytes">AAAAYAAAAAA</bytes>
@@ -708,6 +710,8 @@
 						</object>
 					</object>
 					<string key="NSFrameSize">{800, 600}</string>
+					<reference key="NSSuperview"/>
+					<reference key="NSWindow"/>
 					<reference key="NSNextKeyView" ref="633009941"/>
 				</object>
 				<string key="NSScreenRect">{{0, 0}, {1680, 1028}}</string>
@@ -2122,14 +2126,12 @@
 							<bool key="EncodedWithXMLCoder">YES</bool>
 							<string>polycodeView</string>
 							<string>projectMenu</string>
-							<string>sdfsdf</string>
 							<string>window</string>
 						</object>
 						<object class="NSArray" key="dict.values">
 							<bool key="EncodedWithXMLCoder">YES</bool>
 							<string>PolycodeView</string>
 							<string>NSMenu</string>
-							<string>NSMenuItem</string>
 							<string>NSWindow</string>
 						</object>
 					</object>
@@ -2139,7 +2141,6 @@
 							<bool key="EncodedWithXMLCoder">YES</bool>
 							<string>polycodeView</string>
 							<string>projectMenu</string>
-							<string>sdfsdf</string>
 							<string>window</string>
 						</object>
 						<object class="NSArray" key="dict.values">
@@ -2152,10 +2153,6 @@
 								<string key="name">projectMenu</string>
 								<string key="candidateClassName">NSMenu</string>
 							</object>
-							<object class="IBToOneOutletInfo">
-								<string key="name">sdfsdf</string>
-								<string key="candidateClassName">NSMenuItem</string>
-							</object>
 							<object class="IBToOneOutletInfo">
 								<string key="name">window</string>
 								<string key="candidateClassName">NSWindow</string>

+ 12 - 4
IDE/Build/Mac OS X/PolycodeAppDelegate.m

@@ -42,7 +42,7 @@
 - (void)animationTimer:(NSTimer *)timer
 {
 	if(!app->Update()) {
-		[[NSApplication sharedApplication] stop:self];
+		[[NSApplication sharedApplication] terminate:self];
 	}
 	
 	if(mustShowProjectMenu) {
@@ -70,9 +70,17 @@
 }
 
 - (void)applicationWillTerminate:(NSNotification *)aNotification {
-	NSLog(@"STOPPING\n");
-	app->saveConfigFile();
-	app->core->Shutdown();
+}
+
+- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)theApplication
+{
+	bool retVal = app->quitApp();
+	if(retVal) {
+		app->saveConfigFile();
+		app->core->Shutdown();
+		printf("STOPPING\n");
+	}
+	return retVal;
 }
 
 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication

+ 3 - 0
IDE/Contents/Include/PolycodeIDEApp.h

@@ -98,6 +98,8 @@ public:
 	
 	void refreshProject();	
 	
+	bool quitApp();
+	
 	bool needsRedraw;
 	bool lastConnected;
 	
@@ -106,6 +108,7 @@ public:
 	Core *core;	
 protected:
 
+	bool quittingApp;
 	bool runNextFrame;
 
 	bool willRunProject;

+ 66 - 3
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -184,6 +184,8 @@ PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 	needsRedraw = false;
 	lastConnected = false;
 	
+	quittingApp = false;
+	
 	CoreServices::getInstance()->getCore()->getInput()->addEventListener(this, InputEvent::EVENT_KEYDOWN);
 }
 
@@ -386,6 +388,35 @@ void PolycodeIDEApp::doRunProject() {
 	PolycodeToolLauncher::runPolyapp(outPath);
 }
 
+bool PolycodeIDEApp::quitApp() {	
+
+	quittingApp = true;
+	
+	while(editorManager->getCurrentEditor()) {
+		PolycodeEditor *editor = editorManager->getCurrentEditor();
+		
+		if(editor->hasChanges()) {
+			OSFileEntry entry(editor->getFilePath(), OSFileEntry::TYPE_FILE);	
+			frame->yesNoCancelPopup->setCaption("The file \""+entry.name+"\" has unsaved changes. Save before quitting?");
+			frame->yesNoCancelPopup->action = "closeQuitFile";
+			frame->showModal(frame->yesNoCancelPopup);
+			return false;
+		} else {	
+			frame->removeEditor(editor);
+			editorManager->destroyEditor(editor);
+			if(editorManager->openEditors.size() > 0) {
+				editorManager->setCurrentEditor(editorManager->openEditors[0]);
+				frame->showEditor(editorManager->openEditors[0]);
+			} else{
+				editorManager->setCurrentEditor(NULL);
+			}
+		}
+		
+	}
+	
+	return true;
+}
+
 void PolycodeIDEApp::runProject() {
 	if(projectManager->getActiveProject()) {
 		if(editorManager->hasUnsavedFilesForProject(projectManager->getActiveProject())) {
@@ -679,9 +710,41 @@ void PolycodeIDEApp::handleEvent(Event *event) {
 				case UIEvent::CANCEL_EVENT:
 				break;
 			}
-		}
-		
-		if (frame->yesNoCancelPopup->action == "closeProject") {
+		} else if(frame->yesNoCancelPopup->action == "closeQuitFile") {
+			switch(event->getEventCode()) {
+				case UIEvent::YES_EVENT:
+				{
+					PolycodeEditor *editor = editorManager->getCurrentEditor();
+					if(editor) {
+						editor->saveFile();
+						closeFile();
+					}
+					frame->yesNoCancelPopup->action = "";
+					frame->hideModal();
+					if(quitApp()) {
+						core->Shutdown();
+					}
+				}
+				break;
+				case UIEvent::NO_EVENT:
+				{
+					PolycodeEditor *editor = editorManager->getCurrentEditor();
+					if(editor) {
+						editor->setHasChanges(false);
+						closeFile();
+					}
+					frame->yesNoCancelPopup->action = "";					
+					frame->hideModal();
+					if(quitApp()) {
+						core->Shutdown();
+					}					
+				}
+				break;
+				case UIEvent::CANCEL_EVENT:
+					quittingApp = false;
+				break;
+			}					
+		} else if (frame->yesNoCancelPopup->action == "closeProject") {
 			switch (event->getEventCode()) {
 				case UIEvent::YES_EVENT:
 					cleanupProjectOnClose(true);