Index: ossp-pkg/as/as-gui/TODO RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/TODO,v rcsdiff -q -kk '-r1.70' '-r1.71' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/TODO,v' 2>/dev/null --- TODO 2003/01/30 23:48:00 1.70 +++ TODO 2003/01/31 18:03:36 1.71 @@ -61,6 +61,7 @@ Soll mehr intuitive, mit sekondaer/dritte Keycolumn CRC und Rev sollen nicht in gleiche Methode berechnet No need to have upd slots for non-changeable upd controls +Before openDoc, closeEvent should be used instead of new code Architectural ------------- Index: ossp-pkg/as/as-gui/as_slot.cpp RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_slot.cpp,v rcsdiff -q -kk '-r1.100' '-r1.101' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_slot.cpp,v' 2>/dev/null --- as_slot.cpp 2003/01/31 14:03:03 1.100 +++ as_slot.cpp 2003/01/31 18:03:36 1.101 @@ -338,7 +338,7 @@ m_pMaintable->setNumRows(0); // Remove all data in table this->setCaption(trUtf8("No file name")); m_pStatbar->message(trUtf8("New document"), 4000); - this->setFilename(QString("")); + this->setOpen(); // Signal an open doc state this->addEntry(1); // Default new op adds a row m_pMaintable->setDirty(false); // Start out clean } @@ -350,69 +350,69 @@ { int nResult = 0; // Holds return value from save first messagebox - // Make sure we correctly get the name of the default file to open - QString Openas = m_pPrefs->getString(TITRAQ_PREFASFILE, TITRAQ_DEFASFILE); - if (Openas.startsWith(TITRAQ_HOMEDIRTOK)) - Openas = QDir::homeDirPath() + Openas.remove(0, QString(TITRAQ_HOMEDIRTOK).length() - 1); - - QString Filestring = QFileDialog::getOpenFileName(Openas, trUtf8("Accounting Data (*.as);;Text files (*.txt);;All Files (*)"), this, trUtf8("ChooserDialog"), trUtf8("Choose a file to open"), NULL, false); - - if (!Filestring.isEmpty()) { - QFile Filetemp(Filestring); // File to load - // Check modification state of current data - if (m_pMaintable->isDirty()) { - nResult = QMessageBox::information(this, trUtf8(TITRAQ_APPTITLE), - trUtf8(TITRAQ_SAVEFIRST), trUtf8("&Save"), - trUtf8("&Discard"), trUtf8("Cancel"), 0, 2); - - switch (nResult) { - case 0: // Save first - this->saveFile(); // Save changes first - setFilename(Filestring); // Set the new file name - m_pMaintable->setNumRows(0); // Clear out old data - try { - loadData(Filetemp); // Pass to helper method - } - catch (Genexcept& Genex) { - Genex.reportErr(); - return; - } - break; - case 1: // Don't save first but do load - setFilename(Filestring); // Set the new file name - m_pMaintable->setNumRows(0); // Clear out old data - try { - loadData(Filetemp); // Pass to helper method - } - catch (Genexcept& Genex) { - Genex.reportErr(); - return; - } - break; - case 2: // Don't do a load timesheet - default: - break; - } +// +// This block will guide the user to saving the contents of the timesheet +// before losing them in an open operation. The question and dialog box will +// not be raised if no open timesheet exists or if it was just serialized. +// + if (m_pMaintable->isDirty()) { // Check modification state + nResult = QMessageBox::information(this, trUtf8(TITRAQ_APPTITLE), + trUtf8(TITRAQ_SAVEFIRST), trUtf8("&Save"), + trUtf8("&Discard"), trUtf8("Cancel"), 0, 2); + + switch (nResult) { + case 0: // Save first + this->saveFile(); // Save changes first + break; + case 1: // Don't save first but do load + break; + case 2: // Don't do a load timesheet + default: + m_pStatbar->message(trUtf8("Loading aborted"), 4000); + return; + break; } - else { + } + +// +// This block ensures that conditions of first block logic were met if +// applicable. If so, the user gives a file name to open or cancels the +// operation. The corresponding file will be opened, and if this is +// unsuccessful then the post state is exactly the same as the pre state. +// + if (!m_pMaintable->isDirty() || nResult == 1) { // Check modification state + // Make sure we correctly get the name of the default file to open + QString Openas = m_pPrefs->getString(TITRAQ_PREFASFILE, TITRAQ_DEFASFILE); + if (Openas.startsWith(TITRAQ_HOMEDIRTOK)) + Openas = QDir::homeDirPath() + Openas.remove(0, QString(TITRAQ_HOMEDIRTOK).length() - 1); + + // This dialog asks which file the user wants to open + QString Filestring = QFileDialog::getOpenFileName(Openas, + trUtf8("Accounting Data (*.as);;Text files (*.txt);;All Files (*)"), + this, trUtf8("ChooserDialog"), trUtf8("Choose a file to open"), NULL, false); + + // We might have a filename to work on, so do something with it + if (!Filestring.isEmpty()) { setFilename(Filestring); // Set the new file name m_pMaintable->setNumRows(0); // Clear out old data + m_pMaintable->setDirty(false); // Reset dirty flag + QFile Filetemp(Filestring); // File to load try { loadData(Filetemp); // Pass to helper method + this->setCaption(Filestring); // Caption in the titlebar + m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000); + this->enableIface(true); // Turn on the lights } - catch (Genexcept& Genex) { + catch (Genexcept& Genex) { // Crap, we failed + m_pStatbar->message(trUtf8("Loading failed"), 4000); + this->setOpen(false); Genex.reportErr(); return; } } - - // Fall through to implicit open code - this->setCaption(Filestring); - m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000); - this->enableIface(true); // Turn on the lights + else // An empty filename returning from the file dialog means cancel + m_pStatbar->message(trUtf8("Loading aborted"), 4000); } - else - m_pStatbar->message(trUtf8("Loading aborted"), 4000); } //