mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-13 20:18:50 +03:00
add opened tabs to state
This commit is contained in:
@@ -81,6 +81,28 @@ void ChannelTabSwitcherHandy::ReplaceActiveTab(Snowflake id) {
|
||||
}
|
||||
}
|
||||
|
||||
TabsState ChannelTabSwitcherHandy::GetTabsState() {
|
||||
TabsState state;
|
||||
|
||||
const gint num_pages = hdy_tab_view_get_n_pages(m_tab_view);
|
||||
for (gint i = 0; i < num_pages; i++) {
|
||||
auto *page = hdy_tab_view_get_nth_page(m_tab_view, i);
|
||||
if (page != nullptr) {
|
||||
if (const auto it = m_pages_rev.find(page); it != m_pages_rev.end()) {
|
||||
state.Channels.push_back(it->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
void ChannelTabSwitcherHandy::UseTabsState(const TabsState &state) {
|
||||
for (auto id : state.Channels) {
|
||||
AddChannelTab(id);
|
||||
}
|
||||
}
|
||||
|
||||
void ChannelTabSwitcherHandy::CheckUnread(Snowflake id) {
|
||||
if (auto it = m_pages.find(id); it != m_pages.end()) {
|
||||
hdy_tab_page_set_needs_attention(it->second, Abaddon::Get().GetDiscordClient().GetUnreadStateForChannel(id) > -1);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <unordered_map>
|
||||
#include <handy.h>
|
||||
#include "discord/snowflake.hpp"
|
||||
#include "state.hpp"
|
||||
|
||||
class ChannelData;
|
||||
|
||||
@@ -18,6 +19,8 @@ public:
|
||||
void AddChannelTab(Snowflake id);
|
||||
// switches to existing tab if it exists
|
||||
void ReplaceActiveTab(Snowflake id);
|
||||
TabsState GetTabsState();
|
||||
void UseTabsState(const TabsState &state);
|
||||
|
||||
private:
|
||||
void CheckUnread(Snowflake id);
|
||||
|
||||
@@ -172,6 +172,14 @@ void ChatWindow::SetTopic(const std::string &text) {
|
||||
void ChatWindow::OpenNewTab(Snowflake id) {
|
||||
m_tab_switcher->AddChannelTab(id);
|
||||
}
|
||||
|
||||
TabsState ChatWindow::GetTabsState() {
|
||||
return m_tab_switcher->GetTabsState();
|
||||
}
|
||||
|
||||
void ChatWindow::UseTabsState(const TabsState &state) {
|
||||
m_tab_switcher->UseTabsState(state);
|
||||
}
|
||||
#endif
|
||||
|
||||
Snowflake ChatWindow::GetActiveChannel() const {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <set>
|
||||
#include "discord/discord.hpp"
|
||||
#include "completer.hpp"
|
||||
#include "state.hpp"
|
||||
|
||||
#ifdef WITH_LIBHANDY
|
||||
class ChannelTabSwitcherHandy;
|
||||
@@ -36,6 +37,8 @@ public:
|
||||
|
||||
#ifdef WITH_LIBHANDY
|
||||
void OpenNewTab(Snowflake id);
|
||||
TabsState GetTabsState();
|
||||
void UseTabsState(const TabsState &state);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user