[shotwell] map: Modifier enabled selection



commit 65fb80890057e9cfbb585d32b9f8b920acccdbe4
Author: Andreas Brauchli <a brauchli elementarea net>
Date:   Sat Aug 20 15:12:42 2016 +0200

    map: Modifier enabled selection
    
    Holding CTRL or SHIFT while selecting a marker now has the same effect
    as in the library window and the marker selection will be toggled.
    
    If a group marker that is shown as selected (because it contains a selected
    marker) is pressed, the selection will be cleared when clicked while
    holding modifiers CTRL or SHIFT.

 src/MapWidget.vala | 38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/src/MapWidget.vala b/src/MapWidget.vala
index 2785ac43..df0dee3d 100644
--- a/src/MapWidget.vala
+++ b/src/MapWidget.vala
@@ -12,6 +12,12 @@ private class MarkerImageSet {
     public Clutter.Image? marker_highlighted_image;
 }
 
+private enum SelectionAction {
+    SET,
+    ADD,
+    REMOVE
+}
+
 private abstract class PositionMarker : Object {
     protected bool _highlighted = false;
     protected bool _selected = false;
@@ -78,8 +84,13 @@ private class DataViewPositionMarker : PositionMarker {
         champlain_marker.button_release_event.connect ((event) => {
             if (event.button > 1)
                 return true;
-            selected = true;
-            map_widget.select_data_views(_data_view_position_markers);
+            bool mod = (bool)(event.modifier_state &
+                    (Clutter.ModifierType.CONTROL_MASK | Clutter.ModifierType.SHIFT_MASK));
+            SelectionAction action = SelectionAction.SET;
+            if (mod)
+                action = _selected ? SelectionAction.REMOVE : SelectionAction.ADD;
+            selected = (action != SelectionAction.REMOVE);
+            map_widget.select_data_views(_data_view_position_markers, action);
             return true;
         });
         champlain_marker.enter_event.connect ((event) => {
@@ -105,11 +116,16 @@ private class MarkerGroup : PositionMarker {
         champlain_marker.button_release_event.connect ((event) => {
             if (event.button > 1)
                 return true;
-            selected = true;
+            bool mod = (bool)(event.modifier_state &
+                    (Clutter.ModifierType.CONTROL_MASK | Clutter.ModifierType.SHIFT_MASK));
+            SelectionAction action = SelectionAction.SET;
+            if (mod)
+                action = _selected ? SelectionAction.REMOVE : SelectionAction.ADD;
+            selected = (action != SelectionAction.REMOVE);
             foreach (var m in _data_view_position_markers) {
-                m.selected = true;
+                m.selected = _selected;
             }
-            map_widget.select_data_views(_data_view_position_markers.read_only_view);
+            map_widget.select_data_views(_data_view_position_markers.read_only_view, action);
             return true;
         });
         champlain_marker.enter_event.connect ((event) => {
@@ -445,7 +461,8 @@ private class MapWidget : Gtk.Bin {
         }
     }
 
-    public void select_data_views(Gee.Collection<unowned DataViewPositionMarker> ms) {
+    public void select_data_views(Gee.Collection<unowned DataViewPositionMarker> ms,
+            SelectionAction action = SelectionAction.SET) {
         if (page == null)
             return;
 
@@ -457,8 +474,13 @@ private class MapWidget : Gtk.Bin {
                     marked.mark(m.view);
                 }
             }
-            page_view.unselect_all();
-            page_view.select_marked(marked);
+            if (action == SelectionAction.REMOVE) {
+                page_view.unselect_marked(marked);
+            } else {
+                if (action == SelectionAction.SET)
+                    page_view.unselect_all();
+                page_view.select_marked(marked);
+            }
         }
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]