From 2ab5efc6feffffc24af9977028a8e79d034e799a Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sat, 7 Jan 2023 20:04:51 +0800 Subject: [PATCH] - fix: "Goto declaration" / "Goto definition" / "Find occurences" not correctly disabled for non-c/c++ files. --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 11 +++-------- RedPandaIDE/editor.h | 2 +- RedPandaIDE/mainwindow.cpp | 16 +++++++++------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/NEWS.md b/NEWS.md index d92dc8c3..07f9fd39 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,6 +18,7 @@ Red Panda C++ Version 2.8 - enhancement: Print syntax colored content. - enhancement: Correctly handle tab in the exported RTF. - change: Disable undo limit by default. + - fix: "Goto declaration" / "Goto definition" / "Find occurences" not correctly disabled for non-c/c++ files. Red Panda C++ Version 2.7 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 5cce39e6..bc073584 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -4131,15 +4131,8 @@ void Editor::gotoDeclaration(const QSynedit::BufferCoord &pos) filename(), expression, pos.line); -// QString phrase = getWordAtPosition(this,pos,pBeginPos,pEndPos, WordPurpose::wpInformation); -// if (phrase.isEmpty()) -// return; - -// PStatement statement = mParser->findStatementOf( -// mFilename,phrase,pos.Line); if (!statement) { -// pMainWindow->updateStatusbarMessage(tr("Symbol '%1' not found!").arg(phrase)); return; } QString filename; @@ -4159,6 +4152,8 @@ void Editor::gotoDeclaration(const QSynedit::BufferCoord &pos) void Editor::gotoDefinition(const QSynedit::BufferCoord &pos) { + if (!parser()) + return; QStringList expression = getExpressionAtPosition(pos); // Find it's definition @@ -4587,7 +4582,7 @@ void Editor::checkSyntaxInBack() pMainWindow->checkSyntaxInBack(this); } -const PCppParser &Editor::parser() +const PCppParser &Editor::parser() const { return mParser; } diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 8b815371..d2e00e1c 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -229,7 +229,7 @@ public: const QSynedit::BufferCoord& pos); void resetBookmarks(); - const PCppParser &parser(); + const PCppParser &parser() const; void tab() override; signals: diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 3c4ac922..87068914 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -576,6 +576,10 @@ void MainWindow::updateEditorActions(const Editor *e) ui->actionGo_to_Line->setEnabled(false); ui->actionLocate_in_Files_View->setEnabled(false); ui->actionToggle_Readonly->setEnabled(false); + + ui->actionGoto_Declaration->setEnabled(false); + ui->actionGoto_Definition->setEnabled(false); + ui->actionFind_references->setEnabled(false); } else { ui->actionAuto_Detect->setEnabled(true); ui->actionEncode_in_ANSI->setEnabled(true); @@ -632,6 +636,11 @@ void MainWindow::updateEditorActions(const Editor *e) ui->actionGo_to_Line->setEnabled(true); ui->actionLocate_in_Files_View->setEnabled(!e->isNew()); ui->actionToggle_Readonly->setEnabled(!e->modified()); + + //these actions needs parser + ui->actionGoto_Declaration->setEnabled(e->parser()!=nullptr); + ui->actionGoto_Definition->setEnabled(e->parser()!=nullptr); + ui->actionFind_references->setEnabled(e->parser()!=nullptr); } updateCompileActions(e); @@ -4785,13 +4794,6 @@ void MainWindow::onEditorContextMenu(const QPoint& pos) menu.addAction(ui->actionGo_to_Line); menu.addSeparator(); menu.addAction(ui->actionFile_Properties); - - //these actions needs parser - if (editor->parser() && editor->parser()->enabled()) { - ui->actionGoto_Declaration->setEnabled(!editor->parser()->parsing()); - ui->actionGoto_Definition->setEnabled(!editor->parser()->parsing()); - ui->actionFind_references->setEnabled(!editor->parser()->parsing()); - } } else { //mouse on gutter