Skip to content

Commit

Permalink
Merge pull request #42 from tyeen/xcode6.3.2
Browse files Browse the repository at this point in the history
Support Xcode6.3.2
  • Loading branch information
aliaksandr-andrashuk committed May 19, 2015
2 parents 8a5e693 + b864d7f commit 0253b40
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 71 deletions.
170 changes: 99 additions & 71 deletions Backlight/AAABacklight.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef NS_ENUM(NSInteger, AAABacklightMode) {
static NSString *const kAAALineBacklightColor = @"kAAALineBacklightColorKey";
static NSString *const kAAALineBacklightStrokeEnabled = @"kAAALineBacklightStrokeEnabledKey";
static NSString *const kAAALineBacklightRadiusEnabled = @"kAAALineBacklightRadiusEnabledKey";
static NSString *const kMenuItemTitlePrefix = @"Backlight";

static AAABacklight *sharedPlugin;

Expand Down Expand Up @@ -61,80 +62,11 @@ - (id)initWithBundle:(NSBundle *)plugin

self.bundle = plugin;

NSMenuItem *editMenuItem = [[NSApp mainMenu] itemWithTitle:@"Edit"];

if (!editMenuItem) return self;

NSMenu *backlightMenu = [[NSMenu alloc] initWithTitle:@"Backlight"];
backlightMenu.autoenablesItems = NO;
[[editMenuItem submenu] addItem:[NSMenuItem separatorItem]];

self.underneathModeMenuItem = [[NSMenuItem alloc] initWithTitle:@"Line backlight (Underneath Mode)"
action:@selector(toggleEnableLineBacklightUnderneathMode:)
keyEquivalent:@""];
self.underneathModeMenuItem.target = self;
// Show the "check" mark only when NOT being in "Overlay Mode" and the associated key is enabled.
self.underneathModeMenuItem.state = self.underneathModeMenuItem.enabled && [self settingForKey:kAAAEnableLineBacklightUnderneathMode];
[backlightMenu addItem:self.underneathModeMenuItem];

self.overlayModeMenuItem = [[NSMenuItem alloc] initWithTitle:@"Line backlight (Overlay Mode)"
action:@selector(toggleEnableLineBacklightOverlayMode:)
keyEquivalent:@""];
self.overlayModeMenuItem.target = self;
// Show the "check" mark only when NOT being in "Underneath Mode" and the associated key is enabled.
self.overlayModeMenuItem.state = self.overlayModeMenuItem.enabled && [self settingForKey:kAAAEnableLineBacklightOverlayMode];
[backlightMenu addItem:self.overlayModeMenuItem];

[backlightMenu addItem:({
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"Always backlight"
action:@selector(toggleAlwaysEnableBacklight:)
keyEquivalent:@""];
menuItem.target = self;
menuItem.state = [self settingForKey:kAAAAlwaysEnableLineBacklight];
menuItem;
})];

[backlightMenu addItem:[NSMenuItem separatorItem]];

self.enableStrokeMenuItem = [[NSMenuItem alloc] initWithTitle:@"Enable stroke"
action:@selector(toggleStrokeBacklight:)
keyEquivalent:@""];
self.enableStrokeMenuItem.target = self;
self.enableStrokeMenuItem.enabled = [self settingForKey:kAAAEnableLineBacklightOverlayMode];
// Show the "check" mark only when being in "Overlay Mode" and the associated key is enabled.
self.enableStrokeMenuItem.state = self.enableStrokeMenuItem.enabled && [self settingForKey:kAAALineBacklightStrokeEnabled];
[backlightMenu addItem:self.enableStrokeMenuItem];

self.enableRadiusMenuItem = [[NSMenuItem alloc] initWithTitle:@"Enable round corners"
action:@selector(toggleRadiusBacklight:)
keyEquivalent:@""];
self.enableRadiusMenuItem.target = self;
self.enableRadiusMenuItem.enabled = [self settingForKey:kAAAEnableLineBacklightOverlayMode];
// Show the "check" mark only when being in "Overlay Mode" and the associated key is enabled.
self.enableRadiusMenuItem.state = self.enableStrokeMenuItem.enabled && [self settingForKey:kAAALineBacklightRadiusEnabled];
[backlightMenu addItem:self.enableRadiusMenuItem];

[backlightMenu addItem:[NSMenuItem separatorItem]];

[backlightMenu addItem:({
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"Edit line backlight color"
action:@selector(showColorPanel)
keyEquivalent:@""];
menuItem.target = self;
menuItem;
})];

NSString *versionString = [[NSBundle bundleForClass:[self class]] objectForInfoDictionaryKey:@"CFBundleVersion"];
NSMenuItem *backlightMenuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Backlight (%@)", versionString]
action:nil
keyEquivalent:@""];
backlightMenuItem.submenu = backlightMenu;

[[editMenuItem submenu] addItem:backlightMenuItem];

[self createBacklight];
[self adjustBacklight];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuDidChange:)
name:NSMenuDidChangeItemNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backlightNotification:)
name:NSTextViewDidChangeSelectionNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backlightNotification:)
Expand Down Expand Up @@ -281,6 +213,13 @@ - (void)adjustColor:(id)sender

#pragma mark - Notifications

- (void)menuDidChange:(NSNotification *)notification
{
if (![self hasMenuBuilt]) {
[self buildMenus];
}
}

- (void)backlightNotification:(NSNotification *)notification
{
id firstResponder = [[NSApp keyWindow] firstResponder];
Expand All @@ -304,6 +243,95 @@ - (void)colorPanelWillClose:(NSNotification *)notification

#pragma mark - Private methods

- (BOOL)hasMenuBuilt
{
NSMenuItem *editMenuItem = [[NSApp mainMenu] itemWithTitle:@"Edit"];
if (!editMenuItem) return NO;

BOOL result = NO;
for (NSMenuItem *menu in editMenuItem.submenu.itemArray) {
if ([menu.title hasPrefix:kMenuItemTitlePrefix]) {
result = YES;
break;
}
}
return result;
}

- (void)buildMenus
{
NSMenuItem *editMenuItem = [[NSApp mainMenu] itemWithTitle:@"Edit"];

if (!editMenuItem) return;

NSMenu *backlightMenu = [[NSMenu alloc] initWithTitle:@"Backlight"];
backlightMenu.autoenablesItems = NO;
[[editMenuItem submenu] addItem:[NSMenuItem separatorItem]];

self.underneathModeMenuItem = [[NSMenuItem alloc] initWithTitle:@"Line backlight (Underneath Mode)"
action:@selector(toggleEnableLineBacklightUnderneathMode:)
keyEquivalent:@""];
self.underneathModeMenuItem.target = self;
// Show the "check" mark only when NOT being in "Overlay Mode" and the associated key is enabled.
self.underneathModeMenuItem.state = self.underneathModeMenuItem.enabled && [self settingForKey:kAAAEnableLineBacklightUnderneathMode];
[backlightMenu addItem:self.underneathModeMenuItem];

self.overlayModeMenuItem = [[NSMenuItem alloc] initWithTitle:@"Line backlight (Overlay Mode)"
action:@selector(toggleEnableLineBacklightOverlayMode:)
keyEquivalent:@""];
self.overlayModeMenuItem.target = self;
// Show the "check" mark only when NOT being in "Underneath Mode" and the associated key is enabled.
self.overlayModeMenuItem.state = self.overlayModeMenuItem.enabled && [self settingForKey:kAAAEnableLineBacklightOverlayMode];
[backlightMenu addItem:self.overlayModeMenuItem];

[backlightMenu addItem:({
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"Always backlight"
action:@selector(toggleAlwaysEnableBacklight:)
keyEquivalent:@""];
menuItem.target = self;
menuItem.state = [self settingForKey:kAAAAlwaysEnableLineBacklight];
menuItem;
})];

[backlightMenu addItem:[NSMenuItem separatorItem]];

self.enableStrokeMenuItem = [[NSMenuItem alloc] initWithTitle:@"Enable stroke"
action:@selector(toggleStrokeBacklight:)
keyEquivalent:@""];
self.enableStrokeMenuItem.target = self;
self.enableStrokeMenuItem.enabled = [self settingForKey:kAAAEnableLineBacklightOverlayMode];
// Show the "check" mark only when being in "Overlay Mode" and the associated key is enabled.
self.enableStrokeMenuItem.state = self.enableStrokeMenuItem.enabled && [self settingForKey:kAAALineBacklightStrokeEnabled];
[backlightMenu addItem:self.enableStrokeMenuItem];

self.enableRadiusMenuItem = [[NSMenuItem alloc] initWithTitle:@"Enable round corners"
action:@selector(toggleRadiusBacklight:)
keyEquivalent:@""];
self.enableRadiusMenuItem.target = self;
self.enableRadiusMenuItem.enabled = [self settingForKey:kAAAEnableLineBacklightOverlayMode];
// Show the "check" mark only when being in "Overlay Mode" and the associated key is enabled.
self.enableRadiusMenuItem.state = self.enableStrokeMenuItem.enabled && [self settingForKey:kAAALineBacklightRadiusEnabled];
[backlightMenu addItem:self.enableRadiusMenuItem];

[backlightMenu addItem:[NSMenuItem separatorItem]];

[backlightMenu addItem:({
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"Edit line backlight color"
action:@selector(showColorPanel)
keyEquivalent:@""];
menuItem.target = self;
menuItem;
})];

NSString *versionString = [[NSBundle bundleForClass:[self class]] objectForInfoDictionaryKey:@"CFBundleVersion"];
NSMenuItem *backlightMenuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%@ (%@)", kMenuItemTitlePrefix, versionString]
action:nil
keyEquivalent:@""];
backlightMenuItem.submenu = backlightMenu;

[[editMenuItem submenu] addItem:backlightMenuItem];
}

- (void)updateBacklightViewWithTextView:(NSTextView *)textView
{
// Before changing the textView's instance, remove the old one's highlight.
Expand Down
1 change: 1 addition & 0 deletions Backlight/Backlight-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<string>992275C1-432A-4CF7-B659-D84ED6D42D3F</string>
<string>A16FF353-8441-459E-A50C-B071F53F51B7</string>
<string>9F75337B-21B4-4ADC-B558-F9CADF7073A7</string>
<string>E969541F-E6F9-4D25-8158-72DC3545A6C6</string>
</array>
<key>NSPrincipalClass</key>
<string>AAABacklight</string>
Expand Down

0 comments on commit 0253b40

Please sign in to comment.