Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Xcode6.3.2 #42

Merged
merged 2 commits into from
May 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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