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 chatterino {
|
||||||
namespace widgets {
|
namespace widgets {
|
||||||
|
|
||||||
NotebookTab::NotebookTab(Notebook *_notebook, const std::string &settingPrefix)
|
NotebookTab::NotebookTab(Notebook *_notebook, const std::string &_uuid)
|
||||||
: BaseWidget(_notebook)
|
: BaseWidget(_notebook)
|
||||||
, settingRoot(fS("{}/tab", settingPrefix))
|
, uuid(_uuid)
|
||||||
|
, settingRoot(fS("/containers/{}/tab", this->uuid))
|
||||||
, positionChangedAnimation(this, "pos")
|
, positionChangedAnimation(this, "pos")
|
||||||
, notebook(_notebook)
|
, notebook(_notebook)
|
||||||
, title(fS("{}/title", this->settingRoot), "")
|
, title(fS("{}/title", this->settingRoot), "")
|
||||||
|
|
|
@ -21,10 +21,11 @@ class NotebookTab : public BaseWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
std::string settingRoot;
|
const std::string uuid;
|
||||||
|
const std::string settingRoot;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NotebookTab(Notebook *_notebook, const std::string &settingPrefix);
|
explicit NotebookTab(Notebook *_notebook, const std::string &_uuid);
|
||||||
|
|
||||||
void calcSize();
|
void calcSize();
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ Notebook::Notebook(ChannelManager &_channelManager, Window *parent, bool _showBu
|
||||||
, settingsButton(this)
|
, settingsButton(this)
|
||||||
, userButton(this)
|
, userButton(this)
|
||||||
, showButtons(_showButtons)
|
, showButtons(_showButtons)
|
||||||
|
, tabs(fS("{}/tabs", this->settingRoot))
|
||||||
{
|
{
|
||||||
this->connect(&this->settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked()));
|
this->connect(&this->settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked()));
|
||||||
this->connect(&this->userButton, SIGNAL(clicked()), this, SLOT(usersButtonClicked()));
|
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.hidePreferencesButton.connectSimple([this](auto) { this->performLayout(); });
|
||||||
settingsManager.hideUserButton.connectSimple([this](auto) { this->performLayout(); });
|
settingsManager.hideUserButton.connectSimple([this](auto) { this->performLayout(); });
|
||||||
|
|
||||||
this->loadContainers();
|
this->loadTabs();
|
||||||
}
|
}
|
||||||
|
|
||||||
SplitContainer *Notebook::addNewPage()
|
SplitContainer *Notebook::addNewPage()
|
||||||
|
@ -56,10 +57,8 @@ SplitContainer *Notebook::addNewPage()
|
||||||
|
|
||||||
SplitContainer *Notebook::addPage(const std::string &uuid, bool select)
|
SplitContainer *Notebook::addPage(const std::string &uuid, bool select)
|
||||||
{
|
{
|
||||||
std::string key = fS("{}/containers/{}", this->settingRoot, uuid);
|
auto tab = new NotebookTab(this, uuid);
|
||||||
|
auto page = new SplitContainer(this->channelManager, this, tab, uuid);
|
||||||
auto tab = new NotebookTab(this, key);
|
|
||||||
auto page = new SplitContainer(this->channelManager, this, tab, key);
|
|
||||||
|
|
||||||
tab->show();
|
tab->show();
|
||||||
|
|
||||||
|
@ -268,22 +267,30 @@ void Notebook::addPageButtonClicked()
|
||||||
QTimer::singleShot(80, [this] { this->addNewPage(); });
|
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) {
|
for (const std::string &tabUUID : tabArray) {
|
||||||
this->addPage(key);
|
this->addPage(tabUUID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notebook::save()
|
void Notebook::save()
|
||||||
{
|
{
|
||||||
|
std::vector<std::string> tabArray;
|
||||||
|
|
||||||
for (const auto &page : this->pages) {
|
for (const auto &page : this->pages) {
|
||||||
|
tabArray.push_back(page->getUUID());
|
||||||
page->save();
|
page->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->tabs = tabArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace widgets
|
} // namespace widgets
|
||||||
|
|
|
@ -72,7 +72,9 @@ private:
|
||||||
|
|
||||||
bool showButtons;
|
bool showButtons;
|
||||||
|
|
||||||
void loadContainers();
|
pajlada::Settings::Setting<std::vector<std::string>> tabs;
|
||||||
|
|
||||||
|
void loadTabs();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void save();
|
void save();
|
||||||
|
|
|
@ -26,10 +26,10 @@ Split *SplitContainer::draggingSplit = nullptr;
|
||||||
std::pair<int, int> SplitContainer::dropPosition = std::pair<int, int>(-1, -1);
|
std::pair<int, int> SplitContainer::dropPosition = std::pair<int, int>(-1, -1);
|
||||||
|
|
||||||
SplitContainer::SplitContainer(ChannelManager &_channelManager, Notebook *parent, NotebookTab *_tab,
|
SplitContainer::SplitContainer(ChannelManager &_channelManager, Notebook *parent, NotebookTab *_tab,
|
||||||
const std::string &_settingPrefix)
|
const std::string &_uuid)
|
||||||
: BaseWidget(parent->colorScheme, parent)
|
: BaseWidget(parent->colorScheme, parent)
|
||||||
, settingPrefix(_settingPrefix)
|
, uuid(_uuid)
|
||||||
, settingRoot(fS("{}", this->settingPrefix))
|
, settingRoot(fS("/containers/{}", this->uuid))
|
||||||
, chats(fS("{}/chats", this->settingRoot))
|
, chats(fS("{}/chats", this->settingRoot))
|
||||||
, channelManager(_channelManager)
|
, channelManager(_channelManager)
|
||||||
, tab(_tab)
|
, tab(_tab)
|
||||||
|
|
|
@ -22,12 +22,17 @@ class SplitContainer : public BaseWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
const std::string settingPrefix;
|
const std::string uuid;
|
||||||
std::string settingRoot;
|
const std::string settingRoot;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SplitContainer(ChannelManager &_channelManager, Notebook *parent, NotebookTab *_tab,
|
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;
|
ChannelManager &channelManager;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue