From 49a3b4a3a5f233d99aa1ee42b0ea3241cc23a038 Mon Sep 17 00:00:00 2001 From: Pablo Barciela Date: Tue, 17 Apr 2018 00:33:53 +0200 Subject: avoid 'gtk_file_chooser_dialog_new' with stock ids --- mate-panel/libpanel-util/panel-gtk.c | 58 +++++++++++++++++++++++++++ mate-panel/libpanel-util/panel-gtk.h | 6 +++ mate-panel/libpanel-util/panel-icon-chooser.c | 17 ++++---- 3 files changed, 73 insertions(+), 8 deletions(-) (limited to 'mate-panel/libpanel-util') diff --git a/mate-panel/libpanel-util/panel-gtk.c b/mate-panel/libpanel-util/panel-gtk.c index aed2ce9c..11a7a952 100644 --- a/mate-panel/libpanel-util/panel-gtk.c +++ b/mate-panel/libpanel-util/panel-gtk.c @@ -23,6 +23,7 @@ */ #include +#include #include "panel-gtk.h" @@ -101,3 +102,60 @@ panel_dialog_add_button (GtkDialog *dialog, return button; } + +static GtkWidget * +panel_file_chooser_dialog_new_valist (const gchar *title, + GtkWindow *parent, + GtkFileChooserAction action, + const gchar *first_button_text, + va_list varargs) +{ + GtkWidget *result; + const char *button_text = first_button_text; + gint response_id; + + result = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG, + "title", title, + "action", action, + NULL); + + if (parent) + gtk_window_set_transient_for (GTK_WINDOW (result), parent); + + while (button_text) + { + response_id = va_arg (varargs, gint); + + if (g_strcmp0 (button_text, "process-stop") == 0) + panel_dialog_add_button (GTK_DIALOG (result), _("_Cancel"), button_text, response_id); + else if (g_strcmp0 (button_text, "document-open") == 0) + panel_dialog_add_button (GTK_DIALOG (result), _("_Open"), button_text, response_id); + else if (g_strcmp0 (button_text, "gtk-ok") == 0) + panel_dialog_add_button (GTK_DIALOG (result), _("_OK"), button_text, response_id); + else + gtk_dialog_add_button (GTK_DIALOG (result), button_text, response_id); + + button_text = va_arg (varargs, const gchar *); + } + + return result; +} + +GtkWidget * +panel_file_chooser_dialog_new (const gchar *title, + GtkWindow *parent, + GtkFileChooserAction action, + const gchar *first_button_text, + ...) +{ + GtkWidget *result; + va_list varargs; + + va_start (varargs, first_button_text); + result = panel_file_chooser_dialog_new_valist (title, parent, action, + first_button_text, + varargs); + va_end (varargs); + + return result; +} diff --git a/mate-panel/libpanel-util/panel-gtk.h b/mate-panel/libpanel-util/panel-gtk.h index 19950a71..078dcb05 100644 --- a/mate-panel/libpanel-util/panel-gtk.h +++ b/mate-panel/libpanel-util/panel-gtk.h @@ -40,6 +40,12 @@ GtkWidget* panel_dialog_add_button (GtkDialog *dialog, const gchar *icon_name, gint response_id); +GtkWidget* panel_file_chooser_dialog_new (const gchar *title, + GtkWindow *parent, + GtkFileChooserAction action, + const gchar *first_button_text, + ...); + #ifdef __cplusplus } #endif diff --git a/mate-panel/libpanel-util/panel-icon-chooser.c b/mate-panel/libpanel-util/panel-icon-chooser.c index 5b5ca08a..4850d0ee 100644 --- a/mate-panel/libpanel-util/panel-icon-chooser.c +++ b/mate-panel/libpanel-util/panel-icon-chooser.c @@ -378,14 +378,15 @@ _panel_icon_chooser_clicked (GtkButton *button) else parent = NULL; - filechooser = gtk_file_chooser_dialog_new (_("Choose an icon"), - parent, - GTK_FILE_CHOOSER_ACTION_OPEN, - "gtk-cancel", - GTK_RESPONSE_CANCEL, - "gtk-open", - GTK_RESPONSE_ACCEPT, - NULL); + filechooser = panel_file_chooser_dialog_new (_("Choose an icon"), + parent, + GTK_FILE_CHOOSER_ACTION_OPEN, + "process-stop", + GTK_RESPONSE_CANCEL, + "document-open", + GTK_RESPONSE_ACCEPT, + NULL); + panel_gtk_file_chooser_add_image_preview (GTK_FILE_CHOOSER (filechooser)); path = g_build_filename (DATADIR, "icons", NULL); -- cgit v1.2.1