diff --git a/src/MacVim/MMBackend.h b/src/MacVim/MMBackend.h index 82cd3296a6..dd1fdf091c 100644 --- a/src/MacVim/MMBackend.h +++ b/src/MacVim/MMBackend.h @@ -162,7 +162,7 @@ extern NSTimeInterval MMBalloonEvalInternalDelay; - (void)setLastToolTip:(NSString *)toolTip; #endif -- (void)addToMRU:(NSString *)filename; +- (void)addToMRU:(NSArray *)filenames; @end diff --git a/src/MacVim/MMBackend.m b/src/MacVim/MMBackend.m index ad14c2cde4..d7cb87dd3d 100644 --- a/src/MacVim/MMBackend.m +++ b/src/MacVim/MMBackend.m @@ -1712,10 +1712,10 @@ static void netbeansReadCallback(CFSocketRef s, } #endif -- (void)addToMRU:(NSString *)filename +- (void)addToMRU:(NSArray *)filenames { [self queueMessage:AddToMRUMsgID properties: - [NSDictionary dictionaryWithObject:filename forKey:@"filename"]]; + [NSDictionary dictionaryWithObject:filenames forKey:@"filenames"]]; } @end // MMBackend diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index ab6dd65307..c5bbd98dfa 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -867,10 +867,10 @@ static BOOL isUnsafeMessage(int msgid); [self setToolTipDelay:[delay floatValue]]; } else if (AddToMRUMsgID == msgid) { NSDictionary *dict = [NSDictionary dictionaryWithData:data]; - NSString *filename = dict ? [dict objectForKey:@"filename"] : nil; - if (filename) + NSArray *filenames = dict ? [dict objectForKey:@"filenames"] : nil; + if (filenames) [[NSDocumentController sharedDocumentController] - noteNewRecentFilePath:filename]; + noteNewRecentFilePaths:filenames]; // IMPORTANT: When adding a new message, make sure to update // isUnsafeMessage() if necessary! diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index f72cb94e8d..8d7ab692c0 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -24,6 +24,13 @@ int use_gui_macvim_draw_string = 1; static int use_graphical_sign = 0; +// Max number of files to add to MRU in one go (this matches the maximum that +// Cocoa displays in the MRU -- if this changes in Cocoa then update this +// number as well). +static int MMMaxMRU = 10; +// Enabled when files passed on command line should not be added to MRU. +static BOOL MMNoMRU = NO; + static NSString *MMDefaultFontName = @"Menlo Regular"; static int MMDefaultFontSize = 11; static int MMMinFontSize = 6; @@ -87,28 +94,45 @@ macvim_early_init() void gui_mch_prepare(int *argc, char **argv) { - int i; - for (i = 0; i < *argc; ++i) { - if (strncmp(argv[i], "--mmwaitforack", 14) == 0) { - [[MMBackend sharedInstance] setWaitForAck:YES]; - --*argc; - if (*argc > i) - mch_memmove(&argv[i], &argv[i+1], (*argc-i) * sizeof(char*)); - break; - } - } + // NOTE! Vim expects this method to remove args that it handles from the + // arg list but if the process then forks then these arguments will not + // reach the child process due to the way forking is handled on Mac OS X. + // + // Thus, only delete arguments that imply that no forking is done. + // + // If you add an argument that does not imply no forking, then do not + // delete it from the arg list. Such arguments must be ignored in main.c + // command_line_scan() or Vim will issue an error on startup when that + // argument is used. + int i = 0; + while (i < *argc) { + BOOL delarg = NO; + if (strncmp(argv[i], "--mmwaitforack", 14) == 0) { + // Implies -f (only called from front end) + [[MMBackend sharedInstance] setWaitForAck:YES]; + delarg = YES; + } #ifdef FEAT_NETBEANS_INTG - for (i = 0; i < *argc; ++i) { - if (strncmp(argv[i], "-nb", 3) == 0) { + else if (strncmp(argv[i], "-nb", 3) == 0) { + // TODO: Can this be used without -f? If so, should not del arg. netbeansArg = argv[i]; + delarg = YES; + } +#endif + else if (strncmp(argv[i], "--nomru", 7) == 0) { + // Can be used without -f, do not delete from arg list! + MMNoMRU = YES; + } + + if (delarg) { + // NOTE: See comment above about when to delete arguments! --*argc; if (*argc > i) mch_memmove(&argv[i], &argv[i+1], (*argc-i) * sizeof(char*)); - break; - } + } else + ++i; } -#endif } @@ -208,6 +232,25 @@ gui_mch_init(void) // in [g]vimrc. gui_mch_adjust_charheight(); + if (!MMNoMRU && GARGCOUNT > 0) { + // Add files passed on command line to MRU. + NSMutableArray *filenames = [NSMutableArray array]; + int i, count = GARGCOUNT > MMMaxMRU ? MMMaxMRU : GARGCOUNT; + for (i = 0; i < count; ++i) { + char_u *fname = GARGLIST[i].ae_fname; + if (!fname) continue; + + // Expand to a full file name (including the full path). + char_u *ffname = fix_fname(fname); + if (!ffname) continue; + + [filenames addObject:[NSString stringWithVimString:ffname]]; + vim_free(ffname); + } + + [[MMBackend sharedInstance] addToMRU:filenames]; + } + return OK; } @@ -2267,17 +2310,3 @@ gui_mch_post_balloon(beval, mesg) } #endif // FEAT_BEVAL - - - void -gui_macvim_add_to_mru(char_u *fname) -{ - // Expand to a full file name (including the full path). - char_u *ffname = fix_fname(fname); - if (!ffname) - return; - - NSString *s = [NSString stringWithVimString:ffname]; - [[MMBackend sharedInstance] addToMRU:s]; - vim_free(ffname); -} diff --git a/src/main.c b/src/main.c index 1eeb462ed0..d40cf43d39 100644 --- a/src/main.c +++ b/src/main.c @@ -23,7 +23,7 @@ # include #endif -#if FEAT_GUI_MACVIM +#ifdef FEAT_GUI_MACVIM #include /* for objc_*() and sel_*() */ #endif @@ -173,7 +173,7 @@ main int i; #endif -#if FEAT_GUI_MACVIM +#ifdef FEAT_GUI_MACVIM // Cocoa needs an NSAutoreleasePool in place or it will leak memory. // This particular pool will hold autorelease objects created during // initialization. @@ -1001,7 +1001,7 @@ main TIME_MSG("before starting main loop"); -#if FEAT_GUI_MACVIM +#ifdef FEAT_GUI_MACVIM // The autorelease pool might have filled up quite a bit during // initialization, so purge it before entering the main loop. objc_msgSend(autoreleasePool, sel_getUid("release")); @@ -1024,7 +1024,7 @@ main mzscheme_main(); #endif -#if FEAT_GUI_MACVIM +#ifdef FEAT_GUI_MACVIM objc_msgSend(autoreleasePool, sel_getUid("release")); #endif @@ -1091,7 +1091,7 @@ main_loop(cmdwin, noexmode) #endif ) { -#if FEAT_GUI_MACVIM +#ifdef FEAT_GUI_MACVIM // Cocoa needs an NSAutoreleasePool in place or it will leak memory. // This particular pool gets released once every loop. id autoreleasePool = objc_msgSend(objc_msgSend( @@ -1328,7 +1328,7 @@ main_loop(cmdwin, noexmode) else normal_cmd(&oa, TRUE); -#if FEAT_GUI_MACVIM +#ifdef FEAT_GUI_MACVIM // TODO! Make sure there are no continue statements that will cause // this not to be called or MacVim will leak memory! objc_msgSend(autoreleasePool, sel_getUid("release")); @@ -1783,9 +1783,6 @@ command_line_scan(parmp) int c; char_u *p = NULL; long n; -#ifdef FEAT_GUI_MACVIM - int nomru = FALSE; -#endif --argc; ++argv; @@ -1921,7 +1918,9 @@ command_line_scan(parmp) #endif #ifdef FEAT_GUI_MACVIM else if (STRNICMP(argv[0] + argv_idx, "nomru", 5) == 0) - nomru = TRUE; + { + /* processed in gui_macvim.m, skip */ + } #endif else { @@ -2449,12 +2448,6 @@ scripterror: 2 /* add buffer number now and use curbuf */ #endif ); -#ifdef FEAT_GUI_MACVIM - /* Add files opened from command line to the MRU (most recently - * used) files. */ - if (!nomru) - gui_macvim_add_to_mru(p); -#endif #if defined(FEAT_MBYTE) && defined(WIN32) { diff --git a/src/proto/gui_macvim.pro b/src/proto/gui_macvim.pro index 0bf4b786b4..65d3907727 100644 --- a/src/proto/gui_macvim.pro +++ b/src/proto/gui_macvim.pro @@ -233,5 +233,3 @@ gui_mch_register_sign(char_u *signfile); void gui_mch_destroy_sign(void *sign); - -void gui_macvim_add_to_mru(char_u *fname);