Browse Source

Added fileSave_save.
Fixed fileSave_save and fileSave_saveas so that they would copy from the document to the textBuffer if necessary.


git-svn-id: file:///var/svn/tigccpp/trunk@440 9552661e-59e3-4036-b4f2-dbe53926924f

joeyadams 18 years ago
parent
commit
1ae6dd4c03
2 changed files with 34 additions and 14 deletions
  1. 1 0
      ktigcc/mainform.ui
  2. 33 14
      ktigcc/mainform.ui.h

+ 1 - 0
ktigcc/mainform.ui

@@ -1394,6 +1394,7 @@
     <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_save( QListViewItem * theItem )</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>

+ 33 - 14
ktigcc/mainform.ui.h

@@ -886,19 +886,9 @@ 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());
+    result=KMessageBox::questionYesNoCancel(this,QString("The file \'%1\' has been modified.  Do you want to save the changes?").arg(theFile->text(0)),QString::null,KStdGuiItem::save(),KStdGuiItem::discard());
     if (result==KMessageBox::Yes) {
-        if (theFile->fileName[0]!='/') {
-          fileSave_saveAs(fileItem);
-        }
-        else {
-          if (saveFileText(theFile->fileName,theFile->textBuffer)) {
-            KMessageBox::error(this,QString("Can't save to \'%1\'").arg(fileItem->text(0)));
-          }
-          else {
-            theFile->isDirty=FALSE;
-          }
-        }
+        fileSave_save(fileItem);
     }
     else if (result==KMessageBox::No)
       break;
@@ -913,7 +903,6 @@ 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) {
@@ -940,7 +929,8 @@ int MainForm::savePrompt(void)
     }
     if (IS_FILE(item))
     {
-      fileSavePrompt(item);
+      if (fileSavePrompt(item))
+        return 1;
     }
     next=item->nextSibling();
     while (!next)
@@ -959,11 +949,40 @@ int MainForm::savePrompt(void)
   return 0;
 }
 
+void MainForm::fileSave_save(QListViewItem *theItem)
+{
+  if (!IS_FILE(theItem))
+    return;
+  CATEGORY_OF(category,theItem);
+  if (!IS_EDITABLE_CATEGORY(category))
+    return;
+  //We don't want to make it so you have to click to another file and back to save the current document properly. ;)
+  if (theItem==currentListItem)
+    static_cast<ListViewFile *>(currentListItem)->textBuffer=m_view->getDoc()->text();
+  ListViewFile *theFile=static_cast<ListViewFile *>(theItem);
+  if (theFile->fileName[0]!='/') {
+    fileSave_saveAs(theFile);
+  }
+  else {
+    if (saveFileText(theFile->fileName,theFile->textBuffer)) {
+      KMessageBox::error(this,QString("Can't save to \'%1\'").arg(theFile->text(0)));
+    }
+    else {
+      theFile->isNew=FALSE;
+      theFile->isDirty=FALSE;
+      projectIsDirty=TRUE;
+    }
+  }
+}
+
 void MainForm::fileSave_saveAs(QListViewItem *theItem)
 {
   if (!IS_FILE(theItem))
     return;
   CATEGORY_OF(category,theItem);
+  //We don't want to make it so you have to click to another file and back to save the current document properly. ;)
+  if (theItem==currentListItem && IS_EDITABLE_CATEGORY(category))
+      static_cast<ListViewFile *>(currentListItem)->textBuffer=m_view->getDoc()->text();
   QString saveFileName=SGetFileName(KFileDialog::Saving,
   category==hFilesListItem?TIGCC_H_Filter TIGCCAllFilter:
   category==cFilesListItem?TIGCC_C_Filter TIGCCAllFilter: