aboutsummaryrefslogtreecommitdiff
path: root/src/datetime-prefs-locations.c
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-04-12 22:32:18 -0500
committerTed Gould <ted@gould.cx>2011-04-12 22:32:18 -0500
commit6e96a11fa4adf17f5a439d8dd6a20f59eb679e42 (patch)
tree45598d4cf7f260eb4c90bea1753b6c21a8846688 /src/datetime-prefs-locations.c
parentd4dc8fa632a432ec7255459122f577eddd6b8978 (diff)
parent8603d94b5950329aeb81bcf255fe7f4173eaf6c3 (diff)
downloadayatana-indicator-datetime-6e96a11fa4adf17f5a439d8dd6a20f59eb679e42.tar.gz
ayatana-indicator-datetime-6e96a11fa4adf17f5a439d8dd6a20f59eb679e42.tar.bz2
ayatana-indicator-datetime-6e96a11fa4adf17f5a439d8dd6a20f59eb679e42.zip
* Upstream Merge
* Use GTK directly for detecting when the menu appears and disappears to reset the date (LP: #649800) * Handle items being removed from the locations list by choosing another item in the list (LP: #740948)
Diffstat (limited to 'src/datetime-prefs-locations.c')
-rw-r--r--src/datetime-prefs-locations.c70
1 files changed, 69 insertions, 1 deletions
diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c
index 9c23a40..af0e10d 100644
--- a/src/datetime-prefs-locations.c
+++ b/src/datetime-prefs-locations.c
@@ -77,13 +77,81 @@ handle_remove (GtkWidget * button, GtkTreeView * tree)
gtk_tree_path_free (iter->data);
}
g_list_free (paths);
-
+
+ // Find the next item to select
+ GtkTreeIter *last_selected = g_list_nth_data(tree_iters, 0);
+ GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL (store), last_selected);
+ GtkTreeIter titer;
+ if (!gtk_tree_model_get_iter(GTK_TREE_MODEL (store), &titer, path)) {
+ g_debug("Failed to get last selected iter from path");
+ last_selected = NULL;
+ } else {
+ if (!gtk_tree_model_iter_next(GTK_TREE_MODEL (store), &titer)) {
+ if (gtk_tree_path_prev(path)) {
+ if (!gtk_tree_model_get_iter(GTK_TREE_MODEL (store), &titer, path)) {
+ g_debug("Failed to get iter from path");
+ last_selected = NULL;
+ } else {
+ last_selected = &titer;
+ }
+ } else {
+ g_debug("handle_remove: Failed to find another location to select (assume single selected)");
+ last_selected = NULL;
+ }
+ } else {
+ g_debug("Got next item in model");
+ last_selected = &titer;
+ }
+ }
+
+ if (last_selected) {
+ gboolean clear = TRUE;
+ path = gtk_tree_model_get_path(GTK_TREE_MODEL (store), last_selected);
+
+ // Step over the path to find an item which isn't in the delete list
+ if (g_list_length(tree_iters) > 1) {
+ for (iter = tree_iters; iter; iter = iter->next) {
+ GtkTreePath *ipath = gtk_tree_model_get_path(GTK_TREE_MODEL (store), (GtkTreeIter *)iter->data);
+ if (gtk_tree_path_compare(path, ipath) == 0) {
+ clear = FALSE;
+ break;
+ }
+ }
+ while (clear == FALSE) {
+ if (gtk_tree_path_prev(path)) {
+ clear = TRUE;
+ for (iter = tree_iters; iter; iter = iter->next) {
+ GtkTreePath *ipath = gtk_tree_model_get_path(GTK_TREE_MODEL (store), (GtkTreeIter *)iter->data);
+ if (gtk_tree_path_compare(path, ipath) == 0) {
+ clear = FALSE;
+ break;
+ }
+ }
+ if (clear) {
+ if (!gtk_tree_model_get_iter(GTK_TREE_MODEL (store), &titer, path)) {
+ g_debug("Failed to get iter from path");
+ last_selected = NULL;
+ } else {
+ last_selected = &titer;
+ }
+ }
+ } else {
+ last_selected = NULL;
+ break;
+ }
+ }
+ }
+ }
+
/* Now delete each iterator */
for (iter = tree_iters; iter; iter = iter->next) {
gtk_list_store_remove (store, (GtkTreeIter *)iter->data);
g_free (iter->data);
}
g_list_free (tree_iters);
+
+ if (last_selected)
+ gtk_tree_selection_select_iter(selection, last_selected);
}
static void