diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 3ea3b794..3aa16326 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -99,8 +99,10 @@ Editor::Editor(QWidget *parent, const QString& filename, } else { initParser(); } - mCompletionPopup = std::make_shared(); - mHeaderCompletionPopup = std::make_shared(); +// mCompletionPopup = std::make_shared(); +// mHeaderCompletionPopup = std::make_shared(); + mCompletionPopup = pMainWindow->completionPopup(); + mHeaderCompletionPopup = pMainWindow->headerCompletionPopup(); applySettings(); applyColorScheme(pSettings->editor().colorScheme()); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 09e09a50..da840358 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -122,6 +122,9 @@ MainWindow::MainWindow(QWidget *parent) //class browser ui->classBrowser->setModel(&mClassBrowserModel); + mCompletionPopup = std::make_shared(); + mHeaderCompletionPopup = std::make_shared(); + updateAppTitle(); } @@ -941,7 +944,17 @@ void MainWindow::prepareDebugger() // Reset watch vars -// mDebugger->deleteWatchVars(false); + // mDebugger->deleteWatchVars(false); +} + +const std::shared_ptr &MainWindow::headerCompletionPopup() const +{ + return mHeaderCompletionPopup; +} + +const std::shared_ptr &MainWindow::completionPopup() const +{ + return mCompletionPopup; } SearchDialog *MainWindow::searchDialog() const diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index fdde4479..f5763565 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -5,6 +5,8 @@ #include "common.h" #include "widgets/searchresultview.h" #include "widgets/classbrowser.h" +#include "widgets/codecompletionpopup.h" +#include "widgets/headercompletionpopup.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -91,6 +93,10 @@ public: + const std::shared_ptr &completionPopup() const; + + const std::shared_ptr &headerCompletionPopup() const; + protected: void openFiles(const QStringList& files); void openFile(const QString& filename); @@ -232,6 +238,9 @@ private: bool mQuitting; QElapsedTimer mParserTimer; + std::shared_ptr mCompletionPopup; + std::shared_ptr mHeaderCompletionPopup; + SearchResultModel mSearchResultModel; PSearchResultListModel mSearchResultListModel; PSearchResultTreeModel mSearchResultTreeModel; @@ -244,6 +253,7 @@ private: int mPreviousHeight; PCompileSuccessionTask mCompileSuccessionTask; + // QWidget interface protected: void closeEvent(QCloseEvent *event) override; diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index 0bfe34ce..40145a3e 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -105,6 +105,7 @@ bool CodeCompletionPopup::search(const QString &phrase, bool autoHideOnSingleRes setCursor(oldCursor); if (!mCompletionStatementList.isEmpty()) { + mListView->setCurrentIndex(mModel->index(0,0)); // if only one suggestion, and is exactly the symbol to search, hide the frame (the search is over) // if only one suggestion and auto hide , don't show the frame if(mCompletionStatementList.count() == 1) @@ -223,9 +224,9 @@ static bool sortByScopeComparator(PStatement statement1,PStatement statement2){ } else if (statement2->kind == StatementKind::skKeyword) { return false; // Show stuff from local headers first - } else if (statement1->inSystemHeader && !(statement2->inSystemHeader)) { - return true; } else if (!(statement1->inSystemHeader) && statement2->inSystemHeader) { + return true; + } else if (statement1->inSystemHeader && !(statement2->inSystemHeader)) { return false; // Show local statements first } else if (statement1->scope != StatementScope::ssGlobal @@ -254,11 +255,11 @@ static bool sortWithUsageComparator(PStatement statement1,PStatement statement2) } else if (statement1->freqTop < statement2->freqTop) { return false; // show keywords first - } else if ((statement1->kind == StatementKind::skKeyword) - && (statement2->kind != StatementKind::skKeyword)) { - return true; } else if ((statement1->kind != StatementKind::skKeyword) && (statement2->kind == StatementKind::skKeyword)) { + return true; + } else if ((statement1->kind == StatementKind::skKeyword) + && (statement2->kind != StatementKind::skKeyword)) { return false; } else return statement1->command < statement2->command; diff --git a/RedPandaIDE/widgets/headercompletionpopup.cpp b/RedPandaIDE/widgets/headercompletionpopup.cpp index 932335b2..5634496f 100644 --- a/RedPandaIDE/widgets/headercompletionpopup.cpp +++ b/RedPandaIDE/widgets/headercompletionpopup.cpp @@ -64,6 +64,7 @@ bool HeaderCompletionPopup::search(const QString &phrase, bool autoHideOnSingleR setCursor(oldCursor); if (!mCompletionList.isEmpty()) { + mListView->setCurrentIndex(mModel->index(0,0)); if (mCompletionList.count() == 1) { // if only one suggestion and auto hide , don't show the frame if (autoHideOnSingleResult) @@ -95,7 +96,9 @@ QString HeaderCompletionPopup::selectedFilename() int index = mListView->currentIndex().row(); if (index>=0 && index0) { + return mCompletionList.front(); + } return ""; }