diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h
index f6d916fa..aec3da4f 100644
--- a/RedPandaIDE/editor.h
+++ b/RedPandaIDE/editor.h
@@ -144,6 +144,8 @@ public:
QString getPreviousWordAtPositionForSuggestion(const BufferCoord& p);
void reformat();
void checkSyntaxInBack();
+ void gotoDeclaration(const BufferCoord& pos);
+ void gotoDefinition(const BufferCoord& pos);
const PCppParser &parser() const;
@@ -197,8 +199,6 @@ private:
QString getHintForFunction(const PStatement& statement, const PStatement& scope,
const QString& filename, int line);
- void gotoDeclaration(const BufferCoord& pos);
- void gotoDefinition(const BufferCoord& pos);
private:
static int newfileCount;
diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp
index 00ee33b1..757bb27e 100644
--- a/RedPandaIDE/mainwindow.cpp
+++ b/RedPandaIDE/mainwindow.cpp
@@ -1151,6 +1151,9 @@ void MainWindow::onEditorContextMenu(const QPoint &pos)
menu.addAction(ui->actionCompile_Run);
menu.addAction(ui->actionDebug);
menu.addSeparator();
+ menu.addAction(ui->actionGoto_Declaration);
+ menu.addAction(ui->actionGoto_Definition);
+ menu.addAction(ui->actionFind_references);
} else {
//mouse on gutter
int line;
@@ -2183,3 +2186,23 @@ void MainWindow::on_actionBreakpoint_property_triggered()
}
+
+void MainWindow::on_actionGoto_Declaration_triggered()
+{
+ Editor * editor = mEditorList->getEditor();
+ BufferCoord pos;
+ if (editor && editor->PointToCharLine(mContextMenuPos,pos)) {
+ editor->gotoDeclaration(pos);
+ }
+}
+
+
+void MainWindow::on_actionGoto_Definition_triggered()
+{
+ Editor * editor = mEditorList->getEditor();
+ BufferCoord pos;
+ if (editor && editor->PointToCharLine(mContextMenuPos,pos)) {
+ editor->gotoDefinition(pos);
+ }
+}
+
diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h
index 294bce4b..40ca89de 100644
--- a/RedPandaIDE/mainwindow.h
+++ b/RedPandaIDE/mainwindow.h
@@ -270,6 +270,10 @@ private slots:
void on_actionBreakpoint_property_triggered();
+ void on_actionGoto_Declaration_triggered();
+
+ void on_actionGoto_Definition_triggered();
+
private:
Ui::MainWindow *ui;
EditorList *mEditorList;
diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui
index d5dfb2ed..853fb0b8 100644
--- a/RedPandaIDE/mainwindow.ui
+++ b/RedPandaIDE/mainwindow.ui
@@ -1537,6 +1537,21 @@
Breakpoint property...
+
+
+ Goto Declaration
+
+
+
+
+ Goto Definition
+
+
+
+
+ Find references
+
+
diff --git a/RedPandaIDE/widgets/searchresultview.cpp b/RedPandaIDE/widgets/searchresultview.cpp
index 9a45e11a..3abf0a5d 100644
--- a/RedPandaIDE/widgets/searchresultview.cpp
+++ b/RedPandaIDE/widgets/searchresultview.cpp
@@ -9,7 +9,8 @@ PSearchResults SearchResultModel::addSearchResults(const QString &keyword, SynSe
int index=-1;
for (int i=0;ikeyword == keyword && results->scope == scope) {
+ if (results->keyword == keyword && results->scope == scope
+ && results->searchType == SearchType::Search) {
index=i;
break;
}
@@ -24,6 +25,36 @@ PSearchResults SearchResultModel::addSearchResults(const QString &keyword, SynSe
results->keyword = keyword;
results->options = options;
results->scope = scope;
+ results->searchType = SearchType::Search;
+ mSearchResults.push_front(results);
+ mCurrentIndex = 0;
+ return results;
+}
+
+PSearchResults SearchResultModel::addSearchResults(const QString &keyword, const QString &filename, int symbolLine)
+{
+ int index=-1;
+ for (int i=0;isearchType == SearchType::FindOccurences
+ && results->keyword == keyword
+ && results->filename == filename
+ && results->symbolLine == symbolLine) {
+ index=i;
+ break;
+ }
+ }
+ if (index>=0) {
+ mSearchResults.removeAt(index);
+ }
+ if (mSearchResults.size()>=MAX_SEARCH_RESULTS) {
+ mSearchResults.pop_back();
+ }
+ PSearchResults results = std::make_shared();
+ results->keyword = keyword;
+ results->filename = filename;
+ results->symbolLine = symbolLine;
+ results->searchType = SearchType::FindOccurences;
mSearchResults.push_front(results);
mCurrentIndex = 0;
return results;
@@ -147,7 +178,7 @@ int SearchResultTreeModel::rowCount(const QModelIndex &parent) const
return item->results.count();
}
-int SearchResultTreeModel::columnCount(const QModelIndex &parent) const
+int SearchResultTreeModel::columnCount(const QModelIndex &) const
{
return 1;
}
@@ -199,7 +230,7 @@ SearchResultListModel::SearchResultListModel(SearchResultModel *model, QObject *
this, &SearchResultListModel::onResultModelChanged);
}
-int SearchResultListModel::rowCount(const QModelIndex &parent) const
+int SearchResultListModel::rowCount(const QModelIndex &) const
{
return mSearchResultModel->resultsCount();
}
@@ -212,13 +243,20 @@ QVariant SearchResultListModel::data(const QModelIndex &index, int role) const
PSearchResults results = mSearchResultModel->results(index.row());
if (!results)
return QVariant();
- switch (results->scope) {
- case SearchFileScope::currentFile:
- return tr("Current File:") + QString(" \"%1\"").arg(results->keyword);
- case SearchFileScope::wholeProject:
- return tr("Files In Project:") + QString(" \"%1\"").arg(results->keyword);
- case SearchFileScope::openedFiles:
- return tr("Open Files:") + QString(" \"%1\"").arg(results->keyword);
+ if (results->searchType == SearchType::Search) {
+ switch (results->scope) {
+ case SearchFileScope::currentFile:
+ return tr("Current File:") + QString(" \"%1\"").arg(results->keyword);
+ case SearchFileScope::wholeProject:
+ return tr("Files In Project:") + QString(" \"%1\"").arg(results->keyword);
+ case SearchFileScope::openedFiles:
+ return tr("Open Files:") + QString(" \"%1\"").arg(results->keyword);
+ }
+ } else if (results->searchType == SearchType::FindOccurences) {
+ return tr("References to symbol \'%1\' at '%2':%3")
+ .arg(results->keyword)
+ .arg(baseFileName(results->filename))
+ .arg(results->symbolLine);
}
}
return QVariant();
diff --git a/RedPandaIDE/widgets/searchresultview.h b/RedPandaIDE/widgets/searchresultview.h
index 648b2e48..7db81968 100644
--- a/RedPandaIDE/widgets/searchresultview.h
+++ b/RedPandaIDE/widgets/searchresultview.h
@@ -13,6 +13,11 @@ using PSearchResultTreeItem = std::shared_ptr;
using SearchResultTreeItemList = QList;
using PSearchResultTreeItemList = std::shared_ptr;
+enum class SearchType {
+ Search,
+ FindOccurences
+};
+
struct SearchResultTreeItem {
QString filename;
int line;
@@ -23,12 +28,13 @@ struct SearchResultTreeItem {
SearchResultTreeItemList results;
};
-
-
struct SearchResults{
SynSearchOptions options;
QString keyword;
SearchFileScope scope;
+ SearchType searchType;
+ QString filename;
+ int symbolLine;
QList results;
};
@@ -40,6 +46,10 @@ public:
explicit SearchResultModel(QObject* parent=nullptr);
PSearchResults addSearchResults(const QString& keyword,SynSearchOptions options,
SearchFileScope scope);
+ PSearchResults addSearchResults(
+ const QString& keyword,
+ const QString& filename,
+ int symbolLine);
PSearchResults results(int index);
void notifySearchResultsUpdated();
int currentIndex() const;