diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-08-02 12:48:16 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-08-02 12:50:02 (GMT) |
commit | 04d48741240c61d75933d24084915a98d257d444 (patch) | |
tree | f8c23a2ff7e0d60174d520c6dbeb40007632dac7 /Slimber/Cocoa | |
parent | 2a3da91e474f645fe8d83cb2809dcc4b9bfe6a32 (diff) | |
download | swift-contrib-04d48741240c61d75933d24084915a98d257d444.zip swift-contrib-04d48741240c61d75933d24084915a98d257d444.tar.bz2 |
Slimber: Add restart menu.
Diffstat (limited to 'Slimber/Cocoa')
-rw-r--r-- | Slimber/Cocoa/CocoaMenulet.h | 3 | ||||
-rw-r--r-- | Slimber/Cocoa/CocoaMenulet.mm | 10 | ||||
-rw-r--r-- | Slimber/Cocoa/CocoaMenuletDelegate.h | 14 | ||||
-rw-r--r-- | Slimber/Cocoa/CocoaMenuletDelegate.mm | 17 | ||||
-rw-r--r-- | Slimber/Cocoa/Makefile.inc | 5 |
5 files changed, 47 insertions, 2 deletions
diff --git a/Slimber/Cocoa/CocoaMenulet.h b/Slimber/Cocoa/CocoaMenulet.h index 86f0eaa..73f5c2b 100644 --- a/Slimber/Cocoa/CocoaMenulet.h +++ b/Slimber/Cocoa/CocoaMenulet.h @@ -3,6 +3,7 @@ #include <Cocoa/Cocoa.h> #include "Slimber/Menulet.h" +#include "Slimber/Cocoa/CocoaMenuletDelegate.h" class CocoaMenulet : public Menulet { public: @@ -15,9 +16,11 @@ class CocoaMenulet : public Menulet { virtual void addSeparator(); void setIcon(const Swift::String& icon); virtual void addAboutItem(); + virtual void addRestartItem(); virtual void addExitItem(); private: NSStatusItem* statusItem; NSMenu* menu; + CocoaMenuletDelegate* delegate; }; diff --git a/Slimber/Cocoa/CocoaMenulet.mm b/Slimber/Cocoa/CocoaMenulet.mm index c159aa8..f9981e0 100644 --- a/Slimber/Cocoa/CocoaMenulet.mm +++ b/Slimber/Cocoa/CocoaMenulet.mm @@ -3,6 +3,7 @@ using namespace Swift; CocoaMenulet::CocoaMenulet() { + delegate = [[CocoaMenuletDelegate alloc] initWithMenulet: this]; menu = [[NSMenu alloc] init]; statusItem = [[[NSStatusBar systemStatusBar] @@ -14,8 +15,10 @@ CocoaMenulet::CocoaMenulet() { } CocoaMenulet::~CocoaMenulet() { + [delegate release]; [statusItem release]; [menu release]; + [delegate release]; } void CocoaMenulet::setIcon(const String& icon) { @@ -54,6 +57,13 @@ void CocoaMenulet::addAboutItem() { [item release]; } +void CocoaMenulet::addRestartItem() { + NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"Restart" action: @selector(handleRestartClicked:) keyEquivalent: @""]; + [item setTarget: delegate]; + [menu addItem: item]; + [item release]; +} + void CocoaMenulet::addExitItem() { NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"Exit" action: @selector(terminate:) keyEquivalent: @""]; [item setTarget: [NSApplication sharedApplication]]; diff --git a/Slimber/Cocoa/CocoaMenuletDelegate.h b/Slimber/Cocoa/CocoaMenuletDelegate.h new file mode 100644 index 0000000..5c28130 --- /dev/null +++ b/Slimber/Cocoa/CocoaMenuletDelegate.h @@ -0,0 +1,14 @@ +#pragma once + +#include <Cocoa/Cocoa.h> + +class CocoaMenulet; + +@interface CocoaMenuletDelegate : NSObject { + CocoaMenulet* menulet; +} + +- (id) initWithMenulet: (CocoaMenulet*) m; +- (void) handleRestartClicked: (id) sender; + +@end diff --git a/Slimber/Cocoa/CocoaMenuletDelegate.mm b/Slimber/Cocoa/CocoaMenuletDelegate.mm new file mode 100644 index 0000000..f4a7d7b --- /dev/null +++ b/Slimber/Cocoa/CocoaMenuletDelegate.mm @@ -0,0 +1,17 @@ +#include "Slimber/Cocoa/CocoaMenuletDelegate.h" +#include "Slimber/Cocoa/CocoaMenulet.h" + +@implementation CocoaMenuletDelegate + +- (id) initWithMenulet: (CocoaMenulet*) m { + if ([super init]) { + menulet = m; + } + return self; +} + +- (void) handleRestartClicked: (id) sender { + menulet->onRestartClicked(); +} + +@end diff --git a/Slimber/Cocoa/Makefile.inc b/Slimber/Cocoa/Makefile.inc index 6d225a7..5ea1154 100644 --- a/Slimber/Cocoa/Makefile.inc +++ b/Slimber/Cocoa/Makefile.inc @@ -4,7 +4,8 @@ SLIMBER_COCOA_BINARY = \ SLIMBER_COCOA_SOURCES = \ Slimber/Cocoa/main.mm \ Slimber/Cocoa/CocoaController.mm \ - Slimber/Cocoa/CocoaMenulet.mm + Slimber/Cocoa/CocoaMenulet.mm \ + Slimber/Cocoa/CocoaMenuletDelegate.mm SLIMBER_COCOA_XIBS = \ Slimber/Cocoa/MainMenu.xib SLIMBER_COCOA_RESOURCES = \ @@ -26,7 +27,7 @@ CLEANFILES += \ $(SLIMBER_COCOA_TARGET) \ $(SLIMBER_COCOA_BINARY) DEPS += \ - $(SLIMBER_COCOA_SOURCES:.mm=.dep) + $(patsubst %.m, %.dep, $(patsubst %.mm, %.dep, $(SLIMBER_COCOA_SOURCES))) .PHONY: slimber-cocoa slimber-cocoa: $(SLIMBER_COCOA_TARGET) |