From c7426c9fb97f1afdf2b33a055d977762af92c795 Mon Sep 17 00:00:00 2001 From: frosty Date: Mon, 26 Oct 2026 13:57:33 -0400 Subject: feat: multiline topic entry --- main/src/ui/conversation_details.vala | 4 +- main/src/ui/util/preference_group.vala | 80 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) (limited to 'main/src/ui') diff --git a/main/src/ui/conversation_details.vala b/main/src/ui/conversation_details.vala index f9bae672..ea42e5d8 100644 --- a/main/src/ui/conversation_details.vala +++ b/main/src/ui/conversation_details.vala @@ -201,9 +201,9 @@ namespace Dino.Ui.ConversationDetails { Xep.Muc.Role? own_role = stream_interactor.get_module(MucManager.IDENTITY).get_role(own_muc_jid, conversation.account); if (own_role != null) { if (own_role == MODERATOR) { - var preferences_row_entry = new ViewModel.PreferencesRow.Entry() { + var preferences_row_entry = new ViewModel.PreferencesRow.MultilineEntry() { title = _("Topic"), - text = topic + text = topic ?? "" }; preferences_row_entry.changed.connect(() => { if (preferences_row_entry.text != topic) { diff --git a/main/src/ui/util/preference_group.vala b/main/src/ui/util/preference_group.vala index f34f0d92..4476bd20 100644 --- a/main/src/ui/util/preference_group.vala +++ b/main/src/ui/util/preference_group.vala @@ -6,6 +6,76 @@ using Dino.Entities; using Xmpp.Xep; namespace Dino.Ui.Util { + public class MultilineEntryRow : Adw.PreferencesRow { + public signal void apply(); + + public string text { + owned get { return text_view.buffer.text; } + set { + if (text_view.buffer.text == value) return; + updating_text = true; + text_view.buffer.text = value; + updating_text = false; + apply_button.visible = false; + } + } + + public TextView text_view { get; private set; } + private Button apply_button; + private bool updating_text = false; + + public MultilineEntryRow(string title) { + Object(title: title); + + var title_label = new Label(title) { xalign = 0, hexpand = true }; + apply_button = new Button.from_icon_name("object-select-symbolic") { + valign = Align.CENTER, + tooltip_text = _("Apply"), + visible = false + }; + apply_button.add_css_class("flat"); + apply_button.clicked.connect(() => { + apply_button.visible = false; + apply(); + }); + + var header = new Box(Orientation.HORIZONTAL, 6); + header.append(title_label); + header.append(apply_button); + + text_view = new TextView() { + wrap_mode = WrapMode.WORD_CHAR, + accepts_tab = false, + hexpand = true, + left_margin = 6, + right_margin = 6, + top_margin = 6, + bottom_margin = 6 + }; + text_view.buffer.changed.connect(() => { + if (updating_text) return; + apply_button.visible = true; + notify_property("text"); + }); + + var text_frame = new Frame(null) { + child = text_view, + hexpand = true + }; + + var box = new Box(Orientation.VERTICAL, 6) { + hexpand = true, + margin_start = 12, + margin_end = 12, + margin_top = 6, + margin_bottom = 6 + }; + box.append(header); + box.append(text_frame); + child = box; + } + } + public Gee.List rows_to_preference_window_split_at_text(GLib.ListStore row_view_models) { var preference_groups = new ArrayList(); Adw.PreferencesGroup? preference_group = null; @@ -70,6 +140,16 @@ namespace Dino.Ui.Util { }); } + var multiline_entry_view_model = preferences_row as ViewModel.PreferencesRow.MultilineEntry; + if (multiline_entry_view_model != null) { + var multiline_entry_row = new MultilineEntryRow(preferences_row.title); + multiline_entry_view_model.bind_property("text", multiline_entry_row, "text", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL, null_string_to_empty); + multiline_entry_row.apply.connect(() => { + multiline_entry_view_model.changed(); + }); + view = multiline_entry_row; + } + var password_view_model = preferences_row as ViewModel.PreferencesRow.PrivateText; if (password_view_model != null) { view = new Adw.PasswordEntryRow() { show_apply_button=true }; -- cgit v1.3