diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 35bbe5e7..abc2013e 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -79,7 +79,7 @@ Editor::Editor(QWidget *parent, const QString& filename, } QFileInfo fileInfo(mFilename); if (mParentPageControl!=nullptr) { - mParentPageControl->addTab(this,QString()); + int index = mParentPageControl->addTab(this,QString()); updateCaption(); } @@ -132,6 +132,10 @@ Editor::Editor(QWidget *parent, const QString& filename, this, &Editor::onLinesDeleted); connect(this,&SynEdit::linesInserted, this, &Editor::onLinesInserted); + + setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, &QWidget::customContextMenuRequested, + pMainWindow, &MainWindow::onEditorContextMenu); } Editor::~Editor() { diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index 14e79fef..228c18ee 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -164,6 +164,26 @@ int EditorList::pageCount() return mLeftPageWidget->count()+mRightPageWidget->count(); } +void EditorList::selectNextPage() +{ + QTabWidget * pageControl = getFocusedPageControl(); + if (pageControl && pageControl->count()>0) { + pageControl->setCurrentIndex( + (pageControl->currentIndex()+1) % pageControl->count() + ); + } +} + +void EditorList::selectPreviousPage() +{ + QTabWidget * pageControl = getFocusedPageControl(); + if (pageControl && pageControl->count()>0) { + pageControl->setCurrentIndex( + (pageControl->currentIndex()+pageControl->count()-1) % pageControl->count() + ); + } +} + Editor *EditorList::operator[](int index) { if (index>=0 && indexcount()) { diff --git a/RedPandaIDE/editorlist.h b/RedPandaIDE/editorlist.h index 4c05da6e..79b210b0 100644 --- a/RedPandaIDE/editorlist.h +++ b/RedPandaIDE/editorlist.h @@ -44,6 +44,8 @@ public: void applyColorSchemes(const QString& name); bool isFileOpened(const QString& name); int pageCount(); + void selectNextPage(); + void selectPreviousPage(); Editor* operator[](int index); diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index acacc2b4..c72f3e21 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -136,6 +136,9 @@ MainWindow::MainWindow(QWidget *parent) this, &MainWindow::onAutoSaveTimeout); resetAutoSaveTimer(); + connect(ui->menuFile, &QMenu::aboutToShow, + this,&MainWindow::rebuildOpenedFileHisotryMenu); + buildContextMenus(); } @@ -1082,11 +1085,10 @@ void MainWindow::doAutoSave(Editor *e) void MainWindow::buildContextMenus() { - ui->watchView->setContextMenuPolicy(Qt::ActionsContextMenu); - ui->watchView->addAction(ui->actionAdd_Watch); - ui->watchView->addAction(ui->actionRemove_Watch); - ui->watchView->addAction(ui->actionRemove_All_Watches); - ui->watchView->addAction(ui->actionModify_Watch); + ui->watchView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->watchView,&QWidget::customContextMenuRequested, + this, &MainWindow::onWatchViewContextMenu); + } void MainWindow::maximizeEditor() @@ -1126,6 +1128,34 @@ void MainWindow::onAutoSaveTimeout() updateStatusbarMessage(tr("%1 files autosaved").arg(updateCount)); } +void MainWindow::onWatchViewContextMenu(const QPoint &pos) +{ + QMenu menu(this); + menu.addAction(ui->actionAdd_Watch); + menu.addAction(ui->actionRemove_Watch); + menu.addAction(ui->actionRemove_All_Watches); + menu.addAction(ui->actionModify_Watch); + menu.exec(ui->watchView->mapToGlobal(pos)); +} + +void MainWindow::onEditorContextMenu(const QPoint &pos) +{ + Editor * editor = mEditorList->getEditor(); + if (!editor) + return; + QMenu menu(this); + menu.addAction(ui->actionCompile_Run); + menu.addAction(ui->actionDebug); + int line = editor->caretY(); + if (editor->hasBreakpoint(line)) { + //todo: breakpoint property + } + //todo: goto declaretion + //todo: goto definition + menu.exec(editor->viewport()->mapToGlobal(pos)); + +} + void MainWindow::onFileChanged(const QString &path) { Editor *e = mEditorList->getOpenedEditorByFilename(path); @@ -2096,3 +2126,15 @@ void MainWindow::on_actionMaximize_Editor_triggered() maximizeEditor(); } + +void MainWindow::on_actionNext_Editor_triggered() +{ + mEditorList->selectNextPage(); +} + + +void MainWindow::on_actionPrevious_Editor_triggered() +{ + mEditorList->selectPreviousPage(); +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index a63108fb..e97ebcc8 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -118,6 +118,7 @@ public slots: void onStartParsing(); void onEndParsing(int total, int updateView); void onEvalValueReady(const QString& value); + void onEditorContextMenu(const QPoint& pos); private: void openFiles(const QStringList& files); @@ -134,6 +135,7 @@ private: private slots: void onAutoSaveTimeout(); + void onWatchViewContextMenu(const QPoint& pos); void onFileChanged(const QString& path); void on_actionNew_triggered(); @@ -258,6 +260,10 @@ private slots: void on_actionMaximize_Editor_triggered(); + void on_actionNext_Editor_triggered(); + + void on_actionPrevious_Editor_triggered(); + private: Ui::MainWindow *ui; EditorList *mEditorList; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index b3433fcc..bfb5264e 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -751,7 +751,7 @@ 0 0 946 - 22 + 25 @@ -843,6 +843,9 @@ + + + @@ -1476,6 +1479,32 @@ Ctrl+F11 + + + + :/icons/images/newlook24/038-Forward.png + + + + Next + + + Ctrl+Tab + + + + + + :/icons/images/newlook24/006-Back.png + + + + Previous + + + Ctrl+Shift+Tab + +