diff -rbup xfce4-autostart-editor.orig/xfae-dialog.c xfce4-autostart-editor/xfae-dialog.c --- xfce4-autostart-editor.orig/xfae-dialog.c 2007-01-20 18:48:52.000000000 +0100 +++ xfce4-autostart-editor/xfae-dialog.c 2007-04-01 22:20:59.000000000 +0200 @@ -273,3 +273,34 @@ xfae_dialog_get (XfaeDialog *dialog, } + +/** + * xfae_dialog_set: + * @dialog : a #XfaeDialog. + * @name : location for the name. + * @descr : location for the description. + * @command : location for the command. + * + * Extracts the parameters selected by the user + * from the @dialog. + **/ +void +xfae_dialog_set (XfaeDialog *dialog, + gchar *name, + gchar *descr, + gchar *command) +{ + gint position = 0; + + g_return_if_fail (XFAE_IS_DIALOG (dialog)); + g_return_if_fail (name != NULL); + g_return_if_fail (descr != NULL); + g_return_if_fail (command != NULL); + + + gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry), name, -1, &position); + gtk_editable_insert_text (GTK_EDITABLE (dialog->descr_entry), descr, -1, &position); + gtk_editable_insert_text (GTK_EDITABLE (dialog->command_entry), command, -1, &position); +} + + diff -rbup xfce4-autostart-editor.orig/xfae-model.c xfce4-autostart-editor/xfae-model.c --- xfce4-autostart-editor.orig/xfae-model.c 2007-01-20 18:48:52.000000000 +0100 +++ xfce4-autostart-editor/xfae-model.c 2007-04-02 21:49:36.000000000 +0200 @@ -581,6 +581,66 @@ xfae_model_new (void) } +/** + * xfae_model_get: + * @model : a #XfaeModel. + * @iter : the #GtkTreeIter referring to the item. + * @name : the user visible name of the item. + * @description : the description for the item. + * @command : the command for the item. + * @error : return locations for errors or %NULL. + * + * Attempts to get parameters from an iter + * to @model. + **/ +gboolean +xfae_model_get (XfaeModel *model, + GtkTreeIter *iter, + gchar **name, + gchar **description, + gchar **command, + GError **error) +{ + const gchar *value; + GtkTreePath *path; + XfaeItem *item; + XfceRc *rc; + GList *lp; + + g_return_val_if_fail (XFAE_IS_MODEL (model), FALSE); + g_return_val_if_fail (iter->stamp == model->stamp, FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + lp = iter->user_data; + item = lp->data; + + /* try to open the resource config */ + rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, item->relpath, FALSE); + if (G_UNLIKELY (rc == NULL)) + { + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (EIO), + _("Failed to open %s for writing"), item->relpath); + return FALSE; + } + + /* read the resource config */ + value = xfce_rc_read_entry (rc, "Name", NULL); + if (G_LIKELY (value != NULL)) + *name = g_strdup (value); + + value = xfce_rc_read_entry (rc, "Comment", NULL); + if (G_LIKELY (value != NULL)) + *description = g_strdup (value); + + value = xfce_rc_read_entry (rc, "Exec", NULL); + if (G_LIKELY (value != NULL)) + *command = g_strdup (value); + + xfce_rc_close (rc); + + return TRUE; +} + /** * xfae_model_add: @@ -731,6 +791,67 @@ xfae_model_remove (XfaeModel *model, } +/** + * xfae_model_edit: + * @model : a #XfaeModel. + * @iter : the #GtkTreeIter referring to the item that should be removed. + * @name : the user visible name of the new item. + * @description : the description for the new item. + * @command : the command for the new item. + * @error : return locations for errors or %NULL. + * + * Attempts to edit an item with the given parameters + * to @model. + * + * Return value: %TRUE if successfull, else %FALSE. + **/ +gboolean +xfae_model_edit (XfaeModel *model, + GtkTreeIter *iter, + const gchar *name, + const gchar *description, + const gchar *command, + GError **error) +{ + GtkTreePath *path; + XfaeItem *item; + XfceRc *rc; + GList *lp; + + g_return_val_if_fail (XFAE_IS_MODEL (model), FALSE); + g_return_val_if_fail (iter->stamp == model->stamp, FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + lp = iter->user_data; + item = lp->data; + + /* try to open the resource config */ + rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, item->relpath, FALSE); + if (G_UNLIKELY (rc == NULL)) + { + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (EIO), + _("Failed to open %s for writing"), item->relpath); + return FALSE; + } + + item->name = g_strdup (name); + item->comment = g_strdup (description); + + /* write the result */ + xfce_rc_set_group (rc, "Desktop Entry"); + xfce_rc_write_entry (rc, "Name", name); + xfce_rc_write_entry (rc, "Comment", description); + xfce_rc_write_entry (rc, "Exec", command); + xfce_rc_close (rc); + + /* tell the view that we have most probably a new state */ + path = gtk_tree_path_new_from_indices (g_list_position (model->items, lp), -1); + gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, iter); + gtk_tree_path_free (path); + + return TRUE; +} + /** * xfae_model_toggle: diff -rbup xfce4-autostart-editor.orig/xfae-model.h xfce4-autostart-editor/xfae-model.h --- xfce4-autostart-editor.orig/xfae-model.h 2007-01-20 18:48:52.000000000 +0100 +++ xfce4-autostart-editor/xfae-model.h 2007-04-02 21:50:39.000000000 +0200 @@ -55,6 +55,13 @@ GType xfae_model_get_type (void) GtkTreeModel *xfae_model_new (void); +gboolean xfae_model_get (XfaeModel *model, + GtkTreeIter *iter, + gchar **name, + gchar **description, + gchar **command, + GError **error); + gboolean xfae_model_add (XfaeModel *model, const gchar *name, const gchar *description, @@ -65,6 +72,13 @@ gboolean xfae_model_remove (XfaeM GtkTreeIter *iter, GError **error); +gboolean xfae_model_edit (XfaeModel *model, + GtkTreeIter *iter, + const gchar *name, + const gchar *description, + const gchar *command, + GError **error); + gboolean xfae_model_toggle (XfaeModel *model, GtkTreeIter *iter, GError **error); diff -rbup xfce4-autostart-editor.orig/xfae-window.c xfce4-autostart-editor/xfae-window.c --- xfce4-autostart-editor.orig/xfae-window.c 2007-01-20 18:48:52.000000000 +0100 +++ xfce4-autostart-editor/xfae-window.c 2007-04-02 21:38:09.000000000 +0200 @@ -32,6 +32,7 @@ static void xfae_window_class_init (XfaeWindowClass *klass); static void xfae_window_init (XfaeWindow *window); static void xfae_window_add (XfaeWindow *window); +static void xfae_window_edit (XfaeWindow *window); static void xfae_window_remove (XfaeWindow *window); static gboolean xfae_window_button_press_event (GtkWidget *treeview, GdkEventButton *event, @@ -197,6 +198,14 @@ xfae_window_init (XfaeWindow *window) gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0); gtk_widget_show (button); + button = gtk_button_new_from_stock (GTK_STOCK_EDIT); + g_signal_connect_swapped (G_OBJECT (button), "clicked", + G_CALLBACK (xfae_window_edit), window); + g_signal_connect (G_OBJECT (selection), "changed", + G_CALLBACK (xfae_window_selection_changed), button); + gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0); + gtk_widget_show (button); + button = gtk_button_new_from_stock (GTK_STOCK_REMOVE); g_signal_connect_swapped (G_OBJECT (button), "clicked", G_CALLBACK (xfae_window_remove), window); @@ -250,6 +259,13 @@ xfae_window_button_press_event (GtkWidge gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_EDIT, NULL); + g_signal_connect_swapped (G_OBJECT (item), "activate", + G_CALLBACK (xfae_window_edit), window); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_set_sensitive (item, removable); + gtk_widget_show (item); + item = gtk_image_menu_item_new_from_stock (GTK_STOCK_REMOVE, NULL); g_signal_connect_swapped (G_OBJECT (item), "activate", G_CALLBACK (xfae_window_remove), window); @@ -315,6 +331,58 @@ xfae_window_add (XfaeWindow *window) static void +xfae_window_edit (XfaeWindow *window) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + GtkWidget *dialog; + GError *error = NULL; + gchar *name; + gchar *descr; + gchar *command; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (window->treeview)); + if (gtk_tree_selection_get_selected (selection, &model, &iter)) + { + model = gtk_tree_view_get_model (GTK_TREE_VIEW (window->treeview)); + if (!xfae_model_get (XFAE_MODEL(model), &iter, &name, &descr, &command, &error)) + { + xfce_err (error->message); + g_error_free (error); + } + + dialog = xfae_dialog_new (); + xfae_dialog_set (GTK_WINDOW (dialog), name, descr, command); + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window)); + + g_free (command); + g_free (descr); + g_free (name); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) + { + gtk_widget_hide (dialog); + + xfae_dialog_get (XFAE_DIALOG (dialog), &name, &descr, &command); + + if (!xfae_model_edit (XFAE_MODEL (model), &iter, name, descr, command, &error)) + { + xfce_err (error->message); + g_error_free (error); + } + + g_free (command); + g_free (descr); + g_free (name); + } + gtk_widget_destroy (dialog); + } +} + + + +static void xfae_window_remove (XfaeWindow *window) { GtkTreeSelection *selection;