Add context menu entry to toggle offline tabs (#5318)
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -33,7 +33,6 @@ namespace chatterino {
|
||||
|
||||
Notebook::Notebook(QWidget *parent)
|
||||
: BaseWidget(parent)
|
||||
, menu_(this)
|
||||
, addButton_(new NotebookButton(this))
|
||||
{
|
||||
this->addButton_->setIcon(NotebookButton::Icon::Plus);
|
||||
@@ -81,8 +80,6 @@ Notebook::Notebook(QWidget *parent)
|
||||
<< "Notebook must be created within a BaseWindow";
|
||||
}
|
||||
|
||||
this->addNotebookActionsToMenu(&this->menu_);
|
||||
|
||||
// Manually resize the add button so the initial paint uses the correct
|
||||
// width when computing the maximum width occupied per column in vertical
|
||||
// tab rendering.
|
||||
@@ -1125,7 +1122,14 @@ void Notebook::mousePressEvent(QMouseEvent *event)
|
||||
switch (event->button())
|
||||
{
|
||||
case Qt::RightButton: {
|
||||
this->menu_.popup(event->globalPos() + QPoint(0, 8));
|
||||
event->accept();
|
||||
|
||||
if (!this->menu_)
|
||||
{
|
||||
this->menu_ = new QMenu(this);
|
||||
this->addNotebookActionsToMenu(this->menu_);
|
||||
}
|
||||
this->menu_->popup(event->globalPos() + QPoint(0, 8));
|
||||
}
|
||||
break;
|
||||
default:;
|
||||
@@ -1294,6 +1298,10 @@ SplitNotebook::SplitNotebook(Window *parent)
|
||||
this->addCustomButtons();
|
||||
}
|
||||
|
||||
this->toggleOfflineTabsAction_ = new QAction({}, this);
|
||||
QObject::connect(this->toggleOfflineTabsAction_, &QAction::triggered, this,
|
||||
&SplitNotebook::toggleOfflineTabs);
|
||||
|
||||
getSettings()->tabVisibility.connect(
|
||||
[this](int val, auto) {
|
||||
auto visibility = NotebookTabVisibility(val);
|
||||
@@ -1307,12 +1315,17 @@ SplitNotebook::SplitNotebook(Window *parent)
|
||||
this->setTabVisibilityFilter([](const NotebookTab *tab) {
|
||||
return tab->isLive();
|
||||
});
|
||||
this->toggleOfflineTabsAction_->setText("Show all tabs");
|
||||
break;
|
||||
case NotebookTabVisibility::AllTabs:
|
||||
default:
|
||||
this->setTabVisibilityFilter(nullptr);
|
||||
this->toggleOfflineTabsAction_->setText(
|
||||
"Show live tabs only");
|
||||
break;
|
||||
}
|
||||
|
||||
this->updateToggleOfflineTabsHotkey(visibility);
|
||||
},
|
||||
this->signalHolder_, true);
|
||||
|
||||
@@ -1365,6 +1378,31 @@ SplitNotebook::SplitNotebook(Window *parent)
|
||||
});
|
||||
}
|
||||
|
||||
void SplitNotebook::toggleOfflineTabs()
|
||||
{
|
||||
if (!this->getShowTabs())
|
||||
{
|
||||
// Tabs are currently hidden, so the intention is to show
|
||||
// tabs again before enabling the live only setting
|
||||
this->setShowTabs(true);
|
||||
getSettings()->tabVisibility.setValue(NotebookTabVisibility::LiveOnly);
|
||||
}
|
||||
else
|
||||
{
|
||||
getSettings()->tabVisibility.setValue(
|
||||
getSettings()->tabVisibility.getEnum() ==
|
||||
NotebookTabVisibility::LiveOnly
|
||||
? NotebookTabVisibility::AllTabs
|
||||
: NotebookTabVisibility::LiveOnly);
|
||||
}
|
||||
}
|
||||
|
||||
void SplitNotebook::addNotebookActionsToMenu(QMenu *menu)
|
||||
{
|
||||
Notebook::addNotebookActionsToMenu(menu);
|
||||
menu->addAction(this->toggleOfflineTabsAction_);
|
||||
}
|
||||
|
||||
void SplitNotebook::showEvent(QShowEvent * /*event*/)
|
||||
{
|
||||
if (auto *page = this->getSelectedPage())
|
||||
@@ -1442,6 +1480,42 @@ void SplitNotebook::addCustomButtons()
|
||||
this->updateStreamerModeIcon();
|
||||
}
|
||||
|
||||
void SplitNotebook::updateToggleOfflineTabsHotkey(
|
||||
NotebookTabVisibility newTabVisibility)
|
||||
{
|
||||
auto *hotkeys = getIApp()->getHotkeys();
|
||||
auto getKeySequence = [&](auto argument) {
|
||||
return hotkeys->getDisplaySequence(HotkeyCategory::Window,
|
||||
"setTabVisibility", {{argument}});
|
||||
};
|
||||
|
||||
auto toggleSeq = getKeySequence("toggleLiveOnly");
|
||||
|
||||
switch (newTabVisibility)
|
||||
{
|
||||
case NotebookTabVisibility::AllTabs:
|
||||
if (toggleSeq.isEmpty())
|
||||
{
|
||||
toggleSeq = getKeySequence("liveOnly");
|
||||
}
|
||||
break;
|
||||
|
||||
case NotebookTabVisibility::LiveOnly:
|
||||
if (toggleSeq.isEmpty())
|
||||
{
|
||||
toggleSeq = getKeySequence("toggle");
|
||||
|
||||
if (toggleSeq.isEmpty())
|
||||
{
|
||||
toggleSeq = getKeySequence("on");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
this->toggleOfflineTabsAction_->setShortcut(toggleSeq);
|
||||
}
|
||||
|
||||
void SplitNotebook::updateStreamerModeIcon()
|
||||
{
|
||||
if (this->streamerModeIcon_ == nullptr)
|
||||
|
||||
Reference in New Issue
Block a user