r1433: Properly use GtkTreeView:
authorJelmer Vernooij <jelmer@samba.org>
Sun, 11 Jul 2004 01:42:16 +0000 (01:42 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:56:55 +0000 (12:56 -0500)
 - When a key is selected the values are immediately shown in gregedit
 - Only allow deleting jobs if one is selected.

source/gtk/tools/gregedit.c
source/gtk/tools/gwcrontab.c

index f34ccd9578d04d0b4b18684ec69550f20e527f24..6c13dcaef08776d292788f459f1e4afa6d66876a 100644 (file)
@@ -270,15 +270,18 @@ static void on_about_activate                      (GtkMenuItem     *menuitem,
         gtk_widget_destroy(GTK_WIDGET(aboutwin));
 }
 
-static void on_key_activate (GtkTreeView *treeview,
-                                         GtkTreePath *path,
-                                         gpointer user_data)
+gboolean on_key_activate(GtkTreeSelection *selection,
+                                             GtkTreeModel *model,
+                                             GtkTreePath *path,
+                                             gboolean path_currently_selected,
+                                             gpointer data)
 {
        int i;
        REG_KEY *k;
        REG_VAL *val;
        WERROR error;
        GtkTreeIter parent;
+       if(path_currently_selected)return TRUE;
 
        gtk_tree_model_get_iter(GTK_TREE_MODEL(store_keys), &parent, path);
        gtk_tree_model_get(GTK_TREE_MODEL(store_keys), &parent, 1, &k, -1);
@@ -303,7 +306,11 @@ static void on_key_activate (GtkTreeView *treeview,
                                                -1);
        }
 
-       if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) gtk_show_werror(mainwin, error);
+       if(!W_ERROR_EQUAL(error, WERR_NO_MORE_ITEMS)) {
+                gtk_show_werror(mainwin, error);
+                return FALSE;
+       }
+       return TRUE;
 }
 
 static GtkWidget* create_mainwin (void)
@@ -480,14 +487,13 @@ static GtkWidget* create_mainwin (void)
   gtk_tree_view_set_model(GTK_TREE_VIEW(tree_keys), GTK_TREE_MODEL(store_keys));
   g_object_unref(store_keys);
 
-  g_signal_connect ((gpointer) tree_keys, "row-activated",
-                    G_CALLBACK (on_key_activate),
-                    NULL);
+  gtk_tree_selection_set_select_function (gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_keys)), on_key_activate, NULL, NULL);
 
   g_signal_connect ((gpointer) tree_keys, "row-expanded",
                     G_CALLBACK (expand_key),
                     NULL);
 
+
   scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
   gtk_widget_show (scrolledwindow2);
   gtk_box_pack_start (GTK_BOX (hbox1), scrolledwindow2, TRUE, TRUE, 0);
index cf162f2a2562b5e269891ad74144159e6abc8851..9683570664ab346ecf3e769f6b86a491a240d9ff 100644 (file)
@@ -40,6 +40,7 @@ GtkWidget *tasks;
 GtkWidget *entry_cmd;
 GtkWidget *entry_repeat_weekly;
 GtkWidget *entry_repeat_monthly;
+GtkWidget *delete;
 
 void update_joblist()
 {
@@ -81,6 +82,13 @@ void update_joblist()
        gtk_widget_set_sensitive(tasks, TRUE);
 }
 
+static void on_job_select(GtkTreeSelection *sel,
+                                             gpointer data)
+{
+        gtk_widget_set_sensitive(delete, gtk_tree_selection_get_selected(sel, NULL, NULL));
+}
+
+
 void
 on_connect_activate                    (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
@@ -224,7 +232,6 @@ create_mainwindow (void)
   GtkWidget *new;
   GtkCellRenderer *renderer;
   GtkTreeViewColumn *curcol;
-  GtkWidget *delete;
   GtkWidget *menuitem7;
   GtkWidget *menuitem7_menu;
   GtkWidget *about;
@@ -277,6 +284,7 @@ create_mainwindow (void)
   gtk_container_add (GTK_CONTAINER (task_menu), new);
 
   delete = gtk_menu_item_new_with_mnemonic ("_Delete");
+  gtk_widget_set_sensitive(delete, FALSE);
   gtk_widget_show (delete);
   gtk_container_add (GTK_CONTAINER (task_menu), delete);
 
@@ -339,6 +347,8 @@ create_mainwindow (void)
   gtk_widget_show (tasks);
   gtk_container_add (GTK_CONTAINER (scrolledwindow), tasks);
 
+  g_signal_connect (gtk_tree_view_get_selection(GTK_TREE_VIEW(tasks)) , "changed", G_CALLBACK (on_job_select), NULL);
+
   statusbar = gtk_statusbar_new ();
   gtk_widget_show (statusbar);
   gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 0);