diff -Nuard nautilus-2.4.2.orig/ChangeLog nautilus-2.4.2/ChangeLog --- nautilus-2.4.2.orig/ChangeLog 2004-02-03 01:15:09.000000000 +0100 +++ nautilus-2.4.2/ChangeLog 2004-02-27 00:32:26.901372952 +0100 @@ -1,3 +1,8 @@ +2004-02-27 Marcin Krzyzanowski + + * src/file-manager/fm-properties-window.c: + Allow to modify executable command in desktop launchers + 2004-02-02 Dave Camp * src/Makefile.am: Removed DISABLE_DEPRECATED flags. diff -Nuard nautilus-2.4.2.orig/src/file-manager/fm-properties-window.c nautilus-2.4.2/src/file-manager/fm-properties-window.c --- nautilus-2.4.2.orig/src/file-manager/fm-properties-window.c 2003-10-29 06:46:52.000000000 +0100 +++ nautilus-2.4.2/src/file-manager/fm-properties-window.c 2004-02-27 01:46:42.000000000 +0100 @@ -96,6 +96,7 @@ GtkWidget *icon_image; NautilusEntry *name_field; + NautilusEntry *command_field; char *pending_name; GtkLabel *directory_contents_title_field; @@ -518,6 +519,43 @@ return image; } +static gboolean +should_show_command_target (FMPropertiesWindow *window) +{ + if (!is_multi_file_window(window) + && (!nautilus_file_is_symbolic_link (get_target_file (window))) + && (!nautilus_file_is_directory (get_target_file (window))) + && nautilus_file_can_execute(get_target_file (window))) + return TRUE; + + return FALSE; +} + +static void +update_command_field (FMPropertiesWindow *window) +{ + if ((!is_multi_file_window (window)) || (should_show_command_target (window))) { + const gchar *exec = NULL; + gchar *uri = nautilus_file_get_string_attribute_with_default (NAUTILUS_FILE(window->details->target_files->data), "uri"); + GnomeDesktopItem *gitem = gnome_desktop_item_new_from_uri(uri,0,NULL); + +// if (gnome_desktop_item_exists(gitem)) { + exec = gnome_desktop_item_get_string(gitem,"Exec"); +// } + + if (exec) { + gtk_entry_set_text (GTK_ENTRY(window->details->command_field),exec); + } else { + gtk_widget_set_sensitive (GTK_WIDGET (window->details->command_field), FALSE); + } + + + g_free (uri); + gnome_desktop_item_unref(gitem); + } + +} + static void update_name_field (FMPropertiesWindow *window) { @@ -697,6 +735,49 @@ g_free (new_name); } +static void +command_field_done_editing (NautilusEntry *command_field, FMPropertiesWindow *window) +{ + NautilusFile *file; + gchar *new_exec = NULL; + const gchar *prev_exec = NULL; + gchar *uri = NULL; + GnomeDesktopItem *gitem = NULL; + + g_return_if_fail (NAUTILUS_IS_ENTRY (command_field)); + + /* Don't apply if the dialog has more than one file */ + if (is_multi_file_window (window)) + return; + + file = get_original_file (window); + + /* This gets called when the window is closed, which might be + * caused by the file having been deleted. + */ + if (nautilus_file_is_gone (file)) { + return; + } + + new_exec = gtk_editable_get_chars (GTK_EDITABLE (command_field), 0, -1); + + uri = nautilus_file_get_string_attribute_with_default (NAUTILUS_FILE(window->details->target_files->data), "uri"); + gitem = gnome_desktop_item_new_from_uri(uri,0,NULL); + + /* if there were no previous value do not save it */ + prev_exec = gnome_desktop_item_get_string(gitem,"Exec"); + if (prev_exec && new_exec ) { /*&& (strlen(new_exec) > 0)*/ + gnome_desktop_item_set_string(gitem,"Exec",new_exec); + if (!gnome_desktop_item_save(gitem,NULL,FALSE,NULL)) { + g_print("error while saving new value for Exec\n"); + } + } + + gnome_desktop_item_unref(gitem); + g_free (new_exec); + g_free(uri); +} + static gboolean name_field_focus_out (NautilusEntry *name_field, GdkEventFocus *event, @@ -711,6 +792,20 @@ return FALSE; } +static gboolean +command_field_focus_out (NautilusEntry *command_field, + GdkEventFocus *event, + gpointer callback_data) +{ + g_assert (FM_IS_PROPERTIES_WINDOW (callback_data)); + + if (GTK_WIDGET_SENSITIVE (command_field)) { + command_field_done_editing (command_field, FM_PROPERTIES_WINDOW (callback_data)); + } + + return FALSE; +} + static void name_field_activate (NautilusEntry *name_field, gpointer callback_data) { @@ -723,6 +818,18 @@ nautilus_entry_select_all_at_idle (name_field); } +static void +command_field_activate (NautilusEntry *command_field, gpointer callback_data) +{ + g_assert (NAUTILUS_IS_ENTRY (command_field)); + g_assert (FM_IS_PROPERTIES_WINDOW (callback_data)); + + /* Accept changes. */ + command_field_done_editing (command_field, FM_PROPERTIES_WINDOW (callback_data)); + + nautilus_entry_select_all_at_idle (command_field); +} + static gboolean file_has_keyword (NautilusFile *file, const char *keyword) { @@ -1036,6 +1143,7 @@ update_properties_window_icon (GTK_IMAGE (window->details->icon_image)); update_name_field (window); + update_command_field (window); for (l = window->details->emblem_buttons; l != NULL; l = l->next) { emblem_button_update (window, GTK_TOGGLE_BUTTON (l->data)); @@ -2133,6 +2241,7 @@ return FALSE; } + static gboolean should_show_free_space (FMPropertiesWindow *window) { @@ -2149,9 +2258,10 @@ { GtkTable *table; GtkWidget *container; - GtkWidget *name_field; + GtkWidget *name_field, *command_field; GtkWidget *icon_aligner; GtkWidget *icon_pixmap_widget; + GtkLabel *command_label; GtkWidget *hbox, *name_label; @@ -2275,6 +2385,27 @@ _("--"), FALSE); } + + command_field = nautilus_entry_new (); + window->details->command_field = NAUTILUS_ENTRY (command_field); + if (should_show_command_target (window)) { + guint last_row = append_title_field (table, _("E_xecute:"), &command_label); + gtk_widget_show (command_field); + gtk_table_attach (table, + command_field, + VALUE_COLUMN, + VALUE_COLUMN + 1, + last_row, last_row + 1, + GTK_FILL, 0, + 0, 0); + gtk_label_set_mnemonic_widget (GTK_LABEL (command_label), command_field); + update_command_field (window); + + g_signal_connect_object (command_field, "focus_out_event", + G_CALLBACK (command_field_focus_out), window, 0); + g_signal_connect_object (command_field, "activate", + G_CALLBACK (command_field_activate), window, 0); + } if (should_show_mime_type (window)) { append_title_value_pair (window, table, _("MIME type:"), "mime_type",