add confirmation dialog to leave guild

This commit is contained in:
ouwou 2020-10-12 00:36:18 -04:00
parent 1ff177ad5a
commit 21fdada41c
4 changed files with 51 additions and 1 deletions

View File

@ -138,6 +138,8 @@ add_executable(abaddon
components/chatwindow.cpp
components/memberlist.hpp
components/memberlist.cpp
dialogs/confirm.hpp
dialogs/confirm.cpp
dialogs/editmessage.hpp
dialogs/editmessage.cpp
dialogs/joinguild.hpp

View File

@ -6,6 +6,7 @@
#include "dialogs/token.hpp"
#include "dialogs/editmessage.hpp"
#include "dialogs/joinguild.hpp"
#include "dialogs/confirm.hpp"
#include "abaddon.hpp"
#ifdef _WIN32
@ -314,7 +315,10 @@ void Abaddon::ActionInsertMention(Snowflake id) {
}
void Abaddon::ActionLeaveGuild(Snowflake id) {
m_discord.LeaveGuild(id);
ConfirmDialog dlg(*m_main_window);
auto response = dlg.run();
if (response == Gtk::RESPONSE_OK)
m_discord.LeaveGuild(id);
}
void Abaddon::ActionReloadCSS() {

30
dialogs/confirm.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "confirm.hpp"
ConfirmDialog::ConfirmDialog(Gtk::Window &parent)
: Gtk::Dialog("Confirm", parent, true)
, m_layout(Gtk::ORIENTATION_VERTICAL)
, m_bbox(Gtk::ORIENTATION_HORIZONTAL)
, m_ok("OK")
, m_cancel("Cancel") {
set_default_size(300, 50);
m_label.set_text("Are you sure?");
m_ok.signal_clicked().connect([&]() {
response(Gtk::RESPONSE_OK);
});
m_cancel.signal_clicked().connect([&]() {
response(Gtk::RESPONSE_CANCEL);
});
m_bbox.pack_start(m_ok, Gtk::PACK_SHRINK);
m_bbox.pack_start(m_cancel, Gtk::PACK_SHRINK);
m_bbox.set_layout(Gtk::BUTTONBOX_END);
m_layout.add(m_label);
m_layout.add(m_bbox);
get_content_area()->add(m_layout);
show_all_children();
}

14
dialogs/confirm.hpp Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include <gtkmm.h>
class ConfirmDialog : public Gtk::Dialog {
public:
ConfirmDialog(Gtk::Window &parent);
protected:
Gtk::Label m_label;
Gtk::Box m_layout;
Gtk::Button m_ok;
Gtk::Button m_cancel;
Gtk::ButtonBox m_bbox;
};