From dec82ff94ce18f51867806c75840f824d245f749 Mon Sep 17 00:00:00 2001 From: Eugene G Date: Sat, 8 Nov 2014 18:37:11 +0300 Subject: [PATCH 1/5] autocomplete window now works with mouse --- src/Autocompletion.vala | 11 +++++++++++ src/FinalTerm.vala | 8 ++++++++ src/ScrollableListView.vala | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/src/Autocompletion.vala b/src/Autocompletion.vala index d5086b2..10d9dac 100644 --- a/src/Autocompletion.vala +++ b/src/Autocompletion.vala @@ -49,6 +49,8 @@ public class Autocompletion : Object { scrollable_list_view.set_filter_function(filter_function); scrollable_list_view.set_sort_function(sort_function); + scrollable_list_view.item_hovered.connect(on_item_hovered); + scrollable_list_view.item_clicked.connect(on_item_clicked); on_settings_changed(null); Settings.get_default().changed.connect(on_settings_changed); @@ -212,6 +214,15 @@ public class Autocompletion : Object { stage.set_background_color(Settings.get_default().foreground_color); } + private void on_item_hovered(int index) { + select_entry(index); + } + + private void on_item_clicked(int index) { + run_command(get_selected_command()); + } + + public signal void run_command(string command); private class AutocompletionEntry : Object { diff --git a/src/FinalTerm.vala b/src/FinalTerm.vala index 505d5d8..2cc751b 100644 --- a/src/FinalTerm.vala +++ b/src/FinalTerm.vala @@ -106,6 +106,10 @@ public class FinalTerm : Gtk.Application { im_context.preedit_end.connect(on_preedit_end); main_window.key_press_event.connect(on_key_press_event); main_window.key_release_event.connect(on_key_release_event); + + + autocompletion.run_command.connect(on_autocomplete_run_command); + } protected override void activate() { @@ -243,6 +247,10 @@ public class FinalTerm : Gtk.Application { return true; } + private void on_autocomplete_run_command(string command) { + active_terminal_widget.run_shell_command(command); + } + private bool on_key_release_event(Gdk.EventKey event) { return im_context.filter_keypress(event); } diff --git a/src/ScrollableListView.vala b/src/ScrollableListView.vala index 0bc8f9c..57c53fc 100644 --- a/src/ScrollableListView.vala +++ b/src/ScrollableListView.vala @@ -54,6 +54,8 @@ public class ScrollableListView : Clutter.Actor { list_view.add_attribute(item_property_name, 0); scroll_view.add(list_view); + scroll_view.motion_event.connect(on_motion_event);; + scroll_view.button_press_event.connect(on_button_press_event);; // Synchronize model with list foreach (var item in list) { @@ -143,11 +145,43 @@ public class ScrollableListView : Clutter.Actor { scroll_view.ensure_visible(geometry); } + public int get_item_by_y(int y) { + var index = -1; + var height = 0; + for (var i = 0;i < get_number_of_items();i++) { + var allocation_box = get_item_view(i).get_allocation_box(); + height += (int)allocation_box.get_height(); + if((int)y < height) { + index = i; + break; + } + } + return index; + } + private void on_settings_changed(string? key) { scroll_view.style = Settings.get_default().theme.style; list_view.style = Settings.get_default().theme.style; } + private bool on_motion_event(Clutter.MotionEvent event) { + var index = get_item_by_y((int)event.y); + if(index >= 0) + item_hovered(index); + + return true; + } + + private bool on_button_press_event(Clutter.ButtonEvent event) { + var index = get_item_by_y((int)event.y); + if(index >= 0) + item_clicked(index); + + return true; + } + + public signal void item_hovered(int index); + public signal void item_clicked(int index); private class ItemViewFactory : Object, Mx.ItemFactory { From 6048afab9d7948af168f373da70b46e9d16fc0c8 Mon Sep 17 00:00:00 2001 From: Eugene G Date: Sun, 9 Nov 2014 11:35:15 +0300 Subject: [PATCH 2/5] codestylefixes --- src/FinalTerm.vala | 3 --- src/ScrollableListView.vala | 12 +++++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/FinalTerm.vala b/src/FinalTerm.vala index 2cc751b..b133645 100644 --- a/src/FinalTerm.vala +++ b/src/FinalTerm.vala @@ -106,10 +106,7 @@ public class FinalTerm : Gtk.Application { im_context.preedit_end.connect(on_preedit_end); main_window.key_press_event.connect(on_key_press_event); main_window.key_release_event.connect(on_key_release_event); - - autocompletion.run_command.connect(on_autocomplete_run_command); - } protected override void activate() { diff --git a/src/ScrollableListView.vala b/src/ScrollableListView.vala index 57c53fc..668cb98 100644 --- a/src/ScrollableListView.vala +++ b/src/ScrollableListView.vala @@ -54,7 +54,7 @@ public class ScrollableListView : Clutter.Actor { list_view.add_attribute(item_property_name, 0); scroll_view.add(list_view); - scroll_view.motion_event.connect(on_motion_event);; + scroll_view.motion_event.connect(on_motion_event); scroll_view.button_press_event.connect(on_button_press_event);; // Synchronize model with list @@ -148,10 +148,10 @@ public class ScrollableListView : Clutter.Actor { public int get_item_by_y(int y) { var index = -1; var height = 0; - for (var i = 0;i < get_number_of_items();i++) { + for (int i = 0; i < get_number_of_items(); i++) { var allocation_box = get_item_view(i).get_allocation_box(); height += (int)allocation_box.get_height(); - if((int)y < height) { + if ((int)y < height) { index = i; break; } @@ -166,16 +166,18 @@ public class ScrollableListView : Clutter.Actor { private bool on_motion_event(Clutter.MotionEvent event) { var index = get_item_by_y((int)event.y); - if(index >= 0) + if (index >= 0) { item_hovered(index); + } return true; } private bool on_button_press_event(Clutter.ButtonEvent event) { var index = get_item_by_y((int)event.y); - if(index >= 0) + if (index >= 0) { item_clicked(index); + } return true; } From db715af0f0054fbfe909193072269291470458c7 Mon Sep 17 00:00:00 2001 From: Eugene G Date: Sun, 9 Nov 2014 11:38:21 +0300 Subject: [PATCH 3/5] autocomplete runs command on click using provided index rather than the hover selected command --- src/Autocompletion.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Autocompletion.vala b/src/Autocompletion.vala index 10d9dac..f029450 100644 --- a/src/Autocompletion.vala +++ b/src/Autocompletion.vala @@ -124,7 +124,7 @@ public class Autocompletion : Object { return scrollable_list_view.is_valid_item_index(selected_index); } - public string? get_selected_command() { + public string? scrollable_list_view.get_item(selected_index).text { if (is_command_selected()) return scrollable_list_view.get_item(selected_index).text; @@ -219,7 +219,7 @@ public class Autocompletion : Object { } private void on_item_clicked(int index) { - run_command(get_selected_command()); + run_command(scrollable_list_view.get_item(index).text); } public signal void run_command(string command); From b1cae980902fc01d80df8c2978e770f1494c2c94 Mon Sep 17 00:00:00 2001 From: Eugene G Date: Sat, 15 Nov 2014 15:15:41 +0300 Subject: [PATCH 4/5] fix. sorry --- src/Autocompletion.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Autocompletion.vala b/src/Autocompletion.vala index f029450..c263c50 100644 --- a/src/Autocompletion.vala +++ b/src/Autocompletion.vala @@ -124,7 +124,7 @@ public class Autocompletion : Object { return scrollable_list_view.is_valid_item_index(selected_index); } - public string? scrollable_list_view.get_item(selected_index).text { + public string? get_selected_command() { if (is_command_selected()) return scrollable_list_view.get_item(selected_index).text; From 5e4f7cb6a26f49ac5d13337afcd3918e7d440c18 Mon Sep 17 00:00:00 2001 From: Eugene G Date: Sat, 15 Nov 2014 16:50:23 +0300 Subject: [PATCH 5/5] implementation on click (print command), doubleclick (execute command) autocomplete functionality --- src/Autocompletion.vala | 6 ++++++ src/FinalTerm.vala | 5 +++++ src/ScrollableListView.vala | 26 +++++++++++++++++++++++--- src/Terminal.vala | 2 +- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/Autocompletion.vala b/src/Autocompletion.vala index c263c50..5af88b0 100644 --- a/src/Autocompletion.vala +++ b/src/Autocompletion.vala @@ -51,6 +51,7 @@ public class Autocompletion : Object { scrollable_list_view.set_sort_function(sort_function); scrollable_list_view.item_hovered.connect(on_item_hovered); scrollable_list_view.item_clicked.connect(on_item_clicked); + scrollable_list_view.item_double_clicked.connect(on_item_double_clicked); on_settings_changed(null); Settings.get_default().changed.connect(on_settings_changed); @@ -219,10 +220,15 @@ public class Autocompletion : Object { } private void on_item_clicked(int index) { + select_command(scrollable_list_view.get_item(index).text); + } + + private void on_item_double_clicked(int index) { run_command(scrollable_list_view.get_item(index).text); } public signal void run_command(string command); + public signal void select_command(string command); private class AutocompletionEntry : Object { diff --git a/src/FinalTerm.vala b/src/FinalTerm.vala index b133645..33240cf 100644 --- a/src/FinalTerm.vala +++ b/src/FinalTerm.vala @@ -107,6 +107,7 @@ public class FinalTerm : Gtk.Application { main_window.key_press_event.connect(on_key_press_event); main_window.key_release_event.connect(on_key_release_event); autocompletion.run_command.connect(on_autocomplete_run_command); + autocompletion.select_command.connect(on_autocomplete_select_command); } protected override void activate() { @@ -248,6 +249,10 @@ public class FinalTerm : Gtk.Application { active_terminal_widget.run_shell_command(command); } + private void on_autocomplete_select_command(string command) { + active_terminal_widget.set_shell_command(command); + } + private bool on_key_release_event(Gdk.EventKey event) { return im_context.filter_keypress(event); } diff --git a/src/ScrollableListView.vala b/src/ScrollableListView.vala index 668cb98..717e2c4 100644 --- a/src/ScrollableListView.vala +++ b/src/ScrollableListView.vala @@ -27,6 +27,8 @@ public class ScrollableListView : Clutter.Actor { private Clutter.Model list_model; + private bool process_click = false; + public ScrollableListView(NotifyingList list, Type item_type, Type item_view_type, string item_property_name) { scroll_view = new Mx.ScrollView(); add(scroll_view); @@ -150,7 +152,7 @@ public class ScrollableListView : Clutter.Actor { var height = 0; for (int i = 0; i < get_number_of_items(); i++) { var allocation_box = get_item_view(i).get_allocation_box(); - height += (int)allocation_box.get_height(); + height += (int)allocation_box.get_height(); if ((int)y < height) { index = i; break; @@ -174,9 +176,26 @@ public class ScrollableListView : Clutter.Actor { } private bool on_button_press_event(Clutter.ButtonEvent event) { - var index = get_item_by_y((int)event.y); + int index = get_item_by_y((int)event.y); + process_click = false; + if (index >= 0) { - item_clicked(index); + if (event.click_count == 1) { + process_click = true; + ScrollableListView instance = this; + // Button press event fires twice on double click + // because of this the processing of the first click should be delayed + // if the second click has happened in the meantime process_click would be false + // TODO: look for a better solution + Timeout.add(Clutter.Settings.get_default().double_click_time + 50, () => { + if (instance.process_click) { + instance.item_clicked(index); + } + return false; + }, Priority.DEFAULT); + } else if (event.click_count > 1) { + item_double_clicked(index); + } } return true; @@ -184,6 +203,7 @@ public class ScrollableListView : Clutter.Actor { public signal void item_hovered(int index); public signal void item_clicked(int index); + public signal void item_double_clicked(int index); private class ItemViewFactory : Object, Mx.ItemFactory { diff --git a/src/Terminal.vala b/src/Terminal.vala index ff58dec..a958300 100644 --- a/src/Terminal.vala +++ b/src/Terminal.vala @@ -120,7 +120,7 @@ public class Terminal : Object { } private void on_output_command_updated(string command) { - message(_("Command updated: '%s'"), command); + // message(_("Command updated: '%s'"), command); var stripped_command = command.strip(); if (stripped_command == "") {