Merge pull request #795 from hemirt/splits
ClosedSplits feature (ctrl+shift+t in browsers)
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#include "ClosedSplits.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
std::mutex ClosedSplits::m_;
|
||||
std::vector<ClosedSplits::SplitInfo> ClosedSplits::closedSplits_;
|
||||
|
||||
void ClosedSplits::invalidateTab(NotebookTab *const tab)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(ClosedSplits::m_);
|
||||
auto it = std::find_if(
|
||||
ClosedSplits::closedSplits_.begin(), ClosedSplits::closedSplits_.end(),
|
||||
[tab](const auto &item) -> bool { return item.tab == tab; });
|
||||
if (it == ClosedSplits::closedSplits_.end()) {
|
||||
return;
|
||||
}
|
||||
it->tab = nullptr;
|
||||
}
|
||||
|
||||
void ClosedSplits::push(const SplitInfo &si)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(ClosedSplits::m_);
|
||||
ClosedSplits::closedSplits_.push_back(si);
|
||||
}
|
||||
|
||||
void ClosedSplits::push(SplitInfo &&si)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(ClosedSplits::m_);
|
||||
ClosedSplits::closedSplits_.push_back(std::move(si));
|
||||
}
|
||||
|
||||
ClosedSplits::SplitInfo ClosedSplits::pop()
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(ClosedSplits::m_);
|
||||
SplitInfo si = std::move(ClosedSplits::closedSplits_.back());
|
||||
ClosedSplits::closedSplits_.pop_back();
|
||||
return si;
|
||||
}
|
||||
|
||||
bool ClosedSplits::empty()
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(ClosedSplits::m_);
|
||||
return ClosedSplits::closedSplits_.empty();
|
||||
}
|
||||
|
||||
std::size_t ClosedSplits::size()
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(ClosedSplits::m_);
|
||||
return ClosedSplits::closedSplits_.size();
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/Channel.hpp"
|
||||
#include "widgets/helper/NotebookTab.hpp"
|
||||
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class ClosedSplits
|
||||
{
|
||||
public:
|
||||
struct SplitInfo {
|
||||
QString channelName;
|
||||
NotebookTab *tab; // non owning ptr
|
||||
};
|
||||
|
||||
static void invalidateTab(NotebookTab *const tab);
|
||||
static void push(const SplitInfo &si);
|
||||
static void push(SplitInfo &&si);
|
||||
static SplitInfo pop();
|
||||
static bool empty();
|
||||
static std::size_t size();
|
||||
|
||||
private:
|
||||
static std::mutex m_;
|
||||
static std::vector<SplitInfo> closedSplits_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
||||
@@ -19,9 +19,11 @@
|
||||
#include "widgets/dialogs/UserInfoPopup.hpp"
|
||||
#include "widgets/helper/ChannelView.hpp"
|
||||
#include "widgets/helper/DebugPopup.hpp"
|
||||
#include "widgets/helper/NotebookTab.hpp"
|
||||
#include "widgets/helper/ResizingTextEdit.hpp"
|
||||
#include "widgets/helper/SearchPopup.hpp"
|
||||
#include "widgets/helper/Shortcut.hpp"
|
||||
#include "widgets/splits/ClosedSplits.hpp"
|
||||
#include "widgets/splits/SplitContainer.hpp"
|
||||
#include "widgets/splits/SplitHeader.hpp"
|
||||
#include "widgets/splits/SplitInput.hpp"
|
||||
@@ -415,6 +417,10 @@ void Split::deleteFromContainer()
|
||||
{
|
||||
if (this->container_) {
|
||||
this->container_->deleteSplit(this);
|
||||
auto *tab = this->getContainer()->getTab();
|
||||
tab->connect(tab, &QWidget::destroyed,
|
||||
[tab]() mutable { ClosedSplits::invalidateTab(tab); });
|
||||
ClosedSplits::push({this->getChannel()->getName(), tab});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user