Browse Source

Implement openHeader helper function for "Find symbol declaration".

git-svn-id: file:///var/svn/tigccpp/trunk@823 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 18 years ago
parent
commit
d1091524bc
2 changed files with 63 additions and 1 deletions
  1. 2 1
      ktigcc/mainform.ui
  2. 61 0
      ktigcc/mainform.ui.h

+ 2 - 1
ktigcc/mainform.ui

@@ -1740,8 +1740,9 @@
     <function access="private" specifier="non virtual">updateRightStatusLabel()</function>
     <function access="private" specifier="non virtual">current_view_newLineHook()</function>
     <function access="protected">closeEvent( QCloseEvent * e )</function>
+    <function access="private" specifier="non virtual" returnType="QString">pathInProject( QListViewItem * item )</function>
     <function returnType="QString">textForHeader( const QString &amp; fileName )</function>
-    <function access="private" specifier="non virtual" returnType="QString">pathInProject(QListViewItem *item)</function>
+    <function>openHeader(const QString &amp;fileName, bool systemHeader, unsigned lineno)</function>
 </functions>
 <pixmapinproject/>
 <layoutdefaults spacing="0" margin="0"/>

+ 61 - 0
ktigcc/mainform.ui.h

@@ -3282,6 +3282,67 @@ void MainForm::findOpenFileAtCursor()
   }
 }
 
+void MainForm::openHeader(const QString &fileName, bool systemHeader,
+                          unsigned lineno)
+{
+  if (systemHeader) {
+    // 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)) {
+      bool inProject;
+      void *sourceFile;
+      QString fileNameFull=QDir(QString("%1/include/c/").arg(tigcc_base))
+                           .filePath(fileName);
+      if (findSourceFile(inProject,sourceFile,fileNameFull)) {
+        if (inProject) {
+          fileTreeClicked(reinterpret_cast<ListViewFile *>(sourceFile));
+          if (reinterpret_cast<ListViewFile *>(sourceFile)->kateView)
+            reinterpret_cast<ListViewFile *>(sourceFile)->kateView->setCursorPositionReal(lineno,0);
+        } else {
+          reinterpret_cast<SourceFile *>(sourceFile)->kateView->setCursorPositionReal(lineno,0);
+          KWin::activateWindow(reinterpret_cast<SourceFile *>(sourceFile)->winId());
+        }
+      } else {
+        if (getPathType(fileNameFull)==PATH_FILE) {
+          openProject(fileNameFull);
+          if (findSourceFile(inProject,sourceFile,fileNameFull) && !inProject) {
+            reinterpret_cast<SourceFile *>(sourceFile)->kateView->setCursorPositionReal(lineno,0);
+            KWin::activateWindow(reinterpret_cast<SourceFile *>(sourceFile)->winId());
+          }
+        } else {
+          KMessageBox::error(this,QString("File \'%1\' not found.").arg(fileName),
+                             "Search Failed");
+        }
+      }
+    }
+  } else {
+    QString name=fileName;
+    int pos;
+    QListViewItem *item=hFilesListItem;
+    while ((pos=name.find('/'))>=0) {
+      QString folder=name.left(pos);
+      name.remove(0,pos+1);
+      for (item=item->firstChild();item;item=item->nextSibling()) {
+        if (IS_FOLDER(item)) {
+          if (item->text(0)==folder) break;
+        }
+      }
+      if (!item) return;
+    }
+    for (item=item->firstChild();item;item=item->nextSibling()) {
+      if (IS_FILE(item)) {
+        ListViewFile *fileItem=static_cast<ListViewFile *>(item);
+        if (QFileInfo(fileItem->fileName).fileName()==name) {
+          fileTreeClicked(item);
+          if (fileItem->kateView)
+            fileItem->kateView->setCursorPositionReal(lineno,0);
+          return;
+        }
+      }
+    }
+  }
+}
+
 void MainForm::findFindSymbolDeclaration()
 {