Add context menu entry to toggle offline tabs (#5318)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
nerix 2024-04-12 23:05:47 +02:00 committed by GitHub
parent e6bf503594
commit 1ca77a1e84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 88 additions and 22 deletions

View file

@ -2,6 +2,7 @@
## Unversioned
- Minor: Added context menu action to toggle visibility of offline tabs. (#5318)
- Minor: Report sub duration for more multi-month gift cases. (#5319)
- Bugfix: Fixed split tooltip getting stuck in some cases. (#5309)
- Bugfix: Fixed the version string not showing up as expected in Finder on macOS. (#5311)

View file

@ -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)

View file

@ -118,7 +118,7 @@ public:
bool isNotebookLayoutLocked() const;
void setLockNotebookLayout(bool value);
void addNotebookActionsToMenu(QMenu *menu);
virtual void addNotebookActionsToMenu(QMenu *menu);
// Update layout and tab visibility
void refresh();
@ -182,7 +182,7 @@ private:
size_t visibleButtonCount() const;
QList<Item> items_;
QMenu menu_;
QMenu *menu_ = nullptr;
QWidget *selectedPage_ = nullptr;
NotebookButton *addButton_;
@ -215,6 +215,9 @@ public:
void select(QWidget *page, bool focusPage = true) override;
void themeChangedEvent() override;
void addNotebookActionsToMenu(QMenu *menu) override;
void toggleOfflineTabs();
protected:
void showEvent(QShowEvent *event) override;
@ -223,6 +226,9 @@ private:
pajlada::Signals::SignalHolder signalHolder_;
QAction *toggleOfflineTabsAction_;
void updateToggleOfflineTabsHotkey(NotebookTabVisibility newTabVisibility);
// Main window on Windows has basically a duplicate of this in Window
NotebookButton *streamerModeIcon_{};
void updateStreamerModeIcon();

View file

@ -659,22 +659,7 @@ void Window::addShortcuts()
}
else if (arg == "toggleLiveOnly")
{
if (!this->notebook_->getShowTabs())
{
// Tabs are currently hidden, so the intention is to show
// tabs again before enabling the live only setting
this->notebook_->setShowTabs(true);
getSettings()->tabVisibility.setValue(
NotebookTabVisibility::LiveOnly);
}
else
{
getSettings()->tabVisibility.setValue(
getSettings()->tabVisibility.getEnum() ==
NotebookTabVisibility::LiveOnly
? NotebookTabVisibility::AllTabs
: NotebookTabVisibility::LiveOnly);
}
this->notebook_->toggleOfflineTabs();
}
else
{