Red close button indicates if any buffer is modified
[MacVim/jjgod.git] / MacVim.m
blob814faec1beadc91c0d9e4ed42aa971312d2014fa
1 /* vi:set ts=8 sts=4 sw=4 ft=objc:
2  *
3  * VIM - Vi IMproved            by Bram Moolenaar
4  *                              MacVim GUI port by Bjorn Winckler
5  *
6  * Do ":help uganda"  in Vim to read copying and usage conditions.
7  * Do ":help credits" in Vim to see a list of people who contributed.
8  * See README.txt for an overview of the Vim source code.
9  */
11 #import "MacVim.h"
13 char *MessageStrings[] = 
15     "INVALID MESSAGE ID",
16     "OpenVimWindowMsgID",
17     "InsertTextMsgID",
18     "KeyDownMsgID",
19     "CmdKeyMsgID",
20     "BatchDrawMsgID",
21     "SelectTabMsgID",
22     "CloseTabMsgID",
23     "AddNewTabMsgID",
24     "DraggedTabMsgID",
25     "UpdateTabBarMsgID",
26     "ShowTabBarMsgID",
27     "HideTabBarMsgID",
28     "SetTextDimensionsMsgID",
29     "SetWindowTitleMsgID",
30     "ScrollWheelMsgID",
31     "MouseDownMsgID",
32     "MouseUpMsgID",
33     "MouseDraggedMsgID",
34     "FlushQueueMsgID",
35     "AddMenuMsgID",
36     "AddMenuItemMsgID",
37     "RemoveMenuItemMsgID",
38     "EnableMenuItemMsgID",
39     "ExecuteMenuMsgID",
40     "ShowToolbarMsgID",
41     "ToggleToolbarMsgID",
42     "CreateScrollbarMsgID",
43     "DestroyScrollbarMsgID",
44     "ShowScrollbarMsgID",
45     "SetScrollbarPositionMsgID",
46     "SetScrollbarThumbMsgID",
47     "ScrollbarEventMsgID",
48     "SetFontMsgID",
49     "VimShouldCloseMsgID",
50     "SetDefaultColorsMsgID",
51     "ExecuteActionMsgID",
52     "DropFilesMsgID",
53     "DropStringMsgID",
54     "ShowPopupMenuMsgID",
55     "GotFocusMsgID",
56     "LostFocusMsgID",
57     "MouseMovedMsgID",
58     "SetMouseShapeMsgID",
59     "AdjustLinespaceMsgID",
60     "ActivateMsgID",
61     "SetServerNameMsgID",
62     "EnterFullscreenMsgID",
63     "LeaveFullscreenMsgID",
64     "BuffersNotModifiedMsgID",
65     "BuffersModifiedMsgID",
71 // NSUserDefaults keys
72 NSString *MMNoWindowKey                 = @"MMNoWindow";
73 NSString *MMTabMinWidthKey              = @"MMTabMinWidth";
74 NSString *MMTabMaxWidthKey              = @"MMTabMaxWidth";
75 NSString *MMTabOptimumWidthKey          = @"MMTabOptimumWidth";
76 NSString *MMTextInsetLeftKey            = @"MMTextInsetLeft";
77 NSString *MMTextInsetRightKey           = @"MMTextInsetRight";
78 NSString *MMTextInsetTopKey             = @"MMTextInsetTop";
79 NSString *MMTextInsetBottomKey          = @"MMTextInsetBottom";
80 NSString *MMTerminateAfterLastWindowClosedKey
81                                         = @"MMTerminateAfterLastWindowClosed";
82 NSString *MMTypesetterKey               = @"MMTypesetter";
83 NSString *MMCellWidthMultiplierKey      = @"MMCellWidthMultiplier";
84 NSString *MMBaselineOffsetKey           = @"MMBaselineOffset";
85 NSString *MMTranslateCtrlClickKey       = @"MMTranslateCtrlClick";
86 NSString *MMTopLeftPointKey             = @"MMTopLeftPoint";
87 NSString *MMOpenFilesInTabsKey          = @"MMOpenFilesInTabs";
92     ATSFontContainerRef
93 loadFonts()
95     // This loads all fonts from the Resources folder.  The fonts are only
96     // available to the process which loaded them, so loading has to be done
97     // once for MacVim and an additional time for each Vim process.  The
98     // returned container ref should be used to deactiave the font.
99     //
100     // (Code taken from cocoadev.com)
101     ATSFontContainerRef fontContainerRef = 0;
102     NSString *fontsFolder = [[NSBundle mainBundle] resourcePath];    
103     if (fontsFolder) {
104         NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder];
105         if (fontsURL) {
106             FSRef fsRef;
107             FSSpec fsSpec;
108             CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
110             if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec,
111                         NULL) == noErr) {
112                 ATSFontActivateFromFileSpecification(&fsSpec,
113                         kATSFontContextLocal, kATSFontFormatUnspecified, NULL,
114                         kATSOptionFlagsDefault, &fontContainerRef);
115             }
116         }
117     }
119     return fontContainerRef;
125 @implementation NSString (MMExtras)
127 - (NSString *)stringByEscapingPercent
129     NSMutableString *string = [self mutableCopy];
131     // Some '%' may already be escaped, so un-escape first...
132     [string replaceOccurrencesOfString:@"\\%"
133                             withString:@"%"
134                                options:NSLiteralSearch
135                                  range:NSMakeRange(0, [string length])];
136     // ...then escape all '%'
137     [string replaceOccurrencesOfString:@"%"
138                             withString:@"\\%"
139                                options:NSLiteralSearch
140                                  range:NSMakeRange(0, [string length])];
142     return [string autorelease];
145 - (NSString *)stringByEscapingSpace
147     NSMutableString *string = [self mutableCopy];
149     // Some space chars may already be escaped, so un-escape first...
150     [string replaceOccurrencesOfString:@"\\ "
151                             withString:@" "
152                                options:NSLiteralSearch
153                                  range:NSMakeRange(0, [string length])];
154     // ...then escape all space chars
155     [string replaceOccurrencesOfString:@" "
156                             withString:@"\\ "
157                                options:NSLiteralSearch
158                                  range:NSMakeRange(0, [string length])];
160     return [string autorelease];
163 - (NSString *)stringByEscapingInvalidFilenameCharacters
165     return [[self stringByEscapingSpace] stringByEscapingPercent];
169 @end // NSString (MMExtras)