diff --git a/osx/boe.actions.cpp b/osx/boe.actions.cpp index 299914ca..58ff9092 100644 --- a/osx/boe.actions.cpp +++ b/osx/boe.actions.cpp @@ -1398,10 +1398,8 @@ bool handle_action(sf::Event event) menu_activate(); univ.party.scen_name = ".exs"; // should be harmless... if(cChoiceDlog("congrats-save.xml",{"cancel","save"}).show() == "save"){ - try{ - fs::path file = nav_put_party(); - save_party(file); - } catch(no_file_chosen){} + fs::path file = nav_put_party(); + if(!file.empty()) save_party(file); } } else if (party_toast() == true) { @@ -2146,10 +2144,8 @@ bool handle_keystroke(sf::Event& event){ void do_load() { - try{ - fs::path file_to_load = nav_get_party(); - load_party(file_to_load); - } catch(no_file_chosen){} + fs::path file_to_load = nav_get_party(); + if(!file_to_load.empty()) load_party(file_to_load); if (in_startup_mode == false) post_load(); menu_activate(); @@ -2188,17 +2184,19 @@ void post_load() void do_save(short mode) //mode; // 0 - normal 1 - save as { -// SelectWindow(mainPtr); if (overall_mode > MODE_TOWN) { add_string_to_buf("Save: Only while outdoors, or in "); add_string_to_buf(" town and not looking/casting. "); print_buf(); return; } - try{ - if(mode == 1) univ.file = nav_put_party(); + fs::path file = univ.file; + if(mode == 1) file = nav_put_party(); + if(!file.empty()) { + univ.file = file; save_party(univ.file); - } catch(no_file_chosen){} + } + pause(6); // initiate_redraw(); @@ -2546,10 +2544,8 @@ void handle_death() } else if(choice == "load") { in_startup_mode = false; - try{ - fs::path file_to_load = nav_get_party(); - load_party(file_to_load); - } catch(no_file_chosen){} + fs::path file_to_load = nav_get_party(); + if(!file_to_load.empty()) load_party(file_to_load); if (party_toast() == false) { if (in_startup_mode == false) post_load(); @@ -2617,11 +2613,9 @@ void start_new_game() univ.party[i].max_sp += univ.party[i].skills[9] * 3 + univ.party[i].skills[10] * 3; univ.party[i].cur_sp = univ.party[i].max_sp; } - try{ - fs::path file = nav_put_party(); - save_party(file); - party_in_memory = true; - } catch(no_file_chosen){} + fs::path file = nav_put_party(); + if(!file.empty()) save_party(file); + party_in_memory = true; party_in_memory = true; } diff --git a/osx/boe.main.cpp b/osx/boe.main.cpp index d1de465e..84805eeb 100644 --- a/osx/boe.main.cpp +++ b/osx/boe.main.cpp @@ -665,13 +665,6 @@ void handle_file_menu(int item_hit) do_save(0); break; case 3: -// if (in_startup_mode == true){ -// try{ -// FSSpec file = nav_put_party(); -// save_party(file); -// } catch(no_file_chosen){} -// } -// else do_save(1); break; case 4: diff --git a/osx/boe.startup.cpp b/osx/boe.startup.cpp index 372e7854..1f783595 100644 --- a/osx/boe.startup.cpp +++ b/osx/boe.startup.cpp @@ -119,16 +119,13 @@ bool handle_startup_press(location the_point) void startup_load()//// { - try{ fs::path file_to_load = nav_get_party(); - if(load_party(file_to_load)){ + if(!file_to_load.empty() && load_party(file_to_load)){ party_in_memory = true; if(univ.party.scen_name.length() > 0) in_startup_mode = false; else in_startup_mode = true; } - } catch(no_file_chosen){} - makeFrontWindow(mainPtr); if (!in_startup_mode) { //end_anim(); end_startup(); diff --git a/osx/tools/winutil.h b/osx/tools/winutil.h index 1af785d6..99a6ede7 100644 --- a/osx/tools/winutil.h +++ b/osx/tools/winutil.h @@ -15,16 +15,14 @@ namespace fs = boost::filesystem; // TODO: Centralize this alias bool isFrontWindow(sf::Window& win); -void makeFrontWindow(sf::Window& win, bool acceptKeyInput = true); +void makeFrontWindow(sf::Window& win); void init_fileio(); -struct no_file_chosen {}; // an exception class - -fs::path nav_get_party() throw(no_file_chosen); -fs::path nav_put_party() throw(no_file_chosen); -fs::path nav_get_scenario() throw(no_file_chosen); -fs::path nav_put_scenario() throw(no_file_chosen); +fs::path nav_get_party(); +fs::path nav_put_party(); +fs::path nav_get_scenario(); +fs::path nav_put_scenario(); class ModalSession { void* session; diff --git a/osx/tools/winutil.mac.mm b/osx/tools/winutil.mac.mm index 53360a4b..582bb40d 100644 --- a/osx/tools/winutil.mac.mm +++ b/osx/tools/winutil.mac.mm @@ -8,6 +8,7 @@ #include "winutil.h" #include +#include bool isFrontWindow(sf::Window& win) { sf::WindowHandle handle = win.getSystemHandle(); @@ -53,6 +54,7 @@ NSOpenPanel* dlg_get_scen; NSOpenPanel* dlg_get_game; NSSavePanel* dlg_put_scen; NSSavePanel* dlg_put_game; +extern sf::RenderWindow mainPtr; // TODO: I'm not sure if I'll need delegates to enable selection of files with no file extension that have file creator types? //Boolean scen_file_filter(AEDesc* item, void* info, void * dummy, NavFilterModes filterMode){ @@ -125,27 +127,34 @@ void init_fileio(){ [dlg_put_game retain]; } -fs::path nav_get_scenario() throw(no_file_chosen) { - // TODO: Not quite sure if runModal is right; I want to display it as a dialog, not as a sheet. - if([dlg_get_scen runModal] == NSFileHandlingPanelCancelButton) - throw no_file_chosen(); - return fs::path([[[dlg_get_scen URL] absoluteString] UTF8String]); +fs::path nav_get_scenario() { + bool gotFile = [dlg_get_scen runModal] != NSFileHandlingPanelCancelButton; + makeFrontWindow(mainPtr); + if(gotFile) + return fs::path([[[dlg_get_scen URL] absoluteString] UTF8String]); + return ""; } -fs::path nav_put_scenario() throw(no_file_chosen) { - if([dlg_put_scen runModal] == NSFileHandlingPanelCancelButton) - throw no_file_chosen(); - return [[[dlg_put_scen URL] absoluteString] UTF8String]; +fs::path nav_put_scenario() { + bool gotFile = [dlg_put_scen runModal] != NSFileHandlingPanelCancelButton; + makeFrontWindow(mainPtr); + if(gotFile) + return [[[dlg_put_scen URL] absoluteString] UTF8String]; + return ""; } -fs::path nav_get_party() throw(no_file_chosen) { - if([dlg_get_game runModal] == NSFileHandlingPanelCancelButton) - throw no_file_chosen(); - return fs::path([[[dlg_get_game URL] absoluteString] UTF8String]); +fs::path nav_get_party() { + bool gotFile = [dlg_get_game runModal] != NSFileHandlingPanelCancelButton; + makeFrontWindow(mainPtr); + if(gotFile) + return fs::path([[[dlg_get_game URL] absoluteString] UTF8String]); + return ""; } -fs::path nav_put_party() throw(no_file_chosen) { - if([dlg_put_game runModal] == NSFileHandlingPanelCancelButton) - throw no_file_chosen(); - return fs::path([[[dlg_put_game URL] absoluteString] UTF8String]); +fs::path nav_put_party() { + bool gotFile = [dlg_put_game runModal] != NSFileHandlingPanelCancelButton; + makeFrontWindow(mainPtr); + if(gotFile) + return fs::path([[[dlg_put_game URL] absoluteString] UTF8String]); + return ""; }