aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/conversation_content_view
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2023-02-16 12:49:31 +0100
committerfiaxh <git@lightrise.org>2023-02-16 12:51:33 +0100
commitc526848098ff187615f0be0b531c9b45644d0e03 (patch)
treedeebec52e3067df22a69573a5af8b457d1546779 /main/src/ui/conversation_content_view
parentf7750c548abd9f686b12380a7aa852fe3a2a8d1b (diff)
downloaddino-c526848098ff187615f0be0b531c9b45644d0e03.tar.gz
dino-c526848098ff187615f0be0b531c9b45644d0e03.zip
Stop regenerating message menu buttons
mitigates #1343
Diffstat (limited to 'main/src/ui/conversation_content_view')
-rw-r--r--main/src/ui/conversation_content_view/conversation_view.vala67
-rw-r--r--main/src/ui/conversation_content_view/item_actions.vala11
-rw-r--r--main/src/ui/conversation_content_view/message_widget.vala3
3 files changed, 49 insertions, 32 deletions
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<Widget> action_buttons = new ArrayList<Widget>();
+ private HashMap<string, Widget> action_buttons = new HashMap<string, Widget>();
private Gee.List<Dino.Plugins.MessageAction>? 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);
}
}
diff --git a/main/src/ui/conversation_content_view/item_actions.vala b/main/src/ui/conversation_content_view/item_actions.vala
index 2cca7565..d4195bdd 100644
--- a/main/src/ui/conversation_content_view/item_actions.vala
+++ b/main/src/ui/conversation_content_view/item_actions.vala
@@ -4,14 +4,14 @@ using Gtk;
namespace Dino.Ui {
public Plugins.MessageAction get_reaction_action(ContentItem content_item, Conversation conversation, StreamInteractor stream_interactor) {
Plugins.MessageAction action = new Plugins.MessageAction();
+ action.name = "reaction";
action.icon_name = "dino-emoticon-add-symbolic";
action.tooltip = _("Add reaction");
- EmojiChooser chooser = new EmojiChooser();
- chooser.emoji_picked.connect((emoji) => {
+ action.callback = (variant) => {
+ string emoji = variant.get_string();
stream_interactor.get_module(Reactions.IDENTITY).add_reaction(conversation, content_item, emoji);
- });
- action.popover = chooser;
+ };
// Disable the button if reaction aren't possible.
bool supports_reactions = stream_interactor.get_module(Reactions.IDENTITY).conversation_supports_reactions(conversation);
@@ -29,9 +29,10 @@ namespace Dino.Ui {
public Plugins.MessageAction get_reply_action(ContentItem content_item, Conversation conversation, StreamInteractor stream_interactor) {
Plugins.MessageAction action = new Plugins.MessageAction();
+ action.name = "reply";
action.icon_name = "mail-reply-sender-symbolic";
action.tooltip = _("Reply");
- action.callback = (button, content_meta_item_activated, widget) => {
+ action.callback = () => {
GLib.Application.get_default().activate_action("quote", new GLib.Variant.tuple(new GLib.Variant[] { new GLib.Variant.int32(conversation.id), new GLib.Variant.int32(content_item.id) }));
};
diff --git a/main/src/ui/conversation_content_view/message_widget.vala b/main/src/ui/conversation_content_view/message_widget.vala
index b05fe850..d7733d5a 100644
--- a/main/src/ui/conversation_content_view/message_widget.vala
+++ b/main/src/ui/conversation_content_view/message_widget.vala
@@ -209,9 +209,10 @@ public class MessageMetaItem : ContentMetaItem {
bool correction_allowed = stream_interactor.get_module(MessageCorrection.IDENTITY).is_own_correction_allowed(message_item.conversation, message_item.message);
if (correction_allowed) {
Plugins.MessageAction action1 = new Plugins.MessageAction();
+ action1.name = "correction";
action1.icon_name = "document-edit-symbolic";
action1.tooltip = _("Edit message");
- action1.callback = (button, content_meta_item_activated, widget) => {
+ action1.callback = () => {
this.in_edit_mode = true;
};
actions.add(action1);