From 3fe5d452108fba4785857d0a411f0d9d5cc97fb9 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Thu, 26 Jun 2008 19:27:48 +0200 Subject: [PATCH] Add file for misc code in frontend The files Miscellaneous.[m|h] should be used for code common to the frontend only (code shared with backend belongs in MacVim.[h|m]). Some code has been moved from MacVim.[h|m] and some from other frontend source files. Some code from the previous commit has also been restructured. --- src/MacVim/AuthorizedShellCommand.m | 2 +- src/MacVim/MMAppController.h | 2 - src/MacVim/MMAppController.m | 131 +---------- src/MacVim/MMAtsuiTextView.m | 4 +- src/MacVim/MMFullscreenWindow.m | 6 +- src/MacVim/MMPreferenceController.m | 5 +- src/MacVim/MMTextStorage.m | 1 + src/MacVim/MMTextView.m | 10 +- src/MacVim/MMTypesetter.m | 4 +- src/MacVim/MMVimController.m | 54 +---- src/MacVim/MMVimView.m | 31 +-- src/MacVim/MMWindow.m | 1 - src/MacVim/MMWindowController.m | 5 +- src/MacVim/MacVim.h | 79 +------ src/MacVim/MacVim.m | 159 +------------- src/MacVim/MacVim.xcodeproj/project.pbxproj | 6 + src/MacVim/Miscellaneous.h | 101 +++++++++ src/MacVim/Miscellaneous.m | 324 ++++++++++++++++++++++++++++ src/MacVim/gui_macvim.m | 2 +- 19 files changed, 468 insertions(+), 459 deletions(-) create mode 100644 src/MacVim/Miscellaneous.h create mode 100644 src/MacVim/Miscellaneous.m diff --git a/src/MacVim/AuthorizedShellCommand.m b/src/MacVim/AuthorizedShellCommand.m index 24e8fa9b..5148efbf 100644 --- a/src/MacVim/AuthorizedShellCommand.m +++ b/src/MacVim/AuthorizedShellCommand.m @@ -15,9 +15,9 @@ */ #import "AuthorizedShellCommand.h" - #import + @implementation AuthorizedShellCommand - (AuthorizedShellCommand *)initWithCommands:(NSArray *)theCommands diff --git a/src/MacVim/MMAppController.h b/src/MacVim/MMAppController.h index cef65b43..fcec67f6 100644 --- a/src/MacVim/MMAppController.h +++ b/src/MacVim/MMAppController.h @@ -41,6 +41,4 @@ - (IBAction)showVimHelp:(id)sender; - (IBAction)zoomAll:(id)sender; -- (NSView *)accessoryView; - @end diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 8831b43d..445532f5 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -38,9 +38,10 @@ */ #import "MMAppController.h" +#import "MMPreferenceController.h" #import "MMVimController.h" #import "MMWindowController.h" -#import "MMPreferenceController.h" +#import "Miscellaneous.h" #import @@ -102,23 +103,6 @@ static int executeInLoginShell(NSString *path, NSArray *args); @end -@interface NSNumber (MMExtras) -- (int)tag; -@end - - -@interface NSMenu (MMExtras) -- (int)indexOfItemWithAction:(SEL)action; -- (NSMenuItem *)itemWithAction:(SEL)action; -- (NSMenu *)findMenuContainingItemWithAction:(SEL)action; -- (NSMenu *)findWindowsMenu; -- (NSMenu *)findApplicationMenu; -- (NSMenu *)findServicesMenu; -- (NSMenu *)findFileMenu; -@end - - - @implementation MMAppController @@ -701,7 +685,7 @@ static int executeInLoginShell(NSString *path, NSArray *args); NSOpenPanel *panel = [NSOpenPanel openPanel]; [panel setAllowsMultipleSelection:YES]; - [panel setAccessoryView:[self accessoryView]]; + [panel setAccessoryView:openPanelAccessoryView()]; int result = [panel runModalForDirectory:dir file:nil types:nil]; if (NSOKButton == result) @@ -774,34 +758,6 @@ static int executeInLoginShell(NSString *path, NSArray *args); [NSApp makeWindowsPerform:@selector(performZoom:) inOrder:YES]; } -- (NSView *)accessoryView -{ - // Return a new button object for each NSOpenPanel -- several of them - // could be displayed at once. - // If the accessory view should get more complex, it should probably be - // loaded from a nib file. - NSButton *button = [[[NSButton alloc] - initWithFrame:NSMakeRect(0, 0, 140, 18)] autorelease]; - [button setTitle: - NSLocalizedString(@"Show Hidden Files", @"Open File Dialog")]; - [button setButtonType:NSSwitchButton]; - - [button setTarget:nil]; - [button setAction:@selector(hiddenFilesButtonToggled:)]; - - // use the regular control size (checkbox is a bit smaller without this) - NSControlSize buttonSize = NSRegularControlSize; - float fontSize = [NSFont systemFontSizeForControlSize:buttonSize]; - NSCell *theCell = [button cell]; - NSFont *theFont = [NSFont fontWithName:[[theCell font] fontName] - size:fontSize]; - [theCell setFont:theFont]; - [theCell setControlSize:buttonSize]; - [button sizeToFit]; - - return button; -} - - (byref id ) connectBackend:(byref in id )backend pid:(int)pid @@ -1292,87 +1248,6 @@ static int executeInLoginShell(NSString *path, NSArray *args); -@implementation NSNumber (MMExtras) -- (int)tag -{ - return [self intValue]; -} -@end // NSNumber (MMExtras) - - - - -@implementation NSMenu (MMExtras) - -- (int)indexOfItemWithAction:(SEL)action -{ - int i, count = [self numberOfItems]; - for (i = 0; i < count; ++i) { - NSMenuItem *item = [self itemAtIndex:i]; - if ([item action] == action) - return i; - } - - return -1; -} - -- (NSMenuItem *)itemWithAction:(SEL)action -{ - int idx = [self indexOfItemWithAction:action]; - return idx >= 0 ? [self itemAtIndex:idx] : nil; -} - -- (NSMenu *)findMenuContainingItemWithAction:(SEL)action -{ - // NOTE: We only look for the action in the submenus of 'self' - int i, count = [self numberOfItems]; - for (i = 0; i < count; ++i) { - NSMenu *menu = [[self itemAtIndex:i] submenu]; - NSMenuItem *item = [menu itemWithAction:action]; - if (item) return menu; - } - - return nil; -} - -- (NSMenu *)findWindowsMenu -{ - return [self findMenuContainingItemWithAction: - @selector(performMiniaturize:)]; -} - -- (NSMenu *)findApplicationMenu -{ - // TODO: Just return [self itemAtIndex:0]? - return [self findMenuContainingItemWithAction:@selector(terminate:)]; -} - -- (NSMenu *)findServicesMenu -{ - // NOTE! Our heuristic for finding the "Services" menu is to look for the - // second item before the "Hide MacVim" menu item on the "MacVim" menu. - // (The item before "Hide MacVim" should be a separator, but this is not - // important as long as the item before that is the "Services" menu.) - - NSMenu *appMenu = [self findApplicationMenu]; - if (!appMenu) return nil; - - int idx = [appMenu indexOfItemWithAction: @selector(hide:)]; - if (idx-2 < 0) return nil; // idx == -1, if selector not found - - return [[appMenu itemAtIndex:idx-2] submenu]; -} - -- (NSMenu *)findFileMenu -{ - return [self findMenuContainingItemWithAction:@selector(performClose:)]; -} - -@end // NSMenu (MMExtras) - - - - static int executeInLoginShell(NSString *path, NSArray *args) { diff --git a/src/MacVim/MMAtsuiTextView.m b/src/MacVim/MMAtsuiTextView.m index b41874ae..4072d639 100644 --- a/src/MacVim/MMAtsuiTextView.m +++ b/src/MacVim/MMAtsuiTextView.m @@ -25,11 +25,11 @@ * resized. */ +#import "MMAppController.h" #import "MMAtsuiTextView.h" #import "MMVimController.h" #import "MMWindowController.h" -#import "MMAppController.h" -#import "MacVim.h" +#import "Miscellaneous.h" // TODO: What does DRAW_TRANSP flag do? If the background isn't drawn when diff --git a/src/MacVim/MMFullscreenWindow.m b/src/MacVim/MMFullscreenWindow.m index 57df0704..51a82e31 100644 --- a/src/MacVim/MMFullscreenWindow.m +++ b/src/MacVim/MMFullscreenWindow.m @@ -23,13 +23,13 @@ * Author: Nico Weber */ -#import "MMVimController.h" #import "MMFullscreenWindow.h" -#import -#import "MMVimView.h" #import "MMTextView.h" +#import "MMVimController.h" +#import "MMVimView.h" #import "MMWindowController.h" #import +#import // These have to be the same as in option.h #define FUOPT_MAXVERT 0x001 diff --git a/src/MacVim/MMPreferenceController.m b/src/MacVim/MMPreferenceController.m index b220ec5d..c240f3f5 100644 --- a/src/MacVim/MMPreferenceController.m +++ b/src/MacVim/MMPreferenceController.m @@ -8,10 +8,9 @@ * See README.txt for an overview of the Vim source code. */ -#import "MMPreferenceController.h" -#import "MacVim.h" - #import "AuthorizedShellCommand.h" +#import "MMPreferenceController.h" +#import "Miscellaneous.h" // On Leopard, we want to use the images provided by the OS for some of the // toolbar images (NSImageNamePreferencesGeneral and friends). We need to jump diff --git a/src/MacVim/MMTextStorage.m b/src/MacVim/MMTextStorage.m index 2d6fd775..78b71f46 100644 --- a/src/MacVim/MMTextStorage.m +++ b/src/MacVim/MMTextStorage.m @@ -33,6 +33,7 @@ #import "MMTextStorage.h" #import "MacVim.h" +#import "Miscellaneous.h" diff --git a/src/MacVim/MMTextView.m b/src/MacVim/MMTextView.m index a562854f..965443ef 100644 --- a/src/MacVim/MMTextView.m +++ b/src/MacVim/MMTextView.m @@ -17,13 +17,13 @@ * displayed in a popup window instead of 'in-line' (because it is easier). */ -#import "MMTextView.h" +#import "MMAppController.h" #import "MMTextStorage.h" -#import "MMWindowController.h" -#import "MMVimController.h" +#import "MMTextView.h" #import "MMTypesetter.h" -#import "MMAppController.h" -#import "MacVim.h" +#import "MMVimController.h" +#import "MMWindowController.h" +#import "Miscellaneous.h" diff --git a/src/MacVim/MMTypesetter.m b/src/MacVim/MMTypesetter.m index 44166cb3..481b29db 100644 --- a/src/MacVim/MMTypesetter.m +++ b/src/MacVim/MMTypesetter.m @@ -14,9 +14,9 @@ * issues. */ -#import "MMTypesetter.h" #import "MMTextStorage.h" -#import "MacVim.h" +#import "MMTypesetter.h" +#import "Miscellaneous.h" diff --git a/src/MacVim/MMVimController.m b/src/MacVim/MMVimController.m index 8ccd902c..b8e5662a 100644 --- a/src/MacVim/MMVimController.m +++ b/src/MacVim/MMVimController.m @@ -23,12 +23,13 @@ * frontend and backend are defined in an enum in MacVim.h. */ -#import "MMVimController.h" -#import "MMWindowController.h" #import "MMAppController.h" -#import "MMVimView.h" -#import "MMTextView.h" #import "MMAtsuiTextView.h" +#import "MMTextView.h" +#import "MMVimController.h" +#import "MMVimView.h" +#import "MMWindowController.h" +#import "Miscellaneous.h" static NSString *MMDefaultToolbarImageName = @"Attention"; @@ -92,13 +93,6 @@ static BOOL isUnsafeMessage(int msgid); @end -@interface NSToolbar (MMExtras) -- (int)indexOfItemWithItemIdentifier:(NSString *)identifier; -- (NSToolbarItem *)itemAtIndex:(int)idx; -- (NSToolbarItem *)itemWithItemIdentifier:(NSString *)identifier; -@end - - @implementation MMVimController @@ -414,8 +408,7 @@ static BOOL isUnsafeMessage(int msgid); } else { NSOpenPanel *panel = [NSOpenPanel openPanel]; [panel setAllowsMultipleSelection:NO]; - [panel setAccessoryView: - [[MMAppController sharedInstance] accessoryView]]; + [panel setAccessoryView:openPanelAccessoryView()]; [panel beginSheetForDirectory:dir file:nil types:nil modalForWindow:[windowController window] @@ -1337,41 +1330,6 @@ static BOOL isUnsafeMessage(int msgid); -@implementation NSToolbar (MMExtras) - -- (int)indexOfItemWithItemIdentifier:(NSString *)identifier -{ - NSArray *items = [self items]; - int i, count = [items count]; - for (i = 0; i < count; ++i) { - id item = [items objectAtIndex:i]; - if ([[item itemIdentifier] isEqual:identifier]) - return i; - } - - return NSNotFound; -} - -- (NSToolbarItem *)itemAtIndex:(int)idx -{ - NSArray *items = [self items]; - if (idx < 0 || idx >= [items count]) - return nil; - - return [items objectAtIndex:idx]; -} - -- (NSToolbarItem *)itemWithItemIdentifier:(NSString *)identifier -{ - int idx = [self indexOfItemWithItemIdentifier:identifier]; - return idx != NSNotFound ? [self itemAtIndex:idx] : nil; -} - -@end // NSToolbar (MMExtras) - - - - @implementation MMAlert - (void)dealloc { diff --git a/src/MacVim/MMVimView.m b/src/MacVim/MMVimView.m index 743af3ae..4c2a064b 100644 --- a/src/MacVim/MMVimView.m +++ b/src/MacVim/MMVimView.m @@ -18,13 +18,12 @@ * the view is filled by the text view. */ -#import "MMVimView.h" - -#import -#import "MacVim.h" +#import "MMAtsuiTextView.h" #import "MMTextView.h" #import "MMVimController.h" -#import "MMAtsuiTextView.h" +#import "MMVimView.h" +#import "Miscellaneous.h" +#import @@ -35,11 +34,6 @@ enum { MMScrollerTypeBottom }; -// TODO: Move! -@interface NSTabView (MMExtras) -- (void)removeAllTabViewItems; -@end - // TODO: Move! @interface MMScroller : NSScroller { @@ -827,23 +821,6 @@ enum { -@implementation NSTabView (MMExtras) - -- (void)removeAllTabViewItems -{ - NSArray *existingItems = [self tabViewItems]; - NSEnumerator *e = [existingItems objectEnumerator]; - NSTabViewItem *item; - while (item = [e nextObject]){ - [self removeTabViewItem:item]; - } -} - -@end // NSTabView (MMExtras) - - - - @implementation MMScroller - (id)initWithIdentifier:(long)ident type:(int)theType diff --git a/src/MacVim/MMWindow.m b/src/MacVim/MMWindow.m index 96b65e2b..139db4cf 100644 --- a/src/MacVim/MMWindow.m +++ b/src/MacVim/MMWindow.m @@ -27,7 +27,6 @@ */ #import "MMWindow.h" -#import "MacVim.h" diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index 169fb284..37490611 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -55,7 +55,6 @@ * */ -#import "MMWindowController.h" #import "MMAppController.h" #import "MMAtsuiTextView.h" #import "MMFullscreenWindow.h" @@ -64,8 +63,8 @@ #import "MMVimController.h" #import "MMVimView.h" #import "MMWindow.h" -#import "MacVim.h" - +#import "MMWindowController.h" +#import "Miscellaneous.h" #import diff --git a/src/MacVim/MacVim.h b/src/MacVim/MacVim.h index 0a4148be..44486b03 100644 --- a/src/MacVim/MacVim.h +++ b/src/MacVim/MacVim.h @@ -194,59 +194,15 @@ enum { }; -// NOTE! These values must be close to zero, or the 'add menu' message might -// fail to distinguish type from tag. -enum { - MenuMenubarType = 0, - MenuPopupType, - MenuToolbarType -}; - - enum { ToolbarLabelFlag = 1, ToolbarIconFlag = 2, ToolbarSizeRegularFlag = 4 }; - -// NSUserDefaults keys +// Argument used to stop MacVim from opening an empty window on startup +// (techincally this is a user default but should not be used as such). extern NSString *MMNoWindowKey; -extern NSString *MMTabMinWidthKey; -extern NSString *MMTabMaxWidthKey; -extern NSString *MMTabOptimumWidthKey; -extern NSString *MMTextInsetLeftKey; -extern NSString *MMTextInsetRightKey; -extern NSString *MMTextInsetTopKey; -extern NSString *MMTextInsetBottomKey; -extern NSString *MMTerminateAfterLastWindowClosedKey; -extern NSString *MMTypesetterKey; -extern NSString *MMCellWidthMultiplierKey; -extern NSString *MMBaselineOffsetKey; -extern NSString *MMTranslateCtrlClickKey; -extern NSString *MMTopLeftPointKey; -extern NSString *MMOpenFilesInTabsKey; -extern NSString *MMNoFontSubstitutionKey; -extern NSString *MMLoginShellKey; -extern NSString *MMAtsuiRendererKey; -extern NSString *MMUntitledWindowKey; -extern NSString *MMTexturedWindowKey; -extern NSString *MMZoomBothKey; -extern NSString *MMCurrentPreferencePaneKey; -extern NSString *MMLoginShellCommandKey; -extern NSString *MMLoginShellArgumentKey; -extern NSString *MMDialogsTrackPwdKey; - -// Enum for MMUntitledWindowKey -enum { - MMUntitledWindowNever = 0, - MMUntitledWindowOnOpen = 1, - MMUntitledWindowOnReopen = 2, - MMUntitledWindowAlways = 3 -}; - - - // Vim pasteboard type (holds motion type + string) extern NSString *VimPBoardType; @@ -257,11 +213,6 @@ extern NSString *VimPBoardType; // container reference (which should be used to deactivate the loaded fonts). ATSFontContainerRef loadFonts(); -// Functions to create command strings that can be sent to Vim as input. -NSString *buildTabDropCommand(NSArray *filenames); -NSString *buildSelectRangeCommand(NSRange range); -NSString *buildSearchTextCommand(NSString *searchText); - @interface NSString (MMExtras) @@ -269,30 +220,12 @@ NSString *buildSearchTextCommand(NSString *searchText); @end - - -@interface NSIndexSet (MMExtras) -+ (id)indexSetWithVimList:(NSString *)list; -@end - - - - @interface NSColor (MMExtras) + (NSColor *)colorWithRgbInt:(unsigned)rgb; + (NSColor *)colorWithArgbInt:(unsigned)argb; @end - - -@interface NSDocumentController (MMExtras) -- (void)noteNewRecentFilePath:(NSString *)path; -@end - - - - @interface NSDictionary (MMExtras) + (id)dictionaryWithData:(NSData *)data; - (NSData *)dictionaryAsData; @@ -301,14 +234,6 @@ NSString *buildSearchTextCommand(NSString *searchText); -@interface NSOpenPanel (MMExtras) -- (void)hiddenFilesButtonToggled:(id)sender; -- (void)setShowsHiddenFiles:(BOOL)show; -@end - - - - // ODB Editor Suite Constants (taken from ODBEditorSuite.h) #define keyFileSender 'FSnd' #define keyFileSenderToken 'FTok' diff --git a/src/MacVim/MacVim.m b/src/MacVim/MacVim.m index b96af131..b90db114 100644 --- a/src/MacVim/MacVim.m +++ b/src/MacVim/MacVim.m @@ -82,36 +82,9 @@ char *MessageStrings[] = -// NSUserDefaults keys -NSString *MMNoWindowKey = @"MMNoWindow"; -NSString *MMTabMinWidthKey = @"MMTabMinWidth"; -NSString *MMTabMaxWidthKey = @"MMTabMaxWidth"; -NSString *MMTabOptimumWidthKey = @"MMTabOptimumWidth"; -NSString *MMTextInsetLeftKey = @"MMTextInsetLeft"; -NSString *MMTextInsetRightKey = @"MMTextInsetRight"; -NSString *MMTextInsetTopKey = @"MMTextInsetTop"; -NSString *MMTextInsetBottomKey = @"MMTextInsetBottom"; -NSString *MMTerminateAfterLastWindowClosedKey - = @"MMTerminateAfterLastWindowClosed"; -NSString *MMTypesetterKey = @"MMTypesetter"; -NSString *MMCellWidthMultiplierKey = @"MMCellWidthMultiplier"; -NSString *MMBaselineOffsetKey = @"MMBaselineOffset"; -NSString *MMTranslateCtrlClickKey = @"MMTranslateCtrlClick"; -NSString *MMTopLeftPointKey = @"MMTopLeftPoint"; -NSString *MMOpenFilesInTabsKey = @"MMOpenFilesInTabs"; -NSString *MMNoFontSubstitutionKey = @"MMNoFontSubstitution"; -NSString *MMLoginShellKey = @"MMLoginShell"; -NSString *MMAtsuiRendererKey = @"MMAtsuiRenderer"; -NSString *MMUntitledWindowKey = @"MMUntitledWindow"; -NSString *MMTexturedWindowKey = @"MMTexturedWindow"; -NSString *MMZoomBothKey = @"MMZoomBoth"; -NSString *MMCurrentPreferencePaneKey = @"MMCurrentPreferencePane"; -NSString *MMLoginShellCommandKey = @"MMLoginShellCommand"; -NSString *MMLoginShellArgumentKey = @"MMLoginShellArgument"; -NSString *MMDialogsTrackPwdKey = @"MMDialogsTrackPwd"; - - - +// Argument used to stop MacVim from opening an empty window on startup +// (techincally this is a user default but should not be used as such). +NSString *MMNoWindowKey = @"MMNoWindow"; // Vim pasteboard type (holds motion type + string) NSString *VimPBoardType = @"VimPBoardType"; @@ -152,62 +125,6 @@ loadFonts() - NSString * -buildTabDropCommand(NSArray *filenames) -{ - // Create a command line string that will open the specified files in tabs. - - if (!filenames || [filenames count] == 0) - return [NSString string]; - - NSMutableString *cmd = [NSMutableString stringWithString: - @":tab drop"]; - - NSEnumerator *e = [filenames objectEnumerator]; - id o; - while ((o = [e nextObject])) { - NSString *file = [o stringByEscapingSpecialFilenameCharacters]; - [cmd appendString:@" "]; - [cmd appendString:file]; - } - - [cmd appendString:@"|redr|f"]; - - return cmd; -} - - NSString * -buildSelectRangeCommand(NSRange range) -{ - // Build a command line string that will select the given range of lines. - // If range.length == 0, then position the cursor on the given line but do - // not select. - - if (range.location == NSNotFound) - return [NSString string]; - - NSString *cmd; - if (range.length > 0) { - cmd = [NSString stringWithFormat:@"%dGV%dGz.0", - NSMaxRange(range), range.location]; - } else { - cmd = [NSString stringWithFormat:@"%dGz.0", range.location]; - } - - return cmd; -} - - NSString * -buildSearchTextCommand(NSString *searchText) -{ - // TODO: Searching is an exclusive motion, so if the pattern would match on - // row 0 column 0 then this pattern will miss that match. - return [NSString stringWithFormat:@"gg/\\c%@", searchText]; -} - - - - @implementation NSString (MMExtras) - (NSString *)stringByEscapingSpecialFilenameCharacters @@ -251,28 +168,6 @@ buildSearchTextCommand(NSString *searchText) -@implementation NSIndexSet (MMExtras) - -+ (id)indexSetWithVimList:(NSString *)list -{ - NSMutableIndexSet *idxSet = [NSMutableIndexSet indexSet]; - NSArray *array = [list componentsSeparatedByString:@"\n"]; - unsigned i, count = [array count]; - - for (i = 0; i < count; ++i) { - NSString *entry = [array objectAtIndex:i]; - if ([entry intValue] > 0) - [idxSet addIndex:i]; - } - - return idxSet; -} - -@end // NSIndexSet (MMExtras) - - - - @implementation NSColor (MMExtras) + (NSColor *)colorWithRgbInt:(unsigned)rgb @@ -299,20 +194,6 @@ buildSearchTextCommand(NSString *searchText) -@implementation NSDocumentController (MMExtras) - -- (void)noteNewRecentFilePath:(NSString *)path -{ - NSURL *url = [NSURL fileURLWithPath:path]; - if (url) - [self noteNewRecentDocumentURL:url]; -} - -@end // NSDocumentController (MMExtras) - - - - @implementation NSDictionary (MMExtras) + (id)dictionaryWithData:(NSData *)data @@ -333,37 +214,3 @@ buildSearchTextCommand(NSString *searchText) } @end - - - - -@implementation NSOpenPanel (MMExtras) - -- (void)hiddenFilesButtonToggled:(id)sender -{ - [self setShowsHiddenFiles:[sender intValue]]; -} - -- (void)setShowsHiddenFiles:(BOOL)show -{ - // This is undocumented stuff, so be careful. This does the same as - // [[self _navView] setShowsHiddenFiles:show]; - // but does not produce warnings. - - if (![self respondsToSelector:@selector(_navView)]) - return; - - id navView = [self performSelector:@selector(_navView)]; - if (![navView respondsToSelector:@selector(setShowsHiddenFiles:)]) - return; - - // performSelector:withObject: does not support a BOOL - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: - [navView methodSignatureForSelector:@selector(setShowsHiddenFiles:)]]; - [invocation setTarget:navView]; - [invocation setSelector:@selector(setShowsHiddenFiles:)]; - [invocation setArgument:&show atIndex:2]; - [invocation invoke]; -} - -@end diff --git a/src/MacVim/MacVim.xcodeproj/project.pbxproj b/src/MacVim/MacVim.xcodeproj/project.pbxproj index e9f26a4a..9dfc2646 100644 --- a/src/MacVim/MacVim.xcodeproj/project.pbxproj +++ b/src/MacVim/MacVim.xcodeproj/project.pbxproj @@ -41,6 +41,7 @@ 1D71ACBC0BC702AC002F2B60 /* doc-bm-txt.icns in Resources */ = {isa = PBXBuildFile; fileRef = 1D71ACB10BC702AB002F2B60 /* doc-bm-txt.icns */; }; 1D71ACBD0BC702AC002F2B60 /* doc-bm-xml.icns in Resources */ = {isa = PBXBuildFile; fileRef = 1D71ACB20BC702AB002F2B60 /* doc-bm-xml.icns */; }; 1D71ACBE0BC702AC002F2B60 /* doc-bm.icns in Resources */ = {isa = PBXBuildFile; fileRef = 1D71ACB30BC702AB002F2B60 /* doc-bm.icns */; }; + 1D80591F0E1185EA001699D1 /* Miscellaneous.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D80591D0E1185EA001699D1 /* Miscellaneous.m */; }; 1D80FBD40CBBD3B700102A1C /* MMFullscreenWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D80FBD00CBBD3B700102A1C /* MMFullscreenWindow.m */; }; 1D80FBD60CBBD3B700102A1C /* MMVimView.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D80FBD20CBBD3B700102A1C /* MMVimView.m */; }; 1D80FBE40CBBD6F200102A1C /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D80FBE30CBBD6F200102A1C /* Carbon.framework */; }; @@ -210,6 +211,8 @@ 1D71ACB10BC702AB002F2B60 /* doc-bm-txt.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = "doc-bm-txt.icns"; sourceTree = ""; }; 1D71ACB20BC702AB002F2B60 /* doc-bm-xml.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = "doc-bm-xml.icns"; sourceTree = ""; }; 1D71ACB30BC702AB002F2B60 /* doc-bm.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = "doc-bm.icns"; sourceTree = ""; }; + 1D80591D0E1185EA001699D1 /* Miscellaneous.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Miscellaneous.m; sourceTree = ""; }; + 1D8059220E118663001699D1 /* Miscellaneous.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Miscellaneous.h; sourceTree = ""; }; 1D80FBCF0CBBD3B700102A1C /* MMFullscreenWindow.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MMFullscreenWindow.h; sourceTree = ""; }; 1D80FBD00CBBD3B700102A1C /* MMFullscreenWindow.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = MMFullscreenWindow.m; sourceTree = ""; }; 1D80FBD10CBBD3B700102A1C /* MMVimView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MMVimView.h; sourceTree = ""; }; @@ -299,6 +302,8 @@ 080E96DDFE201D6D7F000001 /* MacVim Source */ = { isa = PBXGroup; children = ( + 1D8059220E118663001699D1 /* Miscellaneous.h */, + 1D80591D0E1185EA001699D1 /* Miscellaneous.m */, 0395A9BD0D75D02400881434 /* AuthorizedShellCommand.h */, 0395A9BE0D75D02400881434 /* AuthorizedShellCommand.m */, 0395A8310D71ED7800881434 /* DBPrefsWindowController.h */, @@ -644,6 +649,7 @@ 1DE3F8EB0D50F84600052B9E /* MMPreferenceController.m in Sources */, 0395A8330D71ED7800881434 /* DBPrefsWindowController.m in Sources */, 0395A9BF0D75D02400881434 /* AuthorizedShellCommand.m in Sources */, + 1D80591F0E1185EA001699D1 /* Miscellaneous.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/MacVim/Miscellaneous.h b/src/MacVim/Miscellaneous.h new file mode 100644 index 00000000..c90223eb --- /dev/null +++ b/src/MacVim/Miscellaneous.h @@ -0,0 +1,101 @@ +/* vi:set ts=8 sts=4 sw=4 ft=objc: + * + * VIM - Vi IMproved by Bram Moolenaar + * MacVim GUI port by Bjorn Winckler + * + * Do ":help uganda" in Vim to read copying and usage conditions. + * Do ":help credits" in Vim to see a list of people who contributed. + * See README.txt for an overview of the Vim source code. + */ + + +#import + + + +// NSUserDefaults keys +extern NSString *MMTabMinWidthKey; +extern NSString *MMTabMaxWidthKey; +extern NSString *MMTabOptimumWidthKey; +extern NSString *MMTextInsetLeftKey; +extern NSString *MMTextInsetRightKey; +extern NSString *MMTextInsetTopKey; +extern NSString *MMTextInsetBottomKey; +extern NSString *MMTerminateAfterLastWindowClosedKey; +extern NSString *MMTypesetterKey; +extern NSString *MMCellWidthMultiplierKey; +extern NSString *MMBaselineOffsetKey; +extern NSString *MMTranslateCtrlClickKey; +extern NSString *MMTopLeftPointKey; +extern NSString *MMOpenFilesInTabsKey; +extern NSString *MMNoFontSubstitutionKey; +extern NSString *MMLoginShellKey; +extern NSString *MMAtsuiRendererKey; +extern NSString *MMUntitledWindowKey; +extern NSString *MMTexturedWindowKey; +extern NSString *MMZoomBothKey; +extern NSString *MMCurrentPreferencePaneKey; +extern NSString *MMLoginShellCommandKey; +extern NSString *MMLoginShellArgumentKey; +extern NSString *MMDialogsTrackPwdKey; + +// Enum for MMUntitledWindowKey +enum { + MMUntitledWindowNever = 0, + MMUntitledWindowOnOpen = 1, + MMUntitledWindowOnReopen = 2, + MMUntitledWindowAlways = 3 +}; + + + + +@interface NSIndexSet (MMExtras) ++ (id)indexSetWithVimList:(NSString *)list; +@end + + +@interface NSDocumentController (MMExtras) +- (void)noteNewRecentFilePath:(NSString *)path; +@end + + +@interface NSOpenPanel (MMExtras) +- (void)hiddenFilesButtonToggled:(id)sender; +- (void)setShowsHiddenFiles:(BOOL)show; +@end + + +@interface NSMenu (MMExtras) +- (int)indexOfItemWithAction:(SEL)action; +- (NSMenuItem *)itemWithAction:(SEL)action; +- (NSMenu *)findMenuContainingItemWithAction:(SEL)action; +- (NSMenu *)findWindowsMenu; +- (NSMenu *)findApplicationMenu; +- (NSMenu *)findServicesMenu; +- (NSMenu *)findFileMenu; +@end + + +@interface NSToolbar (MMExtras) +- (int)indexOfItemWithItemIdentifier:(NSString *)identifier; +- (NSToolbarItem *)itemAtIndex:(int)idx; +- (NSToolbarItem *)itemWithItemIdentifier:(NSString *)identifier; +@end + + +@interface NSTabView (MMExtras) +- (void)removeAllTabViewItems; +@end + + + +// Create a view to be used as accessory for open panel. This function assumes +// ownership of the view so do not release it. +NSView *openPanelAccessoryView(); + +// Functions to create command strings that can be sent to Vim as input. +NSString *buildTabDropCommand(NSArray *filenames); +NSString *buildSelectRangeCommand(NSRange range); +NSString *buildSearchTextCommand(NSString *searchText); + diff --git a/src/MacVim/Miscellaneous.m b/src/MacVim/Miscellaneous.m new file mode 100644 index 00000000..f42debee --- /dev/null +++ b/src/MacVim/Miscellaneous.m @@ -0,0 +1,324 @@ +/* vi:set ts=8 sts=4 sw=4 ft=objc: + * + * VIM - Vi IMproved by Bram Moolenaar + * MacVim GUI port by Bjorn Winckler + * + * Do ":help uganda" in Vim to read copying and usage conditions. + * Do ":help credits" in Vim to see a list of people who contributed. + * See README.txt for an overview of the Vim source code. + */ + +#import "MacVim.h" +#import "Miscellaneous.h" + + + +// NSUserDefaults keys +NSString *MMTabMinWidthKey = @"MMTabMinWidth"; +NSString *MMTabMaxWidthKey = @"MMTabMaxWidth"; +NSString *MMTabOptimumWidthKey = @"MMTabOptimumWidth"; +NSString *MMTextInsetLeftKey = @"MMTextInsetLeft"; +NSString *MMTextInsetRightKey = @"MMTextInsetRight"; +NSString *MMTextInsetTopKey = @"MMTextInsetTop"; +NSString *MMTextInsetBottomKey = @"MMTextInsetBottom"; +NSString *MMTerminateAfterLastWindowClosedKey + = @"MMTerminateAfterLastWindowClosed"; +NSString *MMTypesetterKey = @"MMTypesetter"; +NSString *MMCellWidthMultiplierKey = @"MMCellWidthMultiplier"; +NSString *MMBaselineOffsetKey = @"MMBaselineOffset"; +NSString *MMTranslateCtrlClickKey = @"MMTranslateCtrlClick"; +NSString *MMTopLeftPointKey = @"MMTopLeftPoint"; +NSString *MMOpenFilesInTabsKey = @"MMOpenFilesInTabs"; +NSString *MMNoFontSubstitutionKey = @"MMNoFontSubstitution"; +NSString *MMLoginShellKey = @"MMLoginShell"; +NSString *MMAtsuiRendererKey = @"MMAtsuiRenderer"; +NSString *MMUntitledWindowKey = @"MMUntitledWindow"; +NSString *MMTexturedWindowKey = @"MMTexturedWindow"; +NSString *MMZoomBothKey = @"MMZoomBoth"; +NSString *MMCurrentPreferencePaneKey = @"MMCurrentPreferencePane"; +NSString *MMLoginShellCommandKey = @"MMLoginShellCommand"; +NSString *MMLoginShellArgumentKey = @"MMLoginShellArgument"; +NSString *MMDialogsTrackPwdKey = @"MMDialogsTrackPwd"; + + + + +@implementation NSIndexSet (MMExtras) + ++ (id)indexSetWithVimList:(NSString *)list +{ + NSMutableIndexSet *idxSet = [NSMutableIndexSet indexSet]; + NSArray *array = [list componentsSeparatedByString:@"\n"]; + unsigned i, count = [array count]; + + for (i = 0; i < count; ++i) { + NSString *entry = [array objectAtIndex:i]; + if ([entry intValue] > 0) + [idxSet addIndex:i]; + } + + return idxSet; +} + +@end // NSIndexSet (MMExtras) + + + + +@implementation NSDocumentController (MMExtras) + +- (void)noteNewRecentFilePath:(NSString *)path +{ + NSURL *url = [NSURL fileURLWithPath:path]; + if (url) + [self noteNewRecentDocumentURL:url]; +} + +@end // NSDocumentController (MMExtras) + + + + +@implementation NSOpenPanel (MMExtras) + +- (void)hiddenFilesButtonToggled:(id)sender +{ + [self setShowsHiddenFiles:[sender intValue]]; +} + +- (void)setShowsHiddenFiles:(BOOL)show +{ + // This is undocumented stuff, so be careful. This does the same as + // [[self _navView] setShowsHiddenFiles:show]; + // but does not produce warnings. + + if (![self respondsToSelector:@selector(_navView)]) + return; + + id navView = [self performSelector:@selector(_navView)]; + if (![navView respondsToSelector:@selector(setShowsHiddenFiles:)]) + return; + + // performSelector:withObject: does not support a BOOL + NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: + [navView methodSignatureForSelector:@selector(setShowsHiddenFiles:)]]; + [invocation setTarget:navView]; + [invocation setSelector:@selector(setShowsHiddenFiles:)]; + [invocation setArgument:&show atIndex:2]; + [invocation invoke]; +} + +@end // NSOpenPanel (MMExtras) + + + + +@implementation NSMenu (MMExtras) + +- (int)indexOfItemWithAction:(SEL)action +{ + int i, count = [self numberOfItems]; + for (i = 0; i < count; ++i) { + NSMenuItem *item = [self itemAtIndex:i]; + if ([item action] == action) + return i; + } + + return -1; +} + +- (NSMenuItem *)itemWithAction:(SEL)action +{ + int idx = [self indexOfItemWithAction:action]; + return idx >= 0 ? [self itemAtIndex:idx] : nil; +} + +- (NSMenu *)findMenuContainingItemWithAction:(SEL)action +{ + // NOTE: We only look for the action in the submenus of 'self' + int i, count = [self numberOfItems]; + for (i = 0; i < count; ++i) { + NSMenu *menu = [[self itemAtIndex:i] submenu]; + NSMenuItem *item = [menu itemWithAction:action]; + if (item) return menu; + } + + return nil; +} + +- (NSMenu *)findWindowsMenu +{ + return [self findMenuContainingItemWithAction: + @selector(performMiniaturize:)]; +} + +- (NSMenu *)findApplicationMenu +{ + // TODO: Just return [self itemAtIndex:0]? + return [self findMenuContainingItemWithAction:@selector(terminate:)]; +} + +- (NSMenu *)findServicesMenu +{ + // NOTE! Our heuristic for finding the "Services" menu is to look for the + // second item before the "Hide MacVim" menu item on the "MacVim" menu. + // (The item before "Hide MacVim" should be a separator, but this is not + // important as long as the item before that is the "Services" menu.) + + NSMenu *appMenu = [self findApplicationMenu]; + if (!appMenu) return nil; + + int idx = [appMenu indexOfItemWithAction: @selector(hide:)]; + if (idx-2 < 0) return nil; // idx == -1, if selector not found + + return [[appMenu itemAtIndex:idx-2] submenu]; +} + +- (NSMenu *)findFileMenu +{ + return [self findMenuContainingItemWithAction:@selector(performClose:)]; +} + +@end // NSMenu (MMExtras) + + + + +@implementation NSToolbar (MMExtras) + +- (int)indexOfItemWithItemIdentifier:(NSString *)identifier +{ + NSArray *items = [self items]; + int i, count = [items count]; + for (i = 0; i < count; ++i) { + id item = [items objectAtIndex:i]; + if ([[item itemIdentifier] isEqual:identifier]) + return i; + } + + return NSNotFound; +} + +- (NSToolbarItem *)itemAtIndex:(int)idx +{ + NSArray *items = [self items]; + if (idx < 0 || idx >= [items count]) + return nil; + + return [items objectAtIndex:idx]; +} + +- (NSToolbarItem *)itemWithItemIdentifier:(NSString *)identifier +{ + int idx = [self indexOfItemWithItemIdentifier:identifier]; + return idx != NSNotFound ? [self itemAtIndex:idx] : nil; +} + +@end // NSToolbar (MMExtras) + + + + +@implementation NSTabView (MMExtras) + +- (void)removeAllTabViewItems +{ + NSArray *existingItems = [self tabViewItems]; + NSEnumerator *e = [existingItems objectEnumerator]; + NSTabViewItem *item; + while (item = [e nextObject]){ + [self removeTabViewItem:item]; + } +} + +@end // NSTabView (MMExtras) + + + + + NSView * +openPanelAccessoryView() +{ + // Return a new button object for each NSOpenPanel -- several of them + // could be displayed at once. + // If the accessory view should get more complex, it should probably be + // loaded from a nib file. + NSButton *button = [[[NSButton alloc] + initWithFrame:NSMakeRect(0, 0, 140, 18)] autorelease]; + [button setTitle: + NSLocalizedString(@"Show Hidden Files", @"Open File Dialog")]; + [button setButtonType:NSSwitchButton]; + + [button setTarget:nil]; + [button setAction:@selector(hiddenFilesButtonToggled:)]; + + // use the regular control size (checkbox is a bit smaller without this) + NSControlSize buttonSize = NSRegularControlSize; + float fontSize = [NSFont systemFontSizeForControlSize:buttonSize]; + NSCell *theCell = [button cell]; + NSFont *theFont = [NSFont fontWithName:[[theCell font] fontName] + size:fontSize]; + [theCell setFont:theFont]; + [theCell setControlSize:buttonSize]; + [button sizeToFit]; + + return button; +} + + + NSString * +buildTabDropCommand(NSArray *filenames) +{ + // Create a command line string that will open the specified files in tabs. + + if (!filenames || [filenames count] == 0) + return [NSString string]; + + NSMutableString *cmd = [NSMutableString stringWithString: + @":tab drop"]; + + NSEnumerator *e = [filenames objectEnumerator]; + id o; + while ((o = [e nextObject])) { + NSString *file = [o stringByEscapingSpecialFilenameCharacters]; + [cmd appendString:@" "]; + [cmd appendString:file]; + } + + [cmd appendString:@"|redr|f"]; + + return cmd; +} + + NSString * +buildSelectRangeCommand(NSRange range) +{ + // Build a command line string that will select the given range of lines. + // If range.length == 0, then position the cursor on the given line but do + // not select. + + if (range.location == NSNotFound) + return [NSString string]; + + NSString *cmd; + if (range.length > 0) { + cmd = [NSString stringWithFormat:@"%dGV%dGz.0", + NSMaxRange(range), range.location]; + } else { + cmd = [NSString stringWithFormat:@"%dGz.0", range.location]; + } + + return cmd; +} + + NSString * +buildSearchTextCommand(NSString *searchText) +{ + // TODO: Searching is an exclusive motion, so if the pattern would match on + // row 0 column 0 then this pattern will miss that match. + return [NSString stringWithFormat:@"gg/\\c%@", searchText]; +} + + + + diff --git a/src/MacVim/gui_macvim.m b/src/MacVim/gui_macvim.m index 849f4d4e..e2320f43 100644 --- a/src/MacVim/gui_macvim.m +++ b/src/MacVim/gui_macvim.m @@ -13,10 +13,10 @@ * Hooks for the Vim gui code. Mainly passes control on to MMBackend. */ -#import #import "MMBackend.h" #import "MacVim.h" #import "vim.h" +#import -- 2.11.4.GIT