Remove bundles.h dependency, re-add menu action

This commit is contained in:
jtbandes
2012-08-13 22:06:32 -07:00
parent 757219b8f1
commit 5aaebb9e25
3 changed files with 35 additions and 12 deletions

View File

@@ -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

View File

@@ -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 doesnt */ };
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];

View File

@@ -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];