Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1: Implement the status item.
- Loading branch information
Showing
10 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ | |
|
||
@property(weak) BookmarksManager *bookmarksManager; | ||
|
||
- (IBAction) showPreferences:(id)sender; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// StatusItemController.h | ||
// SpeedDial | ||
// | ||
// Created by Peter Hosey on 2016-07-23. | ||
// Copyright © 2016 Peter Hosey. All rights reserved. | ||
// | ||
|
||
#import <Cocoa/Cocoa.h> | ||
|
||
@class BookmarksManager; | ||
@class PreferencesWindowController; | ||
|
||
@interface StatusItemController : NSObject | ||
|
||
@property(weak) BookmarksManager *bookmarksManager; | ||
@property(weak) PreferencesWindowController *preferencesWindowController; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// StatusItemController.m | ||
// SpeedDial | ||
// | ||
// Created by Peter Hosey on 2016-07-23. | ||
// Copyright © 2016 Peter Hosey. All rights reserved. | ||
// | ||
|
||
#import "StatusItemController.h" | ||
|
||
#import "BookmarksManager.h" | ||
#import "PreferencesWindowController.h" | ||
|
||
@interface StatusItemController () <NSMenuDelegate> | ||
|
||
@end | ||
|
||
@implementation StatusItemController | ||
{ | ||
NSStatusItem *_statusItem; | ||
} | ||
|
||
- (instancetype) init { | ||
if ((self = [super init])) { | ||
_statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength]; | ||
// https://github.com/boredzo/SpeedDial/issues/4 | ||
// _statusItem.image = [NSImage imageNamed:@"SpeedDialStatusItemTemplate"]; | ||
_statusItem.image = [NSImage imageNamed:NSImageNameHomeTemplate]; | ||
|
||
NSMenu *_Nonnull const menu = [[NSMenu alloc] initWithTitle:@""]; | ||
menu.delegate = self; | ||
_statusItem.menu = menu; | ||
} | ||
return self; | ||
} | ||
|
||
#pragma mark NSMenuDelegate conformance | ||
|
||
- (void)menuNeedsUpdate:(NSMenu *_Nonnull)menu { | ||
[menu removeAllItems]; | ||
|
||
for (VNCBookmark *_Nonnull const bookmark in self.bookmarksManager) { | ||
NSMenuItem *_Nonnull const itemForBookmark = [menu addItemWithTitle:bookmark.bookmarkName | ||
action:@selector(openBookmark:) | ||
keyEquivalent:@""]; | ||
itemForBookmark.target = self; | ||
itemForBookmark.representedObject = bookmark; | ||
} | ||
|
||
if (self.preferencesWindowController != nil) { | ||
[menu addItem:[NSMenuItem separatorItem]]; | ||
NSMenuItem *_Nonnull const prefsMenuItem = [menu addItemWithTitle:NSLocalizedString(@"Preferences…", /*menu item in status item menu*/) | ||
action:@selector(showPreferences:) | ||
keyEquivalent:@","]; | ||
prefsMenuItem.target = self.preferencesWindowController; | ||
} | ||
|
||
[menu addItem:[NSMenuItem separatorItem]]; | ||
[menu addItemWithTitle:NSLocalizedString(@"Quit", /*menu item in status item menu*/) | ||
action:@selector(terminate:) | ||
keyEquivalent:@"q"]; | ||
} | ||
|
||
#pragma mark Actions | ||
|
||
- (IBAction) openBookmark:(_Nullable id)sender { | ||
NSAssert([sender isKindOfClass:[NSMenuItem class]], @"Unexpected sender of %s: %@", __func__, sender); | ||
NSMenuItem *_Nullable const menuItem = sender; | ||
VNCBookmark *_Nullable const bookmark = menuItem.representedObject; | ||
NSURL *_Nullable const URL = bookmark.URL; | ||
|
||
if (URL != nil) { | ||
[[NSWorkspace sharedWorkspace] openURL:URL]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters