diff --git a/CHANGELOG.md b/CHANGELOG.md index 8df673c11..39bad50bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ - Minor: Make Tab Layout setting only accept predefined values (#3564) - Minor: Added librewolf, icecat, and waterfox incognito support. (#3588) - Minor: Updated to Emoji v14.0 (#3612) +- Minor: Add support for locking tab arrangement (#3627) - Bugfix: Fix Split Input hotkeys not being available when input is hidden (#3362) - Bugfix: Fixed colored usernames sometimes not working. (#3170) - Bugfix: Restored ability to send duplicate `/me` messages. (#3166) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 15f755405..14ade6c93 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -386,6 +386,7 @@ public: BoolSetting askOnImageUpload = {"/misc/askOnImageUpload", true}; BoolSetting informOnTabVisibilityToggle = {"/misc/askOnTabVisibilityToggle", true}; + BoolSetting lockNotebookLayout = {"/misc/lockNotebookLayout", false}; /// Debug BoolSetting showUnhandledIrcMessages = {"/debug/showUnhandledIrcMessages", diff --git a/src/widgets/Notebook.cpp b/src/widgets/Notebook.cpp index 0aa5baba5..959b277bc 100644 --- a/src/widgets/Notebook.cpp +++ b/src/widgets/Notebook.cpp @@ -34,12 +34,21 @@ Notebook::Notebook(QWidget *parent) this->addButton_->setHidden(true); - this->menu_.addAction( - "Toggle visibility of tabs", - [this]() { - this->setShowTabs(!this->getShowTabs()); - }, - QKeySequence("Ctrl+U")); + this->lockNotebookLayoutAction_ = new QAction("Lock Tab Layout", this); + + // Load lock notebook layout state from settings + this->setLockNotebookLayout(getSettings()->lockNotebookLayout.getValue()); + + this->lockNotebookLayoutAction_->setCheckable(true); + this->lockNotebookLayoutAction_->setChecked(this->lockNotebookLayout_); + + // Update lockNotebookLayout_ value anytime the user changes the checkbox state + QObject::connect(this->lockNotebookLayoutAction_, &QAction::triggered, + [this](bool value) { + this->setLockNotebookLayout(value); + }); + + this->addNotebookActionsToMenu(&this->menu_); } NotebookTab *Notebook::addPage(QWidget *page, QString title, bool select) @@ -316,6 +325,11 @@ QWidget *Notebook::tabAt(QPoint point, int &index, int maxWidth) void Notebook::rearrangePage(QWidget *page, int index) { + if (this->isNotebookLayoutLocked()) + { + return; + } + // Queue up save because: Tab rearranged getApp()->windows->queueSave(); @@ -673,6 +687,30 @@ void Notebook::paintEvent(QPaintEvent *event) } } +bool Notebook::isNotebookLayoutLocked() const +{ + return this->lockNotebookLayout_; +} + +void Notebook::setLockNotebookLayout(bool value) +{ + this->lockNotebookLayout_ = value; + this->lockNotebookLayoutAction_->setChecked(value); + getSettings()->lockNotebookLayout.setValue(value); +} + +void Notebook::addNotebookActionsToMenu(QMenu *menu) +{ + menu->addAction( + "Toggle visibility of tabs", + [this]() { + this->setShowTabs(!this->getShowTabs()); + }, + QKeySequence("Ctrl+U")); + + menu->addAction(this->lockNotebookLayoutAction_); +} + NotebookButton *Notebook::getAddButton() { return this->addButton_; diff --git a/src/widgets/Notebook.hpp b/src/widgets/Notebook.hpp index 9ccc5ede8..42b05fc3f 100644 --- a/src/widgets/Notebook.hpp +++ b/src/widgets/Notebook.hpp @@ -60,6 +60,11 @@ public: void setTabDirection(NotebookTabDirection direction); + bool isNotebookLayoutLocked() const; + void setLockNotebookLayout(bool value); + + void addNotebookActionsToMenu(QMenu *menu); + protected: virtual void scaleChangedEvent(float scale_) override; virtual void resizeEvent(QResizeEvent *) override; @@ -98,7 +103,9 @@ private: bool showTabs_ = true; bool showAddButton_ = false; int lineOffset_ = 20; + bool lockNotebookLayout_ = false; NotebookTabDirection tabDirection_ = NotebookTabDirection::Horizontal; + QAction *lockNotebookLayoutAction_; }; class SplitNotebook : public Notebook diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 3dd18d87e..8fdbe74ed 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -89,12 +89,7 @@ NotebookTab::NotebookTab(Notebook *notebook) this->menu_.addSeparator(); - this->menu_.addAction( - "Toggle visibility of tabs", - [this]() { - this->notebook_->setShowTabs(!this->notebook_->getShowTabs()); - }, - QKeySequence("Ctrl+U")); + this->notebook_->addNotebookActionsToMenu(&this->menu_); } void NotebookTab::showRenameDialog()