summaryrefslogtreecommitdiffstats
path: root/src/gui_gtk.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2004-10-11 10:16:09 +0000
committerBram Moolenaar <Bram@vim.org>2004-10-11 10:16:09 +0000
commit7b0294cb9f7cfcd3fcbbaa523578847a3e6d74c5 (patch)
tree5675edfe10a80abd76b307b855858f136c647d32 /src/gui_gtk.c
parent7171abea1ad8d33cce89a9664873417187139a53 (diff)
updated for version 7.0018v7.0018
Diffstat (limited to 'src/gui_gtk.c')
-rw-r--r--src/gui_gtk.c76
1 files changed, 72 insertions, 4 deletions
diff --git a/src/gui_gtk.c b/src/gui_gtk.c
index ed4e5bc771..f4287ec2e3 100644
--- a/src/gui_gtk.c
+++ b/src/gui_gtk.c
@@ -1276,9 +1276,9 @@ gui_mch_browse(int saving,
char_u *initdir,
char_u *filter)
{
- GtkFileSelection *fs; /* shortcut */
- char_u dirbuf[MAXPATHL];
- char_u *p;
+ GtkFileSelection *fs; /* shortcut */
+ char_u dirbuf[MAXPATHL];
+ char_u *p;
# ifdef HAVE_GTK2
title = CONVERT_TO_UTF8(title);
@@ -1348,6 +1348,75 @@ gui_mch_browse(int saving,
return vim_strsave(p);
}
+/*
+ * Put up a directory selector
+ * Returns the selected name in allocated memory, or NULL for Cancel.
+ * title title for the window
+ * dflt default name
+ * initdir initial directory, NULL for current dir
+ */
+/*ARGSUSED*/
+ char_u *
+gui_mch_browsedir(
+ char_u *title,
+ char_u *initdir)
+{
+# if defined(GTK_FILE_CHOOSER) /* Only in GTK 2.4 and later. */
+ char_u dirbuf[MAXPATHL];
+ char_u *p;
+ GtkWidget *dirdlg; /* file selection dialog */
+ char_u *dirname = NULL;
+
+ title = CONVERT_TO_UTF8(title);
+
+ dirdlg = gtk_file_chooser_dialog_new(
+ (const gchar *)title,
+ GTK_WINDOW(gui.mainwin),
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ CONVERT_TO_UTF8_FREE(title);
+
+ /* if our pointer is currently hidden, then we should show it. */
+ gui_mch_mousehide(FALSE);
+
+ /* GTK appears to insist on an absolute path. */
+ if (initdir == NULL || *initdir == NUL
+ || vim_FullName(initdir, dirbuf, MAXPATHL - 10, FALSE) == FAIL)
+ mch_dirname(dirbuf, MAXPATHL - 10);
+
+ /* Always need a trailing slash for a directory.
+ * Also add a dummy file name, so that we get to the directory. */
+ add_pathsep(dirbuf);
+ STRCAT(dirbuf, "@zd(*&1|");
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dirdlg),
+ (const gchar *)dirbuf);
+
+ /* Run the dialog. */
+ if (gtk_dialog_run(GTK_DIALOG(dirdlg)) == GTK_RESPONSE_ACCEPT)
+ dirname = (char_u *)gtk_file_chooser_get_filename(
+ GTK_FILE_CHOOSER(dirdlg));
+ gtk_widget_destroy(dirdlg);
+ if (dirname == NULL)
+ return NULL;
+
+ /* shorten the file name if possible */
+ mch_dirname(dirbuf, MAXPATHL);
+ p = shorten_fname(dirname, dirbuf);
+ if (p == NULL || *p == NUL)
+ p = dirname;
+ p = vim_strsave(p);
+ g_free(dirname);
+ return p;
+
+# else
+ /* For GTK 2.2 and earlier: fall back to ordinary file selector. */
+ return gui_mch_browse(0, title, NULL, NULL, initdir, NULL);
+# endif
+}
+
#endif /* FEAT_BROWSE */
#if (defined(FEAT_GUI_DIALOG) && !defined(HAVE_GTK2)) || defined(PROTO)
@@ -3038,4 +3107,3 @@ gui_gtk_position_in_parent(
}
#endif /* !HAVE_GTK2 */
-