feature: next / previous editor

fix: history file menu not get updated
This commit is contained in:
royqh1979@gmail.com 2021-09-03 00:26:49 +08:00
parent 2471259a41
commit 56ff4a6c35
6 changed files with 110 additions and 7 deletions

View File

@ -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() {

View File

@ -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 && index<mLeftPageWidget->count()) {

View File

@ -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);

View File

@ -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();
}

View File

@ -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;

View File

@ -751,7 +751,7 @@
<x>0</x>
<y>0</y>
<width>946</width>
<height>22</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -843,6 +843,9 @@
</property>
<addaction name="actionClose_All"/>
<addaction name="actionMaximize_Editor"/>
<addaction name="separator"/>
<addaction name="actionNext_Editor"/>
<addaction name="actionPrevious_Editor"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
@ -1476,6 +1479,32 @@
<string>Ctrl+F11</string>
</property>
</action>
<action name="actionNext_Editor">
<property name="icon">
<iconset>
<normalon>:/icons/images/newlook24/038-Forward.png</normalon>
</iconset>
</property>
<property name="text">
<string>Next</string>
</property>
<property name="shortcut">
<string>Ctrl+Tab</string>
</property>
</action>
<action name="actionPrevious_Editor">
<property name="icon">
<iconset>
<normalon>:/icons/images/newlook24/006-Back.png</normalon>
</iconset>
</property>
<property name="text">
<string>Previous</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+Tab</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>