[PATCH 2/3] Added a quick method to update dive ratings from the dive list
Lubomir I. Ivanov
neolit123 at gmail.com
Fri Jan 25 06:55:54 PST 2013
From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
When hovering over dives in the dive list, it is now possible
to hold the CTRL key and use the mouse wheel to quickly
set the hovered dive rating.
Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
i was first looking at using ALT (GDK_MOD1_MASK), but it had odd behaviour
on Ubuntu 12.04 in a VM. also, i'm not sure if ctrl + mouse wheel is confortable
(or even possible) on the Mac.
---
divelist.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/divelist.c b/divelist.c
index 8b86c53..c5f4c10 100644
--- a/divelist.c
+++ b/divelist.c
@@ -1698,6 +1698,41 @@ static void show_gps_location_cb(GtkWidget *menuitem, struct dive *dive)
}
#endif
+gboolean rating_scroll_cb(GtkWidget *w, GdkEventScroll *event, gpointer data)
+{
+ GtkTreePath *path = NULL;
+ GtkTreeIter iter;
+ GtkTreeViewColumn *col;
+ int idx;
+ struct dive *dive;
+
+ if ((event->state & GDK_CONTROL_MASK) != 0 &&
+ gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(dive_list.tree_view), event->x, event->y, &path, &col, NULL, NULL)) {
+ if (col == data) {
+ gtk_tree_model_get_iter(MODEL(dive_list), &iter, path);
+ gtk_tree_model_get(MODEL(dive_list), &iter, DIVE_INDEX, &idx, -1);
+ dive = get_dive(idx);
+ if (dive) {
+ if (event->direction == GDK_SCROLL_UP) {
+ dive->rating--;
+ if (dive->rating < 0)
+ dive->rating = 0;
+ } else if (event->direction == GDK_SCROLL_DOWN) {
+ dive->rating++;
+ if (dive->rating > 5)
+ dive->rating = 5;
+ }
+ mark_divelist_changed(TRUE);
+ flush_divelist(dive);
+ }
+ }
+ if (path)
+ gtk_tree_path_free(path);
+ return TRUE;
+ }
+ return FALSE;
+}
+
gboolean icon_click_cb(GtkWidget *w, GdkEventButton *event, gpointer data)
{
#if HAVE_OSM_GPS_MAP
@@ -2769,6 +2804,8 @@ GtkWidget *dive_list_create(void)
dive_list.otu = divelist_column(&dive_list, dl_column + DIVE_OTU);
dive_list.maxcns = divelist_column(&dive_list, dl_column + DIVE_MAXCNS);
dive_list.location = divelist_column(&dive_list, dl_column + DIVE_LOCATION);
+ /* update dive rating */
+ g_signal_connect(dive_list.tree_view, "scroll-event", G_CALLBACK(rating_scroll_cb), dive_list.stars);
/* now add the GPS icon to the location column */
tree_view_column_add_pixbuf(dive_list.tree_view, gpsicon_data_func, dive_list.location);
--
1.7.11.msysgit.0
More information about the subsurface
mailing list