Skip to content

Commit

Permalink
Current directory handling changes
Browse files Browse the repository at this point in the history
New processes default to using the user's home directory as the current
directory.  When opening files opened from Finder the current directory
is changed to that of the first file opened.
  • Loading branch information
b4winckler committed Aug 10, 2008
1 parent 85c6b71 commit 772859f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/MacVim/MMAppController.m
Expand Up @@ -161,6 +161,12 @@ + (void)initialize

NSArray *types = [NSArray arrayWithObject:NSStringPboardType];
[NSApp registerServicesMenuSendTypes:types returnTypes:types];

// NOTE: Set the current directory to user's home directory, otherwise it
// will default to the root directory. (This matters since new Vim
// processes inherit MacVim's environment variables.)
[[NSFileManager defaultManager] changeCurrentDirectoryPath:
NSHomeDirectory()];
}

- (id)init
Expand Down
7 changes: 7 additions & 0 deletions src/MacVim/MMBackend.m
Expand Up @@ -2267,6 +2267,13 @@ - (void)handleOpenWithArguments:(NSDictionary *)args
BOOL openFiles = ![[args objectForKey:@"dontOpen"] boolValue];
int layout = [[args objectForKey:@"layout"] intValue];

// Change to directory of first file to open, unless editing remotely.
if (openFiles && numFiles > 0 && ![args objectForKey:@"remoteID"]) {
char_u *s = [[filenames objectAtIndex:0] vimStringSave];
vim_chdirfile(s);
vim_free(s);
}

if (starting > 0) {
// When Vim is starting we simply add the files to be opened to the
// global arglist and Vim will take care of opening them for us.
Expand Down
4 changes: 3 additions & 1 deletion src/main.c
Expand Up @@ -464,6 +464,7 @@ main
{
params.want_full_screen = FALSE;

# ifndef FEAT_GUI_MACVIM
/* Avoid always using "/" as the current directory. Note that when
* started from Finder the arglist will be filled later in
* HandleODocAE() and "fname" will be NULL. */
Expand All @@ -478,6 +479,7 @@ main
vim_chdir(NameBuff);
}
}
# endif
}
#endif

Expand Down Expand Up @@ -1916,7 +1918,7 @@ command_line_scan(parmp)
break;

case 'p': /* "-p[N]" open N tab pages */
#ifdef TARGET_API_MAC_OSX
#if defined(TARGET_API_MAC_OSX) && !defined(FEAT_GUI_MACVIM)
/* For some reason on MacOS X, an argument like:
-psn_0_10223617 is passed in when invoke from Finder
or with the 'open' command */
Expand Down

0 comments on commit 772859f

Please sign in to comment.