Skip to content

Commit

Permalink
Remove bundles.h dependency, re-add menu action
Browse files Browse the repository at this point in the history
  • Loading branch information
jtbandes committed Aug 14, 2012
1 parent 757219b commit 5aaebb9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
8 changes: 5 additions & 3 deletions Frameworks/BundleMenu/src/BundleItemMenuItem.h
@@ -1,5 +1,3 @@
#import <bundles/bundles.h>

struct BundleItemMenuItemAlignment
{
BundleItemMenuItemAlignment () : maxAlignmentWidth(0), maxRightWidth(0) {}
Expand All @@ -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
32 changes: 24 additions & 8 deletions Frameworks/BundleMenu/src/BundleItemMenuItem.mm
Expand Up @@ -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];
Expand Down
7 changes: 6 additions & 1 deletion Frameworks/BundleMenu/src/BundleMenuDelegate.mm
Expand Up @@ -60,7 +60,12 @@ - (void)menuNeedsUpdate:(NSMenu*)aMenu

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

Expand Down

0 comments on commit 5aaebb9

Please sign in to comment.