summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2011-02-15 17:16:29 +0100
committerDenys Vlasenko <dvlasenk@redhat.com>2011-02-15 17:16:29 +0100
commit41799843c27d06629bd6ce4c7fd3a65a1149e08b (patch)
treed7459da0fb3d1cabd22cfa96ba34c68bcb593b14
parent22de22a5c8a02c1c741c13626845983223222c70 (diff)
downloadabrt-41799843c27d06629bd6ce4c7fd3a65a1149e08b.tar.gz
abrt-41799843c27d06629bd6ce4c7fd3a65a1149e08b.tar.xz
abrt-41799843c27d06629bd6ce4c7fd3a65a1149e08b.zip
abrt-gtk: better handling of cursor while deleting
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--src/gui-gtk/abrt-gtk.c37
-rw-r--r--src/gui-gtk/abrt-gtk.h2
-rw-r--r--src/gui-gtk/main.c2
3 files changed, 34 insertions, 7 deletions
diff --git a/src/gui-gtk/abrt-gtk.c b/src/gui-gtk/abrt-gtk.c
index 12c55240..a82f634d 100644
--- a/src/gui-gtk/abrt-gtk.c
+++ b/src/gui-gtk/abrt-gtk.c
@@ -91,6 +91,8 @@ static gint on_key_press_event_cb(GtkTreeView *treeview, GdkEventKey *key, gpoin
GtkTreeModel *store = gtk_tree_view_get_model(treeview);
if (gtk_tree_selection_get_selected(selection, &store, &iter) == TRUE)
{
+ GtkTreePath *old_path = gtk_tree_model_get_path(store, &iter);
+
GValue d_dir = { 0 };
gtk_tree_model_get_value(store, &iter, COLUMN_DUMP_DIR, &d_dir);
const char *dump_dir_name = g_value_get_string(&d_dir);
@@ -121,8 +123,11 @@ static gint on_key_press_event_cb(GtkTreeView *treeview, GdkEventKey *key, gpoin
* Rescan the whole list */
gtk_list_store_clear(s_dumps_list_store);
scan_dirs_and_add_to_dirlist();
- sanitize_cursor();
}
+
+ /* Try to retain the same cursor position */
+ sanitize_cursor(old_path);
+ gtk_tree_path_free(old_path);
}
}
@@ -219,24 +224,46 @@ GtkWidget *create_main_window(void)
return main_window;
}
-void sanitize_cursor(void)
+void sanitize_cursor(GtkTreePath *preferred_path)
{
GtkTreePath *path;
+
gtk_tree_view_get_cursor(GTK_TREE_VIEW(s_treeview), &path, /* GtkTreeViewColumn** */ NULL);
if (path)
{
- /* Cursor exists already */
+ /* Cursor exists already */
gtk_tree_path_free(path);
- return;
+ goto ret;
+ }
+
+ if (preferred_path)
+ {
+ /* Try to position cursor on preferred_path */
+ gtk_tree_view_set_cursor(GTK_TREE_VIEW(s_treeview), preferred_path,
+ /* GtkTreeViewColumn *focus_column */ NULL, /* start_editing */ false);
+
+ /* Did it work? */
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(s_treeview), &path, /* GtkTreeViewColumn** */ NULL);
+ if (path) /* yes */
+ {
+ gtk_tree_path_free(path);
+ goto ret;
+ }
}
+ /* Try to position cursor on 1st element */
GtkTreeIter iter;
if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(s_dumps_list_store), &iter))
{
- /* We have at least one element, put cursor on it */
+ /* We have at least one element, put cursor on it */
path = gtk_tree_model_get_path(GTK_TREE_MODEL(s_dumps_list_store), &iter);
gtk_tree_view_set_cursor(GTK_TREE_VIEW(s_treeview), path,
/* GtkTreeViewColumn *focus_column */ NULL, /* start_editing */ false);
gtk_tree_path_free(path);
}
+ /* else we have no elements */
+
+ ret:
+ /* Without this, the *header* of the list gets the focus. Ugly. */
+ gtk_widget_grab_focus(s_treeview);
}
diff --git a/src/gui-gtk/abrt-gtk.h b/src/gui-gtk/abrt-gtk.h
index 7c197ceb..d67ca6ce 100644
--- a/src/gui-gtk/abrt-gtk.h
+++ b/src/gui-gtk/abrt-gtk.h
@@ -1,5 +1,5 @@
GtkWidget *create_main_window(void);
void add_directory_to_dirlist(const char *dirname);
-void sanitize_cursor(void);
+void sanitize_cursor(GtkTreePath *preferred_path);
void scan_dirs_and_add_to_dirlist();
diff --git a/src/gui-gtk/main.c b/src/gui-gtk/main.c
index aa05a22a..c223d4c6 100644
--- a/src/gui-gtk/main.c
+++ b/src/gui-gtk/main.c
@@ -83,7 +83,7 @@ int main(int argc, char **argv)
gtk_widget_show_all(main_window);
- sanitize_cursor();
+ sanitize_cursor(NULL);
/* Prevent zombies when we spawn wizard */
signal(SIGCHLD, SIG_IGN);