OSSP CVS Repository

ossp - Difference in ossp-pkg/as/as-gui/as_slot.cpp versions 1.42 and 1.43
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/as/as-gui/as_slot.cpp 1.42 -> 1.43

--- as_slot.cpp  2002/12/05 16:08:21     1.42
+++ as_slot.cpp  2002/12/05 18:03:53     1.43
@@ -85,8 +85,10 @@
     nRows = Selection.contains(QChar('\n'));        // How many rows
     this->addEntry(nRows);                          // Reuse slot
 
-    if (Selection)
+    if (Selection) {
         setRowdata(Selection);                      // Use accessor
+        this->setDirty(true);                       // Set dirty state
+    }
 }
 
 //
@@ -104,10 +106,12 @@
         // Add a row after selection and focus to the new row
         if (Select.bottomRow() + 1 != m_pMaintable->numRows()) { // Add upwards
             m_pMaintable->insertRows(Select.topRow(), nTotal);
+            this->setDirty(true);   // Set data to dirty state
             m_pMaintable->setCurrentCell(Select.topRow(), m_pMaintable->currentColumn());
         }
         else { // Special case on last row add downwards
             m_pMaintable->insertRows(Select.bottomRow() + 1, nTotal);
+            this->setDirty(true);   // Set data to dirty state
             m_pMaintable->setCurrentCell(Select.bottomRow() + 1, m_pMaintable->currentColumn());
             m_pMaintable->ensureCellVisible(m_pMaintable->numRows() - 1, 0); // Scroll please
         }
@@ -118,10 +122,12 @@
         // Add a row after selection and focus to the new row
         if (nCurrent + 1 != m_pMaintable->numRows()) { // Add upwards
             m_pMaintable->insertRows(nCurrent, nTotal);
+            this->setDirty(false);  // Reset data to clean state
             m_pMaintable->setCurrentCell(nCurrent, m_pMaintable->currentColumn());
         }
         else { // Special case on last row add downwards
             m_pMaintable->insertRows(nCurrent + 1, nTotal);
+            this->setDirty(false);  // Reset data to clean state
             m_pMaintable->setCurrentCell(nCurrent + 1, m_pMaintable->currentColumn());
             m_pMaintable->ensureCellVisible(m_pMaintable->numRows() - 1, 0); // Scroll please
         }
@@ -157,9 +163,12 @@
     if (m_pMaintable->currentRow() + 1 != m_pMaintable->numRows()) {
         m_pMaintable->setCurrentCell(Select.bottomRow() + 1, m_pMaintable->currentColumn());
         m_pMaintable->removeRows(Rowselect);
+        this->setDirty(true);   // Set data to dirty state
     }
-    else // Special case to handle removing of only row or last row
+    else {  // Special case to handle removing of only row or last row
         m_pMaintable->removeRows(Rowselect);
+        this->setDirty(true);   // Set data to dirty state
+    }
 }
 
 //
@@ -179,41 +188,88 @@
         case 0: // Save first
             this->saveFile();               // Save changes first
             m_pMaintable->setNumRows(0);    // Remove all data in table
+            this->setDirty(false);          // Reset data to clean state
             break;
         case 1: // Don't save first but do new
             m_pMaintable->setNumRows(0);    // Remove all data in table
+            this->setDirty(false);          // Reset data to clean state
             break;
         case 2: // Don't do a new timesheet
         default:
             break;
         }
     }
-    else                                    // Data is already up to date
+    else {                                  // Data is already up to date
         m_pMaintable->setNumRows(0);        // Remove all data in table
-
-    this->setDirty(false);                  // Reset data to clean state
+        this->setDirty(false);              // Reset data to clean state
+    }
 }
 
 //
-// Choose a file using a handy file dialog
+// Open and display an existing document
 //
-void Titraqform::chooseFile(void)
+void Titraqform::openDoc(void)
 {
+    int nResult = 0;    // Holds return value from save first messagebox
     QString Filestring = QFileDialog::getOpenFileName("/e/dev/as", QString::null, this, trUtf8("Chooser Dialog"), trUtf8("Choose a file to open"));
+
     if (!Filestring.isEmpty()) {
-        m_szFilename->operator=(Filestring);
-        m_pMaintable->setNumRows(0);    // Clear out old data
-        QFile Filetemp(Filestring);     // File to load
-        try {
-            loadData(Filetemp);         // Pass to helper method
-        }
-        catch (Genexcept& Genex) {
-            Genex.reportErr();
-        }
-        // Reset and give output to main window
-        this->setCaption(Filestring);
-        m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000);
-        this->setDirty(false);          // Set the clean state
+        QFile Filetemp(Filestring); // File to load
+        // Check modification state of current data
+        if (this->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
+                m_szFilename->operator=(Filestring);
+                m_pMaintable->setNumRows(0);    // Clear out old data
+                try {
+                    loadData(Filetemp);         // Pass to helper method
+                }
+                catch (Genexcept& Genex) {
+                    Genex.reportErr();
+                }
+                // Reset and give output to main window
+                this->setCaption(Filestring);
+                m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000);
+                this->setDirty(false);          // Set the clean state
+                break;
+            case 1: // Don't save first but do load
+                m_szFilename->operator=(Filestring);
+                m_pMaintable->setNumRows(0);    // Clear out old data
+                try {
+                    loadData(Filetemp);         // Pass to helper method
+                }
+                catch (Genexcept& Genex) {
+                    Genex.reportErr();
+                }
+                // Reset and give output to main window
+                this->setCaption(Filestring);
+                m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000);
+                this->setDirty(false);          // Set the clean state
+                break;
+            case 2: // Don't do a load timesheet
+            default:
+                break;
+            }
+        }
+        else {
+            m_szFilename->operator=(Filestring);
+            m_pMaintable->setNumRows(0);    // Clear out old data
+            try {
+                loadData(Filetemp);         // Pass to helper method
+            }
+            catch (Genexcept& Genex) {
+                Genex.reportErr();
+            }
+            // Reset and give output to main window
+            this->setCaption(Filestring);
+            m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000);
+            this->setDirty(false);          // Set the clean state
+        }
     }
     else
         m_pStatbar->message(trUtf8("Loading aborted"), 4000);
@@ -278,9 +334,11 @@
         case 0: // Save first
             this->saveFile();               // Save changes first
             pClosit->accept();              // then close timesheet
+            this->setDirty(false);          // Reset data to clean state
             break;
         case 1: // Don't save first but close
             pClosit->accept();              // Close timesheet
+            this->setDirty(false);          // Reset data to clean state
             break;
         case 2: // Don't close
         default:
@@ -288,10 +346,10 @@
             break;
         }
     }
-    else                                    // Data is already up to date
+    else {                                  // Data is already up to date
         pClosit->accept();
-
-    this->setDirty(false);                  // Reset data to clean state
+        this->setDirty(false);              // Reset data to clean state
+    }
 }
 
 //

CVSTrac 2.0.1