[gedit] Add caller specified responses to file dialogs
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Add caller specified responses to file dialogs
- Date: Sat, 6 Sep 2014 07:44:36 +0000 (UTC)
commit b87dd7e8d2015923a2ff6940a63f77f85ed1f670
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sat Sep 6 09:36:17 2014 +0200
Add caller specified responses to file dialogs
gedit/gedit-commands-file.c | 8 +++++-
gedit/gedit-file-chooser-dialog-gtk.c | 20 ++++++----------
gedit/gedit-file-chooser-dialog-gtk.h | 6 ++++-
gedit/gedit-file-chooser-dialog-osx.c | 40 ++++++++++++++++++++++++++++++--
gedit/gedit-file-chooser-dialog-osx.h | 6 ++++-
gedit/gedit-file-chooser-dialog.c | 18 ++++++++++++--
gedit/gedit-file-chooser-dialog.h | 6 ++++-
7 files changed, 81 insertions(+), 23 deletions(-)
---
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index 768e942..2225d07 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -452,7 +452,9 @@ _gedit_cmd_file_open (GSimpleAction *action,
window ? GTK_WINDOW (window) : NULL,
GEDIT_FILE_CHOOSER_OPEN |
GEDIT_FILE_CHOOSER_ENABLE_ENCODING,
- NULL);
+ NULL,
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ _("_Open"), GTK_RESPONSE_OK);
if (window != NULL)
{
@@ -874,7 +876,9 @@ _gedit_cmd_file_save_as_tab (GeditTab *tab,
GEDIT_FILE_CHOOSER_SAVE |
GEDIT_FILE_CHOOSER_ENABLE_ENCODING |
GEDIT_FILE_CHOOSER_ENABLE_LINE_ENDING,
- NULL);
+ NULL,
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ _("_Save"), GTK_RESPONSE_OK);
gedit_file_chooser_dialog_set_do_overwrite_confirmation (save_dialog, TRUE);
diff --git a/gedit/gedit-file-chooser-dialog-gtk.c b/gedit/gedit-file-chooser-dialog-gtk.c
index 2409f87..4c1aeee 100644
--- a/gedit/gedit-file-chooser-dialog-gtk.c
+++ b/gedit/gedit-file-chooser-dialog-gtk.c
@@ -524,7 +524,11 @@ GeditFileChooserDialog *
gedit_file_chooser_dialog_gtk_create (const gchar *title,
GtkWindow *parent,
GeditFileChooserFlags flags,
- const GtkSourceEncoding *encoding)
+ const GtkSourceEncoding *encoding,
+ const gchar *cancel_label,
+ GtkResponseType cancel_response,
+ const gchar *accept_label,
+ GtkResponseType accept_response)
{
GtkWidget *result;
GtkFileFilter *filter;
@@ -602,18 +606,10 @@ gedit_file_chooser_dialog_gtk_create (const gchar *title,
gtk_window_set_destroy_with_parent (GTK_WINDOW (result), TRUE);
}
- gtk_dialog_add_button (GTK_DIALOG (result), _("_Cancel"), GTK_RESPONSE_CANCEL);
+ gtk_dialog_add_button (GTK_DIALOG (result), cancel_label, cancel_response);
+ gtk_dialog_add_button (GTK_DIALOG (result), accept_label, accept_response);
- if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
- {
- gtk_dialog_add_button (GTK_DIALOG (result), _("_Save"), GTK_RESPONSE_OK);
- }
- else
- {
- gtk_dialog_add_button (GTK_DIALOG (result), _("_Open"), GTK_RESPONSE_OK);
- }
-
- gtk_dialog_set_default_response (GTK_DIALOG (result), GTK_RESPONSE_OK);
+ gtk_dialog_set_default_response (GTK_DIALOG (result), accept_response);
return GEDIT_FILE_CHOOSER_DIALOG (result);
}
diff --git a/gedit/gedit-file-chooser-dialog-gtk.h b/gedit/gedit-file-chooser-dialog-gtk.h
index f2e5da6..065bb2e 100644
--- a/gedit/gedit-file-chooser-dialog-gtk.h
+++ b/gedit/gedit-file-chooser-dialog-gtk.h
@@ -55,7 +55,11 @@ GType gedit_file_chooser_dialog_gtk_get_type (void)
G_GNUC_CONST;
GeditFileChooserDialog *gedit_file_chooser_dialog_gtk_create (const gchar *title,
GtkWindow *parent,
GeditFileChooserFlags flags,
- const GtkSourceEncoding *encoding);
+ const GtkSourceEncoding *encoding,
+ const gchar
*cancel_label,
+ GtkResponseType
cancel_response,
+ const gchar
*accept_label,
+ GtkResponseType
accept_response);
G_END_DECLS
diff --git a/gedit/gedit-file-chooser-dialog-osx.c b/gedit/gedit-file-chooser-dialog-osx.c
index f383a67..51565c5 100644
--- a/gedit/gedit-file-chooser-dialog-osx.c
+++ b/gedit/gedit-file-chooser-dialog-osx.c
@@ -42,6 +42,9 @@ struct _GeditFileChooserDialogOSXPrivate
gboolean is_open;
gboolean is_modal;
+ GtkResponseType cancel_response;
+ GtkResponseType accept_response;
+
GeditFileChooserFlags flags;
};
@@ -728,11 +731,11 @@ chooser_show (GeditFileChooserDialog *dialog)
if (result == NSFileHandlingPanelOKButton)
{
- response = GTK_RESPONSE_OK;
+ response = priv->accept_response;
}
else
{
- response = GTK_RESPONSE_CANCEL;
+ response = priv->cancel_response;
}
g_signal_emit_by_name (dialog, "response", response);
@@ -831,16 +834,43 @@ gedit_file_chooser_dialog_osx_init (GeditFileChooserDialogOSX *dialog)
- (void)setShowsTagField:(BOOL)val;
@end
+static gchar *
+strip_mnemonic (const gchar *s)
+{
+ gchar *escaped;
+ gchar *ret = NULL;
+
+ escaped = g_markup_escape_text (s, -1);
+ pango_parse_markup (escaped, -1, '_', NULL, &ret, NULL, NULL);
+
+ if (ret != NULL)
+ {
+ return ret;
+ }
+ else
+ {
+ return g_strdup (s);
+ }
+}
+
GeditFileChooserDialog *
gedit_file_chooser_dialog_osx_create (const gchar *title,
GtkWindow *parent,
GeditFileChooserFlags flags,
- const GtkSourceEncoding *encoding)
+ const GtkSourceEncoding *encoding,
+ const gchar *cancel_label,
+ GtkResponseType cancel_response,
+ const gchar *accept_label,
+ GtkResponseType accept_response)
{
GeditFileChooserDialogOSX *ret;
+ gchar *nomnem;
ret = g_object_new (GEDIT_TYPE_FILE_CHOOSER_DIALOG_OSX, NULL);
+ ret->priv->cancel_response = cancel_response;
+ ret->priv->accept_response = accept_response;
+
if ((flags & GEDIT_FILE_CHOOSER_SAVE) != 0)
{
NSSavePanel *panel = [[NSSavePanel savePanel] retain];
@@ -864,6 +894,10 @@ gedit_file_chooser_dialog_osx_create (const gchar *title,
ret->priv->is_open = TRUE;
}
+ nomnem = strip_mnemonic (accept_label);
+ [ret->priv->panel setPrompt:[NSString stringWithUTF8String:nomnem]];
+ g_free (nomnem);
+
if (parent != NULL)
{
ret->priv->parent = g_object_ref (parent);
diff --git a/gedit/gedit-file-chooser-dialog-osx.h b/gedit/gedit-file-chooser-dialog-osx.h
index 6192287..215be83 100644
--- a/gedit/gedit-file-chooser-dialog-osx.h
+++ b/gedit/gedit-file-chooser-dialog-osx.h
@@ -55,7 +55,11 @@ GType gedit_file_chooser_dialog_osx_get_type (void)
G_GNUC_CONST;
GeditFileChooserDialog *gedit_file_chooser_dialog_osx_create (const gchar *title,
GtkWindow *parent,
GeditFileChooserFlags flags,
- const GtkSourceEncoding *encoding);
+ const GtkSourceEncoding *encoding,
+ const gchar
*cancel_label,
+ GtkResponseType
cancel_response,
+ const gchar
*accept_label,
+ GtkResponseType
accept_response);
G_END_DECLS
diff --git a/gedit/gedit-file-chooser-dialog.c b/gedit/gedit-file-chooser-dialog.c
index f0f01c2..d8c13cf 100644
--- a/gedit/gedit-file-chooser-dialog.c
+++ b/gedit/gedit-file-chooser-dialog.c
@@ -83,18 +83,30 @@ GeditFileChooserDialog *
gedit_file_chooser_dialog_create (const gchar *title,
GtkWindow *parent,
GeditFileChooserFlags flags,
- const GtkSourceEncoding *encoding)
+ const GtkSourceEncoding *encoding,
+ const gchar *cancel_label,
+ GtkResponseType cancel_response,
+ const gchar *accept_label,
+ GtkResponseType accept_response)
{
#ifdef OS_OSX
return gedit_file_chooser_dialog_osx_create (title,
parent,
flags,
- encoding);
+ encoding,
+ cancel_label,
+ cancel_response,
+ accept_label,
+ accept_response);
#else
return gedit_file_chooser_dialog_gtk_create (title,
parent,
flags,
- encoding);
+ encoding,
+ cancel_label,
+ cancel_response,
+ accept_label,
+ accept_response);
#endif
}
diff --git a/gedit/gedit-file-chooser-dialog.h b/gedit/gedit-file-chooser-dialog.h
index 5923931..41e6771 100644
--- a/gedit/gedit-file-chooser-dialog.h
+++ b/gedit/gedit-file-chooser-dialog.h
@@ -100,7 +100,11 @@ GeditFileChooserDialog *
gedit_file_chooser_dialog_create (const gchar *title,
GtkWindow *parent,
GeditFileChooserFlags flags,
- const GtkSourceEncoding *encoding);
+ const GtkSourceEncoding *encoding,
+ const gchar *cancel_label,
+ GtkResponseType cancel_response,
+ const gchar *accept_label,
+ GtkResponseType accept_response);
void gedit_file_chooser_dialog_destroy (GeditFileChooserDialog *dialog);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]