From 8aaeec62534a2317cf206c15517083b9f128f204 Mon Sep 17 00:00:00 2001 From: Peter de Ridder Date: Fri, 2 Oct 2009 00:01:38 +0200 Subject: [PATCH] Use the Path entry from the .desktop file. Added text entry for editing the Path field in the desktop item editor. --- exo-desktop-item-edit/exo-die-desktop-model.c | 11 ++ exo-desktop-item-edit/exo-die-desktop-model.h | 2 + exo-desktop-item-edit/exo-die-editor.c | 159 ++++++++++++++++++++++++- exo-desktop-item-edit/exo-die-editor.h | 4 + exo-desktop-item-edit/main.c | 13 ++ 5 files changed, 188 insertions(+), 1 deletions(-) diff --git a/exo-desktop-item-edit/exo-die-desktop-model.c b/exo-desktop-item-edit/exo-die-desktop-model.c index 2b50b57..c13adf3 100644 --- a/exo-desktop-item-edit/exo-die-desktop-model.c +++ b/exo-desktop-item-edit/exo-die-desktop-model.c @@ -101,6 +101,7 @@ struct _ExoDieDesktopItem { gchar *command; gchar *comment; + gchar *path; gchar *icon; gchar *name; guint snotify : 1; @@ -208,6 +209,7 @@ exo_die_desktop_model_get_column_type (GtkTreeModel *tree_model, case EXO_DIE_DESKTOP_MODEL_COLUMN_ABSTRACT: case EXO_DIE_DESKTOP_MODEL_COLUMN_COMMAND: case EXO_DIE_DESKTOP_MODEL_COLUMN_COMMENT: + case EXO_DIE_DESKTOP_MODEL_COLUMN_PATH: case EXO_DIE_DESKTOP_MODEL_COLUMN_ICON: case EXO_DIE_DESKTOP_MODEL_COLUMN_NAME: return G_TYPE_STRING; @@ -296,6 +298,11 @@ exo_die_desktop_model_get_value (GtkTreeModel *tree_model, g_value_set_static_string (value, desktop_item->comment); break; + case EXO_DIE_DESKTOP_MODEL_COLUMN_PATH: + g_value_init (value, G_TYPE_STRING); + g_value_set_static_string (value, desktop_item->path); + break; + case EXO_DIE_DESKTOP_MODEL_COLUMN_ICON: g_value_init (value, G_TYPE_STRING); g_value_set_static_string (value, desktop_item->icon); @@ -567,6 +574,7 @@ exo_die_desktop_item_new_from_file (const gchar *file) ExoDieDesktopItem *desktop_item = NULL; const gchar *comment; const gchar *command; + const gchar *path; const gchar *icon; const gchar *name; const gchar *type; @@ -584,6 +592,7 @@ exo_die_desktop_item_new_from_file (const gchar *file) /* determine the attributes from the file */ command = xfce_rc_read_entry_untranslated (rc, "Exec", NULL); comment = xfce_rc_read_entry (rc, "Comment", NULL); + path = xfce_rc_read_entry (rc, "Path", NULL); icon = xfce_rc_read_entry (rc, "Icon", NULL); name = xfce_rc_read_entry (rc, "Name", NULL); type = xfce_rc_read_entry (rc, "Type", "Application"); @@ -595,6 +604,7 @@ exo_die_desktop_item_new_from_file (const gchar *file) desktop_item = g_new (ExoDieDesktopItem, 1); desktop_item->command = g_strdup (command); desktop_item->comment = g_strdup (comment); + desktop_item->path = g_strdup (path); desktop_item->icon = g_strdup (icon); desktop_item->name = g_strdup (name); @@ -648,6 +658,7 @@ exo_die_desktop_item_free (ExoDieDesktopItem *desktop_item) { g_free (desktop_item->command); g_free (desktop_item->comment); + g_free (desktop_item->path); g_free (desktop_item->icon); g_free (desktop_item->name); g_free (desktop_item); diff --git a/exo-desktop-item-edit/exo-die-desktop-model.h b/exo-desktop-item-edit/exo-die-desktop-model.h index 75da167..1c4446d 100644 --- a/exo-desktop-item-edit/exo-die-desktop-model.h +++ b/exo-desktop-item-edit/exo-die-desktop-model.h @@ -40,6 +40,7 @@ typedef struct _ExoDieDesktopModel ExoDieDesktopModel; * @EXO_DIE_DESKTOP_MODEL_COLUMN_ABSTRACT : the column with the markup text for the renderer. * @EXO_DIE_DESKTOP_MODEL_COLUMN_COMMAND : the column with the application command. * @EXO_DIE_DESKTOP_MODEL_COLUMN_COMMENT : the column with the application comment. + * @EXO_DIE_DESKTOP_MODEL_COLUMN_PATH : the column with the application path. * @EXO_DIE_DESKTOP_MODEL_COLUMN_ICON : the column with the application icon. * @EXO_DIE_DESKTOP_MODEL_COLUMN_NAME : the column with the application name. * @EXO_DIE_DESKTOP_MODEL_COLUMN_SNOTIFY : the column with the applications StartupNotify setting. @@ -52,6 +53,7 @@ typedef enum /*< enum >*/ EXO_DIE_DESKTOP_MODEL_COLUMN_ABSTRACT, EXO_DIE_DESKTOP_MODEL_COLUMN_COMMAND, EXO_DIE_DESKTOP_MODEL_COLUMN_COMMENT, + EXO_DIE_DESKTOP_MODEL_COLUMN_PATH, EXO_DIE_DESKTOP_MODEL_COLUMN_ICON, EXO_DIE_DESKTOP_MODEL_COLUMN_NAME, EXO_DIE_DESKTOP_MODEL_COLUMN_SNOTIFY, diff --git a/exo-desktop-item-edit/exo-die-editor.c b/exo-desktop-item-edit/exo-die-editor.c index 262caf4..89f81d0 100644 --- a/exo-desktop-item-edit/exo-die-editor.c +++ b/exo-desktop-item-edit/exo-die-editor.c @@ -37,6 +37,7 @@ enum PROP_NAME, PROP_COMMENT, PROP_COMMAND, + PROP_PATH, PROP_URL, PROP_ICON, PROP_SNOTIFY, @@ -54,6 +55,8 @@ static void exo_die_editor_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); +static void exo_die_editor_path_clicked (GtkWidget *chooser, + ExoDieEditor *editor); static void exo_die_editor_icon_clicked (GtkWidget *button, ExoDieEditor *editor); static gboolean exo_die_editor_match_selected (GtkEntryCompletion *completion, @@ -82,6 +85,7 @@ struct _ExoDieEditor gchar *name; gchar *comment; gchar *command; + gchar *path; gchar *url; gchar *icon; guint snotify : 1; @@ -171,6 +175,20 @@ exo_die_editor_class_init (ExoDieEditorClass *klass) EXO_PARAM_READWRITE)); /** + * ExoDieEditor:path: + * + * The working directory of the desktop item edited by this editor, only + * valid if the mode is %EXO_DIE_EDITOR_MODE_APPLICATION. + **/ + g_object_class_install_property (gobject_class, + PROP_PATH, + g_param_spec_string ("path", + "path", + "path", + NULL, + EXO_PARAM_READWRITE)); + + /** * ExoDieEditor:url: * * The URL of the desktop item edited by this editor, only valid @@ -257,6 +275,8 @@ exo_die_editor_init (ExoDieEditor *editor) GtkWidget *align; GtkWidget *entry; GtkWidget *label; + GtkWidget *image; + GtkWidget *box; gint row; /* start with sane defaults */ @@ -268,7 +288,7 @@ exo_die_editor_init (ExoDieEditor *editor) editor->url = g_strdup (""); /* configure the table */ - gtk_table_resize (GTK_TABLE (editor), 8, 2); + gtk_table_resize (GTK_TABLE (editor), 9, 2); gtk_table_set_col_spacings (GTK_TABLE (editor), 12); gtk_table_set_row_spacings (GTK_TABLE (editor), 0); @@ -321,6 +341,37 @@ exo_die_editor_init (ExoDieEditor *editor) row += 1; + /* TRANSLATORS: Label in "reate Launcher" dialog, make sure to avoid mnemonic conflicts */ + label = gtk_label_new_with_mnemonic (_("_Working direcory:")); + gtk_label_set_use_markup (GTK_LABEL (label), TRUE); + gtk_misc_set_alignment (GTK_MISC (label), 1.0f, 0.5f); + exo_binding_new_full (G_OBJECT (editor), "mode", G_OBJECT (label), "visible", exo_die_true_if_application, NULL, NULL); + gtk_table_attach (GTK_TABLE (editor), label, 0, 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 3); + + /* setup the box */ + box = gtk_hbox_new (FALSE, 6); + + entry = gtk_entry_new (); + gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE); + exo_mutual_binding_new (G_OBJECT (entry), "text", G_OBJECT (editor), "path"); + gtk_box_pack_start (GTK_BOX (box), entry, TRUE, TRUE, 0); + gtk_widget_show (entry); + + button = gtk_button_new (); + g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (exo_die_editor_path_clicked), editor); + gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0); + gtk_widget_show (button); + + image = gtk_image_new_from_stock (GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU); + gtk_container_add (GTK_CONTAINER (button), image); + gtk_widget_show (image); + + exo_binding_new_full (G_OBJECT (editor), "mode", G_OBJECT (box), "visible", exo_die_true_if_application, NULL, NULL); + gtk_table_attach (GTK_TABLE (editor), box, 1, 2, row, row + 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 3); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry); + + row += 1; + /* TRANSLATORS: Label in "Create Link" dialog, make sure to avoid mnemonic conflicts */ label = gtk_label_new_with_mnemonic (_("_URL:")); gtk_label_set_use_markup (GTK_LABEL (label), TRUE); @@ -400,6 +451,7 @@ exo_die_editor_finalize (GObject *object) /* cleanup */ g_free (editor->command); g_free (editor->comment); + g_free (editor->path); g_free (editor->icon); g_free (editor->name); g_free (editor->url); @@ -439,6 +491,10 @@ exo_die_editor_get_property (GObject *object, g_value_set_string (value, exo_die_editor_get_command (editor)); break; + case PROP_PATH: + g_value_set_string (value, exo_die_editor_get_path (editor)); + break; + case PROP_URL: g_value_set_string (value, exo_die_editor_get_url (editor)); break; @@ -489,6 +545,10 @@ exo_die_editor_set_property (GObject *object, exo_die_editor_set_command (editor, g_value_get_string (value)); break; + case PROP_PATH: + exo_die_editor_set_path (editor, g_value_get_string (value)); + break; + case PROP_URL: exo_die_editor_set_url (editor, g_value_get_string (value)); break; @@ -514,6 +574,54 @@ exo_die_editor_set_property (GObject *object, static void +exo_die_editor_path_clicked (GtkWidget *button, + ExoDieEditor *editor) +{ + GtkWidget *toplevel; + GtkWidget *chooser; + gchar *path; + + g_return_if_fail (GTK_IS_BUTTON (button)); + g_return_if_fail (EXO_DIE_IS_EDITOR (editor)); + + /* determine the toplevel widget */ + toplevel = gtk_widget_get_toplevel (button); + if (toplevel == NULL || !GTK_WIDGET_TOPLEVEL (toplevel)) + return; + + /* allocate the folder chooser dialog */ + chooser = gtk_file_chooser_dialog_new (_("Select working directory"), + GTK_WINDOW (toplevel), + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL); + gtk_dialog_set_default_response (GTK_DIALOG (chooser), GTK_RESPONSE_ACCEPT); + gtk_dialog_set_alternative_button_order (GTK_DIALOG (chooser), + GTK_RESPONSE_ACCEPT, + GTK_RESPONSE_CANCEL, + -1); + + /* check if we have an icon to set for the chooser */ + if (G_LIKELY (!exo_str_is_empty (editor->path))) + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (chooser), editor->path); + + /* run the chooser dialog */ + if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT) + { + /* remember the selected icon from the chooser */ + path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); + exo_die_editor_set_path (editor, path); + g_free (path); + } + + /* destroy the chooser */ + gtk_widget_destroy (chooser); +} + + + +static void exo_die_editor_icon_clicked (GtkWidget *button, ExoDieEditor *editor) { @@ -571,6 +679,7 @@ exo_die_editor_match_selected (GtkEntryCompletion *completion, gboolean snotify; gchar *comment; gchar *command; + gchar *path; gchar *icon; gchar *name; @@ -582,6 +691,7 @@ exo_die_editor_match_selected (GtkEntryCompletion *completion, gtk_tree_model_get (model, iter, EXO_DIE_DESKTOP_MODEL_COLUMN_COMMENT, &comment, EXO_DIE_DESKTOP_MODEL_COLUMN_COMMAND, &command, + EXO_DIE_DESKTOP_MODEL_COLUMN_PATH, &path, EXO_DIE_DESKTOP_MODEL_COLUMN_ICON, &icon, EXO_DIE_DESKTOP_MODEL_COLUMN_NAME, &name, EXO_DIE_DESKTOP_MODEL_COLUMN_SNOTIFY, &snotify, @@ -592,6 +702,7 @@ exo_die_editor_match_selected (GtkEntryCompletion *completion, exo_die_editor_set_name (editor, name); exo_die_editor_set_comment (editor, (comment != NULL) ? comment : ""); exo_die_editor_set_command (editor, command); + exo_die_editor_set_path (editor, path); exo_die_editor_set_icon (editor, (icon != NULL) ? icon : ""); exo_die_editor_set_snotify (editor, snotify); exo_die_editor_set_terminal (editor, terminal); @@ -599,6 +710,7 @@ exo_die_editor_match_selected (GtkEntryCompletion *completion, /* cleanup */ g_free (comment); g_free (command); + g_free (path); g_free (icon); g_free (name); @@ -937,6 +1049,51 @@ exo_die_editor_set_command (ExoDieEditor *editor, /** + * exo_die_editor_get_path: + * @editor : an #ExoDieEditor. + * + * Returns the path for @editor. + * + * Return value: the path for @editor. + **/ +const gchar* +exo_die_editor_get_path (ExoDieEditor *editor) +{ + g_return_val_if_fail (EXO_DIE_IS_EDITOR (editor), NULL); + return editor->path; +} + + + +/** + * exo_die_editor_set_path: + * @editor : an #ExoDieEditor. + * @comment : the new path for @editor. + * + * Sets the path for @editor to @path. + **/ +void +exo_die_editor_set_path (ExoDieEditor *editor, + const gchar *path) +{ + g_return_if_fail (EXO_DIE_IS_EDITOR (editor)); + g_return_if_fail (g_utf8_validate (path, -1, NULL)); + + /* check if we have a new path here */ + if (!exo_str_is_equal (editor->path, path)) + { + /* apply the new comment */ + g_free (editor->path); + editor->path = g_strdup (path); + + /* notify listeners */ + g_object_notify (G_OBJECT (editor), "path"); + } +} + + + +/** * exo_die_editor_get_url: * @editor : an #ExoDieEditor. * diff --git a/exo-desktop-item-edit/exo-die-editor.h b/exo-desktop-item-edit/exo-die-editor.h index 778474c..3adff42 100644 --- a/exo-desktop-item-edit/exo-die-editor.h +++ b/exo-desktop-item-edit/exo-die-editor.h @@ -61,6 +61,10 @@ const gchar *exo_die_editor_get_url (ExoDieEditor *editor); void exo_die_editor_set_url (ExoDieEditor *editor, const gchar *url); +const gchar *exo_die_editor_get_path (ExoDieEditor *editor); +void exo_die_editor_set_path (ExoDieEditor *editor, + const gchar *path); + const gchar *exo_die_editor_get_icon (ExoDieEditor *editor); void exo_die_editor_set_icon (ExoDieEditor *editor, const gchar *icon); diff --git a/exo-desktop-item-edit/main.c b/exo-desktop-item-edit/main.c index 8183210..c5099dd 100644 --- a/exo-desktop-item-edit/main.c +++ b/exo-desktop-item-edit/main.c @@ -64,6 +64,7 @@ static gchar *opt_type = NULL; static gchar *opt_name = NULL; static gchar *opt_comment = NULL; static gchar *opt_command = NULL; +static gchar *opt_path = NULL; static gchar *opt_url = NULL; static gchar *opt_icon = NULL; static gint opt_xid = 0; @@ -78,6 +79,7 @@ static GOptionEntry option_entries[] = { "name", 0, 0, G_OPTION_ARG_STRING, &opt_name, N_ ("Preset name when creating a desktop file"), NULL, }, { "comment", 0, 0, G_OPTION_ARG_STRING, &opt_comment, N_ ("Preset comment when creating a desktop file"), NULL, }, { "command", 0, 0, G_OPTION_ARG_STRING, &opt_command, N_ ("Preset command when creating a launcher"), NULL, }, + { "path", 0, 0, G_OPTION_ARG_STRING, &opt_path, N_ ("Preset working directory when creating a desktop file"), NULL, }, { "url", 0, 0, G_OPTION_ARG_STRING, &opt_url, N_ ("Preset URL when creating a link"), NULL, }, { "icon", 0, 0, G_OPTION_ARG_STRING, &opt_icon, N_ ("Preset icon when creating a desktop file"), NULL, }, { "version", 'V', 0, G_OPTION_ARG_NONE, &opt_version, N_ ("Print version information and exit"), NULL, }, @@ -202,6 +204,8 @@ main (int argc, char **argv) g_key_file_set_value (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, STR_FB (opt_command, "")); g_key_file_set_value (key_file, G_KEY_FILE_DESKTOP_GROUP, + G_KEY_FILE_DESKTOP_KEY_PATH, STR_FB (opt_path, "")); + g_key_file_set_value (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, STR_FB (opt_icon, "")); } } @@ -319,6 +323,12 @@ main (int argc, char **argv) exo_die_editor_set_command (EXO_DIE_EDITOR (editor), (value != NULL) ? value : ""); g_free (value); + /* setup the path */ + value = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, + G_KEY_FILE_DESKTOP_KEY_PATH, NULL); + exo_die_editor_set_path (EXO_DIE_EDITOR (editor), (value != NULL) ? value : ""); + g_free (value); + /* setup launcher options */ exo_die_editor_set_snotify (EXO_DIE_EDITOR (editor), g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, @@ -381,6 +391,9 @@ main (int argc, char **argv) g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, exo_die_editor_get_command (EXO_DIE_EDITOR (editor))); + g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP, + G_KEY_FILE_DESKTOP_KEY_PATH, + exo_die_editor_get_path (EXO_DIE_EDITOR (editor))); /* save the new launcher options */ g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, -- 1.6.4.4