# HG changeset patch # User zas_ # Date 1259959202 0 # Node ID f0e9f2dcfe8a1cc89fa423424378100ed2519e60 # Parent df106a76897c95d254b2703dab0c45b0c8b2dede Editors: disable Delete button if a .desktop file is not writeable and disable Edit button when no entry is selected. diff -r df106a76897c -r f0e9f2dcfe8a src/desktop_file.c --- a/src/desktop_file.c Fri Dec 04 19:45:09 2009 +0000 +++ b/src/desktop_file.c Fri Dec 04 20:40:02 2009 +0000 @@ -46,6 +46,8 @@ GtkWidget *window; GtkWidget *view; GenericDialog *gd; /* any open confirm dialogs ? */ + GtkWidget *delete_button; + GtkWidget *edit_button; }; typedef struct _EditorWindowDel_Data EditorWindowDel_Data; @@ -372,6 +374,27 @@ editor_window_new(DESKTOP_FILE_TEMPLATE, _("new.desktop")); } +static void editor_list_window_selection_changed_cb(GtkWidget *widget, gpointer data) +{ + EditorListWindow *ewl = data; + GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(ewl->view)); + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected(sel, NULL, &iter)) + { + GtkTreeModel *store = gtk_tree_view_get_model(GTK_TREE_VIEW(ewl->view)); + gchar *path; + + gtk_tree_model_get(store, &iter, + DESKTOP_FILE_COLUMN_PATH, &path, + -1); + + gtk_widget_set_sensitive(ewl->delete_button, access_file(path, W_OK)); + gtk_widget_set_sensitive(ewl->edit_button, TRUE); + g_free(path); + } + +} static gint editor_list_window_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data) { @@ -456,13 +479,17 @@ G_CALLBACK(editor_list_window_edit_cb), ewl); gtk_container_add(GTK_CONTAINER(hbox), button); GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); + gtk_widget_set_sensitive(button, FALSE); gtk_widget_show(button); + ewl->edit_button = button; button = pref_button_new(NULL, GTK_STOCK_DELETE, NULL, FALSE, G_CALLBACK(editor_list_window_delete_cb), ewl); gtk_container_add(GTK_CONTAINER(hbox), button); GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); + gtk_widget_set_sensitive(button, FALSE); gtk_widget_show(button); + ewl->delete_button = button; button = pref_button_new(NULL, GTK_STOCK_CLOSE, NULL, FALSE, G_CALLBACK(editor_list_window_close_cb), ewl); @@ -480,6 +507,7 @@ ewl->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(desktop_file_list)); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(ewl->view)); gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_SINGLE); + g_signal_connect(selection, "changed", G_CALLBACK(editor_list_window_selection_changed_cb), ewl); gtk_tree_view_set_enable_search(GTK_TREE_VIEW(ewl->view), FALSE);