Code cleanup.

git-svn-id: http://macvim.googlecode.com/svn/trunk@101 96c4425d-ca35-0410-94e5-3396d5c13a8f
This commit is contained in:
Bjorn Winckler
2007-08-08 09:58:41 +00:00
parent ff164a8637
commit 6c59edb93e
13 changed files with 43 additions and 779 deletions
+1 -9
View File
@@ -26,17 +26,9 @@ extern NSString *MMTerminateAfterLastWindowClosed;
@interface MMAppController : NSObject
#if MM_USE_DO
<MMAppProtocol>
#endif
@interface MMAppController : NSObject <MMAppProtocol>
{
NSMutableArray *vimControllers;
#if !MM_USE_DO
NSPort *receivePort;
unsigned terminateNowCount;
BOOL abortTermination;
#endif
}
- (void)removeVimController:(id)controller;
-122
View File
@@ -74,7 +74,6 @@ NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed";
if ((self = [super init])) {
vimControllers = [NSMutableArray new];
#if MM_USE_DO
// NOTE! If the name of the connection changes here it must also be
// updated in MMBackend.m.
NSConnection *connection = [NSConnection defaultConnection];
@@ -92,24 +91,6 @@ NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed";
NSLog(@"WARNING: Failed to register connection with name '%@'",
name);
}
#else
// Init named port for VimTasks to connect to
receivePort = [NSMachPort new];
[receivePort setDelegate:self];
[[NSRunLoop currentRunLoop] addPort:receivePort
forMode:NSDefaultRunLoopMode];
// NOTE! If the name of the port changes here it must also be updated
// in MMBackend.m.
NSString *portName = [NSString stringWithFormat:@"%@-taskport",
[[NSBundle mainBundle] bundleIdentifier]];
//NSLog(@"Starting mach bootstrap server: %@", portName);
if (![[NSMachBootstrapServer sharedInstance] registerPort:receivePort
name:portName]) {
NSLog(@"WARNING: Failed to start mach bootstrap server");
}
#endif
}
return self;
@@ -119,9 +100,6 @@ NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed";
{
//NSLog(@"MMAppController dealloc");
#if !MM_USE_DO
[receivePort release];
#endif
[vimControllers release];
[super dealloc];
@@ -209,7 +187,6 @@ NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed";
- (NSApplicationTerminateReply)applicationShouldTerminate:
(NSApplication *)sender
{
#if MM_USE_DO
int reply = NSTerminateNow;
BOOL modifiedBuffers = NO;
@@ -240,58 +217,6 @@ NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed";
}
return reply;
#else
int reply = NSTerminateNow;
// HACK! Send message to all vim tasks asking if they have modified
// buffers, then hang around for a while waiting for responses to come
// back. If any task has at least one modified buffer an alert dialog is
// displayed telling the user that there are modified buffers. The user
// can then choose whether to quit anyway, or cancel the termination.
// (NSTerminateLater is not supported.)
terminateNowCount = 0;
abortTermination = NO;
unsigned i, count = [vimControllers count];
for (i = 0; i < count; ++i) {
MMVimController *controller = [vimControllers objectAtIndex:i];
[NSPortMessage sendMessage:TaskShouldTerminateMsgID
withSendPort:[controller sendPort]
receivePort:receivePort
wait:NO];
}
NSDate *timeOutDate = [NSDate dateWithTimeIntervalSinceNow:15];
while (terminateNowCount < count && !abortTermination &&
NSOrderedDescending == [timeOutDate compare:[NSDate date]]) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:timeOutDate];
}
//NSLog(@"%s terminateNowCount=%d abortTermination=%s", _cmd,
// terminateNowCount, abortTermination ? "YES" : "NO");
if (abortTermination) {
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"Quit"];
[alert addButtonWithTitle:@"Cancel"];
[alert setMessageText:@"Quit without saving?"];
[alert setInformativeText:@"There are modified buffers, "
" if you quit now all changes will be lost. Quit anyway?"];
[alert setAlertStyle:NSWarningAlertStyle];
if ([alert runModal] != NSAlertFirstButtonReturn) {
reply = NSTerminateCancel;
}
[alert release];
} else if (terminateNowCount < count) {
NSLog(@"WARNING: Not all tasks replied to TaskShouldTerminateMsgID,"
" quitting anyway.");
}
return reply;
#endif
}
- (void)applicationWillTerminate:(NSNotification *)aNotification
@@ -301,27 +226,6 @@ NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed";
[self autorelease];
}
#if !MM_USE_DO
- (void)handlePortMessage:(NSPortMessage *)portMessage
{
unsigned msgid = [portMessage msgid];
if (msgid == CheckinMsgID) {
//NSLog(@"Received checkin message from VimTask.");
MMVimController *wc = [[MMVimController alloc]
initWithPort:[portMessage sendPort]];
[vimControllers addObject:wc];
[wc release];
} else if (msgid == TerminateReplyYesMsgID) {
++terminateNowCount;
} else if (msgid == TerminateReplyNoMsgID) {
abortTermination = YES;
} else {
NSLog(@"WARNING: Unknown message received (msgid=%d)", msgid);
}
}
#endif
- (void)removeVimController:(id)controller
{
[vimControllers removeObject:controller];
@@ -350,15 +254,6 @@ NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed";
- (IBAction)selectNextWindow:(id)sender
{
#if 0
NSArray *windows = [NSApp orderedWindows];
unsigned idx = [windows indexOfObject:[NSApp keyWindow]];
if (NSNotFound != idx) {
if (++idx >= [windows count])
idx = 0;
[[windows objectAtIndex:idx] makeKeyAndOrderFront:self];
}
#else
unsigned i, count = [vimControllers count];
if (!count) return;
@@ -375,23 +270,10 @@ NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed";
MMVimController *vc = [vimControllers objectAtIndex:i];
[[vc windowController] showWindow:self];
}
#endif
}
- (IBAction)selectPreviousWindow:(id)sender
{
#if 0
NSArray *windows = [NSApp orderedWindows];
unsigned idx = [windows indexOfObject:[NSApp keyWindow]];
if (NSNotFound != idx) {
if (idx > 0) {
--idx;
} else {
idx = [windows count] - 1;
}
[[windows objectAtIndex:idx] makeKeyAndOrderFront:self];
}
#else
unsigned i, count = [vimControllers count];
if (!count) return;
@@ -411,11 +293,8 @@ NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed";
MMVimController *vc = [vimControllers objectAtIndex:i];
[[vc windowController] showWindow:self];
}
#endif
}
#if MM_USE_DO
- (byref id <MMFrontendProtocol>)connectBackend:
(byref in id <MMBackendProtocol>)backend;
{
@@ -435,7 +314,6 @@ NSString *MMTerminateAfterLastWindowClosed = @"terminateafterlastwindowclosed";
return wc;
}
#endif
@end // MMAppController
+1 -10
View File
@@ -13,22 +13,13 @@
@interface MMBackend : NSObject
#if MM_USE_DO
<MMBackendProtocol>
#endif
@interface MMBackend : NSObject <MMBackendProtocol>
{
NSMutableArray *queue;
NSMutableData *drawData;
#if MM_USE_DO
NSConnection *connection;
id frontendProxy;
NSString *browseForFileString;
#else
NSPort *sendPort;
NSPort *receivePort;
NSData *replyData;
#endif
NSDictionary *colorDict;
BOOL inputReceived;
BOOL receivedKillTaskMsg;
+9 -219
View File
@@ -26,9 +26,7 @@ static int specialKeyToNSKey(int key);
+ (NSDictionary *)specialKeys;
- (void)handleKeyDown:(NSString *)key modifiers:(int)mods;
- (void)queueMessage:(int)msgid data:(NSData *)data;
#if MM_USE_DO
- (void)connectionDidDie:(NSNotification *)notification;
#endif
@end
@@ -60,13 +58,8 @@ static int specialKeyToNSKey(int key);
[queue release];
[drawData release];
#if MM_USE_DO
[frontendProxy release];
[connection release];
#else
[sendPort release];
[receivePort release];
#endif
[colorDict release];
[super dealloc];
@@ -99,24 +92,12 @@ static int specialKeyToNSKey(int key);
{
NSBundle *mainBundle = [NSBundle mainBundle];
#if MM_USE_DO
// NOTE! If the name of the connection changes here it must also be
// updated in MMAppController.m.
NSString *name = [NSString stringWithFormat:@"%@-connection",
[mainBundle bundleIdentifier]];
connection = [NSConnection connectionWithRegisteredName:name host:nil];
if (!connection)
#else
// NOTE! If the name of the port changes here it must also be updated in
// MMAppController.m.
NSString *portName = [NSString stringWithFormat:@"%@-taskport",
[mainBundle bundleIdentifier]];
NSPort *port = [[[NSMachBootstrapServer sharedInstance]
portForName:portName host:nil] retain];
if (!port)
#endif
{
if (!connection) {
#if 0
NSString *path = [mainBundle bundlePath];
if (![[NSWorkspace sharedWorkspace] launchApplication:path]) {
@@ -147,41 +128,26 @@ static int specialKeyToNSKey(int key);
// HACK! The NSWorkspaceDidLaunchApplicationNotification does not work
// for tasks like this, so poll the mach bootstrap server until it
// returns a valid port. Also set a time-out date so that we don't get
// stuck doing this forever.
// returns a valid connection. Also set a time-out date so that we
// don't get stuck doing this forever.
NSDate *timeOutDate = [NSDate dateWithTimeIntervalSinceNow:15];
while (
#if MM_USE_DO
!connection
#else
!port
#endif
&& NSOrderedDescending == [timeOutDate compare:[NSDate date]])
while (!connection &&
NSOrderedDescending == [timeOutDate compare:[NSDate date]])
{
[[NSRunLoop currentRunLoop]
runMode:NSDefaultRunLoopMode
beforeDate:[NSDate dateWithTimeIntervalSinceNow:1]];
#if MM_USE_DO
connection = [NSConnection connectionWithRegisteredName:name
host:nil];
#else
port = [[NSMachBootstrapServer sharedInstance]
portForName:portName];
#endif
}
#if MM_USE_DO
if (!connection)
#else
if (!port)
#endif
{
if (!connection) {
NSLog(@"WARNING: Timed-out waiting for GUI to launch.");
return NO;
}
}
#if MM_USE_DO
id proxy = [connection rootProxy];
[proxy setProtocolForProxy:@protocol(MMAppProtocol)];
@@ -195,49 +161,10 @@ static int specialKeyToNSKey(int key);
}
return connection && frontendProxy;
#else
receivePort = [NSMachPort new];
[receivePort setDelegate:self];
[[NSRunLoop currentRunLoop] addPort:receivePort
forMode:NSDefaultRunLoopMode];
[NSPortMessage sendMessage:CheckinMsgID withSendPort:port
receivePort:receivePort wait:YES];
return YES;
#endif
}
- (BOOL)openVimWindow
{
#if !MM_USE_DO
if (!sendPort) {
#if 0
// TODO: Wait until connected---maybe time out at some point?
// Note that if we return 'NO' Vim will be started in terminal mode
// (i.e. output goes to stdout).
NSLog(@"WARNING: Trying to open VimWindow but sendPort==nil;"
" waiting for connected message.");
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]];
if (!sendPort)
return NO;
#else
// Wait until the sendPort has actually been set.
//
// TODO: Come up with a more elegant solution to this problem---this
// message should not be called before the sendPort has been
// initialized.
while (!sendPort) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]];
}
#endif
}
#endif // !MM_USE_DO
[self queueMessage:OpenVimWindowMsgID data:nil];
return YES;
}
@@ -332,26 +259,13 @@ static int specialKeyToNSKey(int key);
// TODO: Come up with a better way to handle the insertion point.
[self updateInsertionPoint];
#if MM_USE_DO
[frontendProxy processCommandQueue:queue];
#else
[NSPortMessage sendMessage:FlushQueueMsgID withSendPort:sendPort
components:queue wait:YES];
#endif
[queue removeAllObjects];
}
}
- (BOOL)waitForInput:(int)milliseconds
{
#if !MM_USE_DO
if (![receivePort isValid]) {
// This should only happen if the GUI crashes.
NSLog(@"ERROR: The receive port is no longer valid, quitting...");
getout(0);
}
#endif
NSDate *date = milliseconds > 0 ?
[NSDate dateWithTimeIntervalSinceNow:.001*milliseconds] :
[NSDate distantFuture];
@@ -360,7 +274,7 @@ static int specialKeyToNSKey(int key);
// I know of no way to figure out if the run loop exited because input was
// found or because of a time out, so I need to manually indicate when
// input was received in handlePortMessage and then reset it every time
// input was received in processInput:data: and then reset it every time
// here.
BOOL yn = inputReceived;
inputReceived = NO;
@@ -370,18 +284,11 @@ static int specialKeyToNSKey(int key);
- (void)exit
{
#if MM_USE_DO
// By invalidating the NSConnection the MMWindowController immediately
// finds out that the connection is down and as a result
// [MMWindowController connectionDidDie:] is invoked.
[[NSNotificationCenter defaultCenter] removeObserver:self];
[connection invalidate];
#else
if (!receivedKillTaskMsg) {
[NSPortMessage sendMessage:TaskExitedMsgID withSendPort:sendPort
receivePort:receivePort wait:YES];
}
#endif
}
- (void)selectTab:(int)index
@@ -455,7 +362,6 @@ static int specialKeyToNSKey(int key);
[self queueMessage:SetVimWindowTitleMsgID data:data];
}
#if MM_USE_DO
- (oneway void)setBrowseForFileString:(in bycopy NSString *)string
{
// NOTE: This is called by [MMVimController panelDidEnd:::] to indicate
@@ -463,7 +369,6 @@ static int specialKeyToNSKey(int key);
// the user pressed cancel.
browseForFileString = string ? [string copy] : nil;
}
#endif
- (char *)browseForFileInDirectory:(char *)dir title:(char *)title
saving:(int)saving
@@ -471,7 +376,6 @@ static int specialKeyToNSKey(int key);
//NSLog(@"browseForFileInDirectory:%s title:%s saving:%d", dir, title,
// saving);
#if MM_USE_DO
NSString *ds = dir
? [NSString stringWithCString:dir encoding:NSUTF8StringEncoding]
: nil;
@@ -490,48 +394,6 @@ static int specialKeyToNSKey(int key);
[browseForFileString release]; browseForFileString = nil;
return (char *)s;
#else
NSMutableData *data = [NSMutableData data];
[data appendBytes:&saving length:sizeof(int)];
int len = dir ? strlen(dir) : 0;
[data appendBytes:&len length:sizeof(int)];
if (len > 0)
[data appendBytes:dir length:len];
len = title ? strlen(title) : 0;
[data appendBytes:&len length:sizeof(int)];
if (len > 0)
[data appendBytes:title length:len];
if (![NSPortMessage sendMessage:BrowseForFileMsgID withSendPort:sendPort
data:data wait:YES])
return nil;
// Wait until a reply is sent from MMVimController.
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate distantFuture]];
// Something went wrong if replyData is nil.
if (!replyData)
return nil;
const void *bytes = [replyData bytes];
int ok = *((int*)bytes); bytes += sizeof(int);
len = *((int*)bytes); bytes += sizeof(int);
char_u *s = NULL;
if (ok && len > 0) {
NSString *name = [[NSString alloc] initWithBytes:(void*)bytes
length:len encoding:NSUTF8StringEncoding];
s = vim_strsave((char_u*)[name UTF8String]);
[name release];
}
[replyData release]; replyData = nil;
return (char*)s;
#endif // MM_USE_DO
}
- (void)updateInsertionPoint
@@ -791,7 +653,6 @@ static int specialKeyToNSKey(int key);
return INVALCOLOR;
}
#if MM_USE_DO
- (oneway void)processInput:(int)msgid data:(in NSData *)data
{
[self handleMessage:msgid data:data];
@@ -851,39 +712,6 @@ static int specialKeyToNSKey(int key);
return NO;
}
#else // MM_USE_DO
- (void)handlePortMessage:(NSPortMessage *)portMessage
{
unsigned msgid = [portMessage msgid];
if (ConnectedMsgID == msgid) {
sendPort = [[portMessage sendPort] retain];
//NSLog(@"VimTask connected to MMVimController.");
} else if (TaskShouldTerminateMsgID == msgid) {
int reply = TerminateReplyYesMsgID;
buf_T *buf;
for (buf = firstbuf; buf != NULL; buf = buf->b_next) {
if (bufIsChanged(buf)) {
reply = TerminateReplyNoMsgID;
break;
}
}
//NSLog(@"TaskShouldTerminateMsgID = %s",
// reply == TerminateReplyYesMsgID ? "YES" : "NO");
[NSPortMessage sendMessage:reply withSendPort:[portMessage sendPort]
wait:YES];
} else {
NSArray *components = [portMessage components];
NSData *data = [components count] > 0 ?
[components objectAtIndex:0] : nil;
[self handleMessage:msgid data:data];
}
}
#endif // MM_USE_DO
@end // MMBackend
@@ -906,8 +734,6 @@ static int specialKeyToNSKey(int key);
add_to_input_buf((char_u*)[key UTF8String],
[key lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
[key release];
inputReceived = YES;
} else if (KeyDownMsgID == msgid || CmdKeyMsgID == msgid) {
if (!data) return;
const void *bytes = [data bytes];
@@ -920,25 +746,21 @@ static int specialKeyToNSKey(int key);
[self handleKeyDown:key modifiers:mods];
[key release];
inputReceived = YES;
} else if (SelectTabMsgID == msgid) {
if (!data) return;
const void *bytes = [data bytes];
int idx = *((int*)bytes) + 1;
//NSLog(@"Selecting tab %d", idx);
send_tabline_event(idx);
inputReceived = YES;
} else if (CloseTabMsgID == msgid) {
if (!data) return;
const void *bytes = [data bytes];
int idx = *((int*)bytes) + 1;
//NSLog(@"Closing tab %d", idx);
send_tabline_menu_event(idx, TABLINE_MENU_CLOSE);
inputReceived = YES;
} else if (AddNewTabMsgID == msgid) {
//NSLog(@"Adding new tab");
send_tabline_menu_event(0, TABLINE_MENU_NEW);
inputReceived = YES;
} else if (DraggedTabMsgID == msgid) {
if (!data) return;
const void *bytes = [data bytes];
@@ -946,21 +768,7 @@ static int specialKeyToNSKey(int key);
// based.
int idx = *((int*)bytes);
#if 0
tabpage_T *tp = find_tabpage(oldIdx);
if (tp) {
// HACK! tabpage_move(idx) moves 'curtab' to 'idx', but since it
// is also possible to drag tabs which are not selected we must
// first set 'curtab' to the tab that was actually dragged and then
// reset 'curtab' to what it used to be.
tabpage_T *oldcur = curtab;
curtab = tp;
tabpage_move(idx);
curtab = oldcur;
}
#else
tabpage_move(idx);
#endif
} else if (ScrollWheelMsgID == msgid) {
if (!data) return;
const void *bytes = [data bytes];
@@ -976,7 +784,6 @@ static int specialKeyToNSKey(int key);
flags = eventModifierFlagsToVimMouseModMask(flags);
gui_send_mouse_event(button, col, row, NO, flags);
inputReceived = YES;
} else if (MouseDownMsgID == msgid) {
if (!data) return;
const void *bytes = [data bytes];
@@ -991,8 +798,6 @@ static int specialKeyToNSKey(int key);
flags = eventModifierFlagsToVimMouseModMask(flags);
gui_send_mouse_event(button, col, row, 0 != count, flags);
inputReceived = YES;
} else if (MouseUpMsgID == msgid) {
if (!data) return;
const void *bytes = [data bytes];
@@ -1004,7 +809,6 @@ static int specialKeyToNSKey(int key);
flags = eventModifierFlagsToVimMouseModMask(flags);
gui_send_mouse_event(MOUSE_RELEASE, col, row, NO, flags);
inputReceived = YES;
} else if (MouseDraggedMsgID == msgid) {
if (!data) return;
const void *bytes = [data bytes];
@@ -1016,16 +820,7 @@ static int specialKeyToNSKey(int key);
flags = eventModifierFlagsToVimMouseModMask(flags);
gui_send_mouse_event(MOUSE_DRAG, col, row, NO, flags);
inputReceived = YES;
}
#if !MM_USE_DO
else if (BrowseForFileReplyMsgID == msgid) {
if (!data) return;
[replyData release];
replyData = [data copy];
}
#endif
else if (SetTextDimensionsMsgID == msgid) {
} else if (SetTextDimensionsMsgID == msgid) {
if (!data) return;
const void *bytes = [data bytes];
int rows = *((int*)bytes); bytes += sizeof(int);
@@ -1048,7 +843,6 @@ static int specialKeyToNSKey(int key);
// TODO! Make sure 'menu' is a valid menu pointer!
if (menu) {
gui_menu_cb(menu);
inputReceived = YES;
}
} else if (ScrollbarEventMsgID == msgid) {
if (!data) return;
@@ -1111,8 +905,6 @@ static int specialKeyToNSKey(int key);
identifier:ident];
}
}
inputReceived = YES;
}
} else if (VimShouldCloseMsgID == msgid) {
gui_shell_closed();
@@ -1292,7 +1084,6 @@ static int specialKeyToNSKey(int key);
[queue addObject:[NSData data]];
}
#if MM_USE_DO
- (void)connectionDidDie:(NSNotification *)notification
{
// If the main connection to MacVim is lost this means that MacVim was
@@ -1303,7 +1094,6 @@ static int specialKeyToNSKey(int key);
//NSLog(@"A Vim process lots its connection to MacVim; quitting.");
getout(0);
}
#endif // MM_USE_DO
@end // MMBackend (Private)
-3
View File
@@ -11,15 +11,12 @@
#import <Cocoa/Cocoa.h>
#define MM_TS_LAZY_SET 1
@interface MMTextStorage : NSTextStorage {
NSMutableAttributedString *attribString;
int maxRows, maxColumns;
#if MM_TS_LAZY_SET
int actualRows, actualColumns;
#endif
NSAttributedString *emptyRowString;
NSFont *font;
NSColor *defaultBackgroundColor;
-92
View File
@@ -23,18 +23,12 @@
//static float LINEHEIGHT = 30.0f;
#define MM_SIMPLE_TS_CALC 1
#if MM_TS_LAZY_SET
# define MM_SIMPLE_TS_CALC 1
#endif
@interface MMTextStorage (Private)
#if MM_TS_LAZY_SET
- (void)doSetMaxRows:(int)rows columns:(int)cols;
- (void)lazyResize;
#endif
- (float)cellWidth;
- (float)widthOfEmptyRow;
@end
@@ -129,12 +123,8 @@
- (void)setMaxRows:(int)rows columns:(int)cols
{
#if MM_TS_LAZY_SET
maxRows = rows;
maxColumns = cols;
#else
[self doSetMaxRows:rows columns:cols];
#endif
}
- (void)replaceString:(NSString*)string atRow:(int)row column:(int)col
@@ -356,48 +346,17 @@
{
// NOTE: Foreground color is ignored.
[defaultBackgroundColor release];
#if 0
if (bgColor) {
defaultBackgroundColor = [bgColor retain];
#if 1
NSMutableAttributedString *string = [emptyRowString mutableCopy];
[string addAttribute:NSBackgroundColorAttributeName value:bgColor
range:NSMakeRange(0, [emptyRowString length])];
[emptyRowString release];
emptyRowString = string;
#endif
[self clearAllWithColor:bgColor];
} else {
defaultBackgroundColor = nil;
}
#else
defaultBackgroundColor = bgColor ? [bgColor retain] : nil;
#endif
}
- (void)setFont:(NSFont*)newFont
{
#if 0
if (font != newFont) {
//NSLog(@"Changing font from %@ to %@", font, newFont);
[font release];
font = [newFont retain];
NSRange range = { 0, [attribString length] };
[attribString addAttribute:NSFontAttributeName value:font
range:range];
[self setDefaultFg:norm_pixel bg:gui.back_pixel];
[self edited:NSTextStorageEditedAttributes range:range
changeInLength:0];
}
#else
if (newFont && font != newFont) {
//NSLog(@"Setting font %@", newFont);
[font release];
font = [newFont retain];
// TODO! Change paragraph style to match line height of new font
}
#endif
}
- (NSFont*)font
@@ -410,24 +369,8 @@
if (![[self layoutManagers] count]) return NSZeroSize;
NSLayoutManager *lm = [[self layoutManagers] objectAtIndex:0];
#if MM_SIMPLE_TS_CALC
float h = [lm defaultLineHeightForFont:font];
NSSize size = NSMakeSize([self cellWidth]*maxColumns, h*maxRows);
#else
if (![[lm textContainers] count]) return NSZeroSize;
NSTextContainer *tc = [[lm textContainers] objectAtIndex:0];
NSRange range = [lm glyphRangeForTextContainer:tc];
NSRect rect = [lm boundingRectForGlyphRange:range inTextContainer:tc];
//[lm glyphRangeForTextContainer:tc];
//NSRect rect = [lm usedRectForTextContainer:tc];
NSSize size = NSMakeSize([self widthOfEmptyRow], rect.size.height);
//NSSize size = NSMakeSize([self widthOfEmptyRow], maxRows*LINEHEIGHT);
//NSLog(@"size=(%.2f,%.2f) rows=%d cols=%d layoutManager size=(%.2f,%.2f)",
// size.width, size.height, maxRows, maxColumns, rect.size.width,
// rect.size.height);
#endif
return size;
}
@@ -519,11 +462,6 @@
if (![[self layoutManagers] count]) return size;
NSLayoutManager *lm = [[self layoutManagers] objectAtIndex:0];
#if !MM_SIMPLE_TS_CALC
if (![[lm textContainers] count]) return size;
NSTextContainer *tc = [[lm textContainers] objectAtIndex:0];
#endif
NSSize curSize = [self size];
NSSize fitSize = curSize;
int fitRows = maxRows;
@@ -535,7 +473,6 @@
// text storage. (Why 3? It seem Vim never allows less than 3 lines.)
//
// TODO: Use binary search instead of the current linear one.
#if MM_TS_LAZY_SET
int rowCount = maxRows;
int rowsToRemove;
for (rowsToRemove = 0; rowsToRemove < maxRows-3; ++rowsToRemove) {
@@ -548,23 +485,6 @@
--rowCount;
}
#else
NSRange charRange = { 0, maxRows*(maxColumns+1) };
int rowsToRemove;
for (rowsToRemove = 0; rowsToRemove < maxRows-3; ++rowsToRemove) {
NSRange glyphRange = [lm glyphRangeForCharacterRange:charRange
actualCharacterRange:nil];
float height = [lm boundingRectForGlyphRange:glyphRange
inTextContainer:tc].size.height;
if (height <= size.height) {
fitSize.height = height;
break;
}
charRange.length -= (maxColumns+1);
}
#endif
fitRows -= rowsToRemove;
} else if (size.height > curSize.height) {
@@ -595,32 +515,22 @@
@implementation MMTextStorage (Private)
#if MM_TS_LAZY_SET
- (void)lazyResize
{
if (actualRows != maxRows || actualColumns != maxColumns) {
[self doSetMaxRows:maxRows columns:maxColumns];
}
}
#endif // MM_TS_LAZY_SET
- (void)doSetMaxRows:(int)rows columns:(int)cols
{
int i;
#if MM_TS_LAZY_SET
// Do nothing if the dimensions are already right.
if (actualRows == rows && actualColumns == cols)
return;
NSRange oldRange = NSMakeRange(0, actualRows*(actualColumns+1));
#else
// Do nothing if the dimensions are already right.
if (maxRows == rows && maxColumns == cols)
return;
NSRange oldRange = NSMakeRange(0, maxRows*(maxColumns+1));
#endif
maxRows = rows;
maxColumns = cols;
@@ -655,9 +565,7 @@
[self edited:(NSTextStorageEditedCharacters|NSTextStorageEditedAttributes)
range:oldRange changeInLength:fullRange.length-oldRange.length];
#if MM_TS_LAZY_SET
actualRows = rows; actualColumns = cols;
#endif
}
- (float)cellWidth
-13
View File
@@ -132,16 +132,6 @@
range.length);
}
#if 0
- (IBAction)copy:(id)sender
{
}
- (IBAction)paste:(id)sender
{
}
#endif
- (void)scrollWheel:(NSEvent *)event
{
if ([event deltaY] == 0)
@@ -259,7 +249,6 @@
}
#endif
#if 1
- (NSArray *)acceptableDragTypes
{
return [NSArray arrayWithObjects:NSFilenamesPboardType,
@@ -345,8 +334,6 @@
return NSDragOperationNone;
}
#endif
@end // MMTextView
+1 -16
View File
@@ -15,22 +15,12 @@
@interface MMVimController : NSObject
#if MM_USE_DO
<MMFrontendProtocol>
#endif
@interface MMVimController : NSObject <MMFrontendProtocol>
{
MMWindowController *windowController;
#if MM_USE_DO
id backendProxy;
# if MM_DELAY_SEND_IN_PROCESS_CMD_QUEUE
BOOL inProcessCommandQueue;
NSMutableArray *sendQueue;
# endif
#else
NSPort *sendPort;
NSPort *receivePort;
#endif
NSMutableArray *mainMenuItems;
BOOL shouldUpdateMainMenu;
//NSMutableArray *popupMenus;
@@ -38,13 +28,8 @@
NSMutableDictionary *toolbarItemDict;
}
#if MM_USE_DO
- (id)initWithBackend:(id)backend;
- (id)backendProxy;
#else
- (id)initWithPort:(NSPort *)port;
- (NSPort *)sendPort;
#endif
- (MMWindowController *)windowController;
- (void)windowWillClose:(NSNotification *)notification;
- (void)sendMessage:(int)msgid data:(NSData *)data wait:(BOOL)wait;
+4 -152
View File
@@ -40,9 +40,7 @@ static NSString *DefaultToolbarImageName = @"Attention";
- (void)addToolbarItemWithTag:(int)tag label:(NSString *)label
tip:(NSString *)tip icon:(NSString *)icon
atIndex:(int)idx;
#if MM_USE_DO
- (void)connectionDidDie:(NSNotification *)notification;
#endif
- (BOOL)executeActionWithName:(NSString *)name;
@end
@@ -79,50 +77,20 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
@implementation MMVimController
#if MM_USE_DO
- (id)initWithBackend:(id)backend
#else
- (id)initWithPort:(NSPort *)port
#endif
{
if ((self = [super init])) {
windowController =
[[MMWindowController alloc] initWithVimController:self];
#if MM_USE_DO
backendProxy = [backend retain];
# if MM_DELAY_SEND_IN_PROCESS_CMD_QUEUE
sendQueue = [NSMutableArray new];
# endif
mainMenuItems = [[NSMutableArray alloc] init];
toolbarItemDict = [[NSMutableDictionary alloc] init];
NSConnection *connection = [backendProxy connectionForProxy];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(connectionDidDie:)
name:NSConnectionDidDieNotification object:connection];
#else
sendPort = [port retain];
// Init receive port and send connected message to VimTask
receivePort = [NSMachPort new];
[receivePort setDelegate:self];
// Add to the default run loop mode as well as the event tracking mode;
// the latter ensures that updates from the VimTask reaches
// MMVimController whilst the user resizes a window with the mouse.
[[NSRunLoop currentRunLoop] addPort:receivePort
forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] addPort:receivePort
forMode:NSEventTrackingRunLoopMode];
[NSPortMessage sendMessage:ConnectedMsgID withSendPort:sendPort
receivePort:receivePort wait:YES];
#endif
mainMenuItems = [[NSMutableArray alloc] init];
toolbarItemDict = [[NSMutableDictionary alloc] init];
//[self addToolbarItemToDictionaryWithTag:0 label:@"Attention"
// toolTip:@"A toolbar item is missing"
// icon:@"Attention"];
}
return self;
@@ -134,21 +102,8 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
[[NSNotificationCenter defaultCenter] removeObserver:self];
#if MM_USE_DO
[backendProxy release];
# if MM_DELAY_SEND_IN_PROCESS_CMD_QUEUE
[sendQueue release];
# endif
#else
if (sendPort) {
// Kill task immediately
[NSPortMessage sendMessage:KillTaskMsgID withSendPort:sendPort
receivePort:receivePort wait:NO];
}
[sendPort release];
[receivePort release];
#endif
[toolbarItemDict release];
[toolbar release];
@@ -165,8 +120,6 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
- (void)sendMessage:(int)msgid data:(NSData *)data wait:(BOOL)wait
{
#if MM_USE_DO
# if MM_DELAY_SEND_IN_PROCESS_CMD_QUEUE
if (inProcessCommandQueue) {
//NSLog(@"In process command queue; delaying message send.");
[sendQueue addObject:[NSNumber numberWithInt:msgid]];
@@ -176,7 +129,7 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
[sendQueue addObject:[NSNull null]];
return;
}
# endif
if (wait) {
[backendProxy processInput:msgid data:data];
} else {
@@ -198,13 +151,8 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
}
}
}
#else
[NSPortMessage sendMessage:msgid withSendPort:sendPort data:data
wait:wait];
#endif
}
#if MM_USE_DO
- (id)backendProxy
{
return backendProxy;
@@ -242,9 +190,7 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
return;
}
#if MM_DELAY_SEND_IN_PROCESS_CMD_QUEUE
inProcessCommandQueue = YES;
#endif
//NSLog(@"======== %s BEGIN ========", _cmd);
for (i = 0; i < count; i += 2) {
@@ -267,7 +213,6 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
[self updateMainMenu];
}
#if MM_DELAY_SEND_IN_PROCESS_CMD_QUEUE
inProcessCommandQueue = NO;
count = [sendQueue count];
@@ -287,53 +232,8 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
[sendQueue removeAllObjects];
}
#endif
}
#else // MM_USE_DO
- (NSPort *)sendPort
{
return sendPort;
}
- (void)handlePortMessage:(NSPortMessage *)portMessage
{
//NSLog(@"%@ %s %@", [self className], _cmd, portMessage);
NSArray *components = [portMessage components];
unsigned msgid = [portMessage msgid];
//NSLog(@"%s%d", _cmd, msgid);
if (FlushQueueMsgID == msgid) {
unsigned i, count = [components count];
if (count % 2) {
NSLog(@"WARNING: Uneven number of components (%d) in flush queue "
"message; ignoring this message.", count);
return;
}
for (i = 0; i < count; i += 2) {
NSData *value = [components objectAtIndex:i];
NSData *data = [components objectAtIndex:i+1];
[self handleMessage:*((int*)[value bytes]) data:data];
}
} else {
NSData *data = nil;
if ([components count] > 0)
data = [components objectAtIndex:0];
[self handleMessage:msgid data:data];
}
if (shouldUpdateMainMenu) {
[self updateMainMenu];
}
}
#endif // MM_USE_DO
- (void)windowWillClose:(NSNotification *)notification
{
// NOTE! This causes the call to removeVimController: to be delayed.
@@ -385,23 +285,7 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
if (OpenVimWindowMsgID == msgid) {
[windowController openWindow];
}
#if !MM_USE_DO
else if (TaskExitedMsgID == msgid) {
//NSLog(@"Received task exited message from VimTask; closing window.");
// Release sendPort immediately to avoid dealloc trying to send a 'kill
// task' message to the task.
[sendPort release]; sendPort = nil;
// NOTE! This causes windowWillClose: to be called, which in turn asks
// the MMAppController to remove this MMVimController.
[windowController close];
// HACK! Make sure no menu updating is done, we're about to close.
shouldUpdateMainMenu = NO;
}
#endif // !MM_USE_DO
else if (BatchDrawMsgID == msgid) {
} else if (BatchDrawMsgID == msgid) {
//NSLog(@"Received batch draw message from VimTask.");
[self performBatchDrawWithData:data];
@@ -438,18 +322,8 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
const void *bytes = [data bytes];
int len = *((int*)bytes); bytes += sizeof(int);
#if 0
// BUG! Using this call leads to ALL windows getting the same title
// and then the app crashes if you :q a window.
NSString *string = [[NSString alloc]
initWithBytesNoCopy:(void*)bytes
length:len
encoding:NSUTF8StringEncoding
freeWhenDone:NO];
#else
NSString *string = [[NSString alloc] initWithBytes:(void*)bytes
length:len encoding:NSUTF8StringEncoding];
#endif
[[windowController window] setTitle:string];
@@ -802,30 +676,10 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
- (void)panelDidEnd:(NSSavePanel *)panel code:(int)code context:(void *)context
{
#if MM_USE_DO
[windowController setStatusText:@""];
NSString *string = (code == NSOKButton) ? [panel filename] : nil;
[backendProxy setBrowseForFileString:string];
#else
NSMutableData *data = [NSMutableData data];
int ok = (code == NSOKButton);
NSString *filename = [panel filename];
int len = [filename lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
[data appendBytes:&ok length:sizeof(int)];
[data appendBytes:&len length:sizeof(int)];
if (len > 0)
[data appendBytes:[filename UTF8String] length:len];
if (![NSPortMessage sendMessage:BrowseForFileReplyMsgID
withSendPort:sendPort data:data wait:YES]) {
NSLog(@"WARNING: Failed to send browse for files reply back to "
"VimTask.");
}
[windowController setStatusText:@""];
#endif // !MM_USE_DO
}
- (NSMenuItem *)menuItemForTag:(int)tag
@@ -1024,14 +878,12 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
[toolbar insertItemWithItemIdentifier:label atIndex:idx];
}
#if MM_USE_DO
- (void)connectionDidDie:(NSNotification *)notification
{
//NSLog(@"A MMVimController lost its connection to the backend; "
// "closing the controller.");
[windowController close];
}
#endif // MM_USE_DO
- (BOOL)executeActionWithName:(NSString *)name
{
+4 -11
View File
@@ -559,7 +559,6 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
return frame;
}
#if MM_USE_DO
- (id)validRequestorForSendType:(NSString *)sendType
returnType:(NSString *)returnType
{
@@ -589,7 +588,6 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
id backendProxy = [vimController backendProxy];
return [backendProxy starRegisterToPasteboard:pboard];
}
#endif // MM_USE_DO
@end // MMWindowController
@@ -985,17 +983,12 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
NSRect contentRect = [win contentRectForFrameRect:[win frame]];
NSRect textViewRect = [self textViewRectForContentSize:contentRect.size];
NSSize tsSize = [self textStorageSizeForTextViewSize:textViewRect.size];
#if 0
if ([textStorage resizeToFitSize:tsSize]) {
// Text storage dimensions changed, notify the VimTask.
int dim[2];
[textStorage getMaxRows:&dim[0] columns:&dim[1]];
#else
int dim[2], rows, cols;
[textStorage getMaxRows:&rows columns:&cols];
[textStorage fitToSize:tsSize rows:&dim[0] columns:&dim[1]];
if (dim[0] != rows || dim[1] != cols) {
#endif
NSString *sdim = [NSString stringWithFormat:@"%dx%d", dim[1], dim[0]];
[self flashStatusText:sdim];
@@ -1004,8 +997,8 @@ NSMutableArray *buildMenuAddress(NSMenu *menu)
NSData *data = [NSData dataWithBytes:dim length:2*sizeof(int)];
// NOTE! This can get called a lot when in live resize, which causes
// the ports to fill up. If we wait for the message to be sent then
// the app might become unresponsive.
// the connection buffers to fill up. If we wait for the message to be
// sent then the app might become unresponsive.
[vimController sendMessage:SetTextDimensionsMsgID data:data
wait:![textView inLiveResize]];
}
+21 -28
View File
@@ -11,13 +11,14 @@
#import <Cocoa/Cocoa.h>
#define MM_USE_DO 1
#define MM_DELAY_SEND_IN_PROCESS_CMD_QUEUE 1
#if MM_USE_DO
//
// This is the protocol MMBackend implements.
//
// Only processInput:data: is allowed to cause state changes in Vim; all other
// messages should only read the Vim state.
//
@protocol MMBackendProtocol
- (oneway void)processInput:(int)msgid data:(in NSData *)data;
- (BOOL)checkForModifiedBuffers;
@@ -26,6 +27,10 @@
- (BOOL)starRegisterFromPasteboard:(byref NSPasteboard *)pboard;
@end
//
// This is the protocol MMVimController implements.
//
@protocol MMFrontendProtocol
- (oneway void)processCommandQueue:(in NSArray *)queue;
- (oneway void)showSavePanelForDirectory:(in bycopy NSString *)dir
@@ -33,14 +38,24 @@
saving:(int)saving;
@end
//
// This is the protocol MMAppController implements.
//
// It handles connections between MacVim and Vim.
//
@protocol MMAppProtocol
- (byref id <MMFrontendProtocol>)connectBackend:
(byref in id <MMBackendProtocol>)backend;
@end
#endif
//
// The following enum lists all messages that are passed between MacVim and
// Vim. These can be sent in processInput:data: and in processCommandQueue:.
//
// NOTE! This array must be updated whenever the enum below changes!
extern char *MessageStrings[];
@@ -77,11 +92,6 @@ enum {
EnableMenuItemMsgID,
ExecuteMenuMsgID,
ShowToolbarMsgID,
#if !MM_USE_DO
TaskShouldTerminateMsgID,
TerminateReplyYesMsgID,
TerminateReplyNoMsgID,
#endif
CreateScrollbarMsgID,
DestroyScrollbarMsgID,
ShowScrollbarMsgID,
@@ -122,21 +132,4 @@ enum {
};
@interface NSPortMessage (MacVim)
+ (BOOL)sendMessage:(int)msgid withSendPort:(NSPort *)sendPort
receivePort:(NSPort *)receivePort components:(NSArray *)components
wait:(BOOL)wait;
+ (BOOL)sendMessage:(int)msgid withSendPort:(NSPort *)sendPort
receivePort:(NSPort *)receivePort data:(NSData *)data wait:(BOOL)wait;
+ (BOOL)sendMessage:(int)msgid withSendPort:(NSPort *)sendPort
receivePort:(NSPort *)receivePort wait:(BOOL)wait;
+ (BOOL)sendMessage:(int)msgid withSendPort:(NSPort *)sendPort
components:(NSArray *)components wait:(BOOL)wait;
+ (BOOL)sendMessage:(int)msgid withSendPort:(NSPort *)sendPort
data:(NSData *)data wait:(BOOL)wait;
+ (BOOL)sendMessage:(int)msgid withSendPort:(NSPort *)sendPort wait:(BOOL)wait;
@end
// vim: set ft=objc:
+2 -78
View File
@@ -45,11 +45,6 @@ char *MessageStrings[] =
"EnableMenuItemMsgID",
"ExecuteMenuMsgID",
"ShowToolbarMsgID",
#if !MM_USE_DO
"TaskShouldTerminateMsgID",
"TerminateReplyYesMsgID",
"TerminateReplyNoMsgID",
#endif
"CreateScrollbarMsgID",
"DestroyScrollbarMsgID",
"ShowScrollbarMsgID",
@@ -60,78 +55,7 @@ char *MessageStrings[] =
"VimShouldCloseMsgID",
"SetDefaultColorsMsgID",
"ExecuteActionMsgID",
"DropFilesMsgID",
"DropStringMsgID",
};
@implementation NSPortMessage (MacVim)
+ (BOOL)sendMessage:(int)msgid withSendPort:(NSPort *)sendPort
receivePort:(NSPort *)receivePort components:(NSArray *)components
wait:(BOOL)wait
{
NSPortMessage *msg = [[NSPortMessage alloc]
initWithSendPort:sendPort
receivePort:receivePort
components:components];
[msg setMsgid:msgid];
// HACK! How long should this wait before time out?
NSDate *date = wait ? [NSDate dateWithTimeIntervalSinceNow:1]
: [NSDate date];
BOOL ok = [msg sendBeforeDate:date];
[msg release];
return ok;
}
+ (BOOL)sendMessage:(int)msgid withSendPort:(NSPort *)sendPort
receivePort:(NSPort *)receivePort data:(NSData *)data wait:(BOOL)wait
{
return [NSPortMessage sendMessage:msgid
withSendPort:sendPort
receivePort:receivePort
components:[NSArray arrayWithObject:data]
wait:wait];
}
+ (BOOL)sendMessage:(int)msgid withSendPort:(NSPort *)sendPort
receivePort:(NSPort *)receivePort wait:(BOOL)wait
{
return [NSPortMessage sendMessage:msgid
withSendPort:sendPort
receivePort:receivePort
components:nil
wait:wait];
}
+ (BOOL)sendMessage:(int)msgid withSendPort:(NSPort *)sendPort
components:(NSArray *)components wait:(BOOL)wait
{
return [NSPortMessage sendMessage:msgid
withSendPort:sendPort
receivePort:nil
components:components
wait:wait];
}
+ (BOOL)sendMessage:(int)msgid withSendPort:(NSPort *)sendPort
data:(NSData *)data wait:(BOOL)wait
{
return [NSPortMessage sendMessage:msgid
withSendPort:sendPort
receivePort:nil
components:[NSArray arrayWithObject:data]
wait:wait];
}
+ (BOOL)sendMessage:(int)msgid withSendPort:(NSPort *)sendPort wait:(BOOL)wait
{
return [NSPortMessage sendMessage:msgid
withSendPort:sendPort
receivePort:nil
components:nil
wait:wait];
}
@end
-26
View File
@@ -715,13 +715,6 @@ gui_mch_show_toolbar(int showit)
gui_mch_free_font(font)
GuiFont font;
{
#if 0
static GuiFont last_font = -1;
if (last_font != font) {
NSLog(@"gui_mch_free_font(font=%d)", font);
last_font = font;
}
#endif
}
@@ -774,13 +767,6 @@ gui_mch_init_font(char_u *font_name, int fontset)
void
gui_mch_set_font(GuiFont font)
{
#if 0
static GuiFont last_font = -1;
if (last_font != font) {
NSLog(@"gui_mch_set_font(font=%d)", font);
last_font = font;
}
#endif
}
@@ -857,20 +843,8 @@ gui_mch_set_scrollbar_thumb(
//NSLog(@"gui_mch_set_scrollbar_thumb(id=%d, val=%d, size=%d, max=%d)",
// sb->ident, val, size, max);
#if 0
float value = max-size+1 > 0 ? (float)val/(max-size+1) : 0;
float prop = (float)size/(max+1);
if (value < 0) value = 0;
else if (value > 1.0f) value = 1.0f;
if (prop < 0) prop = 0;
else if (prop > 1.0f) prop = 1.0f;
[[MMBackend sharedInstance]
setScrollbarThumbValue:value proportion:prop identifier:sb->ident];
#else
[[MMBackend sharedInstance]
setScrollbarThumbValue:val size:size max:max identifier:sb->ident];
#endif
}