Treat commit window action command names as format strings

Presently the ‘TM_DISPLAYNAME’ is conditionally available, allowing the name to contain the file name which it will work with.

Also fix a potential “out of range” exception. The validateMenuItem: could be called for a cached menu item (e.g. when the system resolves key equivalents) where we had no selection (nor did click any item), so we would access the row at index -1.
This commit is contained in:
Allan Odgaard
2014-04-11 08:51:04 +07:00
parent 445468cbf5
commit 65e9b45d8a

View File

@@ -546,10 +546,17 @@ static NSUInteger const kOakCommitWindowCommitMessagesMax = 5;
NSInteger row = [_tableView clickedColumn] == -1 || [_tableView clickedRow] == -1 ? [_tableView selectedRow] : [_tableView clickedRow];
if([menuItem action] == @selector(performActionCommand:))
{
if(row == -1)
return NO;
CWItem* cwItem = [[_arrayController arrangedObjects] objectAtIndex:row];
actionCommandObj* cmd = [menuItem representedObject];
if(![cmd.targetStatuses containsObject:cwItem.scmStatus])
active = NO;
std::map<std::string, std::string> variables;
if(active = [cmd.targetStatuses containsObject:cwItem.scmStatus])
variables = { { "TM_DISPLAYNAME", path::display_name(to_s(cwItem.path)) } };
menuItem.title = [NSString stringWithCxxString:format_string::expand(to_s(cmd.name), variables)];
}
return active;
}