mirror of
https://github.com/textmate/textmate.git
synced 2026-02-14 00:15:19 -05:00
Remove bundles.h dependency, re-add menu action
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
#import <bundles/bundles.h>
|
||||
|
||||
struct BundleItemMenuItemAlignment
|
||||
{
|
||||
BundleItemMenuItemAlignment () : maxAlignmentWidth(0), maxRightWidth(0) {}
|
||||
@@ -11,6 +9,10 @@ struct BundleItemMenuItemAlignment
|
||||
{
|
||||
BOOL hasRightPart;
|
||||
}
|
||||
+ (BundleItemMenuItem*)menuItemWithBundleItem:(bundles::item_ptr const&)bundleItem alignmentData:(BundleItemMenuItemAlignment&)alignment;
|
||||
+ (BundleItemMenuItem*)menuItemWithName:(std::string const&)name
|
||||
keyEquivalent:(std::string const&)keyEquiv
|
||||
tabTrigger:(std::string const&)tabTrigger
|
||||
action:(SEL)action
|
||||
alignmentData:(BundleItemMenuItemAlignment&)alignment;
|
||||
- (void)updateAlignment:(BundleItemMenuItemAlignment&)alignment;
|
||||
@end
|
||||
|
||||
@@ -3,29 +3,45 @@
|
||||
#import <ns/ns.h>
|
||||
|
||||
@interface BundleItemMenuItem ()
|
||||
- (BundleItemMenuItem*)initWithBundleItem:(bundles::item_ptr const&)bundleItem alignmentData:(BundleItemMenuItemAlignment&)alignment;
|
||||
- (BundleItemMenuItem*)initWithName:(std::string const&)name
|
||||
keyEquivalent:(std::string const&)keyEquiv
|
||||
tabTrigger:(std::string const&)tabTrigger
|
||||
action:(SEL)action
|
||||
alignmentData:(BundleItemMenuItemAlignment&)alignment;
|
||||
- (void)setAttributedTitleWithTitle:(NSAttributedString*)itemTitle equivLeft:(NSAttributedString*)equivLeft equivRight:(NSAttributedString*)equivRight alignmentData:(BundleItemMenuItemAlignment&)alignment;
|
||||
@end
|
||||
|
||||
@implementation BundleItemMenuItem
|
||||
+ (BundleItemMenuItem*)menuItemWithBundleItem:(bundles::item_ptr const&)bundleItem alignmentData:(BundleItemMenuItemAlignment&)alignment
|
||||
+ (BundleItemMenuItem*)menuItemWithName:(std::string const&)name
|
||||
keyEquivalent:(std::string const&)keyEquiv
|
||||
tabTrigger:(std::string const&)tabTrigger
|
||||
action:(SEL)action
|
||||
alignmentData:(BundleItemMenuItemAlignment&)alignment
|
||||
{
|
||||
return [[[self alloc] initWithBundleItem:bundleItem alignmentData:alignment] autorelease];
|
||||
return [[[self alloc] initWithName:name
|
||||
keyEquivalent:keyEquiv
|
||||
tabTrigger:tabTrigger
|
||||
action:action
|
||||
alignmentData:alignment] autorelease];
|
||||
}
|
||||
|
||||
- (BundleItemMenuItem*)initWithBundleItem:(bundles::item_ptr const&)bundleItem alignmentData:(BundleItemMenuItemAlignment&)alignment
|
||||
|
||||
- (BundleItemMenuItem*)initWithName:(std::string const&)name
|
||||
keyEquivalent:(std::string const&)keyEquiv
|
||||
tabTrigger:(std::string const&)tabTrigger
|
||||
action:(SEL)action
|
||||
alignmentData:(BundleItemMenuItemAlignment&)alignment
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
[self setAction:action];
|
||||
|
||||
NSDictionary* fontAttrs = @{ NSFontAttributeName : [NSFont menuFontOfSize:14] /* passing 0 should return the default size, but it doesn’t */ };
|
||||
NSDictionary* smallFontAttrs = @{ NSFontAttributeName : [NSFont menuFontOfSize:11] };
|
||||
NSAttributedString* title = [[NSAttributedString alloc] initWithString:[NSString stringWithCxxString:bundleItem->name()] attributes:fontAttrs];
|
||||
NSAttributedString* title = [[NSAttributedString alloc] initWithString:[NSString stringWithCxxString:name] attributes:fontAttrs];
|
||||
NSAttributedString* equivLeft = nil;
|
||||
NSAttributedString* equivRight = nil;
|
||||
|
||||
std::string const tabTrigger(bundleItem->value_for_field(bundles::kFieldTabTrigger));
|
||||
std::string const keyEquiv(bundleItem->value_for_field(bundles::kFieldKeyEquivalent));
|
||||
|
||||
if(tabTrigger != NULL_STR)
|
||||
{
|
||||
equivLeft = [[[NSAttributedString alloc] initWithString:[NSString stringWithCxxString:(" "+tabTrigger+"\u21E5 ")] attributes:smallFontAttrs] autorelease];
|
||||
|
||||
@@ -60,7 +60,12 @@ OAK_DEBUG_VAR(BundleMenu);
|
||||
|
||||
default:
|
||||
{
|
||||
BundleItemMenuItem* menuItem = [BundleItemMenuItem menuItemWithBundleItem:*item alignmentData:alignmentData];
|
||||
BundleItemMenuItem* menuItem = [BundleItemMenuItem menuItemWithName:(*item)->name()
|
||||
keyEquivalent:(*item)->value_for_field(bundles::kFieldKeyEquivalent)
|
||||
tabTrigger:(*item)->value_for_field(bundles::kFieldTabTrigger)
|
||||
action:@selector(doBundleItem:)
|
||||
alignmentData:alignmentData];
|
||||
|
||||
[menuItem setRepresentedObject:[NSString stringWithCxxString:(*item)->uuid()]];
|
||||
[aMenu addItem:menuItem];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user