Forráskód Böngészése

Added 'Add Files...' support.
in fileOpen_addList : Fixed suffix truncation for file paths such as "/root/.dot/nodot" so it wouldn't truncate to "/root/"
Changed openFile so it will return NULL on error and not add the file to the project if the file cannot be accessed.


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

joeyadams 18 éve
szülő
commit
795cf45502
4 módosított fájl, 101 hozzáadás és 12 törlés
  1. 8 7
      ktigcc/mainform.ui
  2. 70 5
      ktigcc/mainform.ui.h
  3. 19 0
      ktigcc/tpr.cxx
  4. 4 0
      ktigcc/tpr.h

+ 8 - 7
ktigcc/mainform.ui

@@ -1465,6 +1465,13 @@
     <slot>filePrint()</slot>
     <slot>filePreferences()</slot>
     <slot>editClear()</slot>
+    <slot>editUndo()</slot>
+    <slot>editRedo()</slot>
+    <slot>editCut()</slot>
+    <slot>editCopy()</slot>
+    <slot>editPaste()</slot>
+    <slot>editFind()</slot>
+    <slot>findFindSymbolDeclaration()</slot>
     <slot>editSelectAll()</slot>
     <slot>increaseIndent()</slot>
     <slot>decreaseIndent()</slot>
@@ -1482,13 +1489,6 @@
     <slot>debugPause()</slot>
     <slot>debugReset()</slot>
     <slot>toolsConfigure()</slot>
-    <slot>editUndo()</slot>
-    <slot>editRedo()</slot>
-    <slot>editCut()</slot>
-    <slot>editCopy()</slot>
-    <slot>editPaste()</slot>
-    <slot>editFind()</slot>
-    <slot>findFindSymbolDeclaration()</slot>
     <slot>helpDocumentation()</slot>
     <slot>helpContents()</slot>
     <slot>helpIndex()</slot>
@@ -1531,6 +1531,7 @@
     <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>
+    <function access="private" specifier="non virtual" returnType="int">projectAddFiles_oneFile( const QString &amp; fileName )</function>
     <function access="private" specifier="non virtual">updateSizes()</function>
     <function access="private" specifier="non virtual" returnType="QStringList">extractAllFileNames( void )</function>
     <function access="private" specifier="non virtual">extractFileTreeInfo( QListViewItem * parent, QListViewItem * * p_category, QString * p_folderPath )</function>

+ 70 - 5
ktigcc/mainform.ui.h

@@ -723,6 +723,11 @@ void MainForm::addRecent(const QString &fileName)
 
 QListViewItem * MainForm::openFile(QListViewItem * category, QListViewItem * parent, const QString &fileCaption, const QString &fileName)
 {
+  if (getPathType(fileName)!=PATH_FILE) { //don't include the file if it can't be accessed!
+    KMessageBox::sorry(this,QString("Can't open \'%1\'").arg(fileName),"Warning");
+    return NULL;
+  }
+  
   QListViewItem *item=NULL, *next=parent->firstChild();
   for (; IS_FILE(next); next=item->nextSibling())
     item=next;
@@ -772,7 +777,7 @@ QListViewItem *MainForm::createFolder(QListViewItem *parent,const QString &name)
 void MainForm::fileOpen_addList(QListViewItem *category,void *fileListV,void *dir, const QString &open_file)
 {
   int i,e;
-  int p;
+  int p,pslash;
   KURL tmp;
   TPRFileList *fileList=(TPRFileList*)fileListV;
   QString caption;
@@ -785,10 +790,11 @@ void MainForm::fileOpen_addList(QListViewItem *category,void *fileListV,void *di
     tmp=*reinterpret_cast<const KURL *>(dir);
     kurlNewFileName(tmp,fileList->path[i]);
     caption=fileList->path[i];
+    //fixed suffix truncation for file paths such as "/root/.dot/nodot" so it wouldn't truncate to "/root/"
     p=caption.findRev('.');
-    if (p>=0) caption.truncate(p);
-    p=caption.findRev('/');
-    if (p>=0) caption.remove(0,p+1);
+    pslash=caption.findRev('/');
+    if (p>=0&&p>pslash) caption.truncate(p);
+    if (pslash>=0) caption.remove(0,pslash+1);
     treePath=fileList->folder[i].stripWhiteSpace();
     //check for a backslash at the end and remove it if it's there.
     if (treePath[treePath.length()-1]=='\\')
@@ -805,6 +811,7 @@ void MainForm::fileOpen_addList(QListViewItem *category,void *fileListV,void *di
     }
     
     ListViewFile *newFile=static_cast<ListViewFile *>(openFile(category,parent,caption,tmp.path()));
+    if (!newFile) continue;
     if (!newFile->fileName.compare(open_file))
       fileTreeClicked(newFile);
   }
@@ -1235,9 +1242,67 @@ void MainForm::openFileAtCursor()
   
 }
 
-void MainForm::projectAddFiles()
+//returns 1 on success
+int MainForm::projectAddFiles_oneFile(const QString &fileName)
 {
+  int pathType=getPathType(fileName);
+  if (pathType!=PATH_FILE) {
+    if (pathType==PATH_ERROR) {
+      KMessageBox::error(this,QString("Can't open \'%1\'").arg(fileName));
+    }
+    return 0;
+  }
+  QListViewItem *category=othFilesListItem;
+  QString suffix,caption;
+  int p;
+  
+  p=fileName.findRev('/');
+  if (p<0) p=-1;
+  caption=fileName.mid(p+1);
+  p=caption.findRev('.');
+  if (p>=0) {
+    suffix=caption.mid(p+1);
+    caption.truncate(p);
+  }
+  
+  if (!suffix.compare("h"))
+    category=hFilesListItem;
+  else if (!suffix.compare("c"))
+    category=cFilesListItem;
+  else if (!suffix.compare("s"))
+    category=sFilesListItem;
+  else if (!suffix.compare("asm"))
+    category=asmFilesListItem;
+  else if (!suffix.compare("qll"))
+    category=qllFilesListItem;
+  else if (!suffix.compare("o"))
+    category=oFilesListItem;
+  else if (!suffix.compare("a"))
+    category=aFilesListItem;
+  else if (!suffix.compare("txt"))
+    category=txtFilesListItem;
   
+  if (!category)
+    category=othFilesListItem;
+  
+  if (openFile(category,category,caption,fileName))
+    return 1;
+  return 0;
+}
+
+void MainForm::projectAddFiles()
+{
+  unsigned long i,e;
+  int projectChanged=0;
+  QStringList result=SGetFileName_Multiple(findFilter(TIGCCAddFilesFilter),"Add Files",this);
+  e=result.count();
+  for (i=0;i<e;i++) {
+    if (projectAddFiles_oneFile(result[i]))
+      projectChanged=TRUE;
+  }
+  if (projectChanged) {
+    projectIsDirty=TRUE;
+  }
 }
 
 void MainForm::projectCompile()

+ 19 - 0
ktigcc/tpr.cxx

@@ -25,6 +25,7 @@
 #include <cstdlib>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <sys/dir.h>
 #include <kapplication.h>
 #include <kcmdlineargs.h>
 #include <kaboutdata.h>
@@ -792,3 +793,21 @@ int copyFile(const char *src, const char *dest)
   if (fclose(sf)) return 3;
   return 0;
 }
+
+int getPathType(const QString &thePath)
+{
+  struct stat statvar;
+  int result=stat(thePath,&statvar);
+  if (result)
+    return PATH_ERROR;
+  if (statvar.st_mode&S_IFDIR)
+    return PATH_FOLDER;
+  if (statvar.st_mode&S_IFREG)
+  {
+    FILE *testFile=fopen(thePath,"rb");
+    if (!testFile) return PATH_ERROR;
+    fclose(testFile);
+    return PATH_FILE;
+  }
+  return PATH_ERROR;
+}

+ 4 - 0
ktigcc/tpr.h

@@ -148,6 +148,8 @@ typedef struct
   TPRFileList quill_files;
 } TPRDataStruct;
 
+enum {PATH_ERROR,PATH_FILE,PATH_FOLDER}; //return types for getPathType
+
 int loadTPR(const QString &fileName,TPRDataStruct *dest);
 QString loadFileText(const char *fileName);
 
@@ -158,3 +160,5 @@ void kurlNewFileName(KURL &dir,const QString &newFileName);
 int checkFileName(const QString &fileName,const QStringList &fileNameList);
 
 int copyFile(const char *src, const char *dest);
+
+int getPathType(const QString &thePath);