mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Add the "Close Tabs" feature
Also made notebooks open a container if no tabs are loaded Fixes #166
This commit is contained in:
parent
091e7b9dbe
commit
caddb2c778
6 changed files with 37 additions and 21 deletions
|
@ -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), "")
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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<std::string> 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<std::string> tabArray;
|
||||
|
||||
for (const auto &page : this->pages) {
|
||||
tabArray.push_back(page->getUUID());
|
||||
page->save();
|
||||
}
|
||||
|
||||
this->tabs = tabArray;
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
|
|
|
@ -72,7 +72,9 @@ private:
|
|||
|
||||
bool showButtons;
|
||||
|
||||
void loadContainers();
|
||||
pajlada::Settings::Setting<std::vector<std::string>> tabs;
|
||||
|
||||
void loadTabs();
|
||||
|
||||
public:
|
||||
void save();
|
||||
|
|
|
@ -26,10 +26,10 @@ Split *SplitContainer::draggingSplit = nullptr;
|
|||
std::pair<int, int> SplitContainer::dropPosition = std::pair<int, int>(-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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue