[california/wip/730601-week-drag] Final touches
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/730601-week-drag] Final touches
- Date: Wed, 28 May 2014 23:42:37 +0000 (UTC)
commit 043da68fd35b83a4090a9e5ca450734443da2fd5
Author: Jim Nelson <jim yorba org>
Date: Wed May 28 16:42:30 2014 -0700
Final touches
src/toolkit/toolkit-button-connector.vala | 43 +++++++++--------------------
src/toolkit/toolkit-event-connector.vala | 4 ---
src/toolkit/toolkit-motion-connector.vala | 6 ++--
src/toolkit/toolkit.vala | 10 +++++++
src/view/week/week-grid.vala | 33 +++++++++++++---------
5 files changed, 46 insertions(+), 50 deletions(-)
---
diff --git a/src/toolkit/toolkit-button-connector.vala b/src/toolkit/toolkit-button-connector.vala
index e97e183..19ce292 100644
--- a/src/toolkit/toolkit-button-connector.vala
+++ b/src/toolkit/toolkit-button-connector.vala
@@ -75,24 +75,22 @@ public class ButtonConnector : EventConnector {
Gtk.Widget, InternalButtonEvent>();
private Gee.HashMap<Gtk.Widget, InternalButtonEvent> tertiary_states = new Gee.HashMap<
Gtk.Widget, InternalButtonEvent>();
- private Cancellable cancellable = new Cancellable();
/**
* The "raw" "button-pressed" signal received by { link ButtonConnector}.
*
- * TODO:
- * Signal subscribers should cancel the Cancellable to prevent propagation of the event.
- * This will prevent the various "clicked" signals from firing.
+ * Return { link STOP} to prevent further propagation of the event. This will prevent firing
+ * of synthesized signals, i.e. { link clicked} and { link double_clicked}.
*/
- public signal void pressed(Gtk.Widget widget, Button button, Gdk.Point point, Gdk.EventType event_type);
+ public signal bool pressed(Gtk.Widget widget, Button button, Gdk.Point point, Gdk.EventType event_type);
/**
* The "raw" "button-released" signal received by { link ButtonConnector}.
*
- * Signal subscribers should cancel the Cancellable to prevent propagation of the event.
- * This will prevent the various "clicked" signals from firing.
+ * Return { link STOP} to prevent further propagation of the event. This will prevent firing
+ * of synthesized signals, i.e. { link clicked} and { link double_clicked}.
*/
- public signal void released(Gtk.Widget widget, Button button, Gdk.Point point, Gdk.EventType event_type);
+ public signal bool released(Gtk.Widget widget, Button button, Gdk.Point point, Gdk.EventType event_type);
/**
* Fired when a button is pressed and released once.
@@ -140,9 +138,7 @@ public class ButtonConnector : EventConnector {
*/
protected virtual bool notify_pressed(Gtk.Widget widget, Button button, Gdk.Point point,
Gdk.EventType event_type) {
- pressed(widget, button, point, event_type);
-
- return stop_propagation();
+ return pressed(widget, button, point, event_type);
}
/**
@@ -153,9 +149,7 @@ public class ButtonConnector : EventConnector {
*/
protected virtual bool notify_released(Gtk.Widget widget, Button button, Gdk.Point point,
Gdk.EventType event_type) {
- released(widget, button, point, event_type);
-
- return stop_propagation();
+ return released(widget, button, point, event_type);
}
/**
@@ -203,17 +197,6 @@ public class ButtonConnector : EventConnector {
tertiary_states.unset(widget);
}
- // Checks if the Cancellable has been cancelled, in which case return EVENT_STOP and replaces
- // the Cancellable
- private bool stop_propagation() {
- if (!cancellable.is_cancelled())
- return EVENT_PROPAGATE;
-
- cancellable = new Cancellable();
-
- return EVENT_STOP;
- }
-
private Gee.HashMap<Gtk.Widget, InternalButtonEvent>? get_states_map(Button button) {
switch (button) {
case Button.PRIMARY:
@@ -247,12 +230,12 @@ public class ButtonConnector : EventConnector {
case Gdk.EventType.3BUTTON_PRESS:
// notify of raw event
Gdk.Point point = Gdk.Point() { x = (int) event.x, y = (int) event.y };
- if (notify_pressed(widget, button, point, event.type) == EVENT_STOP) {
+ if (notify_pressed(widget, button, point, event.type) == Toolkit.STOP) {
// drop any lingering state
if (button_states != null)
button_states.unset(widget);
- return EVENT_STOP;
+ return Toolkit.STOP;
}
// save state for the release event, potentially updating existing state from
@@ -273,12 +256,12 @@ public class ButtonConnector : EventConnector {
case Gdk.EventType.BUTTON_RELEASE:
// notify of raw event
Gdk.Point point = Gdk.Point() { x = (int) event.x, y = (int) event.y };
- if (notify_released(widget, button, point, event.type) == EVENT_STOP) {
+ if (notify_released(widget, button, point, event.type) == Toolkit.STOP) {
// release lingering state
if (button_states != null)
button_states.unset(widget);
- return EVENT_STOP;
+ return Toolkit.STOP;
}
// update saved state (if any) with release info and start timer
@@ -308,7 +291,7 @@ public class ButtonConnector : EventConnector {
break;
}
- return EVENT_PROPAGATE;
+ return Toolkit.PROPAGATE;
}
private void on_release_timeout(InternalButtonEvent details) {
diff --git a/src/toolkit/toolkit-event-connector.vala b/src/toolkit/toolkit-event-connector.vala
index 66fa695..484bce9 100644
--- a/src/toolkit/toolkit-event-connector.vala
+++ b/src/toolkit/toolkit-event-connector.vala
@@ -20,10 +20,6 @@ namespace California.Toolkit {
*/
public abstract class EventConnector : BaseObject {
- // helper consts for subclasses
- protected const bool EVENT_PROPAGATE = false;
- protected const bool EVENT_STOP = true;
-
private Gdk.EventMask event_mask;
private Gee.HashSet<Gtk.Widget> widgets = new Gee.HashSet<Gtk.Widget>();
diff --git a/src/toolkit/toolkit-motion-connector.vala b/src/toolkit/toolkit-motion-connector.vala
index dafda24..7915b34 100644
--- a/src/toolkit/toolkit-motion-connector.vala
+++ b/src/toolkit/toolkit-motion-connector.vala
@@ -97,19 +97,19 @@ public class MotionConnector : EventConnector {
if (motion_event.is_any_button_pressed())
notify_button_motion(motion_event);
- return EVENT_PROPAGATE;
+ return Toolkit.PROPAGATE;
}
private bool on_enter_notify_event(Gtk.Widget widget, Gdk.EventCrossing event) {
notify_entered(new MotionEvent.for_crossing(widget, event));
- return EVENT_PROPAGATE;
+ return Toolkit.PROPAGATE;
}
private bool on_leave_notify_event(Gtk.Widget widget, Gdk.EventCrossing event) {
notify_entered(new MotionEvent.for_crossing(widget, event));
- return EVENT_PROPAGATE;
+ return Toolkit.PROPAGATE;
}
}
diff --git a/src/toolkit/toolkit.vala b/src/toolkit/toolkit.vala
index ec84471..41c3030 100644
--- a/src/toolkit/toolkit.vala
+++ b/src/toolkit/toolkit.vala
@@ -22,6 +22,16 @@ public const int DEFAULT_STACK_TRANSITION_DURATION_MSEC = 300;
*/
public const int SLOW_STACK_TRANSITION_DURATION_MSEC = 500;
+/**
+ * Indicates a GTK/GDK event should not be propagated further (no processing by other handlers).
+ */
+public const bool STOP = true;
+
+/**
+ * Indicates a GTK/GDK event should be propagated (continue processing by other handlers).
+ */
+public const bool PROPAGATE = false;
+
private int init_count = 0;
public void init() throws Error {
diff --git a/src/view/week/week-grid.vala b/src/view/week/week-grid.vala
index a6aaa14..a9bd39c 100644
--- a/src/view/week/week-grid.vala
+++ b/src/view/week/week-grid.vala
@@ -46,8 +46,8 @@ internal class Grid : Gtk.Box {
private Toolkit.ButtonConnector instance_container_button_connector = new Toolkit.ButtonConnector();
private Toolkit.ButtonConnector all_day_button_connector = new Toolkit.ButtonConnector();
private Toolkit.ButtonConnector day_pane_button_connector = new Toolkit.ButtonConnector();
- private Toolkit.MotionConnector day_pane_motion_connector = new Toolkit.MotionConnector();
- private Toolkit.MotionConnector all_day_cell_motion_connector = new Toolkit.MotionConnector();
+ private Toolkit.MotionConnector day_pane_motion_connector = new Toolkit.MotionConnector.button_only();
+ private Toolkit.MotionConnector all_day_cell_motion_connector = new
Toolkit.MotionConnector.button_only();
private Gtk.ScrolledWindow scrolled_panes;
private Gtk.Widget right_spacer;
private bool vadj_init = false;
@@ -373,16 +373,20 @@ internal class Grid : Gtk.Box {
day_pane.clear_selection();
}
- private void on_day_pane_button_released(Gtk.Widget widget, Toolkit.Button button, Gdk.Point point,
+ private bool on_day_pane_button_released(Gtk.Widget widget, Toolkit.Button button, Gdk.Point point,
Gdk.EventType event_type) {
if (button != Toolkit.Button.PRIMARY)
- return;
+ return Toolkit.PROPAGATE;
DayPane day_pane = (DayPane) widget;
Calendar.ExactTimeSpan? selection_span = day_pane.get_selection_span();
- if (selection_span != null)
- owner.request_create_timed_event(selection_span, widget, point);
+ if (selection_span == null)
+ return Toolkit.PROPAGATE;
+
+ owner.request_create_timed_event(selection_span, widget, point);
+
+ return Toolkit.STOP;
}
private AllDayCell? get_cell_at(AllDayCell widget, Gdk.Point widget_location) {
@@ -425,24 +429,27 @@ internal class Grid : Gtk.Box {
day_cell.selected = day_cell.date in span;
}
- private void on_all_day_cell_button_released(Gtk.Widget widget, Toolkit.Button button, Gdk.Point point,
+ private bool on_all_day_cell_button_released(Gtk.Widget widget, Toolkit.Button button, Gdk.Point point,
Gdk.EventType event_type) {
if (button != Toolkit.Button.PRIMARY)
- return;
+ return Toolkit.PROPAGATE;
AllDayCell start_cell = (AllDayCell) widget;
// only convert drag-and-release to new event if start is selected (this prevents single-clicks
// from being turned into new events)
if (!start_cell.selected)
- return;
+ return Toolkit.PROPAGATE;
// get widget button was released over
AllDayCell? release_cell = get_cell_at(start_cell, point);
- if (release_cell != null) {
- owner.request_create_all_day_event(new Calendar.DateSpan(start_cell.date, release_cell.date),
- widget, point);
- }
+ if (release_cell == null)
+ return Toolkit.PROPAGATE;
+
+ owner.request_create_all_day_event(new Calendar.DateSpan(start_cell.date, release_cell.date),
+ widget, point);
+
+ return Toolkit.STOP;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]