diff --git a/ogl_editor/src/Editor.c b/ogl_editor/src/Editor.c index c0f2b08..c5a89b7 100644 --- a/ogl_editor/src/Editor.c +++ b/ogl_editor/src/Editor.c @@ -51,6 +51,7 @@ static EditorData s_editorData; static CopyData s_copyData; static bool reset_tracks = true; static char s_filenames[5][2048]; +static char* s_loadedFilename = 0; static char* s_recentFiles[] = { @@ -86,6 +87,7 @@ void setMostRecentFile(const char* filename) strcpy(s_recentFiles[i+1], s_recentFiles[i]); strcpy(s_recentFiles[0], filename); + s_loadedFilename = s_recentFiles[0]; // check if the string was already present and remove it if that is the case by compacting the array @@ -1226,7 +1228,6 @@ static void onFinishedLoad(const char* path) Editor_update(); setWindowTitle(path); setMostRecentFile(path); - //Commands_init(getTracks(), getTrackData()); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1252,22 +1253,41 @@ static void onOpen() /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -static void onSave() +static bool onSaveDialog() { - LoadSave_saveRocketXML(getMostRecentFile(), getTrackData()); + char path[2048]; + int ret; + + if (!(ret = LoadSave_saveRocketXMLDialog(path, getTrackData()))) + return false; + + setMostRecentFile(path); + setWindowTitle(path); + + return true; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -static void onSaveDialog() +static void onSave() { - char path[2048]; + if (!s_loadedFilename) + onSaveDialog(); + else + LoadSave_saveRocketXML(getMostRecentFile(), getTrackData()); +} - if (!LoadSave_saveRocketXMLDialog(path, getTrackData())) - return; +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - setMostRecentFile(path); - setWindowTitle(path); +bool Editor_saveBeforeExit() +{ + if (s_loadedFilename) + { + onSave(); + return true; + } + + return onSaveDialog(); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/ogl_editor/src/Editor.h b/ogl_editor/src/Editor.h index 6a2e06f..859d439 100644 --- a/ogl_editor/src/Editor.h +++ b/ogl_editor/src/Editor.h @@ -14,6 +14,7 @@ void Editor_menuEvent(int menuItem); void Editor_scroll(float deltaX, float deltaY, int flags); void Editor_updateTrackScroll(); void Editor_loadRecentFile(int file); +bool Editor_saveBeforeExit(); char** Editor_getRecentFiles(); diff --git a/ogl_editor/src/macosx/RocketView.m b/ogl_editor/src/macosx/RocketView.m index 28416e5..e56e91e 100644 --- a/ogl_editor/src/macosx/RocketView.m +++ b/ogl_editor/src/macosx/RocketView.m @@ -97,6 +97,48 @@ static int getModifierFlags(int flags) } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +- (void)windowShouldClose:(NSNotification *)aNotification +{ + NSAlert *alert = [NSAlert alertWithMessageText:@"\nDo you really want exit?" + defaultButton:@"Yes" alternateButton:NO otherButton:@"No" + informativeTextWithFormat:@""]; + + int result = [alert runModal]; + + if(result == NSOKButton) + { + + [NSApp terminate:self]; + } + else + { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + //return NSTerminateCancel; + } +} + +- (void)windowWillClose:(NSNotification *)aNotification +{ + NSAlert *alert = [NSAlert alertWithMessageText:@"\nDo you really want exit?" + defaultButton:@"Yes" alternateButton:NO otherButton:@"No" + informativeTextWithFormat:@""]; + + int result = [alert runModal]; + + if(result == NSOKButton) + { + + [NSApp terminate:self]; + } + else + { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + //return NSTerminateCancel; + } +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - (void)keyDown:(NSEvent *)theEvent { diff --git a/ogl_editor/src/macosx/delegate.m b/ogl_editor/src/macosx/delegate.m index dc298e2..38e5499 100644 --- a/ogl_editor/src/macosx/delegate.m +++ b/ogl_editor/src/macosx/delegate.m @@ -12,6 +12,26 @@ void Window_populateRecentList(char** files); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender +{ + int ret = NSRunAlertPanel(@"Save before exit?", @"Do you want save the work?", @"Yes", @"Cancel", @"No"); + + if (ret == NSAlertDefaultReturn) + { + if (!Editor_saveBeforeExit()) + return NSTerminateCancel; + + return NSTerminateNow; + } + + if (ret == NSAlertAlternateReturn) + return NSTerminateCancel; + + return NSTerminateNow; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { char** recent_list = Editor_getRecentFiles();