diff options
Diffstat (limited to 'src/mainwindow/menubar.cpp')
-rw-r--r-- | src/mainwindow/menubar.cpp | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp index 84ce24f..bdfbd23 100644 --- a/src/mainwindow/menubar.cpp +++ b/src/mainwindow/menubar.cpp @@ -27,6 +27,13 @@ #include <QPrinter> #include <QPrinterInfo> #include <QWidgetAction> +#include <functional> + +inline void run_if(SubWindow *_subwindow, std::function<void(SubWindow*, int)> f) +{ + if(_subwindow != nullptr) + f(_subwindow, _subwindow->currentTabIndex()); +} MenuBar::MenuBar(const Configuration *config, MainWindow *parent) : QMenuBar(parent) @@ -164,6 +171,144 @@ MenuBar::MenuBar(const Configuration *config, MainWindow *parent) } }); + subwindow->addSeparator()->setText(tr("Tab Settings")); + + auto *actionPinTab = subwindow->addAction(tr("Pin tab")); + actionPinTab->setCheckable(true); + 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); + data.closeLocked = checked; + _subwindow->setTabData(data, idx); + } + }); + 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); + data.refreshLocked = checked; + _subwindow->setTabData(data, idx); + } + }); + actionLockRefresh->setCheckable(true); + + connect(subwindow, &QMenu::aboutToShow, subwindow, [=]() { + auto *_subwindow = parent->currentSubWindow(); + if(_subwindow != nullptr) { + auto data = _subwindow->tabData(_subwindow->currentTabIndex()); + actionLockClose->setChecked(data.closeLocked); + actionLockRefresh->setChecked(data.refreshLocked); + } + }); + + subwindow->addSeparator()->setText(tr("Tab Actions")); + + auto *leftTab = subwindow->addAction(tr("Switch to tab on the left"), parent, [parent]() { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { + _subwindow->setCurrentTab(qMax(0, currentIdx - 1)); + }); + }); + config->setShortcut(leftTab, "subwindow.shortcuts.left"); + + auto *moveTabLeft = subwindow->addAction(tr("Move tab left"), parent, [parent]() { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { + _subwindow->moveTab(currentIdx, currentIdx - 1); + }); + }); + config->setShortcut(moveTabLeft, "subwindow.shortcuts.moveLeft"); + + auto *rightTab = subwindow->addAction(tr("Switch to tab on the right"), parent, [parent]() { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { + _subwindow->setCurrentTab(qMin(currentIdx + 1, _subwindow->tabCount() - 1)); + }); + }); + config->setShortcut(rightTab, "subwindow.shortcuts.right"); + + auto *moveTabRight = subwindow->addAction(tr("Move tab right"), parent, [parent]() { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { + _subwindow->moveTab(currentIdx, currentIdx + 1); + }); + }); + config->setShortcut(moveTabRight, "subwindow.shortcuts.moveRight"); + + subwindow->addSeparator(); + + auto *closeTab = subwindow->addAction(tr("Close tab"), parent, [parent]() { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { + _subwindow->closeTab(currentIdx); + }); + }); + config->setShortcut(closeTab, "subwindow.shortcuts.close"); + + subwindow->addAction(tr("Close tabs to the left"), parent, [parent]() { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { + for(int i = currentIdx - 1; i >= 0; i--) { + const auto data = _subwindow->tabData(i); + if(!data.closeLocked) + _subwindow->closeTab(i); + } + }); + }); + subwindow->addAction(tr("Close tabs to the right"), parent, [parent]() { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { + for(int i = _subwindow->tabCount() - 1; i > currentIdx; i--) { + const auto data = _subwindow->tabData(i); + if(!data.closeLocked) + _subwindow->closeTab(i); + } + }); + }); + subwindow->addAction(tr("Close all other tabs"), parent, [parent]() { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { + for(int i = _subwindow->tabCount() -1; i >= 0; i--) { + if(i != currentIdx) { + const auto data = _subwindow->tabData(i); + if(!data.closeLocked) + _subwindow->closeTab(i); + } + } + }); + }); + + subwindow->addSeparator(); + + subwindow->addAction(tr("Refresh tabs to the left"), parent, [parent]() { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { + for(int i = 0; i < currentIdx; i++) { + const auto data = _subwindow->tabData(i); + if(!data.refreshLocked) + _subwindow->view(i)->triggerPageAction(QWebEnginePage::Reload); + } + }); + }); + subwindow->addAction(tr("Refresh tabs to the right"), parent, [parent]() { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { + for(int i = currentIdx + 1; i < _subwindow->tabCount(); i++) { + const auto data = _subwindow->tabData(i); + if(!data.refreshLocked) + _subwindow->view(i)->triggerPageAction(QWebEnginePage::Reload); + } + }); + }); + subwindow->addAction(tr("Refresh all other tabs"), parent, [parent]() { + run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { + for(int i = 0; i < _subwindow->tabCount(); i++) { + if(i != currentIdx) { + const auto data = _subwindow->tabData(i); + if(!data.refreshLocked) + _subwindow->view(i)->triggerPageAction(QWebEnginePage::Reload); + } + } + }); + }); + subwindow->addSeparator(); auto *subwindowProfile = subwindow->addMenu(tr("Subwindow Profile")); |