From 7e7dcedaf31ee35499875491c9f569c575d28435 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 14 Feb 2022 14:55:59 +0100 Subject: Port from GTK3 to GTK4 --- main/src/ui/chat_input/edit_history.vala | 77 -------------------------------- 1 file changed, 77 deletions(-) delete mode 100644 main/src/ui/chat_input/edit_history.vala (limited to 'main/src/ui/chat_input/edit_history.vala') diff --git a/main/src/ui/chat_input/edit_history.vala b/main/src/ui/chat_input/edit_history.vala deleted file mode 100644 index 70f6d400..00000000 --- a/main/src/ui/chat_input/edit_history.vala +++ /dev/null @@ -1,77 +0,0 @@ -using Gdk; -using Gee; -using Gtk; - -using Dino.Entities; - -namespace Dino.Ui { - -public class EditHistory { - - private Conversation? conversation; - private TextView text_input; - - private HashMap> histories = new HashMap>(Conversation.hash_func, Conversation.equals_func); - private HashMap indices = new HashMap(Conversation.hash_func, Conversation.equals_func); - - public EditHistory(TextView text_input) { - this.text_input = text_input; - - text_input.key_press_event.connect(on_text_input_key_press); - text_input.cut_clipboard.connect_after(save_state); - text_input.paste_clipboard.connect_after(save_state); - text_input.move_cursor.connect_after(save_state); - text_input.button_release_event.connect_after(() => { save_state(); return false; }); - } - - public void initialize_for_conversation(Conversation conversation) { - this.conversation = conversation; - if (!histories.has_key(conversation)) { - reset_history(); - } - } - - public bool on_text_input_key_press(EventKey event) { - bool ctrl_pressed = (event.state & ModifierType.CONTROL_MASK) > 0; - if (ctrl_pressed && event.keyval == Key.z) { - undo(); - } else if (ctrl_pressed && (event.keyval in new uint[]{ Key.Z, Key.y } )) { - redo(); - } else if (event.keyval in new uint[]{ Key.space, Key.Tab, Key.ISO_Left_Tab }) { - save_state(); - } - return false; - } - - private void undo() { - save_state(); - if (indices[conversation] > 0) { - indices[conversation] = indices[conversation] - 1; - text_input.buffer.text = histories[conversation][indices[conversation]]; - } - } - - private void redo() { - if (indices[conversation] < histories[conversation].size - 1) { - indices[conversation] = indices[conversation] + 1; - text_input.buffer.text = histories[conversation][indices[conversation]]; - } - } - - private void save_state() { - if (histories[conversation][indices[conversation]] == text_input.buffer.text) return; - if (indices[conversation] < histories[conversation].size - 1) { - histories[conversation] = histories[conversation].slice(0, indices[conversation] + 1); - } - histories[conversation].add(text_input.buffer.text); - indices[conversation] = indices[conversation] + 1; - } - - public void reset_history() { - histories[conversation] = new ArrayList(); - histories[conversation].add(""); - indices[conversation] = 0; - } -} - -} -- cgit v1.2.3-54-g00ecf