diff --git a/src/widgets/helper/notebooktab.cpp b/src/widgets/helper/notebooktab.cpp index 2e35f1040..3f7aa146f 100644 --- a/src/widgets/helper/notebooktab.cpp +++ b/src/widgets/helper/notebooktab.cpp @@ -14,9 +14,10 @@ namespace chatterino { namespace widgets { -NotebookTab::NotebookTab(Notebook *_notebook, const std::string &settingPrefix) +NotebookTab::NotebookTab(Notebook *_notebook, const std::string &_uuid) : BaseWidget(_notebook) - , settingRoot(fS("{}/tab", settingPrefix)) + , uuid(_uuid) + , settingRoot(fS("/containers/{}/tab", this->uuid)) , positionChangedAnimation(this, "pos") , notebook(_notebook) , title(fS("{}/title", this->settingRoot), "") diff --git a/src/widgets/helper/notebooktab.hpp b/src/widgets/helper/notebooktab.hpp index e41e32bd9..9988eb6e9 100644 --- a/src/widgets/helper/notebooktab.hpp +++ b/src/widgets/helper/notebooktab.hpp @@ -21,10 +21,11 @@ class NotebookTab : public BaseWidget { Q_OBJECT - std::string settingRoot; + const std::string uuid; + const std::string settingRoot; public: - explicit NotebookTab(Notebook *_notebook, const std::string &settingPrefix); + explicit NotebookTab(Notebook *_notebook, const std::string &_uuid); void calcSize(); diff --git a/src/widgets/notebook.cpp b/src/widgets/notebook.cpp index d26eb3cb9..2e67e59b6 100644 --- a/src/widgets/notebook.cpp +++ b/src/widgets/notebook.cpp @@ -31,6 +31,7 @@ Notebook::Notebook(ChannelManager &_channelManager, Window *parent, bool _showBu , settingsButton(this) , userButton(this) , showButtons(_showButtons) + , tabs(fS("{}/tabs", this->settingRoot)) { this->connect(&this->settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked())); this->connect(&this->userButton, SIGNAL(clicked()), this, SLOT(usersButtonClicked())); @@ -46,7 +47,7 @@ Notebook::Notebook(ChannelManager &_channelManager, Window *parent, bool _showBu settingsManager.hidePreferencesButton.connectSimple([this](auto) { this->performLayout(); }); settingsManager.hideUserButton.connectSimple([this](auto) { this->performLayout(); }); - this->loadContainers(); + this->loadTabs(); } SplitContainer *Notebook::addNewPage() @@ -56,10 +57,8 @@ SplitContainer *Notebook::addNewPage() SplitContainer *Notebook::addPage(const std::string &uuid, bool select) { - std::string key = fS("{}/containers/{}", this->settingRoot, uuid); - - auto tab = new NotebookTab(this, key); - auto page = new SplitContainer(this->channelManager, this, tab, key); + auto tab = new NotebookTab(this, uuid); + auto page = new SplitContainer(this->channelManager, this, tab, uuid); tab->show(); @@ -268,22 +267,30 @@ void Notebook::addPageButtonClicked() QTimer::singleShot(80, [this] { this->addNewPage(); }); } -void Notebook::loadContainers() +void Notebook::loadTabs() { - std::string containersKey = fS("{}/containers", this->settingRoot); + const std::vector tabArray = this->tabs.getValue(); - auto keys = pajlada::Settings::SettingManager::getObjectKeys(containersKey); + if (tabArray.size() == 0) { + this->addNewPage(); + return; + } - for (const std::string &key : keys) { - this->addPage(key); + for (const std::string &tabUUID : tabArray) { + this->addPage(tabUUID); } } void Notebook::save() { + std::vector tabArray; + for (const auto &page : this->pages) { + tabArray.push_back(page->getUUID()); page->save(); } + + this->tabs = tabArray; } } // namespace widgets diff --git a/src/widgets/notebook.hpp b/src/widgets/notebook.hpp index f3a574839..e7b8b32f5 100644 --- a/src/widgets/notebook.hpp +++ b/src/widgets/notebook.hpp @@ -72,7 +72,9 @@ private: bool showButtons; - void loadContainers(); + pajlada::Settings::Setting> tabs; + + void loadTabs(); public: void save(); diff --git a/src/widgets/splitcontainer.cpp b/src/widgets/splitcontainer.cpp index b207b2792..c70e9ab14 100644 --- a/src/widgets/splitcontainer.cpp +++ b/src/widgets/splitcontainer.cpp @@ -26,10 +26,10 @@ Split *SplitContainer::draggingSplit = nullptr; std::pair SplitContainer::dropPosition = std::pair(-1, -1); SplitContainer::SplitContainer(ChannelManager &_channelManager, Notebook *parent, NotebookTab *_tab, - const std::string &_settingPrefix) + const std::string &_uuid) : BaseWidget(parent->colorScheme, parent) - , settingPrefix(_settingPrefix) - , settingRoot(fS("{}", this->settingPrefix)) + , uuid(_uuid) + , settingRoot(fS("/containers/{}", this->uuid)) , chats(fS("{}/chats", this->settingRoot)) , channelManager(_channelManager) , tab(_tab) diff --git a/src/widgets/splitcontainer.hpp b/src/widgets/splitcontainer.hpp index e5ed89ab8..22edac719 100644 --- a/src/widgets/splitcontainer.hpp +++ b/src/widgets/splitcontainer.hpp @@ -22,12 +22,17 @@ class SplitContainer : public BaseWidget { Q_OBJECT - const std::string settingPrefix; - std::string settingRoot; + const std::string uuid; + const std::string settingRoot; public: SplitContainer(ChannelManager &_channelManager, Notebook *parent, NotebookTab *_tab, - const std::string &_settingPrefix); + const std::string &_uuid); + + const std::string &getUUID() const + { + return this->uuid; + } ChannelManager &channelManager;