Browse Source

Implement Find/Open file at cursor.

git-svn-id: file:///var/svn/tigccpp/trunk@714 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 18 years ago
parent
commit
c971d1c680
3 changed files with 91 additions and 7 deletions
  1. 6 5
      ktigcc/mainform.ui
  2. 64 1
      ktigcc/mainform.ui.h
  3. 21 1
      ktigcc/srcfilewin.ui.h

+ 6 - 5
ktigcc/mainform.ui

@@ -1613,7 +1613,7 @@
     <slot>destroy()</slot>
     <slot>te_popup_aboutToShow()</slot>
     <slot>te_popup_activated( int index )</slot>
-    <slot>accel_activated(int)</slot>
+    <slot>accel_activated( int index )</slot>
     <slot>fileTreeAccel_activated( int index )</slot>
     <slot>fileNewProject()</slot>
     <slot>fileOpen()</slot>
@@ -1645,6 +1645,10 @@
     <slot>findReplace_replace( const QString &amp; text, int replacementIndex, int replacedLength, int matchedLength )</slot>
     <slot>findReplace_stop()</slot>
     <slot>findFunctions()</slot>
+    <slot>findFunctions_functionListBox_highlighted( int index )</slot>
+    <slot>findFunctions_functionListBox_selected( int index )</slot>
+    <slot>findFunctions_prototypeButton_clicked()</slot>
+    <slot>findFunctions_implementationButton_clicked()</slot>
     <slot>findFunctionsPopup_aboutToShow()</slot>
     <slot>findFunctionsPopup_aboutToHide()</slot>
     <slot>findFunctionsPopup_aboutToHide_async()</slot>
@@ -1695,10 +1699,6 @@
     <slot>clipboard_dataChanged()</slot>
     <slot>fileTreeItemRenamed( QListViewItem * item, const QString &amp; newName, int col )</slot>
     <slot>KDirWatch_dirty( const QString &amp; fileName )</slot>
-    <slot>findFunctions_functionListBox_highlighted(int index)</slot>
-    <slot>findFunctions_functionListBox_selected(int index)</slot>
-    <slot>findFunctions_prototypeButton_clicked()</slot>
-    <slot>findFunctions_implementationButton_clicked()</slot>
 </slots>
 <functions>
     <function specifier="static">deleteErrorsForLVFile( QListViewItem * item )</function>
@@ -1725,6 +1725,7 @@
     <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">findReplace_next( bool firstTime )</function>
+    <function>findAndOpenFile(const QString &amp; fileName, void *category)</function>
     <function access="private" specifier="non virtual" returnType="int">projectAddFiles_oneFile( const QString &amp; fileName )</function>
     <function returnType="QString">writeTempSourceFile( void * srcFile, bool inProject )</function>
     <function access="private" specifier="non virtual">startCompiling()</function>

+ 64 - 1
ktigcc/mainform.ui.h

@@ -3150,9 +3150,72 @@ void MainForm::findFunctionsPopup_activated(int id)
   }
 }
 
+void MainForm::findAndOpenFile(const QString &fileName, void *category)
+{
+  // Look for the source file with the given name.
+  QString fileNameNoPath=QFileInfo(fileName).fileName();
+  bool inProject;
+  void *sourceFile;
+  if (findSourceFile(inProject,sourceFile,fileNameNoPath)) {
+    if (inProject)
+      fileTreeClicked(reinterpret_cast<ListViewFile *>(sourceFile));
+    else
+      KWin::activateWindow(reinterpret_cast<SourceFile *>(sourceFile)->winId());
+  } else {
+    // Not found. Try to open it instead.
+    // Don't do this if the name ends with ".tpr" because that would cause
+    // openProject to close the current project and load the new one instead.
+    if (!fileName.endsWith(".tpr",FALSE)) {
+      QString fileNameFull=QFileInfo(projectFileName).dir().filePath(fileName);
+      if (getPathType(fileNameFull)==PATH_FILE) {
+        openProject(fileNameFull);
+        if (findSourceFile(inProject,sourceFile,fileNameFull) && !inProject)
+           KWin::activateWindow(reinterpret_cast<SourceFile *>(sourceFile)->winId());
+      } else {
+        QListViewItem *cat=reinterpret_cast<QListViewItem *>(category);
+        QString includeDir=(cat==asmFilesListItem)?"asm":
+                           (cat==sFilesListItem)?"s":"c";
+        fileNameFull=QDir(QString("%1/include/%2/").arg(tigcc_base)
+                          .arg(includeDir)).filePath(fileName);
+        if (getPathType(fileNameFull)==PATH_FILE) {
+          openProject(fileNameFull);
+          if (findSourceFile(inProject,sourceFile,fileNameFull) && !inProject)
+             KWin::activateWindow(reinterpret_cast<SourceFile *>(sourceFile)->winId());
+        } else {
+          KMessageBox::error(this,QString("File \'%1\' not found.").arg(fileName),
+                             "Search Failed");
+        }
+      }
+    }
+  }
+}
+
 void MainForm::findOpenFileAtCursor()
 {
-  
+  if (CURRENT_VIEW && IS_FILE(currentListItem)) {
+    unsigned line,col,i;
+    CURRENT_VIEW->cursorPositionReal(&line,&col);
+    QString textLine=CURRENT_VIEW->getDoc()->textLine(line);
+    unsigned l=textLine.length();
+    bool quotesInLine=textLine.contains("\"");
+    QString fileName;
+    for (i=col;i<l;i--) {
+      QChar c=textLine[i];
+      if (!((quotesInLine && c==' ') || (c>='A' && c<="Z") || (c>='a' && c<='z')
+            || (c>='0' && c<='9') || QString("_-./\\:").contains(c)))
+        break;
+      fileName.prepend(c);
+    }
+    for (i=col+1;i<l;i++) {
+      QChar c=textLine[i];
+      if (!((quotesInLine && c==' ') || (c>='A' && c<="Z") || (c>='a' && c<='z')
+            || (c>='0' && c<='9') || QString("_-./\\:").contains(c)))
+        break;
+      fileName.append(c);
+    }
+    CATEGORY_OF(category,currentListItem);
+    findAndOpenFile(fileName,category);
+  }
 }
 
 void MainForm::findFindSymbolDeclaration()

+ 21 - 1
ktigcc/srcfilewin.ui.h

@@ -1031,7 +1031,27 @@ void SourceFileWindow::findFunctionsPopup_activated(int id)
 
 void SourceFileWindow::findOpenFileAtCursor()
 {
-  
+  unsigned line,col,i;
+  CURRENT_VIEW->cursorPositionReal(&line,&col);
+  QString textLine=CURRENT_VIEW->getDoc()->textLine(line);
+  unsigned l=textLine.length();
+  bool quotesInLine=textLine.contains("\"");
+  QString fileName;
+  for (i=col;i<l;i--) {
+    QChar c=textLine[i];
+    if (!((quotesInLine && c==' ') || (c>='A' && c<="Z") || (c>='a' && c<='z')
+          || (c>='0' && c<='9') || QString("_-./\\:").contains(c)))
+      break;
+    fileName.prepend(c);
+  }
+  for (i=col+1;i<l;i++) {
+    QChar c=textLine[i];
+    if (!((quotesInLine && c==' ') || (c>='A' && c<="Z") || (c>='a' && c<='z')
+          || (c>='0' && c<='9') || QString("_-./\\:").contains(c)))
+      break;
+    fileName.append(c);
+  }
+  THIS->mainForm->findAndOpenFile(fileName,THIS->category);
 }
 
 void SourceFileWindow::findFindSymbolDeclaration()