Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add context menu entry to toggle offline tabs #5318

Merged
merged 5 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
82 changes: 78 additions & 4 deletions src/widgets/Notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace chatterino {

Notebook::Notebook(QWidget *parent)
: BaseWidget(parent)
, menu_(this)
, addButton_(new NotebookButton(this))
{
this->addButton_->setIcon(NotebookButton::Icon::Plus);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:;
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions src/widgets/Notebook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Notebook : public BaseWidget
bool isNotebookLayoutLocked() const;
void setLockNotebookLayout(bool value);

void addNotebookActionsToMenu(QMenu *menu);
virtual void addNotebookActionsToMenu(QMenu *menu);

// Update layout and tab visibility
void refresh();
Expand Down Expand Up @@ -182,7 +182,7 @@ class Notebook : public BaseWidget
size_t visibleButtonCount() const;

QList<Item> items_;
QMenu menu_;
QMenu *menu_ = nullptr;
QWidget *selectedPage_ = nullptr;

NotebookButton *addButton_;
Expand Down Expand Up @@ -215,6 +215,9 @@ class SplitNotebook : public Notebook
void select(QWidget *page, bool focusPage = true) override;
void themeChangedEvent() override;

void addNotebookActionsToMenu(QMenu *menu) override;
void toggleOfflineTabs();

protected:
void showEvent(QShowEvent *event) override;

Expand All @@ -223,6 +226,9 @@ class SplitNotebook : public Notebook

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();
Expand Down
17 changes: 1 addition & 16 deletions src/widgets/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading