Commit b87dd7e8 authored by Jesse van den Kieboom's avatar Jesse van den Kieboom

Add caller specified responses to file dialogs

parent a40a370f
......@@ -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);
......
......@@ -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);
}
......
......@@ -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
......
......@@ -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);
......
......@@ -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
......
......@@ -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
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment