mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
TabManager: Add tab context-menu to treewidget context-menu.
This commit is contained in:
parent
04b288b395
commit
f17eb82cf9
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "tabmanagerplugin.h"
|
||||
#include "tldextractor/tldextractor.h"
|
||||
#include "tabmanagerdelegate.h"
|
||||
|
||||
#include "tabcontextmenu.h"
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <QDialogButtonBox>
|
||||
|
@ -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<BrowserWindow*>(qvariant_cast<QWidget*>(item->data(0, BrowserWindowPointerRole)));
|
||||
QWidget* tabWidget = qvariant_cast<QWidget*>(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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user