[shotwell] Create disjoint selection using keyboard: Bug #716663



commit 9f93c37e98f37443b6e37ee73a8925d93afbe8e0
Author: Daniel Landau <daniel landau iki fi>
Date:   Tue Jun 10 13:03:02 2014 -0700

    Create disjoint selection using keyboard: Bug #716663

 src/CheckerboardLayout.vala |   37 +++++++++++++++++++++++++++++++++++++
 src/Page.vala               |   24 ++++++++++++++++++------
 2 files changed, 55 insertions(+), 6 deletions(-)
---
diff --git a/src/CheckerboardLayout.vala b/src/CheckerboardLayout.vala
index 398152e..a542462 100644
--- a/src/CheckerboardLayout.vala
+++ b/src/CheckerboardLayout.vala
@@ -126,6 +126,7 @@ public abstract class CheckerboardItem : ThumbnailView {
     private bool comment_visible = true;
     private CheckerboardItemText? subtitle = null;
     private bool subtitle_visible = false;
+    private bool is_cursor = false;
     private Gdk.Pixbuf pixbuf = null;
     private Gdk.Pixbuf display_pixbuf = null;
     private Gdk.Pixbuf brightened = null;
@@ -275,6 +276,14 @@ public abstract class CheckerboardItem : ThumbnailView {
         recalc_size("set_subtitle_visible");
         notify_view_altered();
     }
+
+    public void set_is_cursor(bool is_cursor) {
+        this.is_cursor = is_cursor;
+    }
+
+    public bool get_is_cusor() {
+        return is_cursor;
+    }
     
     protected override void notify_membership_changed(DataCollection? collection) {
         bool title_visible = (bool) get_collection_property(PROP_SHOW_TITLES, true);
@@ -549,6 +558,16 @@ public abstract class CheckerboardItem : ThumbnailView {
             ctx.restore();
         }
         
+        // draw a border for the cursor with the selection width and normal border color
+        if (is_cursor) {
+            ctx.save();
+            ctx.set_source_rgba(border_color.red, border_color.green, border_color.blue,
+                    border_color.alpha);
+            paint_border(ctx, pixbuf_dim, pixbuf_origin,
+                get_selection_border_width(int.max(pixbuf_dim.width, pixbuf_dim.height)));
+            ctx.restore();
+        }
+        
         // draw selection border
         if (is_selected()) {
             // border thickness depends on the size of the thumbnail
@@ -795,6 +814,7 @@ public class CheckerboardLayout : Gtk.DrawingArea {
     private bool flow_scheduled = false;
     private bool exposure_dirty = true;
     private CheckerboardItem? anchor = null;
+    private CheckerboardItem? cursor = null;
     private bool in_center_on_anchor = false;
     private bool size_allocate_due_to_reflow = false;
     private bool is_in_view = false;
@@ -964,6 +984,23 @@ public class CheckerboardLayout : Gtk.DrawingArea {
 
         in_center_on_anchor = false;
     }
+
+    public void set_cursor(CheckerboardItem item) {
+        Gee.HashSet<DataView> collection = new Gee.HashSet<DataView>();
+        if (cursor != null) {
+            cursor.set_is_cursor(false);
+            collection.add(cursor);
+        }
+        item.set_is_cursor(true);
+        cursor = item;
+        collection.add(item);
+        on_items_state_changed(collection);
+    }
+    
+    public CheckerboardItem get_cursor() {
+        return cursor;
+    }
+    
     
     private void on_contents_altered(Gee.Iterable<DataObject>? added, 
         Gee.Iterable<DataObject>? removed) {
diff --git a/src/Page.vala b/src/Page.vala
index fd69431..57e5b4a 100644
--- a/src/Page.vala
+++ b/src/Page.vala
@@ -1448,6 +1448,11 @@ public abstract class CheckerboardPage : Page {
                     handled = false;
             break;
             
+            case "space":
+                Marker marker = get_view().mark(layout.get_cursor());
+                get_view().toggle_marked(marker);
+            break;
+            
             default:
                 handled = false;
             break;
@@ -1528,6 +1533,7 @@ public abstract class CheckerboardPage : Page {
                     cursor = item;
                 break;
             }
+            layout.set_cursor(item);
         } else {
             // user clicked on "dead" area; only unselect if control is not pressed
             // do we want similar behavior for shift as well?
@@ -1777,11 +1783,13 @@ public abstract class CheckerboardPage : Page {
 
         cursor = item;
         
-        get_view().unselect_all();
+        if (!get_ctrl_pressed()) {
+            get_view().unselect_all();
+            Marker marker = get_view().mark(item);
+            get_view().select_marked(marker);
+        }
+        layout.set_cursor(item);
         
-        Marker marker = get_view().mark(item);
-        get_view().select_marked(marker);
-
         // if item is in any way out of view, scroll to it
         Gtk.Adjustment vadj = get_vadjustment();
         if (get_adjustment_relation(vadj, item.allocation.y) == AdjustmentRelation.IN_RANGE
@@ -1806,14 +1814,18 @@ public abstract class CheckerboardPage : Page {
         if (get_view().get_count() == 0)
             return;
             
-        // if nothing is selected, simply select the first and exit
-        if (get_view().get_selected_count() == 0 || cursor == null) {
+        // if there is no better starting point, simply select the first and exit
+        if (cursor == null && layout.get_cursor() == null) {
             CheckerboardItem item = layout.get_item_at_coordinate(0, 0);
             cursor_to_item(item);
             anchor = item;
 
             return;
         }
+
+        if (cursor == null) {
+            cursor = layout.get_cursor() as CheckerboardItem;
+        }
                
         // move the cursor relative to the "first" item
         CheckerboardItem? item = layout.get_item_relative_to(cursor, point);


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