diff --git a/src/lib/tabwidget/tabcontextmenu.cpp b/src/lib/tabwidget/tabcontextmenu.cpp index 1abe5b581..a261664ae 100644 --- a/src/lib/tabwidget/tabcontextmenu.cpp +++ b/src/lib/tabwidget/tabcontextmenu.cpp @@ -27,12 +27,13 @@ #include "checkboxdialog.h" -TabContextMenu::TabContextMenu(int index, Qt::Orientation orientation, BrowserWindow* window, TabWidget* tabWidget) +TabContextMenu::TabContextMenu(int index, Qt::Orientation orientation, BrowserWindow* window, TabWidget* tabWidget, bool showCloseOtherTabs) : QMenu() , m_clickedTab(index) , m_tabsOrientation(orientation) , m_window(window) , m_tabWidget(tabWidget) + , m_showCloseOtherTabs(showCloseOtherTabs) { setObjectName("tabcontextmenu"); @@ -129,10 +130,14 @@ void TabContextMenu::init() addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs())); addAction(tr("Bookmark &All Tabs"), m_window, SLOT(bookmarkAllTabs())); addSeparator(); - addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent())); - addAction(m_tabsOrientation == Qt::Horizontal ? tr("Close Tabs To The Right") : tr("Close Tabs To The Bottom"), this, SLOT(closeToRight())); - addAction(m_tabsOrientation == Qt::Horizontal ? tr("Close Tabs To The Left") : tr("Close Tabs To The Top"), this, SLOT(closeToLeft())); - addSeparator(); + + if (m_showCloseOtherTabs) { + addAction(tr("Close Ot&her Tabs"), this, SLOT(closeAllButCurrent())); + addAction(m_tabsOrientation == Qt::Horizontal ? tr("Close Tabs To The Right") : tr("Close Tabs To The Bottom"), this, SLOT(closeToRight())); + addAction(m_tabsOrientation == Qt::Horizontal ? tr("Close Tabs To The Left") : tr("Close Tabs To The Top"), this, SLOT(closeToLeft())); + addSeparator(); + } + addAction(m_window->action(QSL("Other/RestoreClosedTab"))); addAction(QIcon::fromTheme("window-close"), tr("Cl&ose Tab"), this, SLOT(closeTab())); } else { diff --git a/src/lib/tabwidget/tabcontextmenu.h b/src/lib/tabwidget/tabcontextmenu.h index 67cb1a447..65e1079d9 100644 --- a/src/lib/tabwidget/tabcontextmenu.h +++ b/src/lib/tabwidget/tabcontextmenu.h @@ -29,7 +29,7 @@ class FALKON_EXPORT TabContextMenu : public QMenu { Q_OBJECT public: - explicit TabContextMenu(int index, Qt::Orientation orientation, BrowserWindow* window, TabWidget* tabWidget); + explicit TabContextMenu(int index, Qt::Orientation orientation, BrowserWindow* window, TabWidget* tabWidget, bool showCloseOtherTabs = true); signals: @@ -63,6 +63,7 @@ private: Qt::Orientation m_tabsOrientation; BrowserWindow* m_window; TabWidget* m_tabWidget; + bool m_showCloseOtherTabs; }; #endif // TABCONTEXTMENU_H diff --git a/src/plugins/TabManager/tabmanagerwidget.cpp b/src/plugins/TabManager/tabmanagerwidget.cpp index 322596e0e..7ba020d2a 100644 --- a/src/plugins/TabManager/tabmanagerwidget.cpp +++ b/src/plugins/TabManager/tabmanagerwidget.cpp @@ -30,7 +30,7 @@ #include "tabmanagerplugin.h" #include "tldextractor/tldextractor.h" #include "tabmanagerdelegate.h" - +#include "tabcontextmenu.h" #include #include @@ -261,7 +261,30 @@ bool TabManagerWidget::isTabSelected() void TabManagerWidget::customContextMenuRequested(const QPoint &pos) { - QMenu menu; + QMenu* menu = nullptr; + + QTreeWidgetItem* item = ui->treeWidget->itemAt(pos); + + if (item) { + BrowserWindow* mainWindow = qobject_cast(qvariant_cast(item->data(0, BrowserWindowPointerRole))); + QWidget* tabWidget = qvariant_cast(item->data(0, WebTabPointerRole)); + + if (mainWindow && tabWidget) { + int index = mainWindow->tabWidget()->indexOf(tabWidget); + + // if items are not grouped by Window then actions "Close Other Tabs", + // "Close Tabs To The Bottom" and "Close Tabs To The Top" + // are ambiguous and should be hidden. + menu = new TabContextMenu(index, Qt::Vertical, mainWindow, mainWindow->tabWidget(), m_groupType == GroupByWindow); + menu->addSeparator(); + } + } + + if (!menu) + menu = new QMenu; + + menu->setAttribute(Qt::WA_DeleteOnClose); + QAction* action; QMenu groupTypeSubmenu(tr("Group by")); action = groupTypeSubmenu.addAction(tr("&Window"), this, SLOT(changeGroupType())); @@ -279,21 +302,21 @@ void TabManagerWidget::customContextMenuRequested(const QPoint &pos) action->setCheckable(true); action->setChecked(m_groupType == GroupByHost); - menu.addMenu(&groupTypeSubmenu); + menu->addMenu(&groupTypeSubmenu); if (m_isDefaultWidget) { - menu.addAction(QIcon(":/tabmanager/data/side-by-side.png"), tr("&Show side by side"), this, SIGNAL(showSideBySide()))->setObjectName("sideBySide"); + menu->addAction(QIcon(":/tabmanager/data/side-by-side.png"), tr("&Show side by side"), this, SIGNAL(showSideBySide()))->setObjectName("sideBySide"); } - menu.addSeparator(); + menu->addSeparator(); if (isTabSelected()) { - menu.addAction(QIcon(":/tabmanager/data/tab-detach.png"), tr("&Detach checked tabs"), this, SLOT(processActions()))->setObjectName("detachSelection"); - menu.addAction(QIcon(":/tabmanager/data/tab-bookmark.png"), tr("Book&mark checked tabs"), this, SLOT(processActions()))->setObjectName("bookmarkSelection"); - menu.addAction(QIcon(":/tabmanager/data/tab-close.png"), tr("&Close checked tabs"), this, SLOT(processActions()))->setObjectName("closeSelection"); + menu->addAction(QIcon(":/tabmanager/data/tab-detach.png"), tr("&Detach checked tabs"), this, SLOT(processActions()))->setObjectName("detachSelection"); + menu->addAction(QIcon(":/tabmanager/data/tab-bookmark.png"), tr("Book&mark checked tabs"), this, SLOT(processActions()))->setObjectName("bookmarkSelection"); + menu->addAction(QIcon(":/tabmanager/data/tab-close.png"), tr("&Close checked tabs"), this, SLOT(processActions()))->setObjectName("closeSelection"); } - menu.exec(ui->treeWidget->viewport()->mapToGlobal(pos)); + menu->exec(ui->treeWidget->viewport()->mapToGlobal(pos)); } void TabManagerWidget::filterChanged(const QString &filter, bool force)