aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/conversation_content_view
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2020-04-05 16:19:56 +0200
committerfiaxh <git@lightrise.org>2020-04-05 16:19:56 +0200
commitd091a6c3cd0812873bcdef53c51a2f60e12f2b8a (patch)
treed350880657a77e04a777a4d6072b5951c7cd58c0 /main/src/ui/conversation_content_view
parent8f7595418890cc2dac62dc4903405c49e61176d2 (diff)
downloaddino-d091a6c3cd0812873bcdef53c51a2f60e12f2b8a.tar.gz
dino-d091a6c3cd0812873bcdef53c51a2f60e12f2b8a.zip
Add keyboard shortcut (up key) to activate last message correction
Diffstat (limited to 'main/src/ui/conversation_content_view')
-rw-r--r--main/src/ui/conversation_content_view/conversation_view.vala18
-rw-r--r--main/src/ui/conversation_content_view/message_widget.vala24
2 files changed, 41 insertions, 1 deletions
diff --git a/main/src/ui/conversation_content_view/conversation_view.vala b/main/src/ui/conversation_content_view/conversation_view.vala
index 808c6cad..aadb5fdc 100644
--- a/main/src/ui/conversation_content_view/conversation_view.vala
+++ b/main/src/ui/conversation_content_view/conversation_view.vala
@@ -76,6 +76,24 @@ public class ConversationView : Box, Plugins.ConversationItemCollection, Plugins
return this;
}
+ public void activate_last_message_correction() {
+ Gee.BidirIterator<Plugins.MetaConversationItem> iter = content_items.bidir_iterator();
+ iter.last();
+ for (int i = 0; i < 10 && content_items.size > i; i++) {
+ Plugins.MetaConversationItem item = iter.get();
+ MessageMetaItem message_item = item as MessageMetaItem;
+ if (message_item != null) {
+ if ((conversation.type_ == Conversation.Type.CHAT && message_item.jid.equals_bare(conversation.account.bare_jid)) ||
+ (conversation.type_ == Conversation.Type.GROUPCHAT &&
+ message_item.jid.equals(stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account)))) {
+ message_item.in_edit_mode = true;
+ break;
+ }
+ }
+ iter.previous();
+ }
+ }
+
private bool on_enter_notify_event(Gdk.EventCrossing event) {
mouse_inside = true;
update_highlight((int)event.x_root, (int)event.y_root);
diff --git a/main/src/ui/conversation_content_view/message_widget.vala b/main/src/ui/conversation_content_view/message_widget.vala
index 71094c71..aefab6e1 100644
--- a/main/src/ui/conversation_content_view/message_widget.vala
+++ b/main/src/ui/conversation_content_view/message_widget.vala
@@ -28,6 +28,16 @@ public class MessageMetaItem : ContentMetaItem {
stream_interactor.get_module(MessageCorrection.IDENTITY).received_correction.connect(on_received_correction);
+ this.notify["in-edit-mode"].connect(() => {
+ if (in_edit_mode == false) return;
+ bool allowed = stream_interactor.get_module(MessageCorrection.IDENTITY).is_own_correction_allowed(message_item.conversation, message_item.message);
+ if (allowed) {
+ message_item_widget.set_edit_mode();
+ } else {
+ this.in_edit_mode = false;
+ }
+ });
+
return message_item_widget;
}
@@ -106,7 +116,11 @@ public class MessageItemWidget : SizeRequestBin {
unset_edit_mode();
});
edit_mode.send.connect(() => {
- edit_sent(edit_mode.chat_text_view.text_view.buffer.text);
+ if (((MessageItem) content_item).message.body != edit_mode.chat_text_view.text_view.buffer.text) {
+ edit_sent(edit_mode.chat_text_view.text_view.buffer.text);
+ } else {
+ edit_cancelled();
+ }
unset_edit_mode();
});
}
@@ -122,6 +136,9 @@ public class MessageItemWidget : SizeRequestBin {
public void unset_edit_mode() {
this.remove(edit_mode);
this.add(label);
+ label.grab_focus();
+ label.selectable = false;
+ label.selectable = true;
}
public void update_label() {
@@ -200,11 +217,16 @@ public class MessageItemEditMode : Box {
});
emoji_button.set_popover(chooser);
+ chat_text_view.text_view.buffer.changed.connect_after(on_text_view_changed);
+
cancel_button.clicked.connect(() => cancelled());
send_button.clicked.connect(() => send());
chat_text_view.cancel_input.connect(() => cancelled());
chat_text_view.send_text.connect(() => send());
+ }
+ private void on_text_view_changed() {
+ send_button.sensitive = chat_text_view.text_view.buffer.text != "";
}
}