From 1c11fbe6451efc4ad98d7540f29bdddb6f3d3db3 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 15 Dec 2018 22:21:33 +0100 Subject: Add restore last tab shortcut --- src/mainwindow/menubar.cpp | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'src/mainwindow') diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp index bdfbd23..bc06f65 100644 --- a/src/mainwindow/menubar.cpp +++ b/src/mainwindow/menubar.cpp @@ -144,23 +144,22 @@ MenuBar::MenuBar(const Configuration *config, MainWindow *parent) auto *subwindow = this->addMenu(tr("Subwindow")); { auto *actionNewTab = subwindow->addAction(tr("New Tab"), parent, [parent]() { - auto *_subwindow = parent->currentSubWindow(); - if(_subwindow != nullptr) { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int) { const int index = _subwindow->addTab(); _subwindow->setCurrentTab(index); - } + }); }); config->setShortcut(actionNewTab, "subwindow.shortcuts.new"); subwindow->addSeparator(); - subwindow->addAction(tr("Restore last tab"), parent, [parent]() { - auto *_subwindow = parent->currentSubWindow(); - if(_subwindow != nullptr) { + auto *actionRestoreTab = subwindow->addAction(tr("Restore last tab"), parent, [parent]() { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int) { const int index = _subwindow->restoreLastTab(); _subwindow->setCurrentTab(index); - } + }); }); + config->setShortcut(actionRestoreTab, "subwindow.shortcuts.restoreTab"); auto *restoreTabsMenu = subwindow->addMenu(tr("Restore previous tab")); connect(restoreTabsMenu, &QMenu::aboutToShow, parent, [parent, restoreTabsMenu]() { @@ -178,34 +177,29 @@ MenuBar::MenuBar(const Configuration *config, MainWindow *parent) actionPinTab->setEnabled(false); auto *actionLockClose = subwindow->addAction(tr("Prevent tab from closing"), parent, [parent](bool checked) { - auto *_subwindow = parent->currentSubWindow(); - if(_subwindow != nullptr) { - const int idx = _subwindow->currentTabIndex(); - auto data = _subwindow->tabData(idx); + run_if(parent->currentSubWindow(), [checked](SubWindow *_subwindow, int currentIdx) { + auto data = _subwindow->tabData(currentIdx); data.closeLocked = checked; - _subwindow->setTabData(data, idx); - } + _subwindow->setTabData(data, currentIdx); + }); }); actionLockClose->setCheckable(true); auto *actionLockRefresh = subwindow->addAction(tr("Prevent tab from refreshing"), parent, [parent](bool checked) { - auto *_subwindow = parent->currentSubWindow(); - if(_subwindow != nullptr) { - const int idx = _subwindow->currentTabIndex(); - auto data = _subwindow->tabData(idx); + run_if(parent->currentSubWindow(), [checked](SubWindow *_subwindow, int currentIdx) { + auto data = _subwindow->tabData(currentIdx); data.refreshLocked = checked; - _subwindow->setTabData(data, idx); - } + _subwindow->setTabData(data, currentIdx); + }); }); actionLockRefresh->setCheckable(true); connect(subwindow, &QMenu::aboutToShow, subwindow, [=]() { - auto *_subwindow = parent->currentSubWindow(); - if(_subwindow != nullptr) { - auto data = _subwindow->tabData(_subwindow->currentTabIndex()); + run_if(parent->currentSubWindow(), [=](SubWindow *_subwindow, int currentIdx) { + auto data = _subwindow->tabData(currentIdx); actionLockClose->setChecked(data.closeLocked); actionLockRefresh->setChecked(data.refreshLocked); - } + }); }); subwindow->addSeparator()->setText(tr("Tab Actions")); -- cgit v1.2.1