fix: tristate toggle logic for tab visibilty (#5530)

Co-authored-by: Nerixyz <nerixdev@outlook.de>
This commit is contained in:
pajlada
2024-08-24 11:42:42 +02:00
committed by GitHub
parent f36c73019d
commit 5170085d7c
14 changed files with 326 additions and 199 deletions
+76 -101
View File
@@ -20,6 +20,7 @@
#include "widgets/Window.hpp"
#include <boost/foreach.hpp>
#include <QActionGroup>
#include <QDebug>
#include <QFile>
#include <QFormLayout>
@@ -54,11 +55,6 @@ Notebook::Notebook(QWidget *parent)
[this](bool value) {
this->setLockNotebookLayout(value);
});
this->showTabsAction_ = new QAction("Toggle visibility of tabs");
QObject::connect(this->showTabsAction_, &QAction::triggered, [this]() {
this->setShowTabs(!this->getShowTabs());
});
this->updateTabVisibilityMenuAction();
this->toggleTopMostAction_ = new QAction("Top most window", this);
this->toggleTopMostAction_->setCheckable(true);
@@ -597,7 +593,6 @@ void Notebook::setShowTabs(bool value)
this->performLayout();
this->updateTabVisibility();
this->updateTabVisibilityMenuAction();
// show a popup upon hiding tabs
if (!value && getSettings()->informOnTabVisibilityToggle.getValue())
@@ -668,35 +663,6 @@ void Notebook::updateTabVisibility()
}
}
void Notebook::updateTabVisibilityMenuAction()
{
const auto *hotkeys = getApp()->getHotkeys();
auto toggleSeq = hotkeys->getDisplaySequence(
HotkeyCategory::Window, "setTabVisibility", {std::vector<QString>()});
if (toggleSeq.isEmpty())
{
toggleSeq = hotkeys->getDisplaySequence(
HotkeyCategory::Window, "setTabVisibility", {{"toggle"}});
}
if (toggleSeq.isEmpty())
{
// show contextual shortcuts
if (this->getShowTabs())
{
toggleSeq = hotkeys->getDisplaySequence(
HotkeyCategory::Window, "setTabVisibility", {{"off"}});
}
else if (!this->getShowTabs())
{
toggleSeq = hotkeys->getDisplaySequence(
HotkeyCategory::Window, "setTabVisibility", {{"on"}});
}
}
this->showTabsAction_->setShortcut(toggleSeq);
}
bool Notebook::getShowAddButton() const
{
return this->showAddButton_;
@@ -1274,8 +1240,6 @@ void Notebook::setLockNotebookLayout(bool value)
void Notebook::addNotebookActionsToMenu(QMenu *menu)
{
menu->addAction(this->showTabsAction_);
menu->addAction(this->lockNotebookLayoutAction_);
menu->addAction(this->toggleTopMostAction_);
@@ -1368,9 +1332,64 @@ SplitNotebook::SplitNotebook(Window *parent)
this->addCustomButtons();
}
this->toggleOfflineTabsAction_ = new QAction({}, this);
QObject::connect(this->toggleOfflineTabsAction_, &QAction::triggered, this,
&SplitNotebook::toggleOfflineTabs);
auto *tabVisibilityActionGroup = new QActionGroup(this);
tabVisibilityActionGroup->setExclusionPolicy(
QActionGroup::ExclusionPolicy::Exclusive);
this->showAllTabsAction = new QAction("Show all tabs", this);
this->showAllTabsAction->setCheckable(true);
this->showAllTabsAction->setShortcut(
getApp()->getHotkeys()->getDisplaySequence(
HotkeyCategory::Window, "setTabVisibility", {{"on"}}));
QObject::connect(this->showAllTabsAction, &QAction::triggered, this,
[this] {
this->setShowTabs(true);
getSettings()->tabVisibility.setValue(
NotebookTabVisibility::AllTabs);
this->showAllTabsAction->setChecked(true);
});
tabVisibilityActionGroup->addAction(this->showAllTabsAction);
this->onlyShowLiveTabsAction = new QAction("Only show live tabs", this);
this->onlyShowLiveTabsAction->setCheckable(true);
this->onlyShowLiveTabsAction->setShortcut(
getApp()->getHotkeys()->getDisplaySequence(
HotkeyCategory::Window, "setTabVisibility", {{"liveOnly"}}));
QObject::connect(this->onlyShowLiveTabsAction, &QAction::triggered, this,
[this] {
this->setShowTabs(true);
getSettings()->tabVisibility.setValue(
NotebookTabVisibility::LiveOnly);
this->onlyShowLiveTabsAction->setChecked(true);
});
tabVisibilityActionGroup->addAction(this->onlyShowLiveTabsAction);
this->hideAllTabsAction = new QAction("Hide all tabs", this);
this->hideAllTabsAction->setCheckable(true);
this->hideAllTabsAction->setShortcut(
getApp()->getHotkeys()->getDisplaySequence(
HotkeyCategory::Window, "setTabVisibility", {{"off"}}));
QObject::connect(this->hideAllTabsAction, &QAction::triggered, this,
[this] {
this->setShowTabs(false);
getSettings()->tabVisibility.setValue(
NotebookTabVisibility::AllTabs);
this->hideAllTabsAction->setChecked(true);
});
tabVisibilityActionGroup->addAction(this->hideAllTabsAction);
switch (getSettings()->tabVisibility.getEnum())
{
case NotebookTabVisibility::AllTabs: {
this->showAllTabsAction->setChecked(true);
}
break;
case NotebookTabVisibility::LiveOnly: {
this->onlyShowLiveTabsAction->setChecked(true);
}
break;
}
getSettings()->tabVisibility.connect(
[this](int val, auto) {
@@ -1385,17 +1404,12 @@ 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);
@@ -1448,29 +1462,26 @@ 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_);
auto *submenu = menu->addMenu("Tab visibility");
submenu->addAction(this->showAllTabsAction);
submenu->addAction(this->onlyShowLiveTabsAction);
submenu->addAction(this->hideAllTabsAction);
}
void SplitNotebook::toggleTabVisibility()
{
if (this->getShowTabs())
{
this->hideAllTabsAction->trigger();
}
else
{
this->showAllTabsAction->trigger();
}
}
void SplitNotebook::showEvent(QShowEvent * /*event*/)
@@ -1550,42 +1561,6 @@ void SplitNotebook::addCustomButtons()
this->updateStreamerModeIcon();
}
void SplitNotebook::updateToggleOfflineTabsHotkey(
NotebookTabVisibility newTabVisibility)
{
auto *hotkeys = getApp()->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)
+12 -9
View File
@@ -116,9 +116,6 @@ public:
bool getAllowUserTabManagement() const;
void setAllowUserTabManagement(bool value);
bool getShowTabs() const;
void setShowTabs(bool value);
bool getShowAddButton() const;
void setShowAddButton(bool value);
@@ -133,6 +130,9 @@ public:
void refresh();
protected:
bool getShowTabs() const;
void setShowTabs(bool value);
void scaleChangedEvent(float scale_) override;
void resizeEvent(QResizeEvent *) override;
void mousePressEvent(QMouseEvent *event) override;
@@ -178,7 +178,6 @@ private:
* @brief Updates the visibility state of all tabs
**/
void updateTabVisibility();
void updateTabVisibilityMenuAction();
void resizeAddButton();
bool containsPage(QWidget *page);
@@ -209,7 +208,6 @@ private:
NotebookTabLocation tabLocation_ = NotebookTabLocation::Top;
QAction *lockNotebookLayoutAction_;
QAction *showTabsAction_;
QAction *toggleTopMostAction_;
// This filter, if set, is used to figure out the visibility of
@@ -230,7 +228,15 @@ public:
void themeChangedEvent() override;
void addNotebookActionsToMenu(QMenu *menu) override;
void toggleOfflineTabs();
/**
* Toggles between the "Show all tabs" and "Hide all tabs" tab visibility states
*/
void toggleTabVisibility();
QAction *showAllTabsAction;
QAction *onlyShowLiveTabsAction;
QAction *hideAllTabsAction;
protected:
void showEvent(QShowEvent *event) override;
@@ -240,9 +246,6 @@ 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();
+9 -15
View File
@@ -642,39 +642,33 @@ void Window::addShortcuts()
if (arg == "off")
{
this->notebook_->setShowTabs(false);
getSettings()->tabVisibility.setValue(
NotebookTabVisibility::AllTabs);
this->notebook_->hideAllTabsAction->trigger();
}
else if (arg == "on")
{
this->notebook_->setShowTabs(true);
getSettings()->tabVisibility.setValue(
NotebookTabVisibility::AllTabs);
this->notebook_->showAllTabsAction->trigger();
}
else if (arg == "toggle")
{
this->notebook_->setShowTabs(!this->notebook_->getShowTabs());
getSettings()->tabVisibility.setValue(
NotebookTabVisibility::AllTabs);
this->notebook_->toggleTabVisibility();
}
else if (arg == "liveOnly")
{
this->notebook_->setShowTabs(true);
getSettings()->tabVisibility.setValue(
NotebookTabVisibility::LiveOnly);
this->notebook_->onlyShowLiveTabsAction->trigger();
}
else if (arg == "toggleLiveOnly")
{
this->notebook_->toggleOfflineTabs();
// NOOP: Removed 2024-08-04 https://github.com/Chatterino/chatterino2/pull/5530
return "toggleLiveOnly is no longer a valid argument for "
"setTabVisibility";
}
else
{
qCWarning(chatterinoHotkeys)
<< "Invalid argument for setTabVisibility hotkey: " << arg;
return QString("Invalid argument for setTabVisibility hotkey: "
"%1. Use \"on\", \"off\", \"toggle\", "
"\"liveOnly\", or \"toggleLiveOnly\".")
"%1. Use \"on\", \"off\", \"toggle\", or "
"\"liveOnly\".")
.arg(arg);
}
+1 -1
View File
@@ -26,7 +26,7 @@ EditHotkeyDialog::EditHotkeyDialog(const std::shared_ptr<Hotkey> hotkey,
this->ui_->easyArgsPicker->setVisible(false);
this->ui_->easyArgsLabel->setVisible(false);
// dynamically add category names to the category picker
for (const auto &[_, hotkeyCategory] : getApp()->getHotkeys()->categories())
for (const auto &[_, hotkeyCategory] : hotkeyCategories())
{
this->ui_->categoryPicker->addItem(hotkeyCategory.displayName,
hotkeyCategory.name);
@@ -91,6 +91,42 @@ KeyboardSettingsPage::KeyboardSettingsPage()
}
});
view->addCustomButton(resetEverything);
// We only check this once since a user *should* not have the ability to create a new hotkey with a deprecated or removed action
// However, we also don't update this after the user has deleted a hotkey. This is a big lift that should probably be solved on the model level rather
// than individually here. Same goes for marking specific rows as deprecated/removed
const auto &removedOrDeprecatedHotkeys =
getApp()->getHotkeys()->removedOrDeprecatedHotkeys();
if (!removedOrDeprecatedHotkeys.empty())
{
QString warningMessage =
"Some of your hotkeys use deprecated actions and will not "
"work as expected: ";
bool first = true;
for (const auto &hotkeyName : removedOrDeprecatedHotkeys)
{
if (!first)
{
warningMessage.append(',');
}
warningMessage.append(' ');
warningMessage.append('"');
warningMessage.append(hotkeyName);
warningMessage.append('"');
first = false;
}
warningMessage.append('.');
auto deprecatedWarning = layout.emplace<QLabel>(warningMessage);
deprecatedWarning->setStyleSheet("color: yellow");
deprecatedWarning->setWordWrap(true);
auto deprecatedWarning2 = layout.emplace<QLabel>(
"You can ignore this warning after you have removed or edited the "
"above-mentioned hotkeys.");
deprecatedWarning2->setStyleSheet("color: yellow");
}
}
} // namespace chatterino