Browse Source

Added functions MainForm::fileSavePrompt and MainForm::savePrompt. Didn't use them for anything yet.

git-svn-id: file:///var/svn/tigccpp/trunk@437 9552661e-59e3-4036-b4f2-dbe53926924f
joeyadams 18 years ago
parent
commit
38300639e5
2 changed files with 75 additions and 0 deletions
  1. 2 0
      ktigcc/mainform.ui
  2. 73 0
      ktigcc/mainform.ui.h

+ 2 - 0
ktigcc/mainform.ui

@@ -1391,6 +1391,8 @@
     <function access="private" specifier="static" returnType="QListViewItem *">createFolder( QListViewItem * parent, const QString &amp; name )</function>
     <function access="private" specifier="non virtual">fileOpen_addList( QListViewItem * category, void * fileListV, void * dir, const QString &amp; open_file )</function>
     <function access="private" specifier="non virtual">openProject( const QString &amp; fileName )</function>
+    <function access="private" specifier="non virtual" returnType="int">fileSavePrompt( QListViewItem * fileItem )</function>
+    <function access="private" specifier="non virtual" returnType="int">savePrompt( void )</function>
     <function access="private" specifier="non virtual">fileSave_saveAs( QListViewItem * theItem )</function>
     <function access="private" specifier="non virtual">fileSave_loadList( QListViewItem * category, void * fileListV, const QString &amp; base_dir, void * dir_new, QString * open_file )</function>
     <function>fileSave_fromto( const QString &amp; lastProj, const QString &amp; nextProj )</function>

+ 73 - 0
ktigcc/mainform.ui.h

@@ -879,6 +879,79 @@ void MainForm::fileRecent4()
   openProject(fileRecent4Action->statusTip());
 }
 
+int MainForm::fileSavePrompt(QListViewItem *fileItem)
+{
+  int result;
+  ListViewFile *theFile=static_cast<ListViewFile *>(fileItem);
+  while (theFile->isDirty) { // "while" in case saving fails!
+    result=KMessageBox::questionYesNoCancel(this,QString("The file \'%1\' has been modified.  Do you want to save the changes?").arg(fileItem->text(0)),QString::null,KStdGuiItem::save(),KStdGuiItem::discard());
+    if (result==KMessageBox::Yes) {
+        if (saveFileText(theFile->fileName,theFile->textBuffer)) {
+          KMessageBox::error(this,QString("Can't save to \'%1\'").arg(fileItem->text(0)));
+        }
+        else {
+          theFile->isDirty=FALSE;
+        }
+    }
+    else if (result==KMessageBox::No)
+      break;
+    else
+      return 1;
+  }
+  return 0;
+}
+
+//returns 1 if the current project data should not be cleared out, 0 if it can be cleared out.
+int MainForm::savePrompt(void)
+{
+  int result;
+  
+  
+  while (projectIsDirty) {
+    result=KMessageBox::questionYesNoCancel(this,"The current project has been modified.  Do you want to save the changes?",QString::null,KStdGuiItem::save(),KStdGuiItem::discard());
+    if (result==KMessageBox::Yes) {
+      fileSave();
+    }
+    else if (result==KMessageBox::No) {
+      break;
+    }
+    else
+      return 1;
+  }
+  
+  QListViewItem *item=rootListItem->firstChild(),*next;
+  while (item)
+  {
+    if (IS_FOLDER(item))
+    {
+      next=item->firstChild();
+      if (next)
+      {
+        item=next;
+        continue;
+      }
+    }
+    if (IS_FILE(item))
+    {
+      fileSavePrompt(item);
+    }
+    next=item->nextSibling();
+    while (!next)
+    {
+      next=item->parent();
+      if (next==rootListItem||!next)
+      {
+        return 0;
+      }
+      item=next;
+      next=item->nextSibling();
+    }
+    item=next;
+  }
+  
+  return 0;
+}
+
 void MainForm::fileSave_saveAs(QListViewItem *theItem)
 {
   if (!IS_FILE(theItem))