Sun, 19 May 2013 13:51:38 +0300
Prompt for unsaved changes before loading or creating a new file
src/dialogs.cpp | file | annotate | diff | comparison | revisions | |
src/file.cpp | file | annotate | diff | comparison | revisions | |
src/file.h | file | annotate | diff | comparison | revisions | |
src/gui.cpp | file | annotate | diff | comparison | revisions | |
src/gui_actions.cpp | file | annotate | diff | comparison | revisions |
--- a/src/dialogs.cpp Sun May 19 13:21:06 2013 +0300 +++ b/src/dialogs.cpp Sun May 19 13:51:38 2013 +0300 @@ -387,39 +387,40 @@ // ============================================================================= void NewPartDialog::StaticDialog () { NewPartDialog dlg (g_win); - if (dlg.exec ()) { - newFile (); - - short idx; - str author = dlg.le_author->text (); - vector<LDObject*>& objs = g_curfile->m_objs; - - idx = dlg.rb_BFC->value (); - const LDBFC::Type BFCType = - (idx == CCW) ? LDBFC::CertifyCCW : - (idx == CW) ? LDBFC::CertifyCW : - LDBFC::NoCertify; - - idx = dlg.rb_license->value (); - const char* license = - (idx == CCAL) ? "Redistributable under CCAL version 2.0 : see CAreadme.txt" : - (idx == NonCA) ? "Not redistributable : see NonCAreadme.txt" : - null; - - objs.push_back (new LDComment (dlg.le_name->text ())); - objs.push_back (new LDComment ("Name: <untitled>.dat")); - objs.push_back (new LDComment (fmt ("Author: %s", author.chars()))); - objs.push_back (new LDComment (fmt ("!LDRAW_ORG Unofficial_Part"))); - - if (license != null) - objs.push_back (new LDComment (fmt ("!LICENSE %s", license))); - - objs.push_back (new LDEmpty); - objs.push_back (new LDBFC (BFCType)); - objs.push_back (new LDEmpty); - - g_win->fullRefresh (); - } + if (dlg.exec () == false) + return; + + newFile (); + + short idx; + str author = dlg.le_author->text (); + vector<LDObject*>& objs = g_curfile->m_objs; + + idx = dlg.rb_BFC->value (); + const LDBFC::Type BFCType = + (idx == CCW) ? LDBFC::CertifyCCW : + (idx == CW) ? LDBFC::CertifyCW : + LDBFC::NoCertify; + + idx = dlg.rb_license->value (); + const char* license = + (idx == CCAL) ? "Redistributable under CCAL version 2.0 : see CAreadme.txt" : + (idx == NonCA) ? "Not redistributable : see NonCAreadme.txt" : + null; + + objs.push_back (new LDComment (dlg.le_name->text ())); + objs.push_back (new LDComment ("Name: <untitled>.dat")); + objs.push_back (new LDComment (fmt ("Author: %s", author.chars()))); + objs.push_back (new LDComment (fmt ("!LDRAW_ORG Unofficial_Part"))); + + if (license != null) + objs.push_back (new LDComment (fmt ("!LICENSE %s", license))); + + objs.push_back (new LDEmpty); + objs.push_back (new LDBFC (BFCType)); + objs.push_back (new LDEmpty); + + g_win->fullRefresh (); } RotationPointDialog::RotationPointDialog (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f) {
--- a/src/file.cpp Sun May 19 13:21:06 2013 +0300 +++ b/src/file.cpp Sun May 19 13:51:38 2013 +0300 @@ -330,8 +330,11 @@ g_loadedFiles.push_back (f); g_curfile = f; - g_BBox.calculate(); + History::clear (); + + g_BBox.reset (); g_win->fullRefresh (); + g_win->updateTitle (); } // ============================================================================= @@ -789,4 +792,13 @@ strcpy (entry.sTitle, sTitle); g_PartList.push_back (entry); } +} + +// ============================================================================= +bool safeToCloseAll () { + for (OpenFile* f : g_loadedFiles) + if (!f->safeToClose ()) + return false; + + return true; } \ No newline at end of file
--- a/src/file.h Sun May 19 13:21:06 2013 +0300 +++ b/src/file.h Sun May 19 13:51:38 2013 +0300 @@ -111,6 +111,9 @@ // Re-caches all subfiles. void reloadAllSubfiles (); +// Is it safe to close all files? +bool safeToCloseAll (); + typedef struct { char sName[65], sTitle[81]; } partListEntry;
--- a/src/gui.cpp Sun May 19 13:21:06 2013 +0300 +++ b/src/gui.cpp Sun May 19 13:51:38 2013 +0300 @@ -889,11 +889,9 @@ // ============================================================================= void ForgeWindow::closeEvent (QCloseEvent* ev) { // Check whether it's safe to close all files. - for (OpenFile* f : g_loadedFiles) { - if (!f->safeToClose ()) { - ev->ignore (); - return; - } + if (!safeToCloseAll ()) { + ev->ignore (); + return; } // Save the configuration before leaving so that, for instance, grid choice
--- a/src/gui_actions.cpp Sun May 19 13:21:06 2013 +0300 +++ b/src/gui_actions.cpp Sun May 19 13:51:38 2013 +0300 @@ -40,6 +40,9 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= MAKE_ACTION (newFile, "&New", "brick", "Create a new part model.", CTRL (N)) { + if (safeToCloseAll () == false) + return; + NewPartDialog::StaticDialog (); } @@ -47,10 +50,16 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= MAKE_ACTION (open, "&Open", "file-open", "Load a part model from a file.", CTRL (O)) { + if (safeToCloseAll () == false) + return; + str name = QFileDialog::getOpenFileName (g_win, "Open File", "", "LDraw files (*.dat *.ldr)"); - if (~name) - openMainFile (name); + if (name.len () == 0) + return; + + closeAll (); + openMainFile (name); } // =============================================================================