summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-01-07 23:14:48 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-01-07 23:14:48 +0100
commit3849236adab80e6169e4f37c35eb4245f495da46 (patch)
tree67341d7553a382e6053bae1a005cbf46d6dfab7b
parent90df6aec51309372260b02b3a9bd518d35da4f40 (diff)
Added browse tree popup with update option.
Fixed running consecutive directory adds/updates.
-rw-r--r--walls.ui2
-rw-r--r--window_main.c76
2 files changed, 78 insertions, 0 deletions
diff --git a/walls.ui b/walls.ui
index 7bff6c6..5309439 100644
--- a/walls.ui
+++ b/walls.ui
@@ -106,6 +106,8 @@
<object class="GtkTreeView" id="foldtree">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <signal name="button_press_event" handler="on_foldtree_button_press_event"/>
+ <signal name="popup_menu" handler="on_foldtree_popup_menu"/>
</object>
</child>
</object>
diff --git a/window_main.c b/window_main.c
index a550943..715da9c 100644
--- a/window_main.c
+++ b/window_main.c
@@ -437,6 +437,8 @@ gpointer add_dir_thread(gpointer data) {
g_free(directory);
+ add_thread = NULL;
+
return NULL;
}
@@ -460,6 +462,80 @@ void on_add_dir_action_activate(GtkAction *action, gpointer user_data) {
gtk_widget_destroy(dialog);
}
+void on_foldtree_update_activate(GtkMenuItem *menuitem, gpointer user_data) {
+ GtkTreeSelection *treeselection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ struct directory_t *dir;
+ GError *error;
+
+ if(add_thread) return;
+
+ treeselection = gtk_tree_view_get_selection(GTK_TREE_VIEW(foldtree));
+
+ if(gtk_tree_selection_get_selected(treeselection, &model, &iter)) {
+ browse_model_get_dir_record(model, &iter, &dir);
+
+ add_thread = g_thread_create(add_dir_thread, g_strdup(dir->name), FALSE, &error);
+
+ if(!add_thread) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ }
+ }
+}
+
+inline static void foldtree_popup_add_items(GtkWidget *menu) {
+ GtkWidget *update;
+ GtkTreeSelection *selection;
+
+ update = gtk_menu_item_new_with_label("Update");
+
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(foldtree));
+ gtk_widget_set_sensitive(update, (gtk_tree_selection_count_selected_rows(selection) == 1 ? TRUE : FALSE));
+
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), update);
+
+ g_signal_connect(G_OBJECT(update), "activate", G_CALLBACK(on_foldtree_update_activate), NULL);
+
+ gtk_widget_show(update);
+}
+
+static void do_foldtree_popup(GtkWidget *widget, GdkEventButton *event) {
+ GtkWidget *menu;
+ int button, event_time;
+
+ menu = gtk_menu_new();
+ g_signal_connect(menu, "selection-done", G_CALLBACK(gtk_widget_destroy), NULL);
+
+ foldtree_popup_add_items(menu);
+
+ if(event) {
+ button = event->button;
+ event_time = event->time;
+ } else {
+ button = 0;
+ event_time = gtk_get_current_event_time();
+ }
+
+ gtk_menu_attach_to_widget(GTK_MENU(menu), widget, NULL);
+ gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, button, event_time);
+}
+
+gboolean on_foldtree_popup_menu(GtkWidget *widget, gpointer user_data) {
+ do_foldtree_popup(widget, NULL);
+
+ return TRUE;
+}
+
+gboolean on_foldtree_button_press_event(GtkWidget *widget, GdkEventButton *event) {
+ if(event->button == 3 && event->type == GDK_BUTTON_PRESS) {
+ do_foldtree_popup(widget, event);
+ return TRUE;
+ }
+ return FALSE;
+}
+
/**
* Callback for adding selected wallpapers to an array.
*/