summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Slimber/Cocoa/CocoaMenulet.mm')
-rw-r--r--Slimber/Cocoa/CocoaMenulet.mm66
1 files changed, 66 insertions, 0 deletions
diff --git a/Slimber/Cocoa/CocoaMenulet.mm b/Slimber/Cocoa/CocoaMenulet.mm
new file mode 100644
index 0000000..c159aa8
--- /dev/null
+++ b/Slimber/Cocoa/CocoaMenulet.mm
@@ -0,0 +1,66 @@
+#include "Slimber/Cocoa/CocoaMenulet.h"
+
+using namespace Swift;
+
+CocoaMenulet::CocoaMenulet() {
+ menu = [[NSMenu alloc] init];
+
+ statusItem = [[[NSStatusBar systemStatusBar]
+ statusItemWithLength: NSVariableStatusItemLength] retain];
+ [statusItem setHighlightMode: YES];
+ [statusItem setEnabled: YES];
+ [statusItem setToolTip: @"Slimber"];
+ [statusItem setMenu: menu];
+}
+
+CocoaMenulet::~CocoaMenulet() {
+ [statusItem release];
+ [menu release];
+}
+
+void CocoaMenulet::setIcon(const String& icon) {
+ NSString* path = [[NSBundle mainBundle] pathForResource:
+ [NSString stringWithUTF8String: icon.getUTF8Data()] ofType:@"png"];
+ NSImage* image = [[NSImage alloc] initWithContentsOfFile: path];
+ [statusItem setImage: image];
+ [image release];
+}
+
+void CocoaMenulet::clear() {
+ while ([menu numberOfItems] > 0) {
+ [menu removeItemAtIndex: 0];
+ }
+}
+
+void CocoaMenulet::addItem(const Swift::String& name, const String& icon) {
+ NSMenuItem* item = [[NSMenuItem alloc] initWithTitle:
+ [NSString stringWithUTF8String: name.getUTF8Data()]
+ action: NULL keyEquivalent: @""];
+ if (!icon.isEmpty()) {
+ NSString* path = [[NSBundle mainBundle] pathForResource:
+ [NSString stringWithUTF8String: icon.getUTF8Data()] ofType:@"png"];
+ NSImage* image = [[NSImage alloc] initWithContentsOfFile: path];
+ [item setImage: [[NSImage alloc] initWithContentsOfFile: path]];
+ [image release];
+ }
+ [menu addItem: item];
+ [item release];
+}
+
+void CocoaMenulet::addAboutItem() {
+ NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"About Slimber" action: @selector(orderFrontStandardAboutPanel:) keyEquivalent: @""];
+ [item setTarget: [NSApplication sharedApplication]];
+ [menu addItem: item];
+ [item release];
+}
+
+void CocoaMenulet::addExitItem() {
+ NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"Exit" action: @selector(terminate:) keyEquivalent: @""];
+ [item setTarget: [NSApplication sharedApplication]];
+ [menu addItem: item];
+ [item release];
+}
+
+void CocoaMenulet::addSeparator() {
+ [menu addItem: [NSMenuItem separatorItem]];
+}