[gnome-documents] view: enter selection mode with Ctrl+Click
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] view: enter selection mode with Ctrl+Click
- Date: Wed, 23 Nov 2011 19:35:24 +0000 (UTC)
commit 8b4dc310fff51af9c65724f230f1b00ec8199167
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Nov 23 14:30:23 2011 -0500
view: enter selection mode with Ctrl+Click
This also changes the button event handlers in View to listen to
button-release events instead of button-press events, so we will be able
to implement DnD later (and it's generally a better behaviour).
src/iconView.js | 11 --------
src/lib/gd-utils.c | 47 -----------------------------------
src/lib/gd-utils.h | 2 -
src/listView.js | 11 --------
src/view.js | 70 ++++++++++++++++++++++++++++++++++------------------
5 files changed, 46 insertions(+), 95 deletions(-)
---
diff --git a/src/iconView.js b/src/iconView.js
index ea8d32a..3d968ad 100644
--- a/src/iconView.js
+++ b/src/iconView.js
@@ -47,9 +47,6 @@ IconView.prototype = {
this.widget.column_spacing = _VIEW_COLUMN_SPACING;
this.widget.margin = _VIEW_MARGIN;
- this.widget.connect('item-activated',
- Lang.bind(this, this._onItemActivated));
-
// chain up to the parent
View.View.prototype._init.call(this);
},
@@ -74,10 +71,6 @@ IconView.prototype = {
this.getSelectionObject().set_selection_mode(mode);
},
- setSingleClickMode: function(mode) {
- Gd.gtk_icon_view_set_activate_on_single_click(this.widget, mode);
- },
-
scrollToPath: function(path) {
this.widget.scroll_to_path(path, true, 0.5, 0.5);
},
@@ -101,9 +94,5 @@ IconView.prototype = {
'text', Documents.ModelColumns.TITLE);
this.widget.add_attribute(textRenderer,
'line-two', Documents.ModelColumns.AUTHOR);
- },
-
- _onItemActivated: function(view, path, column) {
- this.activateItem(path);
}
};
diff --git a/src/lib/gd-utils.c b/src/lib/gd-utils.c
index a5804fd..4096091 100644
--- a/src/lib/gd-utils.c
+++ b/src/lib/gd-utils.c
@@ -257,53 +257,6 @@ gd_gtk_tree_view_set_activate_on_single_click (GtkTreeView *tree_view,
}
}
-static gboolean
-icon_view_button_press_callback (GtkWidget *icon_view,
- GdkEventButton *event,
- gpointer data)
-{
- GtkTreePath *path;
-
- if (event->button == 1 && event->type == GDK_BUTTON_PRESS) {
- path = gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (icon_view),
- event->x, event->y);
-
- if (path != NULL) {
- gtk_icon_view_item_activated (GTK_ICON_VIEW (icon_view), path);
- gtk_tree_path_free (path);
- }
- }
-
- return FALSE;
-}
-
-void
-gd_gtk_icon_view_set_activate_on_single_click (GtkIconView *icon_view,
- gboolean should_activate)
-{
- guint button_press_id;
-
- button_press_id = GPOINTER_TO_UINT
- (g_object_get_data (G_OBJECT (icon_view),
- "gd-icon-view-activate"));
-
- if (button_press_id && !should_activate) {
- g_signal_handler_disconnect (icon_view, button_press_id);
- g_object_set_data (G_OBJECT (icon_view),
- "gd-icon-view-activate",
- NULL);
- } else if (!button_press_id && should_activate) {
- button_press_id =
- g_signal_connect (icon_view,
- "button_press_event",
- G_CALLBACK (icon_view_button_press_callback),
- NULL);
- g_object_set_data (G_OBJECT (icon_view),
- "gd-icon-view-activate",
- GUINT_TO_POINTER (button_press_id));
- }
-}
-
/**
* gd_embed_image_in_frame:
* @source_image:
diff --git a/src/lib/gd-utils.h b/src/lib/gd-utils.h
index c0d5757..813cdf0 100644
--- a/src/lib/gd-utils.h
+++ b/src/lib/gd-utils.h
@@ -55,8 +55,6 @@ gboolean gd_queue_thumbnail_job_for_file_finish (GAsyncResult *res);
void gd_gtk_tree_view_set_activate_on_single_click (GtkTreeView *tree_view,
gboolean should_activate);
-void gd_gtk_icon_view_set_activate_on_single_click (GtkIconView *icon_view,
- gboolean should_activate);
GdkPixbuf *gd_embed_image_in_frame (GdkPixbuf *source_image,
const gchar *frame_image_path,
diff --git a/src/listView.js b/src/listView.js
index 6c14b08..bcf62e7 100644
--- a/src/listView.js
+++ b/src/listView.js
@@ -41,19 +41,12 @@ ListView.prototype = {
vexpand: true,
headers_visible: false });
- this.widget.connect('row-activated',
- Lang.bind(this, this._onItemActivated));
-
this.widget.show();
// chain up to the parent
View.View.prototype._init.call(this);
},
- _onItemActivated: function(view, path, column) {
- this.activateItem(path);
- },
-
connectToSelectionChanged: function(callback) {
this.getSelectionObject().connect('changed', callback);
},
@@ -78,10 +71,6 @@ ListView.prototype = {
this.getSelectionObject().set_mode(mode);
},
- setSingleClickMode: function(mode) {
- Gd.gtk_tree_view_set_activate_on_single_click(this.widget, mode);
- },
-
createRenderers: function() {
let col = new Gtk.TreeViewColumn();
this.widget.append_column(col);
diff --git a/src/view.js b/src/view.js
index c00b57c..cf3d858 100644
--- a/src/view.js
+++ b/src/view.js
@@ -19,6 +19,7 @@
*
*/
+const Gdk = imports.gi.Gdk;
const Gtk = imports.gi.Gtk;
const _ = imports.gettext.gettext;
@@ -127,6 +128,8 @@ View.prototype = {
Global.trackerController.connect('query-status-changed',
Lang.bind(this, this._onQueryStatusChanged));
+ this.widget.connect('button-release-event',
+ Lang.bind(this, this._onButtonReleaseEvent));
this.widget.connect('button-press-event',
Lang.bind(this, this._onButtonPressEvent));
this.widget.connect('destroy', Lang.bind(this,
@@ -205,13 +208,10 @@ View.prototype = {
// setup the GtkSelectionMode of the view according to whether or not
// the view is in "selection mode"
- if (selectionMode) {
- this.setSingleClickMode(false);
+ if (selectionMode)
this.setSelectionMode(Gtk.SelectionMode.MULTIPLE);
- } else {
- this.setSingleClickMode(true);
+ else
this.setSelectionMode(Gtk.SelectionMode.NONE);
- }
},
_onSelectionChanged: function() {
@@ -221,37 +221,59 @@ View.prototype = {
Global.selectionController.setSelection(selectedURNs);
},
- _onButtonPressEvent: function(widget, event) {
+ _onButtonReleaseEvent: function(widget, event) {
let button = event.get_button()[1];
- let enteredMode = false;
+ let modifier = event.get_state()[1];
+ let coords = [ event.get_coords()[1] , event.get_coords()[2] ];
- if (!Global.selectionController.getSelectionMode()) {
- if (button == 3) {
- Global.selectionController.setSelectionMode(true);
- enteredMode = true;
- } else {
- return false;
- }
- }
+ let selectionMode = Global.selectionController.getSelectionMode();
+ let enteredMode = false;
// eat double/triple click events
let clickCount = event.get_click_count()[1];
if (clickCount > 1)
return true;
- let coords = [ event.get_coords()[1] , event.get_coords()[2] ];
+ // don't eat events if we didn't click any path
let path = this.getPathAtPos(coords);
+ if (!path)
+ return false;
- if (path) {
- let selectionObj = this.getSelectionObject();
- let isSelected = selectionObj.path_is_selected(path);
-
- if (isSelected && !enteredMode)
- selectionObj.unselect_path(path);
- else if (!isSelected)
- selectionObj.select_path(path);
+ if (!selectionMode) {
+ if ((button == 3) ||
+ ((button == 1) && (modifier & Gdk.ModifierType.CONTROL_MASK))) {
+ Global.selectionController.setSelectionMode(true);
+ selectionMode = true;
+ enteredMode = true;
+ }
}
+ if (selectionMode)
+ return this._selectionModeReleaseEvent(event, enteredMode, path);
+ else
+ return this._viewModeReleaseEvent(event, path);
+ },
+
+ _selectionModeReleaseEvent: function(event, enteredMode, path) {
+ let selectionObj = this.getSelectionObject();
+ let isSelected = selectionObj.path_is_selected(path);
+
+ if (isSelected && !enteredMode)
+ selectionObj.unselect_path(path);
+ else if (!isSelected)
+ selectionObj.select_path(path);
+
+ return true;
+ },
+
+ _viewModeReleaseEvent: function(event, path) {
+ this.activateItem(path);
+ return true;
+ },
+
+ _onButtonPressEvent: function(widget, event) {
+ // eat button press events for now; in the future we might
+ // want to hook up support for DnD here
return true;
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]