Commit 33d0366b authored by Allison Barlow's avatar Allison Barlow

#1612 drag select while ctrl pressed

parent 96da3196
......@@ -162,9 +162,15 @@ public class DataSet {
// an iterator.
public interface Marker : Object {
public abstract void mark(DataObject object);
public abstract void unmark(DataObject object);
public abstract bool toggle(DataObject object);
public abstract void mark_many(Gee.Iterable<DataObject> list);
public abstract void unmark_many(Gee.Iterable<DataObject> list);
public abstract void mark_all();
// Returns the number of marked items, or the number of items when the marker was frozen
......@@ -257,6 +263,24 @@ public class DataCollection {
marked.add(object);
}
public void unmark(DataObject object) {
assert(owner.internal_contains(object));
marked.remove(object);
}
public bool toggle(DataObject object) {
assert(owner.internal_contains(object));
if (marked.contains(object)) {
marked.remove(object);
} else {
marked.add(object);
}
return marked.contains(object);
}
public void mark_many(Gee.Iterable<DataObject> list) {
foreach (DataObject object in list) {
......@@ -266,6 +290,14 @@ public class DataCollection {
}
}
public void unmark_many(Gee.Iterable<DataObject> list) {
foreach (DataObject object in list) {
assert(owner.internal_contains(object));
marked.remove(object);
}
}
public void mark_all() {
foreach (DataObject object in owner.get_all())
marked.add(object);
......@@ -1866,7 +1898,8 @@ public class ViewCollection : DataCollection {
return;
Marker marker = start_marking();
marker.mark_all();
marker.mark_many(get_selected());
unselect_marked(marker);
}
......
......@@ -774,6 +774,7 @@ public abstract class CheckerboardPage : Page {
private CheckerboardItem highlighted = null;
private bool autoscroll_scheduled = false;
private CheckerboardItem activated_item = null;
private Gee.ArrayList<CheckerboardItem> previously_selected = null;
public CheckerboardPage(string page_name) {
base(page_name);
......@@ -1009,23 +1010,30 @@ public abstract class CheckerboardPage : Page {
break;
}
} else {
// user clicked on "dead" area
get_view().unselect_all();
}
// user clicked on "dead" area; only unselect if control is not pressed
// do we want similar behavior for shift as well?
if (state != Gdk.ModifierType.CONTROL_MASK)
get_view().unselect_all();
// need to determine if the signal should be passed to the DnD handlers
// Return true to block the DnD handler, false otherwise
// grab previously marked items
previously_selected = new Gee.ArrayList<CheckerboardItem>();
foreach (DataView view in get_view().get_selected())
previously_selected.add((CheckerboardItem) view);
if (item == null) {
layout.set_drag_select_origin((int) event.x, (int) event.y);
return true;
}
// need to determine if the signal should be passed to the DnD handlers
// Return true to block the DnD handler, false otherwise
return get_view().get_selected_count() == 0;
}
protected override bool on_left_released(Gdk.EventButton event) {
previously_selected = null;
// if drag-selecting, stop here and do nothing else
if (layout.is_drag_select_active()) {
layout.clear_drag_select();
......@@ -1174,28 +1182,33 @@ public abstract class CheckerboardPage : Page {
Gee.List<CheckerboardItem>? intersection = layout.items_in_selection_band();
if (intersection == null)
return;
// unselect everything not in the intersection
Marker marker = get_view().start_marking();
foreach (DataView view in get_view().get_selected()) {
CheckerboardItem item = (CheckerboardItem) view;
if (!intersection.contains(item))
marker.mark(item);
}
get_view().unselect_marked(marker);
Marker to_unselect = get_view().start_marking();
Marker to_select = get_view().start_marking();
// mark all selected items to be unselected
to_unselect.mark_many(get_view().get_selected());
// except for the items that were selected before the drag began
assert(previously_selected != null);
to_unselect.unmark_many(previously_selected);
to_select.mark_many(previously_selected);
// select everything in the intersection and update the cursor
marker = get_view().start_marking();
// toggle selection on everything in the intersection and update the cursor
cursor = null;
foreach (CheckerboardItem item in intersection) {
marker.mark(item);
if (to_select.toggle(item))
to_unselect.unmark(item);
else
to_unselect.mark(item);
if (cursor == null)
cursor = item;
}
get_view().select_marked(marker);
get_view().select_marked(to_select);
get_view().unselect_marked(to_unselect);
}
private bool selection_autoscroll() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment