From c526848098ff187615f0be0b531c9b45644d0e03 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Thu, 16 Feb 2023 12:49:31 +0100 Subject: Stop regenerating message menu buttons mitigates #1343 --- .../conversation_view.vala | 67 +++++++++++++--------- 1 file changed, 41 insertions(+), 26 deletions(-) (limited to 'main/src/ui/conversation_content_view/conversation_view.vala') diff --git a/main/src/ui/conversation_content_view/conversation_view.vala b/main/src/ui/conversation_content_view/conversation_view.vala index 36e19474..ae7ed657 100644 --- a/main/src/ui/conversation_content_view/conversation_view.vala +++ b/main/src/ui/conversation_content_view/conversation_view.vala @@ -20,7 +20,7 @@ public class ConversationView : Widget, Plugins.ConversationItemCollection, Plug [GtkChild] private unowned Box main; [GtkChild] private unowned Box main_wrap_box; - private ArrayList action_buttons = new ArrayList(); + private HashMap action_buttons = new HashMap(); private Gee.List? message_actions = null; private StreamInteractor stream_interactor; @@ -46,6 +46,30 @@ public class ConversationView : Widget, Plugins.ConversationItemCollection, Plug construct { this.layout_manager = new BinLayout(); + + // Setup all message menu buttons + var correction_button = new Button() { name="correction" }; + correction_button.clicked.connect((button) => { + on_action_button_clicked(button, null); + }); + action_buttons["correction"] = correction_button; + message_menu_box.append(correction_button); + + var reply_button = new Button() { name="reply" }; + reply_button.clicked.connect((button) => { + on_action_button_clicked(button, null); + }); + action_buttons["reply"] = reply_button; + message_menu_box.append(reply_button); + + var reaction_button = new MenuButton() { name="reaction" }; + EmojiChooser chooser = new EmojiChooser(); + chooser.emoji_picked.connect((emoji) => { + on_action_button_clicked(reaction_button, new GLib.Variant.string(emoji)); + }); + reaction_button.popover = chooser; + action_buttons["reaction"] = reaction_button; + message_menu_box.append(reaction_button); } public ConversationView init(StreamInteractor stream_interactor) { @@ -112,7 +136,7 @@ public class ConversationView : Widget, Plugins.ConversationItemCollection, Plug } private bool is_highlight_fixed() { - foreach (Widget widget in action_buttons) { + foreach (Widget widget in action_buttons.values) { MenuButton? menu_button = widget as MenuButton; if (menu_button != null && menu_button.popover.visible) return true; @@ -192,40 +216,33 @@ public class ConversationView : Widget, Plugins.ConversationItemCollection, Plug return; } - foreach (Widget widget in action_buttons) { - message_menu_box.remove(widget); - } - action_buttons.clear(); + var current_message_actions = current_meta_item.get_item_actions(Plugins.WidgetType.GTK4); message_actions = current_meta_item.get_item_actions(Plugins.WidgetType.GTK4); if (message_actions != null) { message_menu_box.visible = true; + foreach (Widget widget in action_buttons.values) { + widget.visible = false; + } + // Configure as many buttons as we need with the actions for the current meta item - foreach (var message_action in message_actions) { - if (message_action.popover != null) { - MenuButton button = new MenuButton(); + foreach (var message_action in current_message_actions) { + Widget button_widget = action_buttons[message_action.name]; + button_widget.visible = true; + if (message_action.name == "reaction") { + MenuButton button = (MenuButton) button_widget; button.sensitive = message_action.sensitive; button.icon_name = message_action.icon_name; - button.set_popover(message_action.popover as Popover); button.tooltip_text = Util.string_if_tooltips_active(message_action.tooltip); - action_buttons.add(button); } else if (message_action.callback != null) { - Button button = new Button(); + Button button = (Button) button_widget; button.sensitive = message_action.sensitive; button.icon_name = message_action.icon_name; - button.clicked.connect(() => { - message_action.callback(button, current_meta_item, currently_highlighted); - }); button.tooltip_text = Util.string_if_tooltips_active(message_action.tooltip); - action_buttons.add(button); } } - - foreach (Widget widget in action_buttons) { - message_menu_box.append(widget); - } } else { message_menu_box.visible = false; } @@ -498,12 +515,10 @@ public class ConversationView : Widget, Plugins.ConversationItemCollection, Plug (upper_item.mark == Message.Marked.WONTSEND) == (lower_item.mark == Message.Marked.WONTSEND); } - private void on_action_button_clicked(ToggleButton button) { - int button_idx = action_buttons.index_of(button); - print(button_idx.to_string() + "\n"); - Plugins.MessageAction message_action = message_actions[button_idx]; - if (message_action.callback != null) { - message_action.callback(button, current_meta_item, currently_highlighted); + private void on_action_button_clicked(Widget widget, GLib.Variant? variant = null) { + foreach (var action in message_actions) { + if (action.name != widget.name) continue; + action.callback(variant); } } -- cgit v1.2.3-54-g00ecf