Adds quote functionality
This commit is contained in:
parent
be78daef22
commit
55668fa93b
|
@ -10,6 +10,7 @@ namespace Dino.Ui.ConversationSummary {
|
|||
[GtkTemplate (ui = "/im/dino/Dino/conversation_content_view/view.ui")]
|
||||
public class ConversationView : Box, Plugins.ConversationItemCollection, Plugins.NotificationCollection {
|
||||
|
||||
public signal void on_quote_text(string text);
|
||||
public Conversation? conversation { get; private set; }
|
||||
|
||||
[GtkChild] public unowned ScrolledWindow scrolled;
|
||||
|
@ -308,6 +309,9 @@ public class ConversationView : Box, Plugins.ConversationItemCollection, Plugins
|
|||
insert_new(item);
|
||||
if (item as ContentMetaItem != null) {
|
||||
content_items.add(item);
|
||||
|
||||
MessageMetaItem current_item = item as MessageMetaItem;
|
||||
current_item.on_quote_text.connect((t, text) => on_quote_text(text));
|
||||
}
|
||||
meta_items.add(item);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Dino.Ui.ConversationSummary {
|
|||
|
||||
public class MessageMetaItem : ContentMetaItem {
|
||||
|
||||
public signal void on_quote_text(string text);
|
||||
private StreamInteractor stream_interactor;
|
||||
private MessageItemWidget message_item_widget;
|
||||
private MessageItem message_item;
|
||||
|
@ -54,6 +55,15 @@ public class MessageMetaItem : ContentMetaItem {
|
|||
};
|
||||
actions.add(action1);
|
||||
}
|
||||
|
||||
Plugins.MessageAction action2 = new Plugins.MessageAction();
|
||||
action2.icon_name = "go-previous-symbolic-rtl";
|
||||
action2.callback = (button, content_meta_item_activated, widget) => {
|
||||
string text_to_quote = ((MessageItem) message_item_widget.content_item).message.body;
|
||||
on_quote_text(text_to_quote);
|
||||
};
|
||||
actions.add(action2);
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,33 @@ public class ConversationView : Gtk.Overlay {
|
|||
|
||||
construct {
|
||||
white_revealer.notify["child-revealed"].connect_after(on_child_revealed_changed);
|
||||
conversation_frame.on_quote_text.connect((t, text) => on_quote_text(text));
|
||||
}
|
||||
|
||||
public void on_quote_text(string text) {
|
||||
unowned TextBuffer buffer = chat_input.chat_text_view.text_view.buffer;
|
||||
string text_to_quote = text;
|
||||
|
||||
Regex quotes = new Regex("((?<=\n)>.*(\n|$))|(^>.*(\n|$))");
|
||||
Regex whitespace = new Regex("(\n *){2,}");
|
||||
Regex first_column = new Regex("(^|\n)(.+)");
|
||||
Regex end = new Regex("\n*$");
|
||||
|
||||
text_to_quote = quotes.replace(text_to_quote, -1, 0, "");
|
||||
text_to_quote = whitespace.replace(text_to_quote, -1, 0, "\n");
|
||||
text_to_quote = "%s".printf(text_to_quote);
|
||||
|
||||
text_to_quote = first_column.replace(text_to_quote, -1, 0, "\\1> \\2");
|
||||
|
||||
string to_replace = "\n";
|
||||
if(buffer.cursor_position > 0) {
|
||||
to_replace = "";
|
||||
text_to_quote = "\n" + text_to_quote;
|
||||
}
|
||||
|
||||
text_to_quote = end.replace(text_to_quote, -1, 0, to_replace);
|
||||
|
||||
buffer.insert_at_cursor(text_to_quote, -1);
|
||||
}
|
||||
|
||||
public void add_overlay_dialog(Widget widget) {
|
||||
|
|
Loading…
Reference in New Issue