From f1eb85cacfbf6bf0f6730e4db9fe294a0f41c827 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 14 May 2002 18:37:25 +0000 Subject: [PATCH] r1473: Put all the backdrop settings in a dialog from the pinboard menu. --- ROX-Filer/src/icon.c | 24 +++---- ROX-Filer/src/icon.h | 3 +- ROX-Filer/src/menu.c | 10 +-- ROX-Filer/src/panel.c | 2 +- ROX-Filer/src/pinboard.c | 182 +++++++++++++++++++++++++++++++++++++---------- ROX-Filer/src/pinboard.h | 2 +- ROX-Filer/src/type.c | 2 +- 7 files changed, 159 insertions(+), 66 deletions(-) diff --git a/ROX-Filer/src/icon.c b/ROX-Filer/src/icon.c index 35697b4a..e9a3a6da 100644 --- a/ROX-Filer/src/icon.c +++ b/ROX-Filer/src/icon.c @@ -57,7 +57,7 @@ static gboolean have_primary = FALSE; /* We own the PRIMARY selection? */ GtkWidget *icon_menu; /* The popup icon menu */ -GtkWidget *icon_menu_remove_backdrop; +static GtkWidget *icon_menu_set_backdrop; static GtkWidget *icon_file_menu; /* The file submenu */ static GtkWidget *icon_file_item; /* 'File' label */ static GtkWidget *file_shift_item; /* 'Shift Open' label */ @@ -84,7 +84,7 @@ static void selection_get(GtkClipboard *primary, guint info, gpointer data); static void remove_items(gpointer data, guint action, GtkWidget *widget); -static void remove_backdrop(gpointer data, guint action, GtkWidget *widget); +static void set_backdrop(gpointer data, guint action, GtkWidget *widget); static void file_op(gpointer data, guint action, GtkWidget *widget); static void show_rename_box(Icon *icon); static void icon_set_selected_int(Icon *icon, gboolean selected); @@ -99,7 +99,6 @@ enum { ACTION_INFO, ACTION_RUN_ACTION, ACTION_SET_ICON, - ACTION_BACKDROP, ACTION_EDIT, ACTION_LOCATION, }; @@ -117,11 +116,10 @@ static GtkItemFactoryEntry menu_def[] = { {">" N_("Info"), NULL, file_op, ACTION_INFO, NULL}, {">" N_("Set Run Action..."), NULL, file_op, ACTION_RUN_ACTION, NULL}, {">" N_("Set Icon..."), NULL, file_op, ACTION_SET_ICON, NULL}, -{">" N_("Use for Backdrop"), NULL, file_op, ACTION_BACKDROP, NULL}, {N_("Edit Item"), NULL, file_op, ACTION_EDIT, NULL}, {N_("Show Location"), NULL, file_op, ACTION_LOCATION, NULL}, {N_("Remove Item(s)"), NULL, remove_items, 0, NULL}, -{N_("Remove Backdrop"), NULL, remove_backdrop, 0, NULL}, +{N_("Backdrop..."), NULL, set_backdrop, 0, NULL}, }; /**************************************************************** @@ -207,13 +205,16 @@ gboolean icons_require(const gchar *path) * add app menu stuff, etc). * You should show icon_menu after calling this... */ -void icon_prepare_menu(Icon *icon) +void icon_prepare_menu(Icon *icon, gboolean pinboard) { appmenu_remove(); menu_icon = icon; - gtk_widget_hide(icon_menu_remove_backdrop); + if (pinboard) + gtk_widget_show(icon_menu_set_backdrop); + else + gtk_widget_hide(icon_menu_set_backdrop); /* Shade Remove Item(s) unless there is a selection */ menu_set_items_shaded(icon_menu, @@ -507,9 +508,9 @@ static void selection_get(GtkClipboard *primary, 8, text, strlen(text)); } -static void remove_backdrop(gpointer data, guint action, GtkWidget *widget) +static void set_backdrop(gpointer data, guint action, GtkWidget *widget) { - pinboard_set_backdrop(NULL, NULL); + pinboard_set_backdrop(); } static void remove_items(gpointer data, guint action, GtkWidget *widget) @@ -571,9 +572,6 @@ static void file_op(gpointer data, guint action, GtkWidget *widget) icon_set_handler_dialog(menu_icon->item, menu_icon->path); break; - case ACTION_BACKDROP: - pinboard_set_backdrop(menu_icon->item, menu_icon->path); - break; } } @@ -727,7 +725,7 @@ static void icon_class_init(gpointer gclass, gpointer data) g_list_free(items); items = gtk_container_get_children(GTK_CONTAINER(icon_menu)); - icon_menu_remove_backdrop = g_list_nth(items, 5)->data; + icon_menu_set_backdrop = g_list_nth(items, 5)->data; g_list_free(items); g_signal_connect(icon_menu, "unmap_event", diff --git a/ROX-Filer/src/icon.h b/ROX-Filer/src/icon.h index b5fb9f4f..8f31600e 100644 --- a/ROX-Filer/src/icon.h +++ b/ROX-Filer/src/icon.h @@ -12,7 +12,6 @@ extern GList *icon_selection; extern GtkWidget *icon_menu; /* The popup icon menu */ -extern GtkWidget *icon_menu_remove_backdrop; /* 'Remove Backdrop' menu item */ typedef struct _IconClass IconClass; @@ -43,7 +42,7 @@ GType icon_get_type(void); gboolean icons_require(const gchar *path); void icon_may_update(Icon *icon); void icons_may_update(const gchar *path); -void icon_prepare_menu(Icon *icon); +void icon_prepare_menu(Icon *icon, gboolean pinboard); void icon_set_selected(Icon *icon, gboolean selected); void icon_select_only(Icon *select); void icon_set_path(Icon *icon, const char *pathname, const char *name); diff --git a/ROX-Filer/src/menu.c b/ROX-Filer/src/menu.c index 9c992451..1370be36 100644 --- a/ROX-Filer/src/menu.c +++ b/ROX-Filer/src/menu.c @@ -69,7 +69,6 @@ typedef enum { FILE_SHOW_FILE_INFO, FILE_RUN_ACTION, FILE_SET_ICON, - FILE_BACKDROP, FILE_SEND_TO, FILE_DELETE, FILE_USAGE, @@ -213,7 +212,6 @@ static GtkItemFactoryEntry filer_menu_def[] = { {">" N_("Info"), NULL, file_op, FILE_SHOW_FILE_INFO, NULL}, {">" N_("Set Run Action..."), NULL, file_op, FILE_RUN_ACTION, NULL}, {">" N_("Set Icon..."), NULL, file_op, FILE_SET_ICON, NULL}, -{">" N_("Use for Backdrop"), NULL, file_op, FILE_BACKDROP, NULL}, {">" N_("Open AVFS"), NULL, file_op, FILE_OPEN_VFS_AVFS, NULL}, {">", NULL, NULL, 0, ""}, {">" N_("Send To..."), NULL, file_op, FILE_SEND_TO, NULL}, @@ -366,7 +364,7 @@ void menuitem_no_shortcuts(GtkWidget *item) static void items_sensitive(gboolean state) { - int n = 10; + int n = 9; GList *items, *item; items = gtk_container_get_children(GTK_CONTAINER(filer_file_menu)); @@ -1754,9 +1752,6 @@ static void file_op(gpointer data, FileOp action, GtkWidget *widget) case FILE_SET_ICON: prompt = _("Set icon for ... ?"); break; - case FILE_BACKDROP: - prompt = _("Use ... for backdrop ?"); - break; case FILE_SEND_TO: prompt = _("Send ... to ... ?"); break; @@ -1859,9 +1854,6 @@ static void file_op(gpointer data, FileOp action, GtkWidget *widget) case FILE_SET_ICON: icon_set_handler_dialog(item, path); break; - case FILE_BACKDROP: - pinboard_set_backdrop(item, path); - break; case FILE_OPEN_VFS_AVFS: open_vfs_avfs(window_with_focus, item); break; diff --git a/ROX-Filer/src/panel.c b/ROX-Filer/src/panel.c index 1f056008..11643534 100644 --- a/ROX-Filer/src/panel.c +++ b/ROX-Filer/src/panel.c @@ -1711,7 +1711,7 @@ static void panel_show_menu(GdkEventButton *event, PanelIcon *pi, Panel *panel) pos[1] = event->y_root; pos[2] = 1; - icon_prepare_menu((Icon *) pi); + icon_prepare_menu((Icon *) pi, FALSE); if (side == PANEL_LEFT) pos[0] = -2; diff --git a/ROX-Filer/src/pinboard.c b/ROX-Filer/src/pinboard.c index 0e8a200a..c0f4d5e5 100644 --- a/ROX-Filer/src/pinboard.c +++ b/ROX-Filer/src/pinboard.c @@ -192,6 +192,15 @@ static void set_backdrop(const gchar *path, BackdropStyle style); void pinboard_reshape_icon(Icon *icon); static gint draw_wink(GtkWidget *widget, GdkEventExpose *event, PinIcon *pi); static void abandon_backdrop_app(Pinboard *pinboard); +static void drag_backdrop_dropped(GtkWidget *frame, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection_data, + guint drag_info, + guint32 time, + GtkWidget *dialog); +static void backdrop_response(GtkWidget *dialog, gint response, gpointer data); /**************************************************************** @@ -508,62 +517,160 @@ void pinboard_set_backdrop_app(const gchar *app) if (can_set) set_backdrop(app, BACKDROP_PROGRAM); else - delayed_error(_("This program does not know how to " - "manage ROX-Filer's backdrop image.")); + delayed_error(_("You can only set the backdrop to an image " + "or to a program which knows how to " + "manage ROX-Filer's backdrop.")); } -/* Use this icon / program as the backdrop for the current pinboard. - * NULL removes the backdrop. If type is BACKDROP_NONE then will try - * to work it out ourself. - * If no pinboard is in use, activates 'Default'. - */ -void pinboard_set_backdrop(DirItem *item, const gchar *path) +/* Open a dialog box allowing the user to set the backdrop */ +void pinboard_set_backdrop(void) +{ + GtkWidget *dialog, *frame, *label, *radio, *hbox; + GtkBox *vbox; + GtkTargetEntry targets[] = { + {"text/uri-list", 0, TARGET_URI_LIST}, + }; + + dialog = gtk_dialog_new_with_buttons(_("Set backdrop"), NULL, + GTK_DIALOG_NO_SEPARATOR, + GTK_STOCK_CLEAR, GTK_RESPONSE_NO, + GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); + vbox = GTK_BOX(GTK_DIALOG(dialog)->vbox); + + gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE); + + label = gtk_label_new("Display backdrop image:"); + gtk_misc_set_padding(GTK_MISC(label), 4, 0); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0); + gtk_box_pack_start(vbox, label, TRUE, TRUE, 4); + + /* The Centred, Scaled, Tiled radios... */ + hbox = gtk_hbox_new(TRUE, 2); + gtk_box_pack_start(vbox, hbox, TRUE, TRUE, 4); + + radio = gtk_radio_button_new_with_label(NULL, _("Centred")); + g_object_set_data(G_OBJECT(dialog), "radio_centred", radio); + gtk_box_pack_start(GTK_BOX(hbox), radio, FALSE, TRUE, 0); + + radio = gtk_radio_button_new_with_label( + gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)), + _("Scaled")); + g_object_set_data(G_OBJECT(dialog), "radio_scaled", radio); + gtk_box_pack_start(GTK_BOX(hbox), radio, FALSE, TRUE, 0); + + radio = gtk_radio_button_new_with_label( + gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)), + _("Tiled")); + gtk_box_pack_start(GTK_BOX(hbox), radio, FALSE, TRUE, 0); + + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE); + + /* The drop area... */ + frame = gtk_frame_new(NULL); + gtk_box_pack_start(vbox, frame, TRUE, TRUE, 4); + gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_container_set_border_width(GTK_CONTAINER(frame), 4); + + gtk_drag_dest_set(frame, GTK_DEST_DEFAULT_ALL, + targets, sizeof(targets) / sizeof(*targets), + GDK_ACTION_COPY); + g_signal_connect(frame, "drag_data_received", + G_CALLBACK(drag_backdrop_dropped), dialog); + + label = gtk_label_new(_("Drop an image here")); + gtk_misc_set_padding(GTK_MISC(label), 10, 20); + gtk_container_add(GTK_CONTAINER(frame), label); + + g_signal_connect(dialog, "response", + G_CALLBACK(backdrop_response), NULL); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); + + gtk_widget_show_all(dialog); +} + +/**************************************************************** + * INTERNAL FUNCTIONS * + ****************************************************************/ + +static void backdrop_response(GtkWidget *dialog, gint response, gpointer data) +{ + if (response == GTK_RESPONSE_NO) + set_backdrop(NULL, BACKDROP_NONE); + + gtk_widget_destroy(dialog); +} + +static void drag_backdrop_dropped(GtkWidget *frame, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection_data, + guint drag_info, + guint32 time, + GtkWidget *dialog) { - if (path == NULL || item == NULL) + struct stat info; + const gchar *path = NULL; + GList *uris; + + if (!selection_data->data) + return; /* Timeout? */ + + uris = uri_list_to_glist(selection_data->data); + + if (g_list_length(uris) == 1) + path = get_local_path((guchar *) uris->data); + g_list_free(uris); + + if (!path) { - /* Remove backdrop */ + delayed_error( + _("You should drop a single (local) image file " + "onto the drop box - that image will be " + "used for the desktop background. You can also " + "drag certain applications onto this box.")); + return; + } - if (current_pinboard && current_pinboard->backdrop) - set_backdrop(NULL, BACKDROP_NONE); - else - delayed_error(_("No backdrop image is currently " - "set. Use the 'Use for Backdrop' menu " - "item to set an image (or program) for " - "the backdrop.")); + if (mc_stat(path, &info)) + { + delayed_error( + _("Can't access '%s':\n%s"), path, + g_strerror(errno)); return; } - if (item->flags & ITEM_FLAG_APPDIR) + if (S_ISDIR(info.st_mode)) { /* Use this program to set the backdrop */ pinboard_set_backdrop_app(path); } - else if (item->base_type == TYPE_FILE) + else if (S_ISREG(info.st_mode)) { - int i; + GtkWidget *radio; - /* Use this file as the backdrop */ + radio = g_object_get_data(G_OBJECT(dialog), "radio_scaled"); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio))) + { + set_backdrop(path, BACKDROP_SCALE); + return; + } - i = get_choice(_("Set backdrop"), - _("How should this image be displayed?"), - 4, GTK_STOCK_CANCEL, - _("Centred"), _("_Scaled"), _("Tiled")); + radio = g_object_get_data(G_OBJECT(dialog), "radio_centred"); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radio))) + { + set_backdrop(path, BACKDROP_CENTRE); + return; + } - if (i >= 0) - set_backdrop(path, - i == 1 ? BACKDROP_CENTRE : - i == 2 ? BACKDROP_SCALE : - BACKDROP_TILE); + set_backdrop(path, BACKDROP_TILE); } else - delayed_error(_("Only files and certain applications can be " + delayed_error(_("Only files (and certain applications) can be " "used to set the background image.")); } -/**************************************************************** - * INTERNAL FUNCTIONS * - ****************************************************************/ - static void pinboard_check_options(void) { GdkColor n_fg, n_bg; @@ -1503,10 +1610,7 @@ static void pinboard_show_menu(GdkEventButton *event, PinIcon *pi) pos[1] = event->y_root; pos[2] = 1; - icon_prepare_menu((Icon *) pi); - gtk_widget_show(icon_menu_remove_backdrop); - gtk_widget_set_sensitive(GTK_BIN(icon_menu_remove_backdrop)->child, - current_pinboard->backdrop != NULL); + icon_prepare_menu((Icon *) pi, TRUE); gtk_menu_popup(GTK_MENU(icon_menu), NULL, NULL, position_menu, diff --git a/ROX-Filer/src/pinboard.h b/ROX-Filer/src/pinboard.h index 076a8efb..e2b95ab1 100644 --- a/ROX-Filer/src/pinboard.h +++ b/ROX-Filer/src/pinboard.h @@ -25,7 +25,7 @@ void pinboard_activate(const gchar *name); void pinboard_pin(const gchar *path, const gchar *name, int x, int y); void pinboard_move_icons(void); const gchar *pinboard_get_name(void); -void pinboard_set_backdrop(DirItem *item, const gchar *path); +void pinboard_set_backdrop(void); void pinboard_set_backdrop_app(const gchar *app); GdkWindow *pinboard_get_window(void); void pinboard_add_widget(GtkWidget *widget, int x, int y); diff --git a/ROX-Filer/src/type.c b/ROX-Filer/src/type.c index 9f7be2b5..6b44ee26 100644 --- a/ROX-Filer/src/type.c +++ b/ROX-Filer/src/type.c @@ -509,7 +509,7 @@ static void set_action_response(GtkWidget *dialog, gint response, gpointer data) * dialog. Make sure it's an application, and make that the default * handler. */ -void drag_app_dropped(GtkWidget *eb, +static void drag_app_dropped(GtkWidget *eb, GdkDragContext *context, gint x, gint y, -- 2.11.4.GIT