Bläddra i källkod

Fixed file saving. Looks like it works now.

Note: When the project is opened, although the correct Open File is automatically opened, it's not shown as selected on the tree list.


git-svn-id: file:///var/svn/tigccpp/trunk@384 9552661e-59e3-4036-b4f2-dbe53926924f
joeyadams 18 år sedan
förälder
incheckning
b39855d17c
2 ändrade filer med 27 tillägg och 46 borttagningar
  1. 14 9
      ktigcc/mainform.ui.h
  2. 13 37
      ktigcc/tpr.cxx

+ 14 - 9
ktigcc/mainform.ui.h

@@ -692,17 +692,18 @@ void MainForm::fileOpen()
 
 void MainForm::fileSave_loadList(QListViewItem *category,void *fileListV,const QString &base_dir,QString *open_file)
 {
+  if (!category)
+    return;
   TPRFileList *fileList=(TPRFileList*)fileListV;
-  ListViewFile *item=(ListViewFile*)category->firstChild();
-  ListViewFile *next;
-    //Is this a valid conversion to the ListViewFile system?
+  QListViewItem *item=category->firstChild();
+  QListViewItem *next;
   QString folderSpec=QString::null;
   int o;
   while (item)
   {
     if (IS_FILE(item))
     {
-      QString relPath=KURL::relativePath(base_dir,item->fileName);
+      QString relPath=KURL::relativePath(base_dir,static_cast<ListViewFile *>(item)->fileName);
       QString suffix;
       o=relPath.findRev('.');
       if (o>=0)
@@ -720,17 +721,20 @@ void MainForm::fileSave_loadList(QListViewItem *category,void *fileListV,const Q
       else
         relPath.truncate(0);
       relPath+=item->text(0);
+      relPath+='.';
       relPath+=suffix;
+      if (relPath.find("./")==0)
+        relPath=relPath.mid(2);
       
       fileList->path << relPath;
-      fileList->folder << relPath;
+      fileList->folder << folderSpec;
       
       if (item==currentListItem)
-        *open_file=item->fileName;
+        *open_file=static_cast<ListViewFile *>(item)->fileName;
     }
     else if (IS_FOLDER(item))
     {
-      next=(ListViewFile*)item->firstChild();
+      next=item->firstChild();
       if (next)
       {
         if (folderSpec.isEmpty())
@@ -745,10 +749,10 @@ void MainForm::fileSave_loadList(QListViewItem *category,void *fileListV,const Q
       }
     }
 fsll_seeknext:
-    next=(ListViewFile*)item->nextSibling();
+    next=item->nextSibling();
     if (!next)
     {
-      next=(ListViewFile*)item->parent();
+      next=item->parent();
       if (next==category||!next)
         break;
       item=next;
@@ -785,6 +789,7 @@ void MainForm::fileSave()
   fileSave_loadList(txtFilesListItem,&TPRData.txt_files,base_dir,&open_file);
   fileSave_loadList(othFilesListItem,&TPRData.oth_files,base_dir,&open_file);
   TPRData.prj_name=rootListItem->text(0);
+  TPRData.open_file=open_file;
   TPRData.settings=settings;
   TPRData.libopts=libopts;
   

+ 13 - 37
ktigcc/tpr.cxx

@@ -488,20 +488,12 @@ QString convert_path_separators_save(QString s)
 	return s;
 }
 
-char *grabQString(const QString &s,char **buffer)
+//this is here because QString::ascii() returns "(null)" on a null string.
+const char *smartAscii(const QString &s)
 {
-  int i,e;
-  char *ptr;
-  e=s.length();
-  ptr=(char*)realloc(*buffer,e+1);
-  if (!ptr) return NULL;
-  *buffer=ptr;
-  for (i=0;i<e;i++)
-  {
-    *ptr++=s[i];
-  }
-  ptr[e]=0;
-  return *buffer;
+  if (s.isNull())
+    return "";
+  return s.ascii();
 }
 
 //To do:
@@ -509,21 +501,15 @@ char *grabQString(const QString &s,char **buffer)
 //can a macro have absolutely nothing in it?  that's why I said i there, since it had to be something to do.
 //reloc_param's macro here just puts "None" for the RT_NONE macro, which is probably not entirely correct, but it should work in all cases anyway.
 //some parameters are booleans for if a parameter is defined or not.  should the parameter be shown anyway, even if the associated boolean is false?
-int save_tpr(FILE *f,TPRDataStruct *dest,char **buffer)
+int save_tpr(FILE *f,TPRDataStruct *dest)
 {
 	int i=0,e;
 	QString tmp;
-    char *ptr;
 	
 #define boolean_param(token,setting) fprintf(f,"%s%d\r\n",token,!!dest->settings.setting);
-#define string_vparam(token,var) \
-    { \
-        ptr=grabQString(dest->var,buffer); \
-        if (!ptr) return -2; \
-        fprintf(f,"%s%s\r\n",token,ptr); \
-    }
+#define string_vparam(token,var) fprintf(f,"%s%s\r\n",token,smartAscii(dest->var));
 #define string_param(token,setting) string_vparam(token,settings.setting)
-#define ignore_param(token) i=0;
+#define ignore_param(token) /**/
 	
 	fputs("[Settings]\r\n",f);
 	boolean_param("Archive=",archive)
@@ -623,25 +609,17 @@ int save_tpr(FILE *f,TPRDataStruct *dest,char **buffer)
 #undef reloc_param
 #undef minams_param
 	
-    ptr=grabQString(dest->open_file,buffer);
-    if (!ptr) return -2;
-	fprintf(f,"\r\n[File Editing]\r\nOpen File=%s\r\n\r\n[Included Files]\r\n",ptr);
+	fprintf(f,"\r\n[File Editing]\r\nOpen File=%s\r\n\r\n[Included Files]\r\n",smartAscii(dest->open_file));
 	
 #define filepath_param(token,filetype) \
 	e=dest->filetype.path.count(); \
 	for(i=0;i<e;i++) \
 	{ \
-		tmp=convert_path_separators_save(dest->filetype.path[i]); \
-        ptr=grabQString(tmp,buffer); \
-        if (!ptr) \
-          return -2; \
-		fprintf(f,"%s %ld=%s\r\n",token,(long)(i+1),ptr); \
+		tmp=convert_path_separators_save(smartAscii(dest->filetype.path[i])); \
+		fprintf(f,"%s %ld=%s\r\n",token,(long)(i+1),smartAscii(tmp)); \
 		if (!dest->filetype.folder[i].isEmpty()) \
 		{ \
-          ptr=grabQString(dest->filetype.folder[i],buffer); \
-          if (!ptr) \
-            return -2; \
-          fprintf(f,"%s %ld Folder=%s\r\n",token,(long)(i+1),ptr); \
+          fprintf(f,"%s %ld Folder=%s\r\n",token,(long)(i+1),smartAscii(dest->filetype.folder[i])); \
         } \
 	}
 	
@@ -667,14 +645,12 @@ int saveTPR(QString &fileName,TPRDataStruct *src)
 {
   FILE *f;
   int ret;
-  char *buffer=NULL; //this buffer is used to grab QStrings so that fprintf can handle them.
   f=fopen(fileName,"wb");
   if (!f)
   {
     return -1;
   }
-  ret=save_tpr(f,src,&buffer);
-  free(buffer);
+  ret=save_tpr(f,src);
   fclose(f);
   return ret;
 }