mirror of
https://github.com/textmate/textmate.git
synced 2026-01-20 04:08:04 -05:00
Introduce updateTitle: for NSMenuItem
Since we create an attributed title when the menu item has a tab trigger or “inactive” key equivalent, we can’t later update the title via the title property.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
@interface NSMenuItem (FileIcon)
|
||||
- (void)updateTitle:(NSString*)newTitle;
|
||||
- (void)setIconForFile:(NSString*)path;
|
||||
- (void)setKeyEquivalentCxxString:(std::string const&)aKeyEquivalent;
|
||||
- (void)setInactiveKeyEquivalentCxxString:(std::string const&)aKeyEquivalent;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#import <OakFoundation/NSString Additions.h>
|
||||
#import <text/case.h>
|
||||
#import <text/utf8.h>
|
||||
#import <ns/event.h>
|
||||
#import <ns/ns.h>
|
||||
|
||||
@interface MenuMutableAttributedString : NSMutableAttributedString
|
||||
{
|
||||
@@ -103,6 +103,9 @@
|
||||
|
||||
@end
|
||||
|
||||
static char const* kOakMenuItemKeyEquivalent = "OakMenuItemKeyEquivalent";
|
||||
static char const* kOakMenuItemTabTrigger = "OakMenuItemTabTrigger";
|
||||
|
||||
@implementation NSMenuItem (FileIcon)
|
||||
- (void)setIconForFile:(NSString*)path;
|
||||
{
|
||||
@@ -121,6 +124,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateTitle:(NSString*)newTitle
|
||||
{
|
||||
if([self.title isEqualToString:newTitle])
|
||||
return;
|
||||
|
||||
self.title = newTitle;
|
||||
if(NSString* keyEquivalent = objc_getAssociatedObject(self, kOakMenuItemKeyEquivalent))
|
||||
[self setInactiveKeyEquivalentCxxString:to_s(keyEquivalent)];
|
||||
if(NSString* tabTrigger = objc_getAssociatedObject(self, kOakMenuItemTabTrigger))
|
||||
[self setTabTriggerCxxString:to_s(tabTrigger)];
|
||||
}
|
||||
|
||||
- (void)setKeyEquivalentCxxString:(std::string const&)aKeyEquivalent
|
||||
{
|
||||
if(aKeyEquivalent == NULL_STR || aKeyEquivalent.empty())
|
||||
@@ -154,6 +169,7 @@
|
||||
|
||||
- (void)setInactiveKeyEquivalentCxxString:(std::string const&)aKeyEquivalent
|
||||
{
|
||||
objc_setAssociatedObject(self, kOakMenuItemKeyEquivalent, [NSString stringWithCxxString:aKeyEquivalent], OBJC_ASSOCIATION_RETAIN);
|
||||
if(aKeyEquivalent == NULL_STR || aKeyEquivalent.empty())
|
||||
return;
|
||||
|
||||
@@ -174,6 +190,7 @@
|
||||
|
||||
- (void)setTabTriggerCxxString:(std::string const&)aTabTrigger
|
||||
{
|
||||
objc_setAssociatedObject(self, kOakMenuItemTabTrigger, [NSString stringWithCxxString:aTabTrigger], OBJC_ASSOCIATION_RETAIN);
|
||||
if(aTabTrigger == NULL_STR)
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user