Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
avoid 'gtk_file_chooser_dialog_new' with stock ids
  • Loading branch information
sc0w authored and lukefromdc committed Apr 18, 2018
1 parent 8248680 commit 49a3b4a
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 21 deletions.
58 changes: 58 additions & 0 deletions mate-panel/libpanel-util/panel-gtk.c
Expand Up @@ -23,6 +23,7 @@
*/

#include <gtk/gtk.h>
#include <glib/gi18n.h>

#include "panel-gtk.h"

Expand Down Expand Up @@ -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;
}
6 changes: 6 additions & 0 deletions mate-panel/libpanel-util/panel-gtk.h
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions mate-panel/libpanel-util/panel-icon-chooser.c
Expand Up @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions mate-panel/panel-ditem-editor.c
Expand Up @@ -1009,13 +1009,14 @@ command_browse_button_clicked (PanelDItemEditor *dialog)
return;
}

chooser = gtk_file_chooser_dialog_new ("", GTK_WINDOW (dialog),
GTK_FILE_CHOOSER_ACTION_OPEN,
"gtk-cancel",
GTK_RESPONSE_CANCEL,
"gtk-open",
GTK_RESPONSE_ACCEPT,
NULL);
chooser = panel_file_chooser_dialog_new ("", GTK_WINDOW (dialog),
GTK_FILE_CHOOSER_ACTION_OPEN,
"process-stop",
GTK_RESPONSE_CANCEL,
"document-open",
GTK_RESPONSE_ACCEPT,
NULL);

gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser), TRUE);

g_signal_connect (chooser, "response",
Expand Down
12 changes: 6 additions & 6 deletions mate-panel/panel-run-dialog.c
Expand Up @@ -1232,12 +1232,12 @@ file_button_clicked (GtkButton *button,
{
GtkWidget *chooser;

chooser = gtk_file_chooser_dialog_new (_("Choose a file to append to the command..."),
GTK_WINDOW (dialog->run_dialog),
GTK_FILE_CHOOSER_ACTION_OPEN,
"gtk-cancel", GTK_RESPONSE_CANCEL,
"gtk-ok", GTK_RESPONSE_OK,
NULL);
chooser = panel_file_chooser_dialog_new (_("Choose a file to append to the command..."),
GTK_WINDOW (dialog->run_dialog),
GTK_FILE_CHOOSER_ACTION_OPEN,
"process-stop", GTK_RESPONSE_CANCEL,
"gtk-ok", GTK_RESPONSE_OK,
NULL);

gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
g_get_home_dir ());
Expand Down
1 change: 1 addition & 0 deletions po/POTFILES.in
Expand Up @@ -31,6 +31,7 @@ applets/wncklet/workspace-switcher.c
[type: gettext/gsettings]data/org.mate.panel.toplevel.gschema.xml.in
mate-panel/libegg/eggdesktopfile.c
mate-panel/libegg/eggsmclient.c
mate-panel/libpanel-util/panel-gtk.c
mate-panel/libpanel-util/panel-error.c
mate-panel/libpanel-util/panel-icon-chooser.c
mate-panel/libpanel-util/panel-launch.c
Expand Down

0 comments on commit 49a3b4a

Please sign in to comment.