aboutsummaryrefslogtreecommitdiff
path: root/main
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
parent8f7595418890cc2dac62dc4903405c49e61176d2 (diff)
downloaddino-d091a6c3cd0812873bcdef53c51a2f60e12f2b8a.tar.gz
dino-d091a6c3cd0812873bcdef53c51a2f60e12f2b8a.zip
Add keyboard shortcut (up key) to activate last message correction
Diffstat (limited to 'main')
-rw-r--r--main/data/message_item_widget_edit_mode.ui4
-rw-r--r--main/src/ui/chat_input/chat_input_controller.vala13
-rw-r--r--main/src/ui/conversation_content_view/conversation_view.vala18
-rw-r--r--main/src/ui/conversation_content_view/message_widget.vala24
-rw-r--r--main/src/ui/conversation_view_controller.vala2
5 files changed, 57 insertions, 4 deletions
diff --git a/main/data/message_item_widget_edit_mode.ui b/main/data/message_item_widget_edit_mode.ui
index 8a4faca2..b33d8aa3 100644
--- a/main/data/message_item_widget_edit_mode.ui
+++ b/main/data/message_item_widget_edit_mode.ui
@@ -51,13 +51,13 @@
<property name="visible">True</property>
<child>
<object class="GtkButton" id="cancel_button">
- <property name="label">Cancel</property>
+ <property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkButton" id="send_button">
- <property name="label">Update message</property>
+ <property name="label" translatable="yes">Update message</property>
<property name="visible">True</property>
<style>
<class name="suggested-action"/>
diff --git a/main/src/ui/chat_input/chat_input_controller.vala b/main/src/ui/chat_input/chat_input_controller.vala
index c0878c36..4844ff6c 100644
--- a/main/src/ui/chat_input/chat_input_controller.vala
+++ b/main/src/ui/chat_input/chat_input_controller.vala
@@ -8,6 +8,8 @@ namespace Dino.Ui {
public class ChatInputController : Object {
+ public signal void activate_last_message_correction();
+
public new string? conversation_display_name { get; set; }
public string? conversation_topic { get; set; }
@@ -30,6 +32,7 @@ public class ChatInputController : Object {
reset_input_field_status();
chat_input.chat_text_view.text_view.buffer.changed.connect(on_text_input_changed);
+ chat_input.chat_text_view.text_view.key_press_event.connect(on_text_input_key_press);
chat_text_view_controller.send_text.connect(send_text);
chat_input.encryption_widget.encryption_changed.connect(on_encryption_changed);
@@ -145,6 +148,16 @@ public class ChatInputController : Object {
stream_interactor.get_module(ChatInteraction.IDENTITY).on_message_cleared(conversation);
}
}
+
+ private bool on_text_input_key_press(EventKey event) {
+ if (event.keyval == Gdk.Key.Up && chat_input.chat_text_view.text_view.buffer.text == "") {
+ activate_last_message_correction();
+ return true;
+ } else {
+ chat_input.chat_text_view.text_view.grab_focus();
+ }
+ return false;
+ }
}
}
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 != "";
}
}
diff --git a/main/src/ui/conversation_view_controller.vala b/main/src/ui/conversation_view_controller.vala
index 2e03de8f..31c7e612 100644
--- a/main/src/ui/conversation_view_controller.vala
+++ b/main/src/ui/conversation_view_controller.vala
@@ -44,6 +44,7 @@ public class ConversationViewController : Object {
view.drag_data_received.connect(this.on_drag_data_received);
// forward key presses
+ chat_input_controller.activate_last_message_correction.connect(() => view.conversation_frame.activate_last_message_correction());
view.chat_input.key_press_event.connect(forward_key_press_to_chat_input);
view.conversation_frame.key_press_event.connect(forward_key_press_to_chat_input);
titlebar.key_press_event.connect(forward_key_press_to_chat_input);
@@ -160,7 +161,6 @@ public class ConversationViewController : Object {
return false;
}
if (view.chat_input.chat_text_view.text_view.key_press_event(event)) {
- view.chat_input.chat_text_view.text_view.grab_focus();
return true;
}
return false;