diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-08-02 13:15:38 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-08-02 13:18:16 (GMT) |
commit | 475cec615cda74aa34d9519239e2f627256ef71d (patch) | |
tree | f70c4d7ffb221eefd2b31a38ff1b948ad0faab1a /Slimber/Cocoa | |
parent | 04d48741240c61d75933d24084915a98d257d444 (diff) | |
download | swift-475cec615cda74aa34d9519239e2f627256ef71d.zip swift-475cec615cda74aa34d9519239e2f627256ef71d.tar.bz2 |
Created a generic CocoaAction.
Diffstat (limited to 'Slimber/Cocoa')
-rw-r--r-- | Slimber/Cocoa/CocoaAction.h | 15 | ||||
-rw-r--r-- | Slimber/Cocoa/CocoaAction.mm | 22 | ||||
-rw-r--r-- | Slimber/Cocoa/CocoaMenulet.h | 4 | ||||
-rw-r--r-- | Slimber/Cocoa/CocoaMenulet.mm | 13 | ||||
-rw-r--r-- | Slimber/Cocoa/CocoaMenuletDelegate.h | 14 | ||||
-rw-r--r-- | Slimber/Cocoa/CocoaMenuletDelegate.mm | 17 | ||||
-rw-r--r-- | Slimber/Cocoa/Makefile.inc | 2 |
7 files changed, 48 insertions, 39 deletions
diff --git a/Slimber/Cocoa/CocoaAction.h b/Slimber/Cocoa/CocoaAction.h new file mode 100644 index 0000000..13be6b9 --- /dev/null +++ b/Slimber/Cocoa/CocoaAction.h @@ -0,0 +1,15 @@ +#pragma once + +#include <Cocoa/Cocoa.h> +#include <boost/function.hpp> + +class CocoaMenulet; + +@interface CocoaAction : NSObject { + boost::function<void ()>* function; +} + +- (id) initWithFunction: (boost::function<void()>*) f; +- (void) doAction: (id) sender; + +@end diff --git a/Slimber/Cocoa/CocoaAction.mm b/Slimber/Cocoa/CocoaAction.mm new file mode 100644 index 0000000..15498a1 --- /dev/null +++ b/Slimber/Cocoa/CocoaAction.mm @@ -0,0 +1,22 @@ +#include "Slimber/Cocoa/CocoaAction.h" + +@implementation CocoaAction + +- (id) initWithFunction: (boost::function<void()>*) f { + if ([super init]) { + function = f; + } + return self; +} + +- (void) dealloc { + delete function; + [super dealloc]; +} + +- (void) doAction: (id) sender { + (void) sender; + (*function)(); +} + +@end diff --git a/Slimber/Cocoa/CocoaMenulet.h b/Slimber/Cocoa/CocoaMenulet.h index 73f5c2b..913731f 100644 --- a/Slimber/Cocoa/CocoaMenulet.h +++ b/Slimber/Cocoa/CocoaMenulet.h @@ -3,7 +3,7 @@ #include <Cocoa/Cocoa.h> #include "Slimber/Menulet.h" -#include "Slimber/Cocoa/CocoaMenuletDelegate.h" +#include "Slimber/Cocoa/CocoaAction.h" class CocoaMenulet : public Menulet { public: @@ -22,5 +22,5 @@ class CocoaMenulet : public Menulet { private: NSStatusItem* statusItem; NSMenu* menu; - CocoaMenuletDelegate* delegate; + CocoaAction* restartAction; }; diff --git a/Slimber/Cocoa/CocoaMenulet.mm b/Slimber/Cocoa/CocoaMenulet.mm index f9981e0..72ab000 100644 --- a/Slimber/Cocoa/CocoaMenulet.mm +++ b/Slimber/Cocoa/CocoaMenulet.mm @@ -1,9 +1,12 @@ #include "Slimber/Cocoa/CocoaMenulet.h" +#include <boost/function.hpp> + using namespace Swift; CocoaMenulet::CocoaMenulet() { - delegate = [[CocoaMenuletDelegate alloc] initWithMenulet: this]; + restartAction = [[CocoaAction alloc] initWithFunction: + new boost::function<void()>(boost::ref(onRestartClicked))]; menu = [[NSMenu alloc] init]; statusItem = [[[NSStatusBar systemStatusBar] @@ -15,10 +18,9 @@ CocoaMenulet::CocoaMenulet() { } CocoaMenulet::~CocoaMenulet() { - [delegate release]; [statusItem release]; [menu release]; - [delegate release]; + [restartAction release]; } void CocoaMenulet::setIcon(const String& icon) { @@ -58,8 +60,9 @@ void CocoaMenulet::addAboutItem() { } void CocoaMenulet::addRestartItem() { - NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"Restart" action: @selector(handleRestartClicked:) keyEquivalent: @""]; - [item setTarget: delegate]; + NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: + @"Restart" action: @selector(doAction:) keyEquivalent: @""]; + [item setTarget: restartAction]; [menu addItem: item]; [item release]; } diff --git a/Slimber/Cocoa/CocoaMenuletDelegate.h b/Slimber/Cocoa/CocoaMenuletDelegate.h deleted file mode 100644 index 5c28130..0000000 --- a/Slimber/Cocoa/CocoaMenuletDelegate.h +++ /dev/null @@ -1,14 +0,0 @@ -#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 deleted file mode 100644 index f4a7d7b..0000000 --- a/Slimber/Cocoa/CocoaMenuletDelegate.mm +++ /dev/null @@ -1,17 +0,0 @@ -#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 5ea1154..2c364b6 100644 --- a/Slimber/Cocoa/Makefile.inc +++ b/Slimber/Cocoa/Makefile.inc @@ -5,7 +5,7 @@ SLIMBER_COCOA_SOURCES = \ Slimber/Cocoa/main.mm \ Slimber/Cocoa/CocoaController.mm \ Slimber/Cocoa/CocoaMenulet.mm \ - Slimber/Cocoa/CocoaMenuletDelegate.mm + Slimber/Cocoa/CocoaAction.mm SLIMBER_COCOA_XIBS = \ Slimber/Cocoa/MainMenu.xib SLIMBER_COCOA_RESOURCES = \ |