mirror of
https://github.com/uowuo/abaddon.git
synced 2024-11-10 14:10:10 +00:00
create folders in guild list
This commit is contained in:
parent
2168f011f5
commit
09cfa864be
@ -12,15 +12,37 @@ void GuildList::UpdateListing() {
|
|||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
// does this function still even work ??lol
|
// does this function still even work ??lol
|
||||||
const auto ids = discord.GetUserSortedGuilds();
|
const auto folders = discord.GetUserSettings().GuildFolders;
|
||||||
for (const auto id : ids) {
|
const auto guild_ids = discord.GetUserSortedGuilds();
|
||||||
AddGuild(id);
|
|
||||||
|
// same logic from ChannelListTree
|
||||||
|
|
||||||
|
std::set<Snowflake> foldered_guilds;
|
||||||
|
for (const auto &group : folders) {
|
||||||
|
foldered_guilds.insert(group.GuildIDs.begin(), group.GuildIDs.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto iter = guild_ids.crbegin(); iter != guild_ids.crend(); iter++) {
|
||||||
|
if (foldered_guilds.find(*iter) == foldered_guilds.end()) {
|
||||||
|
AddGuild(*iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto &group : folders) {
|
||||||
|
AddFolder(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuildList::AddGuild(Snowflake id) {
|
void GuildList::AddGuild(Snowflake id) {
|
||||||
|
if (auto item = CreateGuildWidget(id)) {
|
||||||
|
item->show();
|
||||||
|
add(*item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GuildListGuildItem *GuildList::CreateGuildWidget(Snowflake id) {
|
||||||
const auto guild = Abaddon::Get().GetDiscordClient().GetGuild(id);
|
const auto guild = Abaddon::Get().GetDiscordClient().GetGuild(id);
|
||||||
if (!guild.has_value()) return;
|
if (!guild.has_value()) return nullptr;
|
||||||
|
|
||||||
auto *item = Gtk::make_managed<GuildListGuildItem>(*guild);
|
auto *item = Gtk::make_managed<GuildListGuildItem>(*guild);
|
||||||
item->signal_button_press_event().connect([this, id](GdkEventButton *event) -> bool {
|
item->signal_button_press_event().connect([this, id](GdkEventButton *event) -> bool {
|
||||||
@ -29,8 +51,29 @@ void GuildList::AddGuild(Snowflake id) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
item->show();
|
|
||||||
add(*item);
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GuildList::AddFolder(const UserSettingsGuildFoldersEntry &folder) {
|
||||||
|
// groups with no ID arent actually folders
|
||||||
|
if (!folder.ID.has_value()) {
|
||||||
|
if (!folder.GuildIDs.empty()) {
|
||||||
|
AddGuild(folder.GuildIDs[0]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *folder_widget = Gtk::make_managed<GuildListFolderItem>();
|
||||||
|
for (const auto guild_id : folder.GuildIDs) {
|
||||||
|
if (auto *guild_widget = CreateGuildWidget(guild_id)) {
|
||||||
|
guild_widget->show();
|
||||||
|
folder_widget->AddGuildWidget(guild_widget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
folder_widget->show();
|
||||||
|
add(*folder_widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuildList::Clear() {
|
void GuildList::Clear() {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <gtkmm/listbox.h>
|
#include <gtkmm/listbox.h>
|
||||||
#include "discord/snowflake.hpp"
|
#include "discord/snowflake.hpp"
|
||||||
|
#include "discord/usersettings.hpp"
|
||||||
|
|
||||||
|
class GuildListGuildItem;
|
||||||
|
|
||||||
class GuildList : public Gtk::ListBox {
|
class GuildList : public Gtk::ListBox {
|
||||||
public:
|
public:
|
||||||
@ -10,8 +13,11 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void AddGuild(Snowflake id);
|
void AddGuild(Snowflake id);
|
||||||
|
void AddFolder(const UserSettingsGuildFoldersEntry &folder);
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
|
GuildListGuildItem *CreateGuildWidget(Snowflake id);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using type_signal_guild_selected = sigc::signal<void, Snowflake>;
|
using type_signal_guild_selected = sigc::signal<void, Snowflake>;
|
||||||
|
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#include "guildlistfolderitem.hpp"
|
#include "guildlistfolderitem.hpp"
|
||||||
|
#include "guildlistguilditem.hpp"
|
||||||
|
|
||||||
GuildListFolderItem::GuildListFolderItem() {
|
GuildListFolderItem::GuildListFolderItem() {
|
||||||
m_revealer.add(m_box);
|
m_revealer.add(m_box);
|
||||||
m_revealer.set_reveal_child(true);
|
m_revealer.set_reveal_child(true);
|
||||||
|
|
||||||
|
m_image.property_pixbuf() = Abaddon::Get().GetImageManager().GetPlaceholder(48);
|
||||||
|
|
||||||
m_ev.signal_button_press_event().connect([this](GdkEventButton *event) -> bool {
|
m_ev.signal_button_press_event().connect([this](GdkEventButton *event) -> bool {
|
||||||
if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY) {
|
if (event->type == GDK_BUTTON_PRESS && event->button == GDK_BUTTON_PRIMARY) {
|
||||||
m_revealer.set_reveal_child(!m_revealer.get_reveal_child());
|
m_revealer.set_reveal_child(!m_revealer.get_reveal_child());
|
||||||
@ -16,3 +19,7 @@ GuildListFolderItem::GuildListFolderItem() {
|
|||||||
add(m_revealer);
|
add(m_revealer);
|
||||||
show_all_children();
|
show_all_children();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GuildListFolderItem::AddGuildWidget(GuildListGuildItem *widget) {
|
||||||
|
m_box.add(*widget);
|
||||||
|
}
|
||||||
|
@ -6,10 +6,14 @@
|
|||||||
|
|
||||||
#include "guildlistguilditem.hpp"
|
#include "guildlistguilditem.hpp"
|
||||||
|
|
||||||
|
class GuildListGuildItem;
|
||||||
|
|
||||||
class GuildListFolderItem : public Gtk::VBox {
|
class GuildListFolderItem : public Gtk::VBox {
|
||||||
public:
|
public:
|
||||||
GuildListFolderItem();
|
GuildListFolderItem();
|
||||||
|
|
||||||
|
void AddGuildWidget(GuildListGuildItem *widget);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Gtk::EventBox m_ev;
|
Gtk::EventBox m_ev;
|
||||||
Gtk::Image m_image;
|
Gtk::Image m_image;
|
||||||
|
Loading…
Reference in New Issue
Block a user