Commit 43999e1
Support for double clicks in text area (select one word)
Changed files (4)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/Renderer/TextArea.valamodifiedlibbirdfont/TableLayout.valamodifiedlibbirdfont/Widget.vala
Diff
@@ -689,9 +689,7 @@ public class GlyphCanvasArea : DrawingArea { event_flags |= EventMask.SCROLL_MASK; add_events (event_flags);-- bool button_down = false;-+ glyph_canvas.signal_redraw_area.connect ((x, y, w, h) => { queue_draw_area ((int)x, (int)y, (int)w, (int)h); });@@ -725,10 +723,6 @@ public class GlyphCanvasArea : DrawingArea { button_press_event.connect ((t, e)=> { GtkWindow.reset_modifier (e.state); - if (button_down) {- warning (@"Button already is down. $(e.button)");- }- if (e.time < last_press) { warning ("Discarding event."); return true;@@ -738,7 +732,6 @@ public class GlyphCanvasArea : DrawingArea { if (e.type == EventType.BUTTON_PRESS) { TabContent.button_press (e.button, e.x, e.y);- button_down = true; } else if (e.type == EventType.2BUTTON_PRESS) { TabContent.double_click (e.button, e.x, e.y); }@@ -747,10 +740,6 @@ public class GlyphCanvasArea : DrawingArea { }); button_release_event.connect ((t, e)=> {- if (!button_down) {- warning (@"Button is not down $(e.button)");- }- if (e.time < last_release) { warning ("Discarding event."); return true;@@ -758,10 +747,10 @@ public class GlyphCanvasArea : DrawingArea { if (e.type == EventType.BUTTON_RELEASE) { TabContent.button_release ((int) e.button, e.x, e.y);- last_release = e.time;- button_down = false; } + last_release = e.time;+ return true; }); @@ -1660,6 +1660,44 @@ public class TextArea : Widget { return c; } }+ + public override void double_click (uint button, double x, double y) {+ if (is_over (x, y)) {+ carret = get_carret_at (x, y);+ + Paragraph paragraph = paragraphs.get (carret.paragraph);+ + int index = carret.character_index;+ int prev_index = index;+ unichar c;+ + while (paragraph.text.get_prev_char (ref index, out c)) {+ if (c == '\t' || c == ' ' || c == '\n') {+ break;+ }+ + prev_index = index;+ }+ + carret.character_index = prev_index;+ + selection_end = carret.copy ();+ index = selection_end.character_index;+ + while (paragraph.text.get_next_char (ref index, out c)) {+ if (c == '\t' || c == ' ' || c == '\n') {+ break;+ }+ + prev_index = index;+ }+ + selection_end.character_index = prev_index;+ show_selection = selection_is_visible (); + + update_selection = true;+ }+ } } }@@ -25,7 +25,8 @@ public class TableLayout : FontDisplay { public Gee.ArrayList<Widget> widgets = new Gee.ArrayList<Widget> (); public Gee.ArrayList<Widget> focus_ring = new Gee.ArrayList<Widget> (); public int focus_index = 0;- + bool ignore_input = true;+ public Widget? keyboard_focus = null; public TableLayout () {@@ -125,6 +126,11 @@ public class TableLayout : FontDisplay { Widget t; Widget old; CheckBox c;+ + if (ignore_input) {+ printd (@"Ignoring extra clicks.");+ return;+ } foreach (Widget w in widgets) { if (w.is_over (x, y)) {@@ -172,6 +178,11 @@ public class TableLayout : FontDisplay { public override void button_release (int button, double x, double y) { Widget t;++ if (ignore_input) {+ printd (@"Ignoring extra clicks.");+ return;+ } if (keyboard_focus != null) { t = (!) keyboard_focus;@@ -231,6 +242,15 @@ public class TableLayout : FontDisplay { } public override void selected_canvas () {+ ignore_input = true;+ + TimeoutSource input_delay = new TimeoutSource (250);+ input_delay.set_callback(() => {+ ignore_input = false;+ return false;+ });+ input_delay.attach (null);+ KeyBindings.set_require_modifier (true); update_scrollbar (); GlyphCanvas.redraw ();@@ -251,6 +271,29 @@ public class TableLayout : FontDisplay { public override bool needs_modifier () { return true; }+ + public override void double_click (uint button, double x, double y) {+ Widget t;+ + if (ignore_input) {+ printd (@"Ignoring extra clicks.");+ return;+ }+ + if (keyboard_focus != null) {+ t = (!) keyboard_focus;+ set_focus (t);+ t.double_click (button, x, y);+ }++ foreach (Widget w in widgets) {+ if (w.is_over (x, y)) {+ w.double_click (button, x, y);+ }+ }+ + GlyphCanvas.redraw ();+ } } }@@ -69,6 +69,9 @@ public abstract class Widget : GLib.Object { public virtual void button_release (uint button, double x, double y) { } + public virtual void double_click (uint button, double x, double y) {+ } + public virtual bool motion (double x, double y) { return false; }