summaryrefslogtreecommitdiff
path: root/src/components/channeltabswitcherhandy.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2022-04-08 23:47:12 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2022-04-08 23:47:12 -0400
commit5b806a25894bf183515c64ac8099911da8f4a0c7 (patch)
tree405f58152c12e1c3d25ebe5644cac6c45d0622cc /src/components/channeltabswitcherhandy.cpp
parent5a13c7fef71662ca5c829a80ef57d42741e23f3a (diff)
downloadabaddon-portaudio-5b806a25894bf183515c64ac8099911da8f4a0c7.tar.gz
abaddon-portaudio-5b806a25894bf183515c64ac8099911da8f4a0c7.zip
basic tabs system
Diffstat (limited to 'src/components/channeltabswitcherhandy.cpp')
-rw-r--r--src/components/channeltabswitcherhandy.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/components/channeltabswitcherhandy.cpp b/src/components/channeltabswitcherhandy.cpp
new file mode 100644
index 0000000..94d5c29
--- /dev/null
+++ b/src/components/channeltabswitcherhandy.cpp
@@ -0,0 +1,58 @@
+#ifdef WITH_LIBHANDY
+
+ #include "channeltabswitcherhandy.hpp"
+ #include "abaddon.hpp"
+
+void selected_page_notify_cb(HdyTabView *view, GParamSpec *pspec, ChannelTabSwitcherHandy *switcher) {
+ auto *page = hdy_tab_view_get_selected_page(view);
+ if (auto it = switcher->m_pages_rev.find(page); it != switcher->m_pages_rev.end()) {
+ switcher->m_signal_channel_switched_to.emit(it->second);
+ }
+}
+
+ChannelTabSwitcherHandy::ChannelTabSwitcherHandy() {
+ m_tab_bar = hdy_tab_bar_new();
+ m_tab_bar_wrapped = Glib::wrap(GTK_WIDGET(m_tab_bar));
+ m_tab_view = hdy_tab_view_new();
+ m_tab_view_wrapped = Glib::wrap(GTK_WIDGET(m_tab_view));
+
+ g_signal_connect(m_tab_view, "notify::selected-page", G_CALLBACK(selected_page_notify_cb), this);
+
+ hdy_tab_bar_set_view(m_tab_bar, m_tab_view);
+ add(*m_tab_bar_wrapped);
+ m_tab_bar_wrapped->show();
+}
+
+void ChannelTabSwitcherHandy::AddChannelTab(Snowflake id) {
+ auto &discord = Abaddon::Get().GetDiscordClient();
+ const auto channel = discord.GetChannel(id);
+ if (!channel.has_value()) return;
+
+ auto *dummy = Gtk::make_managed<Gtk::Box>(); // minimal
+ auto *page = hdy_tab_view_append(m_tab_view, GTK_WIDGET(dummy->gobj()));
+
+ hdy_tab_page_set_title(page, ("#" + *channel->Name).c_str());
+
+ m_pages[id] = page;
+ m_pages_rev[page] = id;
+}
+
+void ChannelTabSwitcherHandy::ReplaceActiveTab(Snowflake id) {
+ auto *page = hdy_tab_view_get_selected_page(m_tab_view);
+ if (page == nullptr) {
+ AddChannelTab(id);
+ } else {
+ auto &discord = Abaddon::Get().GetDiscordClient();
+ const auto channel = discord.GetChannel(id);
+ if (!channel.has_value()) return;
+
+ hdy_tab_page_set_title(page, ("#" + *channel->Name).c_str());
+ m_pages_rev[page] = id;
+ }
+}
+
+ChannelTabSwitcherHandy::type_signal_channel_switched_to ChannelTabSwitcherHandy::signal_channel_switched_to() {
+ return m_signal_channel_switched_to;
+}
+
+#endif