From 65e9b45d8ae8e4d4bad43e6e06f35daef7ab2545 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Fri, 11 Apr 2014 08:51:04 +0700 Subject: [PATCH] Treat commit window action command names as format strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Frameworks/CommitWindow/src/CommitWindow.mm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Frameworks/CommitWindow/src/CommitWindow.mm b/Frameworks/CommitWindow/src/CommitWindow.mm index 8ce64b62..4141c983 100644 --- a/Frameworks/CommitWindow/src/CommitWindow.mm +++ b/Frameworks/CommitWindow/src/CommitWindow.mm @@ -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 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; }