From ac9bf87fc04717ec025749dfe2442ebcb17ca720 Mon Sep 17 00:00:00 2001 From: Stephen Watson Date: Sat, 11 Sep 2004 12:38:46 +0000 Subject: [PATCH] r3660: Panel and pinboard icons can now have a single argument set for them. --- ROX-Filer/Help/Changes | 6 ++++++ ROX-Filer/src/icon.c | 40 ++++++++++++++++++++++++++++++++++++---- ROX-Filer/src/icon.h | 2 ++ ROX-Filer/src/panel.c | 29 +++++++++++++++++++---------- ROX-Filer/src/pinboard.c | 22 +++++++++++++++++----- ROX-Filer/src/pinboard.h | 2 ++ ROX-Filer/src/run.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- ROX-Filer/src/run.h | 7 +++++++ 8 files changed, 132 insertions(+), 22 deletions(-) diff --git a/ROX-Filer/Help/Changes b/ROX-Filer/Help/Changes index 18b84ef2..97a3c56c 100644 --- a/ROX-Filer/Help/Changes +++ b/ROX-Filer/Help/Changes @@ -2,6 +2,12 @@ A RISC OS-like filer for X by Thomas Leonard +11-Sep-2004 +~~~~~~~~~~~ +Panel and pinboard icons can now have a single argument set for them. +If you need more than one argument, consider creating a wrapper +(Stephen Watson). + 09-Sep-2004 ~~~~~~~~~~~ Added --massif option for profiling memory usage (Thomas Leonard). diff --git a/ROX-Filer/src/icon.c b/ROX-Filer/src/icon.c index c2df3222..fb2ec162 100644 --- a/ROX-Filer/src/icon.c +++ b/ROX-Filer/src/icon.c @@ -440,6 +440,21 @@ void icon_set_shortcut(Icon *icon, const gchar *shortcut) grab_key(icon); } +void icon_set_argument(Icon *icon, const gchar *arg) +{ + g_return_if_fail(icon != NULL); + + if (arg && !*arg) + arg = NULL; + if (icon->arg == arg) + return; + if (icon->arg && arg && strcmp(icon->arg, arg) == 0) + return; + + g_free(icon->arg); + icon->arg = g_strdup(arg); +} + /**************************************************************** * INTERNAL FUNCTIONS * ****************************************************************/ @@ -484,25 +499,28 @@ static void icon_unhash_path(Icon *icon) static void rename_activate(GtkWidget *dialog) { - GtkWidget *entry, *src, *shortcut; + GtkWidget *entry, *src, *shortcut, *arg; Icon *icon; - const guchar *new_name, *new_src, *new_shortcut; + const guchar *new_name, *new_src, *new_shortcut, *new_arg; entry = g_object_get_data(G_OBJECT(dialog), "new_name"); icon = g_object_get_data(G_OBJECT(dialog), "callback_icon"); src = g_object_get_data(G_OBJECT(dialog), "new_path"); shortcut = g_object_get_data(G_OBJECT(dialog), "new_shortcut"); + arg = g_object_get_data(G_OBJECT(dialog), "new_arg"); g_return_if_fail(entry != NULL && src != NULL && icon != NULL && - shortcut != NULL); + shortcut != NULL && + arg != NULL); new_name = gtk_entry_get_text(GTK_ENTRY(entry)); new_src = gtk_entry_get_text(GTK_ENTRY(src)); new_shortcut = gtk_label_get_text(GTK_LABEL(shortcut)); if (strcmp(new_shortcut, CLICK_TO_SET) == 0) new_shortcut = NULL; + new_arg = gtk_entry_get_text(GTK_ENTRY(arg)); if (*new_src == '\0') report_error( @@ -511,6 +529,7 @@ static void rename_activate(GtkWidget *dialog) { icon_set_path(icon, new_src, new_name); icon_set_shortcut(icon, new_shortcut); + icon_set_argument(icon, new_arg); g_signal_emit_by_name(icon, "update"); gtk_widget_destroy(dialog); } @@ -784,6 +803,16 @@ static void show_rename_box(Icon *icon) g_signal_connect_swapped(entry, "activate", G_CALLBACK(rename_activate), dialog); + label = gtk_label_new(_("Argument to pass (for executables):")); + gtk_box_pack_start(vbox, label, TRUE, TRUE, 0); + + entry = gtk_entry_new(); + gtk_box_pack_start(vbox, entry, TRUE, FALSE, 2); + gtk_entry_set_text(GTK_ENTRY(entry), icon->arg? icon->arg: ""); + g_object_set_data(G_OBJECT(dialog), "new_arg", entry); + g_signal_connect_swapped(entry, "activate", + G_CALLBACK(rename_activate), dialog); + spacer = gtk_drawing_area_new(); gtk_widget_set_size_request(spacer, 4, 4); gtk_box_pack_start(vbox, spacer, FALSE, FALSE, 0); @@ -850,6 +879,7 @@ static void icon_finialize(GObject *object) icon_set_path(icon, NULL, NULL); icon_set_shortcut(icon, NULL); + icon_set_argument(icon, NULL); G_OBJECT_CLASS(parent_class)->finalize(object); } @@ -907,6 +937,7 @@ static void icon_init(GTypeInstance *object, gpointer gclass) icon->shortcut = NULL; icon->shortcut_key.keycode = 0; icon->shortcut_key.modifier = 0; + icon->arg = NULL; } /* As icon_set_selected(), but doesn't automatically unselect incompatible @@ -1141,7 +1172,8 @@ static GdkFilterReturn filter_keys(GdkXEvent *xevent, icon->shortcut_key.modifier == state) { icon_wink(icon); - run_diritem(icon->path, icon->item, NULL, NULL, FALSE); + run_diritem_with_arg(icon->path, icon->item, icon->arg, + NULL, NULL, FALSE); } } diff --git a/ROX-Filer/src/icon.h b/ROX-Filer/src/icon.h index 2af17674..436cb0e1 100644 --- a/ROX-Filer/src/icon.h +++ b/ROX-Filer/src/icon.h @@ -41,6 +41,7 @@ struct _Icon { DirItem *item; gchar *shortcut; /* Eg: Control + x */ MyKey shortcut_key; /* Parsed version of shortcut */ + gchar *arg; /* Arg to pass for apps and executables*/ GtkWidget *dialog; /* Current rename box, if any */ }; @@ -56,5 +57,6 @@ void icon_set_path(Icon *icon, const char *pathname, const char *name); gchar *icon_create_uri_list(void); void icon_destroy(Icon *icon); void icon_set_shortcut(Icon *icon, const gchar *shortcut); +void icon_set_argument(Icon *icon, const gchar *arg); #endif /* _ICON_H */ diff --git a/ROX-Filer/src/panel.c b/ROX-Filer/src/panel.c index aa512cd7..db964428 100644 --- a/ROX-Filer/src/panel.c +++ b/ROX-Filer/src/panel.c @@ -132,7 +132,8 @@ static void panel_add_item(Panel *panel, const gchar *path, const gchar *name, gboolean after, - const gchar *shortcut); + const gchar *shortcut, + const gchar *arg); static gboolean panel_drag_motion(GtkWidget *widget, GdkDragContext *context, gint x, @@ -385,12 +386,12 @@ Panel *panel_new(const gchar *name, PanelSide side) /* Don't scare users with an empty panel... */ guchar *apps; - panel_add_item(panel, "~", "Home", FALSE, NULL); + panel_add_item(panel, "~", "Home", FALSE, NULL, NULL); apps = pathdup(make_path(app_dir, "..")); if (apps) { - panel_add_item(panel, apps, "Apps", FALSE, NULL); + panel_add_item(panel, apps, "Apps", FALSE, NULL, NULL); g_free(apps); } } @@ -430,7 +431,7 @@ gboolean panel_add(PanelSide side, g_return_val_if_fail(current_panel[side] != NULL, FALSE); - panel_add_item(current_panel[side], path, label, after, NULL); + panel_add_item(current_panel[side], path, label, after, NULL, NULL); return TRUE; } @@ -509,7 +510,7 @@ static void panel_destroyed(GtkWidget *widget, Panel *panel) static void panel_load_side(Panel *panel, xmlNodePtr side, gboolean after) { xmlNodePtr node; - char *label, *path, *shortcut; + char *label, *path, *shortcut, *arg; for (node = side->xmlChildrenNode; node; node = node->next) { @@ -525,12 +526,14 @@ static void panel_load_side(Panel *panel, xmlNodePtr side, gboolean after) if (!path) path = g_strdup(""); shortcut = xmlGetProp(node, "shortcut"); + arg = xmlGetProp(node, "arg"); - panel_add_item(panel, path, label, after, shortcut); + panel_add_item(panel, path, label, after, shortcut, arg); g_free(path); g_free(label); g_free(shortcut); + g_free(arg); } } @@ -564,7 +567,8 @@ static const char *pan_from_file(gchar *line) else leaf = NULL; - panel_add_item(loading_panel, sep + 1, leaf, sep[0] == '>', NULL); + panel_add_item(loading_panel, sep + 1, leaf, sep[0] == '>', + NULL, NULL); g_free(leaf); @@ -654,7 +658,8 @@ static void panel_add_item(Panel *panel, const gchar *path, const gchar *name, gboolean after, - const gchar *shortcut) + const gchar *shortcut, + const gchar *arg) { GtkWidget *widget; PanelIcon *pi; @@ -726,6 +731,7 @@ static void panel_add_item(Panel *panel, } icon_set_shortcut(icon, shortcut); + icon_set_argument(icon, arg); if (!loading_panel) panel_save(panel); @@ -882,7 +888,8 @@ static void perform_action(Panel *panel, PanelIcon *pi, GdkEventButton *event) case ACT_OPEN_ITEM: dnd_motion_ungrab(); wink_widget(pi->widget); - run_diritem(icon->path, icon->item, NULL, NULL, FALSE); + run_diritem_with_arg(icon->path, icon->item, icon->arg, + NULL, NULL, FALSE); break; case ACT_EDIT_ITEM: dnd_motion_ungrab(); @@ -1261,7 +1268,7 @@ static void add_uri_list(GtkWidget *widget, path = get_local_path((guchar *) next->data); if (path) { - panel_add_item(panel, path, NULL, after, NULL); + panel_add_item(panel, path, NULL, after, NULL, NULL); g_free(path); } } @@ -1321,6 +1328,8 @@ static void make_widgets(xmlNodePtr side, GList *widgets) xmlSetProp(tree, "label", icon->item->leafname); if (icon->shortcut) xmlSetProp(tree, "shortcut", icon->shortcut); + if (icon->arg) + xmlSetProp(tree, "arg", icon->arg); } if (widgets) diff --git a/ROX-Filer/src/pinboard.c b/ROX-Filer/src/pinboard.c index 1f938b54..58d3da77 100644 --- a/ROX-Filer/src/pinboard.c +++ b/ROX-Filer/src/pinboard.c @@ -445,8 +445,8 @@ void pinboard_moved_widget(GtkWidget *widget, const gchar *name, * 'x' and 'y' are the coordinates of the point in the middle of the text. * 'name' is the name to use. If NULL then the leafname of path is used. */ -void pinboard_pin(const gchar *path, const gchar *name, int x, int y, - const gchar *shortcut) +void pinboard_pin_with_arg(const gchar *path, const gchar *name, int x, int y, + const gchar *shortcut, const gchar *arg) { GtkWidget *align, *vbox; GdkWindow *events; @@ -532,11 +532,18 @@ void pinboard_pin(const gchar *path, const gchar *name, int x, int y, pin_icon_set_tip(pi); icon_set_shortcut(icon, shortcut); + icon_set_argument(icon, arg); if (!loading_pinboard) pinboard_save(); } +void pinboard_pin(const gchar *path, const gchar *name, int x, int y, + const gchar *shortcut) +{ + pinboard_pin_with_arg(path, name, x, y, shortcut, NULL); +} + /* Put a border around the icon, briefly. * If icon is NULL then cancel any existing wink. * The icon will automatically unhighlight unless timeout is FALSE, @@ -1153,7 +1160,8 @@ static void perform_action(PinIcon *pi, GdkEventButton *event) pinboard_wink_item(pi, TRUE); if (event->type == GDK_2BUTTON_PRESS) icon_set_selected(icon, FALSE); - run_diritem(icon->path, icon->item, NULL, NULL, FALSE); + run_diritem_with_arg(icon->path, icon->item, + icon->arg, NULL, NULL, FALSE); break; case ACT_EDIT_ITEM: dnd_motion_ungrab(); @@ -1358,7 +1366,7 @@ static void backdrop_from_xml(xmlNode *node) static void pinboard_load_from_xml(xmlDocPtr doc) { xmlNodePtr node, root; - char *tmp, *label, *path, *shortcut; + char *tmp, *label, *path, *shortcut, *arg; int x, y; root = xmlDocGetRootElement(doc); @@ -1394,12 +1402,14 @@ static void pinboard_load_from_xml(xmlDocPtr doc) if (!path) path = g_strdup(""); shortcut = xmlGetProp(node, "shortcut"); + arg = xmlGetProp(node, "arg"); - pinboard_pin(path, label, x, y, shortcut); + pinboard_pin_with_arg(path, label, x, y, shortcut, arg); g_free(path); g_free(label); g_free(shortcut); + g_free(arg); } } @@ -1505,6 +1515,8 @@ static void pinboard_save(void) xmlSetProp(tree, "label", icon->item->leafname); if (icon->shortcut) xmlSetProp(tree, "shortcut", icon->shortcut); + if (icon->arg) + xmlSetProp(tree, "arg", icon->arg); } save_new = g_strconcat(save, ".new", NULL); diff --git a/ROX-Filer/src/pinboard.h b/ROX-Filer/src/pinboard.h index 176f912d..c0f419b6 100644 --- a/ROX-Filer/src/pinboard.h +++ b/ROX-Filer/src/pinboard.h @@ -23,6 +23,8 @@ void pinboard_init(void); void pinboard_activate(const gchar *name); void pinboard_pin(const gchar *path, const gchar *name, int x, int y, const gchar *shortcut); +void pinboard_pin_with_arg(const gchar *path, const gchar *name, int x, int y, + const gchar *shortcut, const char *arg); void pinboard_move_icons(void); const gchar *pinboard_get_name(void); void pinboard_set_backdrop_box(void); diff --git a/ROX-Filer/src/run.c b/ROX-Filer/src/run.c index a5136c88..fc7e46b9 100644 --- a/ROX-Filer/src/run.c +++ b/ROX-Filer/src/run.c @@ -81,6 +81,20 @@ void run_app(const char *path) g_string_free(apprun, TRUE); } +void run_app_with_arg(const char *path, const char *arg) +{ + GString *apprun; + const char *argv[] = {NULL, NULL, NULL}; + + apprun = g_string_new(path); + argv[0] = g_string_append(apprun, "/AppRun")->str; + argv[1] = arg; + + rox_spawn(home_dir, argv); + + g_string_free(apprun, TRUE); +} + /* Execute this program, passing all the URIs in the list as arguments. * URIs that are files on the local machine will be passed as simple * pathnames. The uri_list should be freed after this function returns. @@ -194,14 +208,17 @@ void run_with_data(const char *path, gpointer data, gulong length) /* Load a file, open a directory or run an application. Or, if 'edit' is set: * edit a file, open an application, follow a symlink or mount a device. * + * arg is a string to append to the command when running apps or executables, + * or NULL. Ignored for non-executables * filer_window is the window to use for displaying a directory. * NULL will always use a new directory when needed. * src_window is the window to copy options from, or NULL. * * Returns TRUE on success. */ -gboolean run_diritem(const guchar *full_path, +gboolean run_diritem_with_arg(const guchar *full_path, DirItem *item, + const gchar *arg, FilerWindow *filer_window, FilerWindow *src_window, gboolean edit) @@ -214,7 +231,10 @@ gboolean run_diritem(const guchar *full_path, case TYPE_DIRECTORY: if (item->flags & ITEM_FLAG_APPDIR && !edit) { - run_app(full_path); + if(arg) + run_app_with_arg(full_path, arg); + else + run_app(full_path); return TRUE; } @@ -231,12 +251,13 @@ gboolean run_diritem(const guchar *full_path, case TYPE_FILE: if (item->mime_type == application_executable && !edit) { - const char *argv[] = {NULL, NULL}; + const char *argv[] = {NULL, NULL, NULL}; guchar *dir = filer_window ? filer_window->sym_path : NULL; argv[0] = full_path; + argv[1] = arg; return rox_spawn(dir, argv) != 0; } @@ -254,6 +275,25 @@ gboolean run_diritem(const guchar *full_path, } } +/* Load a file, open a directory or run an application. Or, if 'edit' is set: + * edit a file, open an application, follow a symlink or mount a device. + * + * filer_window is the window to use for displaying a directory. + * NULL will always use a new directory when needed. + * src_window is the window to copy options from, or NULL. + * + * Returns TRUE on success. + */ +gboolean run_diritem(const guchar *full_path, + DirItem *item, + FilerWindow *filer_window, + FilerWindow *src_window, + gboolean edit) +{ + run_diritem_with_arg(full_path, item, NULL, filer_window, + src_window, edit); +} + /* Attempt to open this item */ gboolean run_by_path(const guchar *full_path) { diff --git a/ROX-Filer/src/run.h b/ROX-Filer/src/run.h index ef6d8d0e..78475a53 100644 --- a/ROX-Filer/src/run.h +++ b/ROX-Filer/src/run.h @@ -9,6 +9,7 @@ #include void run_app(const char *path); +void run_app_with_arg(const char *path, const char *arg); void run_with_files(const char *path, GList *uri_list); void run_with_data(const char *path, gpointer data, gulong length); gboolean run_by_path(const guchar *full_path); @@ -17,6 +18,12 @@ gboolean run_diritem(const guchar *full_path, FilerWindow *filer_window, FilerWindow *src_window, gboolean edit); +gboolean run_diritem_with_arg(const guchar *full_path, + DirItem *item, + const gchar *arg, + FilerWindow *filer_window, + FilerWindow *src_window, + gboolean edit); void open_to_show(const guchar *path); void examine(const guchar *path); void show_help_files(const char *dir); -- 2.11.4.GIT