add change filename

This commit is contained in:
ouwou 2022-06-23 00:48:00 -04:00
parent 4ee7025ab0
commit d841a2c862
6 changed files with 68 additions and 0 deletions

View File

@ -11,6 +11,7 @@
#include "dialogs/setstatus.hpp"
#include "dialogs/friendpicker.hpp"
#include "dialogs/verificationgate.hpp"
#include "dialogs/textinput.hpp"
#include "abaddon.hpp"
#include "windows/guildsettingswindow.hpp"
#include "windows/profilewindow.hpp"
@ -867,6 +868,15 @@ void Abaddon::ActionViewThreads(Snowflake channel_id) {
window->show();
}
std::optional<Glib::ustring> Abaddon::ShowTextPrompt(const Glib::ustring &prompt, const Glib::ustring &title, const Glib::ustring &placeholder, Gtk::Window *window) {
TextInputDialog dlg(prompt, title, placeholder, window != nullptr ? *window : *m_main_window);
const auto code = dlg.run();
if (code == Gtk::RESPONSE_OK)
return dlg.GetInput();
else
return {};
}
bool Abaddon::ShowConfirm(const Glib::ustring &prompt, Gtk::Window *window) {
ConfirmDialog dlg(window != nullptr ? *window : *m_main_window);
dlg.SetConfirmText(prompt);

View File

@ -51,6 +51,7 @@ public:
void ActionViewPins(Snowflake channel_id);
void ActionViewThreads(Snowflake channel_id);
std::optional<Glib::ustring> ShowTextPrompt(const Glib::ustring &prompt, const Glib::ustring &title, const Glib::ustring &placeholder = "", Gtk::Window *window = nullptr);
bool ShowConfirm(const Glib::ustring &prompt, Gtk::Window *window = nullptr);
void ActionReloadCSS();

View File

@ -220,6 +220,7 @@ ChatInputAttachmentItem::ChatInputAttachmentItem(const Glib::RefPtr<Gio::File> &
show_all_children();
SetupMenu();
UpdateTooltip();
}
Glib::RefPtr<Gio::File> ChatInputAttachmentItem::GetFile() const {
@ -249,6 +250,16 @@ void ChatInputAttachmentItem::SetupMenu() {
m_signal_item_removed.emit();
});
m_menu_set_filename.set_label("Change Filename");
m_menu_set_filename.signal_activate().connect([this] {
const auto name = Abaddon::Get().ShowTextPrompt("Enter new filename for attachment", "Enter filename", m_filename);
if (name.has_value()) {
m_filename = *name;
UpdateTooltip();
}
});
m_menu.add(m_menu_set_filename);
m_menu.add(m_menu_remove);
m_menu.show_all();
@ -262,6 +273,10 @@ void ChatInputAttachmentItem::SetupMenu() {
});
}
void ChatInputAttachmentItem::UpdateTooltip() {
set_tooltip_text(m_filename);
}
ChatInputAttachmentItem::type_signal_item_removed ChatInputAttachmentItem::signal_item_removed() {
return m_signal_item_removed;
}

View File

@ -16,9 +16,11 @@ public:
private:
void SetupMenu();
void UpdateTooltip();
Gtk::Menu m_menu;
Gtk::MenuItem m_menu_remove;
Gtk::MenuItem m_menu_set_filename;
Gtk::Box m_box;
Gtk::Image *m_img = nullptr;

26
src/dialogs/textinput.cpp Normal file
View File

@ -0,0 +1,26 @@
#include "textinput.hpp"
TextInputDialog::TextInputDialog(const Glib::ustring &prompt, const Glib::ustring &title, const Glib::ustring &placeholder, Gtk::Window &parent)
: Gtk::Dialog(title, parent, true)
, m_label(prompt) {
get_style_context()->add_class("app-window");
get_style_context()->add_class("app-popup");
auto ok = add_button("OK", Gtk::RESPONSE_OK);
auto cancel = add_button("Cancel", Gtk::RESPONSE_CANCEL);
get_content_area()->add(m_label);
get_content_area()->add(m_entry);
m_entry.set_text(placeholder);
m_entry.set_activates_default(true);
ok->set_can_default(true);
ok->grab_default();
show_all_children();
}
Glib::ustring TextInputDialog::GetInput() const {
return m_entry.get_text();
}

14
src/dialogs/textinput.hpp Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include <gtkmm/dialog.h>
#include <gtkmm/entry.h>
class TextInputDialog : public Gtk::Dialog {
public:
TextInputDialog(const Glib::ustring &prompt, const Glib::ustring &title, const Glib::ustring &placeholder, Gtk::Window &parent);
Glib::ustring GetInput() const;
private:
Gtk::Label m_label;
Gtk::Entry m_entry;
};