0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.1649: GTK3: using old file chooser

Problem:    GTK3: using old file chooser.
Solution:   Use native file chooser on GTK 3.20 and above. (Yogeshwar
            Velingker, closes #6909)
This commit is contained in:
Bram Moolenaar
2020-09-09 20:58:55 +02:00
parent a62372be1f
commit 3e4cc9671c
2 changed files with 29 additions and 6 deletions

View File

@@ -1199,7 +1199,11 @@ gui_mch_browse(int saving UNUSED,
char_u *filter) char_u *filter)
{ {
#ifdef USE_FILE_CHOOSER #ifdef USE_FILE_CHOOSER
# if GTK_CHECK_VERSION(3,20,0)
GtkFileChooserNative *fc;
# else
GtkWidget *fc; GtkWidget *fc;
# endif
#endif #endif
char_u dirbuf[MAXPATHL]; char_u dirbuf[MAXPATHL];
guint log_handler; guint log_handler;
@@ -1226,10 +1230,18 @@ gui_mch_browse(int saving UNUSED,
#ifdef USE_FILE_CHOOSER #ifdef USE_FILE_CHOOSER
// We create the dialog each time, so that the button text can be "Open" // We create the dialog each time, so that the button text can be "Open"
// or "Save" according to the action. // or "Save" according to the action.
fc = gtk_file_chooser_dialog_new((const gchar *)title, # if GTK_CHECK_VERSION(3,20,0)
fc = gtk_file_chooser_native_new(
# else
fc = gtk_file_chooser_dialog_new(
# endif
(const gchar *)title,
GTK_WINDOW(gui.mainwin), GTK_WINDOW(gui.mainwin),
saving ? GTK_FILE_CHOOSER_ACTION_SAVE saving ? GTK_FILE_CHOOSER_ACTION_SAVE
: GTK_FILE_CHOOSER_ACTION_OPEN, : GTK_FILE_CHOOSER_ACTION_OPEN,
# if GTK_CHECK_VERSION(3,20,0)
saving ? _("_Save") : _("_Open"), _("_Cancel"));
# else
# if GTK_CHECK_VERSION(3,10,0) # if GTK_CHECK_VERSION(3,10,0)
_("_Cancel"), GTK_RESPONSE_CANCEL, _("_Cancel"), GTK_RESPONSE_CANCEL,
saving ? _("_Save") : _("_Open"), GTK_RESPONSE_ACCEPT, saving ? _("_Save") : _("_Open"), GTK_RESPONSE_ACCEPT,
@@ -1238,6 +1250,7 @@ gui_mch_browse(int saving UNUSED,
saving ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, saving ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
# endif # endif
NULL); NULL);
# endif
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc), gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(fc),
(const gchar *)dirbuf); (const gchar *)dirbuf);
@@ -1263,7 +1276,7 @@ gui_mch_browse(int saving UNUSED,
gtk_file_filter_add_pattern(gfilter, (gchar *)patt); gtk_file_filter_add_pattern(gfilter, (gchar *)patt);
if (*p == '\n') if (*p == '\n')
{ {
gtk_file_chooser_add_filter((GtkFileChooser *)fc, gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fc),
gfilter); gfilter);
if (*(p + 1) != NUL) if (*(p + 1) != NUL)
gfilter = gtk_file_filter_new(); gfilter = gtk_file_filter_new();
@@ -1284,7 +1297,11 @@ gui_mch_browse(int saving UNUSED,
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fc), (char *)dflt); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fc), (char *)dflt);
gui.browse_fname = NULL; gui.browse_fname = NULL;
# if GTK_CHECK_VERSION(3,20,0)
if (gtk_native_dialog_run(GTK_NATIVE_DIALOG(fc)) == GTK_RESPONSE_ACCEPT)
# else
if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT) if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT)
#endif
{ {
char *filename; char *filename;
@@ -1292,7 +1309,11 @@ gui_mch_browse(int saving UNUSED,
gui.browse_fname = (char_u *)g_strdup(filename); gui.browse_fname = (char_u *)g_strdup(filename);
g_free(filename); g_free(filename);
} }
# if GTK_CHECK_VERSION(3,20,0)
g_object_unref(fc);
# else
gtk_widget_destroy(GTK_WIDGET(fc)); gtk_widget_destroy(GTK_WIDGET(fc));
# endif
#else // !USE_FILE_CHOOSER #else // !USE_FILE_CHOOSER

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1649,
/**/ /**/
1648, 1648,
/**/ /**/