From e33692a5eea49ba9b236dbf1b5cd6ccf7f4672aa Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Sat, 18 Aug 2007 16:41:46 +0000 Subject: [PATCH] - Changed the way input text field is place in dialogs - If a dialog has no title but a message with newlines, then use the first line of the message as a title (this makes dialogs look better) git-svn-id: http://macvim.googlecode.com/svn/trunk@159 96c4425d-ca35-0410-94e5-3396d5c13a8f --- MMBackend.m | 17 ++++++++++++++++- MMVimController.m | 31 +++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/MMBackend.m b/MMBackend.m index ca2a54705c..250f6043a9 100644 --- a/MMBackend.m +++ b/MMBackend.m @@ -432,8 +432,23 @@ static int specialKeyToNSKey(int key); } if (title) message = [NSString stringWithUTF8String:title]; - if (msg) + if (msg) { text = [NSString stringWithUTF8String:msg]; + if (!message) { + // HACK! If there is a '\n\n' or '\n' sequence in the message, then + // make the part up to there into the title. We only do this + // because Vim has lots of dialogs without a title and they look + // ugly that way. + // TODO: Fix the actual dialog texts. + NSRange eolRange = [text rangeOfString:@"\n\n"]; + if (NSNotFound == eolRange.location) + eolRange = [text rangeOfString:@"\n"]; + if (NSNotFound != eolRange.location) { + message = [text substringToIndex:eolRange.location]; + text = [text substringFromIndex:NSMaxRange(eolRange)]; + } + } + } if (txtfield) textFieldString = [NSString stringWithUTF8String:txtfield]; diff --git a/MMVimController.m b/MMVimController.m index 69f1baac46..c4e868e1d2 100644 --- a/MMVimController.m +++ b/MMVimController.m @@ -18,6 +18,8 @@ //static NSString *AttentionToolbarItemID = @"Attention"; static NSString *DefaultToolbarImageName = @"Attention"; +static int MMAlertTextFieldHeight = 22; + @interface MMAlert : NSAlert { NSTextField *textField; @@ -251,9 +253,19 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag) [alert setAlertStyle:style]; - if (message) [alert setMessageText:message]; - else [alert setMessageText:@""]; - if (text) [alert setInformativeText:text]; + if (message) { + [alert setMessageText:message]; + } else { + // If no message text is specified 'Alert' is used. + [alert setMessageText:@""]; + } + + if (text) { + [alert setInformativeText:text]; + } else if (textFieldString) { + // Make sure there is always room for the input text field. + [alert setInformativeText:@""]; + } unsigned i, count = [buttonTitles count]; for (i = 0; i < count; ++i) { @@ -1168,18 +1180,25 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag) didEndSelector:didEndSelector contextInfo:contextInfo]; + // HACK! Place the input text field at the bottom of the informative text + // (which has been made a bit larger by adding newline characters). NSView *contentView = [[self window] contentView]; - NSRect rect = NSZeroRect; + NSRect rect = [contentView frame]; + rect.origin.y = rect.size.height; + NSArray *subviews = [contentView subviews]; unsigned i, count = [subviews count]; for (i = 0; i < count; ++i) { NSView *view = [subviews objectAtIndex:i]; - if ([view isKindOfClass:[NSTextField class]]) { + if ([view isKindOfClass:[NSTextField class]] + && [view frame].origin.y < rect.origin.y) { + // NOTE: The informative text field is the lowest NSTextField in + // the alert dialog. rect = [view frame]; } } - rect.size.height = 22; + rect.size.height = MMAlertTextFieldHeight; [textField setFrame:rect]; [contentView addSubview:textField]; [textField becomeFirstResponder];