mirror of
https://github.com/macvim-dev/macvim.git
synced 2026-06-07 15:37:14 +02:00
Dialog buttons are assigned key equivalents
git-svn-id: http://macvim.googlecode.com/svn/trunk@156 96c4425d-ca35-0410-94e5-3396d5c13a8f
This commit is contained in:
+2
-10
@@ -421,16 +421,8 @@ static int specialKeyToNSKey(int key);
|
||||
if (VIM_WARNING == type) style = NSWarningAlertStyle;
|
||||
else if (VIM_ERROR == type) style = NSCriticalAlertStyle;
|
||||
|
||||
NSString *hotkey = [NSString stringWithFormat:@"%c", DLG_HOTKEY_CHAR];
|
||||
NSMutableString *btnString = [NSMutableString stringWithUTF8String:btns];
|
||||
[btnString replaceOccurrencesOfString:hotkey
|
||||
withString:@""
|
||||
options:0
|
||||
range:NSMakeRange(0, [btnString length])];
|
||||
|
||||
NSString *separator = [NSString stringWithFormat:@"%c", DLG_BUTTON_SEP];
|
||||
NSArray *buttons = [btnString componentsSeparatedByString:separator];
|
||||
|
||||
NSString *btnString = [NSString stringWithUTF8String:btns];
|
||||
NSArray *buttons = [btnString componentsSeparatedByString:@"\n"];
|
||||
NSString *message = [NSString stringWithUTF8String:title];
|
||||
NSString *text = [NSString stringWithUTF8String:msg];
|
||||
|
||||
|
||||
@@ -243,7 +243,33 @@ static NSMenuItem *findMenuItemWithTagInMenu(NSMenu *root, int tag)
|
||||
unsigned i, count = [buttons count];
|
||||
for (i = 0; i < count; ++i) {
|
||||
NSString *title = [buttons objectAtIndex:i];
|
||||
// NOTE: The title of the button may contain the character '&' to
|
||||
// indicate that the following letter should be the key equivalent
|
||||
// associated with the button. Extract this letter and lowercase it.
|
||||
NSString *keyEquivalent = nil;
|
||||
NSRange hotkeyRange = [title rangeOfString:@"&"];
|
||||
if (NSNotFound != hotkeyRange.location) {
|
||||
if ([title length] > NSMaxRange(hotkeyRange)) {
|
||||
NSRange keyEquivRange = NSMakeRange(hotkeyRange.location+1, 1);
|
||||
keyEquivalent = [[title substringWithRange:keyEquivRange]
|
||||
lowercaseString];
|
||||
}
|
||||
|
||||
NSMutableString *string = [NSMutableString stringWithString:title];
|
||||
[string deleteCharactersInRange:hotkeyRange];
|
||||
title = string;
|
||||
}
|
||||
|
||||
[alert addButtonWithTitle:title];
|
||||
|
||||
// Set key equivalent for the button, but only if NSAlert hasn't
|
||||
// already done so. (Check the documentation for
|
||||
// - [NSAlert addButtonWithTitle:] to see what key equivalents are
|
||||
// automatically assigned.)
|
||||
NSButton *btn = [[alert buttons] lastObject];
|
||||
if ([[btn keyEquivalent] length] == 0 && keyEquivalent) {
|
||||
[btn setKeyEquivalent:keyEquivalent];
|
||||
}
|
||||
}
|
||||
|
||||
[alert beginSheetModalForWindow:[windowController window]
|
||||
|
||||
Reference in New Issue
Block a user