瀏覽代碼

Added Save As support. However, it still needs to make new files when you do save as.

git-svn-id: file:///var/svn/tigccpp/trunk@385 9552661e-59e3-4036-b4f2-dbe53926924f
joeyadams 18 年之前
父節點
當前提交
248e61ad26
共有 3 個文件被更改,包括 42 次插入2 次删除
  1. 29 2
      ktigcc/mainform.ui.h
  2. 12 0
      ktigcc/tpr.cxx
  3. 1 0
      ktigcc/tpr.h

+ 29 - 2
ktigcc/mainform.ui.h

@@ -655,6 +655,8 @@ void MainForm::fileOpen()
   QString fileName=SGetFileName(KFileDialog::Opening,TIGCCOpenProjectFileFilter,"Open Project/File",this);
   KURL dir;
   dir.setPath(fileName);
+  if (fileName.isEmpty())
+    return;
   int ret=loadTPR(fileName, &TPRData);
   if (ret == -1) {
     KMessageBox::error(this,QString("Can't open \'%1\'").arg(fileName));
@@ -690,11 +692,13 @@ void MainForm::fileOpen()
   updateRightStatusLabel();
 }
 
+//loadList also saves the file contents
 void MainForm::fileSave_loadList(QListViewItem *category,void *fileListV,const QString &base_dir,QString *open_file)
 {
   if (!category)
     return;
   TPRFileList *fileList=(TPRFileList*)fileListV;
+  KURL tmpPath;
   QListViewItem *item=category->firstChild();
   QListViewItem *next;
   QString folderSpec=QString::null;
@@ -726,6 +730,10 @@ void MainForm::fileSave_loadList(QListViewItem *category,void *fileListV,const Q
       if (relPath.find("./")==0)
         relPath=relPath.mid(2);
       
+      tmpPath.setPath(base_dir);
+      tmpPath.setFileName(relPath);
+      saveFileText(tmpPath.path(),static_cast<ListViewFile *>(item)->textBuffer);
+      
       fileList->path << relPath;
       fileList->folder << folderSpec;
       
@@ -769,9 +777,13 @@ fsll_seeknext:
 
 //TODO: Check if there is a project name.  If not, do a save as dialog.
 //TODO: Show error if TPR couldn't be saved.
-//TODO: Resolve TPRData.open_file
 void MainForm::fileSave()
 {
+  if (projectFileName.isEmpty())
+  {
+    fileSaveAs();
+  }
+  
   int result;
   
   TPRDataStruct TPRData;
@@ -779,6 +791,11 @@ void MainForm::fileSave()
   KURL base_dir_k(projectFileName);
   base_dir_k.setFileName("");
   QString base_dir=base_dir_k.path();
+  
+  if (IS_FILE(currentListItem))
+    static_cast<ListViewFile *>(currentListItem)->textBuffer=m_view->getDoc()->text();
+    //we don't want to make it so you have to click to another file and back to save the current document properly ;)
+  
   fileSave_loadList(hFilesListItem,&TPRData.h_files,base_dir,&open_file);
   fileSave_loadList(cFilesListItem,&TPRData.c_files,base_dir,&open_file);
   fileSave_loadList(qllFilesListItem,&TPRData.quill_files,base_dir,&open_file);
@@ -799,7 +816,17 @@ void MainForm::fileSave()
 void MainForm::fileSaveAs()
 {
   QString fileName=SGetFileName(KFileDialog::Saving,TIGCCSaveProjectFilter,"Save Project",this);
-  
+  if (fileName.isEmpty())
+    return;
+  FILE *testf=fopen(projectFileName,"wb");
+  if (!testf)
+  {
+    KMessageBox::error(this,QString("Can't save to \'%1\'").arg(fileName));
+  }
+  else
+    fclose(testf);
+  projectFileName=fileName;
+  fileSave();
 }
 
 void MainForm::filePrint()

+ 12 - 0
ktigcc/tpr.cxx

@@ -654,3 +654,15 @@ int saveTPR(QString &fileName,TPRDataStruct *src)
   fclose(f);
   return ret;
 }
+
+int saveFileText(const char *fileName,QString &fileText)
+{
+  FILE *f;
+  const char *s;
+  f=fopen(fileName,"wb");
+  if (!f)
+    return -1;
+  s=smartAscii(fileText);
+  fwrite(s,1,strlen(s),f);
+  return 0;
+}

+ 1 - 0
ktigcc/tpr.h

@@ -149,3 +149,4 @@ int loadTPR(QString &fileName,TPRDataStruct *dest);
 QString loadFileText(const char *fileName);
 
 int saveTPR(QString &fileName,TPRDataStruct *src);
+int saveFileText(const char *fileName,QString &fileText);