Browse Source

Implement Functions dialog.

git-svn-id: file:///var/svn/tigccpp/trunk@700 9552661e-59e3-4036-b4f2-dbe53926924f
kevinkofler 18 years ago
parent
commit
3276320053
10 changed files with 316 additions and 16 deletions
  1. 4 2
      ktigcc/KTIGCC.prj
  2. 122 0
      ktigcc/functions.ui
  3. 37 0
      ktigcc/functions.ui.h
  4. 2 1
      ktigcc/ktigcc.pro
  5. 5 1
      ktigcc/mainform.ui
  6. 69 3
      ktigcc/mainform.ui.h
  7. 5 5
      ktigcc/parsing.h
  8. 2 0
      ktigcc/srcfile.h
  9. 5 1
      ktigcc/srcfilewin.ui
  10. 65 3
      ktigcc/srcfilewin.ui.h

+ 4 - 2
ktigcc/KTIGCC.prj

@@ -79,7 +79,8 @@ module.include.files=\
 	tiemu.h\
 	tiemu_stub.h\
 	callbacks.h\
-	parsing.h
+	parsing.h\
+	functions.ui.h
 
 module.source.name=.
 module.source.type=
@@ -99,7 +100,8 @@ module.source.files=\
 	programoutput.ui\
 	tiemu_stub.cpp\
 	callbacks.cpp\
-	parsing.cpp
+	parsing.cpp\
+	functions.ui
 
 module.pixmap.name=.
 module.pixmap.type=

+ 122 - 0
ktigcc/functions.ui

@@ -0,0 +1,122 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>FunctionDialog</class>
+<widget class="QDialog">
+    <property name="name">
+        <cstring>FunctionDialog</cstring>
+    </property>
+    <property name="geometry">
+        <rect>
+            <x>0</x>
+            <y>0</y>
+            <width>494</width>
+            <height>377</height>
+        </rect>
+    </property>
+    <property name="caption">
+        <string>Functions</string>
+    </property>
+    <hbox>
+        <property name="name">
+            <cstring>unnamed</cstring>
+        </property>
+        <widget class="QListBox">
+            <property name="name">
+                <cstring>functionListBox</cstring>
+            </property>
+        </widget>
+        <widget class="QLayoutWidget">
+            <property name="name">
+                <cstring>layout43</cstring>
+            </property>
+            <vbox>
+                <property name="name">
+                    <cstring>unnamed</cstring>
+                </property>
+                <widget class="KPushButton">
+                    <property name="name">
+                        <cstring>prototypeButton</cstring>
+                    </property>
+                    <property name="enabled">
+                        <bool>false</bool>
+                    </property>
+                    <property name="text">
+                        <string>&amp;Prototype</string>
+                    </property>
+                    <property name="accel">
+                        <string>Alt+P</string>
+                    </property>
+                </widget>
+                <widget class="KPushButton">
+                    <property name="name">
+                        <cstring>implementationButton</cstring>
+                    </property>
+                    <property name="enabled">
+                        <bool>false</bool>
+                    </property>
+                    <property name="text">
+                        <string>&amp;Implementation</string>
+                    </property>
+                    <property name="accel">
+                        <string>Alt+I</string>
+                    </property>
+                </widget>
+                <spacer>
+                    <property name="name">
+                        <cstring>spacer50</cstring>
+                    </property>
+                    <property name="orientation">
+                        <enum>Vertical</enum>
+                    </property>
+                    <property name="sizeType">
+                        <enum>Expanding</enum>
+                    </property>
+                    <property name="sizeHint">
+                        <size>
+                            <width>20</width>
+                            <height>331</height>
+                        </size>
+                    </property>
+                </spacer>
+                <widget class="KPushButton">
+                    <property name="name">
+                        <cstring>cancelButton</cstring>
+                    </property>
+                    <property name="text">
+                        <string>&amp;Cancel</string>
+                    </property>
+                    <property name="accel">
+                        <string>Alt+C</string>
+                    </property>
+                    <property name="autoDefault">
+                        <bool>true</bool>
+                    </property>
+                    <property name="stdItem" stdset="0">
+                        <number>2</number>
+                    </property>
+                </widget>
+            </vbox>
+        </widget>
+    </hbox>
+</widget>
+<connections>
+    <connection>
+        <sender>cancelButton</sender>
+        <signal>clicked()</signal>
+        <receiver>FunctionDialog</receiver>
+        <slot>reject()</slot>
+    </connection>
+</connections>
+<includes>
+    <include location="local" impldecl="in implementation">functions.ui.h</include>
+</includes>
+<slots>
+    <slot>accept()</slot>
+</slots>
+<pixmapinproject/>
+<layoutdefaults spacing="6" margin="11"/>
+<includehints>
+    <includehint>kpushbutton.h</includehint>
+    <includehint>kpushbutton.h</includehint>
+    <includehint>kpushbutton.h</includehint>
+</includehints>
+</UI>

+ 37 - 0
ktigcc/functions.ui.h

@@ -0,0 +1,37 @@
+/****************************************************************************
+** ui.h extension file, included from the uic-generated form implementation.
+**
+** If you want to add, delete, or rename functions or slots, use
+** Qt Designer to update this file, preserving your code.
+**
+** You should not define a constructor or destructor in this file.
+** Instead, write your code in functions called init() and destroy().
+** These will automatically be called by the form's constructor and
+** destructor.
+*****************************************************************************/
+
+/*
+   ktigcc - TIGCC IDE for KDE
+
+   Copyright (C) 2006 Kevin Kofler
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
+*/
+
+// Make this slot public.
+void FunctionDialog::accept()
+{
+  QDialog::accept();
+}

+ 2 - 1
ktigcc/ktigcc.pro

@@ -27,7 +27,8 @@ FORMS	= srcfilewin.ui \
 	preferencesdlg.ui \
 	mainform.ui \
 	errorlist.ui \
-	programoutput.ui
+	programoutput.ui \
+	functions.ui
 
 IMAGES	= images/00 \
 	images/01 \

+ 5 - 1
ktigcc/mainform.ui

@@ -1647,6 +1647,7 @@
     <slot>findFunctions()</slot>
     <slot>findFunctionsPopup_aboutToShow()</slot>
     <slot>findFunctionsPopup_aboutToHide()</slot>
+    <slot>findFunctionsPopup_aboutToHide_async()</slot>
     <slot>findFunctionsPopup_activated( int id )</slot>
     <slot>findOpenFileAtCursor()</slot>
     <slot>findFindSymbolDeclaration()</slot>
@@ -1694,7 +1695,10 @@
     <slot>clipboard_dataChanged()</slot>
     <slot>fileTreeItemRenamed( QListViewItem * item, const QString &amp; newName, int col )</slot>
     <slot>KDirWatch_dirty( const QString &amp; fileName )</slot>
-    <slot>findFunctionsPopup_aboutToHide_async()</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>

+ 69 - 3
ktigcc/mainform.ui.h

@@ -50,6 +50,7 @@
 #include <qstylesheet.h>
 #include <qtimer.h>
 #include <qtoolbutton.h>
+#include <qlistbox.h>
 #include <kapplication.h>
 #include <kparts/factory.h>
 #include <klibloader.h>
@@ -76,6 +77,7 @@
 #include <kshell.h>
 #include <ktextbrowser.h>
 #include <krun.h>
+#include <kpushbutton.h>
 #include <dcopclient.h>
 #include <cstdio>
 #include <cstdlib>
@@ -96,6 +98,7 @@
 #include "tiemu.h"
 #include "callbacks.h"
 #include "parsing.h"
+#include "functions.h"
 
 using std::puts;
 using std::exit;
@@ -3041,10 +3044,74 @@ void MainForm::findReplace_stop()
 }
 
 static SourceFileFunctions sourceFileFunctions;
+static FunctionDialog *functionDialog;
 
 void MainForm::findFunctions()
 {
-  
+  if (CURRENT_VIEW) {
+    functionDialog=new FunctionDialog(this);
+    connect(functionDialog->functionListBox,SIGNAL(highlighted(int)),
+            this,SLOT(findFunctions_functionListBox_highlighted(int)));
+    connect(functionDialog->functionListBox,SIGNAL(selected(int)),
+            this,SLOT(findFunctions_functionListBox_selected(int)));
+    connect(functionDialog->prototypeButton,SIGNAL(clicked()),
+            this,SLOT(findFunctions_prototypeButton_clicked()));
+    connect(functionDialog->implementationButton,SIGNAL(clicked()),
+            this,SLOT(findFunctions_implementationButton_clicked()));
+    functionDialog->functionListBox->clear();
+    CATEGORY_OF(category,currentListItem);
+    sourceFileFunctions=getFunctions(CURRENT_VIEW->getDoc()->text(),
+      category==asmFilesListItem||category==sFilesListItem);
+    for (SourceFileFunctions::Iterator it=sourceFileFunctions.begin();
+         it!=sourceFileFunctions.end(); ++it)
+      functionDialog->functionListBox->insertItem((*it).name);
+    functionDialog->exec();
+    delete functionDialog;
+  }
+}
+
+void MainForm::findFunctions_functionListBox_highlighted(int index)
+{
+  if (index>=0) {
+    functionDialog->prototypeButton->setEnabled(
+      sourceFileFunctions[index].prototypeLine>=0);
+    functionDialog->implementationButton->setEnabled(
+      sourceFileFunctions[index].implementationLine>=0);
+  } else {
+    functionDialog->prototypeButton->setEnabled(FALSE);
+    functionDialog->implementationButton->setEnabled(FALSE);
+  }
+}
+
+void MainForm::findFunctions_functionListBox_selected(int index)
+{
+  if (index>=0) {
+    int line=sourceFileFunctions[index].implementationLine>=0
+             ?sourceFileFunctions[index].implementationLine
+             :sourceFileFunctions[index].prototypeLine;
+    CURRENT_VIEW->setCursorPositionReal(line,0);
+    functionDialog->accept();
+  }
+}
+
+void MainForm::findFunctions_prototypeButton_clicked()
+{
+  int index=functionDialog->functionListBox->currentItem();
+  if (index>=0 && sourceFileFunctions[index].prototypeLine>=0) {
+    CURRENT_VIEW->setCursorPositionReal(
+      sourceFileFunctions[index].prototypeLine,0);
+    functionDialog->accept();
+  }
+}
+
+void MainForm::findFunctions_implementationButton_clicked()
+{
+  int index=functionDialog->functionListBox->currentItem();
+  if (index>=0 && sourceFileFunctions[index].implementationLine>=0) {
+    CURRENT_VIEW->setCursorPositionReal(
+      sourceFileFunctions[index].implementationLine,0);
+    functionDialog->accept();
+  }
 }
 
 void MainForm::findFunctionsPopup_aboutToShow()
@@ -3056,9 +3123,8 @@ void MainForm::findFunctionsPopup_aboutToShow()
       category==asmFilesListItem||category==sFilesListItem);
     int idx=0;
     for (SourceFileFunctions::Iterator it=sourceFileFunctions.begin();
-         it!=sourceFileFunctions.end(); ++it,++idx) {
+         it!=sourceFileFunctions.end(); ++it,++idx)
       findFunctionsPopup->insertItem((*it).name,idx);
-    }
   }
 }
 

+ 5 - 5
ktigcc/parsing.h

@@ -23,16 +23,16 @@
 #include <qstring.h>
 #include <qvaluelist.h>
 struct SourceFileFunction {
-  SourceFileFunction() : name(), implementationLine(-1), prototypeLine(-1) {}
+  SourceFileFunction() : name(), prototypeLine(-1), implementationLine(-1) {}
   SourceFileFunction(const QString &n) :
-    name(n), implementationLine(-1), prototypeLine(-1) {}
-  SourceFileFunction(const QString &n, int i, int p) :
-    name(n), implementationLine(i), prototypeLine(p) {}
+    name(n), prototypeLine(-1), implementationLine(-1) {}
+  SourceFileFunction(const QString &n, int p, int i) :
+    name(n), prototypeLine(p), implementationLine(i) {}
   bool operator==(const SourceFileFunction &other) const
     {return name==other.name;}
   QString name;
-  int implementationLine;
   int prototypeLine;
+  int implementationLine;
 };
 typedef QValueList<SourceFileFunction> SourceFileFunctions;
 SourceFileFunctions getCFunctions(const QString &text);

+ 2 - 0
ktigcc/srcfile.h

@@ -36,6 +36,7 @@ class QClipboard;
 class QAccel;
 class KFindDialog;
 class KDirWatch;
+class FunctionDialog;
 
 struct SourceFile : public SourceFileWindow {
   SourceFile(MainForm *mainfrm, const QString &fn, const QString &ft,
@@ -70,4 +71,5 @@ struct SourceFile : public SourceFileWindow {
   KDirWatch *dirWatch;
   QPopupMenu *findFunctionsPopup;
   SourceFileFunctions sourceFileFunctions;
+  FunctionDialog *functionDialog;
 };

+ 5 - 1
ktigcc/srcfilewin.ui

@@ -646,6 +646,7 @@
     <slot>findFunctions()</slot>
     <slot>findFunctionsPopup_aboutToShow()</slot>
     <slot>findFunctionsPopup_aboutToHide()</slot>
+    <slot>findFunctionsPopup_aboutToHide_async()</slot>
     <slot>findFunctionsPopup_activated( int id )</slot>
     <slot>findOpenFileAtCursor()</slot>
     <slot>findFindSymbolDeclaration()</slot>
@@ -658,7 +659,10 @@
     <slot>current_view_charactersInteractivelyInserted( int line, int col, const QString &amp; characters )</slot>
     <slot>clipboard_dataChanged()</slot>
     <slot>KDirWatch_dirty( const QString &amp; fileName )</slot>
-    <slot>findFunctionsPopup_aboutToHide_async()</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>initBase()</function>

+ 65 - 3
ktigcc/srcfilewin.ui.h

@@ -42,6 +42,7 @@
 #include <qeventloop.h>
 #include <qlayout.h>
 #include <qtoolbutton.h>
+#include <qlistbox.h>
 #include <kparts/factory.h>
 #include <klibloader.h>
 #include <kate/document.h>
@@ -61,6 +62,7 @@
 #include <kglobal.h>
 #include <kicontheme.h>
 #include <kiconloader.h>
+#include <kpushbutton.h>
 #include <cstdio>
 #include <cstdlib>
 #include "ktigcc.h"
@@ -69,6 +71,7 @@
 #include "preferences.h"
 #include "projectoptions.h"
 #include "srcfile.h"
+#include "functions.h"
 
 using std::puts;
 using std::exit;
@@ -940,7 +943,67 @@ void SourceFileWindow::findReplace_stop()
 
 void SourceFileWindow::findFunctions()
 {
-  
+  THIS->functionDialog=new FunctionDialog(this);
+  connect(THIS->functionDialog->functionListBox,SIGNAL(highlighted(int)),
+          this,SLOT(findFunctions_functionListBox_highlighted(int)));
+  connect(THIS->functionDialog->functionListBox,SIGNAL(selected(int)),
+          this,SLOT(findFunctions_functionListBox_selected(int)));
+  connect(THIS->functionDialog->prototypeButton,SIGNAL(clicked()),
+          this,SLOT(findFunctions_prototypeButton_clicked()));
+  connect(THIS->functionDialog->implementationButton,SIGNAL(clicked()),
+          this,SLOT(findFunctions_implementationButton_clicked()));
+  THIS->functionDialog->functionListBox->clear();
+  THIS->sourceFileFunctions=getFunctions(CURRENT_VIEW->getDoc()->text(),
+                                         THIS->isASMFile);
+  for (SourceFileFunctions::Iterator it=THIS->sourceFileFunctions.begin();
+       it!=THIS->sourceFileFunctions.end(); ++it)
+    THIS->functionDialog->functionListBox->insertItem((*it).name);
+  THIS->functionDialog->exec();
+  delete THIS->functionDialog;
+}
+
+void SourceFileWindow::findFunctions_functionListBox_highlighted(int index)
+{
+  if (index>=0) {
+    THIS->functionDialog->prototypeButton->setEnabled(
+      THIS->sourceFileFunctions[index].prototypeLine>=0);
+    THIS->functionDialog->implementationButton->setEnabled(
+      THIS->sourceFileFunctions[index].implementationLine>=0);
+  } else {
+    THIS->functionDialog->prototypeButton->setEnabled(FALSE);
+    THIS->functionDialog->implementationButton->setEnabled(FALSE);
+  }
+}
+
+void SourceFileWindow::findFunctions_functionListBox_selected(int index)
+{
+  if (index>=0) {
+    int line=THIS->sourceFileFunctions[index].implementationLine>=0
+             ?THIS->sourceFileFunctions[index].implementationLine
+             :THIS->sourceFileFunctions[index].prototypeLine;
+    CURRENT_VIEW->setCursorPositionReal(line,0);
+    THIS->functionDialog->accept();
+  }
+}
+
+void SourceFileWindow::findFunctions_prototypeButton_clicked()
+{
+  int index=THIS->functionDialog->functionListBox->currentItem();
+  if (index>=0 && THIS->sourceFileFunctions[index].prototypeLine>=0) {
+    CURRENT_VIEW->setCursorPositionReal(
+      THIS->sourceFileFunctions[index].prototypeLine,0);
+    THIS->functionDialog->accept();
+  }
+}
+
+void SourceFileWindow::findFunctions_implementationButton_clicked()
+{
+  int index=THIS->functionDialog->functionListBox->currentItem();
+  if (index>=0 && THIS->sourceFileFunctions[index].implementationLine>=0) {
+    CURRENT_VIEW->setCursorPositionReal(
+      THIS->sourceFileFunctions[index].implementationLine,0);
+    THIS->functionDialog->accept();
+  }
 }
 
 void SourceFileWindow::findFunctionsPopup_aboutToShow()
@@ -950,9 +1013,8 @@ void SourceFileWindow::findFunctionsPopup_aboutToShow()
                                          THIS->isASMFile);
   int idx=0;
   for (SourceFileFunctions::Iterator it=THIS->sourceFileFunctions.begin();
-       it!=THIS->sourceFileFunctions.end(); ++it,++idx) {
+       it!=THIS->sourceFileFunctions.end(); ++it,++idx)
     THIS->findFunctionsPopup->insertItem((*it).name,idx);
-  }
 }
 
 void SourceFileWindow::findFunctionsPopup_aboutToHide()