Permalink
Browse files

Only select directories in browsedir()

  • Loading branch information...
1 parent b13abfe commit 4aeadf51a54dd2765b02a97ddd1ce08f3b1db27f @b4winckler committed Oct 12, 2012
Showing with 39 additions and 3 deletions.
  1. +6 −0 src/MacVim/MMVimController.m
  2. +28 −0 src/MacVim/gui_macvim.m
  3. +3 −3 src/message.c
  4. +2 −0 src/proto/gui_macvim.pro
@@ -1374,6 +1374,7 @@ - (void)handleBrowseForFile:(NSDictionary *)attr
NSString *dir = [attr objectForKey:@"dir"];
BOOL saving = [[attr objectForKey:@"saving"] boolValue];
+ BOOL browsedir = [[attr objectForKey:@"browsedir"] boolValue];
if (!dir) {
// 'dir == nil' means: set dir to the pwd of the Vim process, or let
@@ -1422,6 +1423,11 @@ - (void)handleBrowseForFile:(NSDictionary *)attr
[panel setAllowsMultipleSelection:NO];
[panel setAccessoryView:showHiddenFilesView()];
+ if (browsedir) {
+ [panel setCanChooseDirectories:YES];
+ [panel setCanChooseFiles:NO];
+ }
+
#if (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6)
// NOTE: -[NSOpenPanel beginSheetForDirectory:::::::] is deprecated on
// 10.6 but -[NSOpenPanel setDirectoryURL:] requires 10.6 so jump
View
@@ -1431,6 +1431,34 @@
return s;
}
+
+/*
+ * Put up a directory selector
+ * Returns the selected name in allocated memory, or NULL for Cancel.
+ * title title for the window (UNUSED)
+ * initdir initial directory, NULL for current dir
+ */
+ char_u *
+gui_mch_browsedir(
+ char_u *title,
+ char_u *initdir)
+{
+ ASLogDebug(@"title='%s' initdir='%s'", title, initdir);
+
+ // Ensure no data is on the output queue before presenting the dialog.
+ gui_macvim_force_flush();
+
+ NSMutableDictionary *attr = [NSMutableDictionary
+ dictionaryWithObject:[NSNumber numberWithBool:YES]
+ forKey:@"browsedir"];
+ if (initdir)
+ [attr setObject:[NSString stringWithVimString:initdir] forKey:@"dir"];
+
+ char_u *s = (char_u*)[[MMBackend sharedInstance]
+ browseForFileWithAttributes:attr];
+
+ return s;
+}
#endif /* FEAT_BROWSE */
View
@@ -3825,17 +3825,17 @@ do_browse(flags, title, dflt, ext, initdir, filter, buf)
filter = BROWSE_FILTER_DEFAULT;
if (flags & BROWSE_DIR)
{
-# if defined(FEAT_GUI_GTK) || defined(WIN3264)
+# if defined(FEAT_GUI_GTK) || defined(WIN3264) || defined(FEAT_GUI_MACVIM)
/* For systems that have a directory dialog. */
fname = gui_mch_browsedir(title, initdir);
# else
/* Generic solution for selecting a directory: select a file and
* remove the file name. */
fname = gui_mch_browse(0, title, dflt, ext, initdir, (char_u *)"");
# endif
-# if !defined(FEAT_GUI_GTK)
+# if !(defined(FEAT_GUI_GTK) || defined(FEAT_GUI_MACVIM))
/* Win32 adds a dummy file name, others return an arbitrary file
- * name. GTK+ 2 returns only the directory, */
+ * name. GTK+ 2 and MacVim returns only the directory, */
if (fname != NULL && *fname != NUL && !mch_isdir(fname))
{
/* Remove the file name. */
View
@@ -92,6 +92,8 @@ gui_mch_browse(
char_u *ext,
char_u *initdir,
char_u *filter);
+ char_u *
+gui_mch_browsedir(char_u *title, char_u *initdir);
void
gui_mch_create_scrollbar(
scrollbar_T *sb,

0 comments on commit 4aeadf5

Please sign in to comment.