This repository has been archived by the owner on Nov 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 179
Issue #381 clickable autocomplete #383
Open
Eugene-msc
wants to merge
5
commits into
p-e-w:master
Choose a base branch
from
Eugene-msc:autocomplete-clickable
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dec82ff
autocomplete window now works with mouse
Eugene-msc 6048afa
codestylefixes
Eugene-msc db715af
autocomplete runs command on click using provided index rather than t…
Eugene-msc b1cae98
fix. sorry
Eugene-msc 5e4f7cb
implementation on click (print command), doubleclick (execute command…
Eugene-msc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ public class ScrollableListView<T, E> : Clutter.Actor { | |
|
||
private Clutter.Model list_model; | ||
|
||
private bool process_click = false; | ||
|
||
public ScrollableListView(NotifyingList<T> list, Type item_type, Type item_view_type, string item_property_name) { | ||
scroll_view = new Mx.ScrollView(); | ||
add(scroll_view); | ||
|
@@ -54,6 +56,8 @@ public class ScrollableListView<T, E> : 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);; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doubled semicolons |
||
|
||
// Synchronize model with list | ||
foreach (var item in list) { | ||
|
@@ -143,11 +147,63 @@ public class ScrollableListView<T, E> : Clutter.Actor { | |
scroll_view.ensure_visible(geometry); | ||
} | ||
|
||
public int get_item_by_y(int y) { | ||
var index = -1; | ||
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(); | ||
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) { | ||
int index = get_item_by_y((int)event.y); | ||
process_click = false; | ||
|
||
if (index >= 0) { | ||
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; | ||
} | ||
|
||
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<G> : Object, Mx.ItemFactory { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure what the expected behavior really is here. Maybe on a simple click, the system should actually just put the command in the prompt without executing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel that left click should do the same as pressing enter.
And when someone is using mouse his right hand is on the mouse and not on the keyboard, so to execute a command after click he'll have to move it to the enter button.
But maybe we can put the command in prompt on right click.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think right click should either provide a menu or do nothing at all. Single click should copy the command in the prompt, double click should run the command. I quite sure about the double click though. Mouse usage is not supposed to be fast anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find any reference to double click event in Clutter. Is there one?
If there is not, it should be implemented for the whole of finalterm not just autocomplete, because it will be needed in other cases (text selection by words, for example).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very good question. I spent quite a while looking, and indeed I found that the
Clutter.ButtonEvent
object that you receive in the signal has aclick_count
property that counts the number of clicks in that "click sequence", so checking whether this is >= 2 should do the trick.However, the docs have something weird to say about this: "The clicks do not have to occur on the same actor: providing they occur within the double click distance and time, they are counted as part of the same click sequence."
Still, this is obviously intended to provide double-click support so we should probably just use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also agree with @arkocal's proposal: Single click should copy the command into the prompt, double click should run it, and right/middle/etc. clicks should do nothing.