we have a menu bar

master
Jordan Orelli 8 years ago
parent 1c3612e33f
commit e4d9a1a47f

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"strings" "strings"
@ -30,10 +31,13 @@ func must(fn failable, status int, msg string) {
} }
func main() { func main() {
log.Println("Creating new Desktop UI")
ui, err := ui.NewDesktop() ui, err := ui.NewDesktop()
if err != nil { if err != nil {
exit(1, "unable to create desktop ui: %s", err) exit(1, "unable to create desktop ui: %s", err)
} }
log.Println("Initializing Desktop UI")
must(ui.Init, 1, "unable to initialize desktop ui") must(ui.Init, 1, "unable to initialize desktop ui")
log.Println("Running Desktop UI")
must(ui.Run, 1, "unable to run desktop ui") must(ui.Run, 1, "unable to run desktop ui")
} }

@ -1,5 +1,5 @@
#import <AppKit/AppKit.h> #import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate> @interface AppDelegate : NSObject <NSApplicationDelegate>
- (void) createMenuBar;
@end @end

@ -2,29 +2,110 @@
@implementation AppDelegate @implementation AppDelegate
// Application Startup ------------------------------------------------------{{{
- (void) applicationWillFinishLaunching:(NSNotification *)notification { - (void) applicationWillFinishLaunching:(NSNotification *)notification {
NSLog(@"applicationWillFinishLaunching"); NSLog(@"applicationWillFinishLaunching notification: %@", notification);
NSLog(@"Main Menu in applicationWillFinishLaunching: %@", [NSApp mainMenu]);
} }
- (void) applicationDidFinishLaunching:(NSNotification *)notification { - (void) applicationDidFinishLaunching:(NSNotification *)notification {
NSLog(@"applicationDidFinishLaunching"); NSLog(@"applicationDidFinishLaunching notification: %@", notification);
NSLog(@"Main Menu in applicationDidFinishLaunching: %@", [NSApp mainMenu]);
[NSApp activateIgnoringOtherApps:YES];
} }
// Application Termination ----------------------------------------------------- // --------------------------------------------------------------------------}}}
// Application Termination --------------------------------------------------{{{
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
NSLog(@"applicationShouldTerminate"); NSLog(@"applicationShouldTerminate sender: %@", sender);
return NSTerminateNow; return NSTerminateNow;
} }
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender { - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
NSLog(@"applicationShouldTerminateAfterLastWindowClosed"); NSLog(@"applicationShouldTerminateAfterLastWindowClosed sender: %@", sender);
return YES; return YES;
} }
- (void)applicationWillTerminate:(NSNotification *)notification { - (void)applicationWillTerminate:(NSNotification *)notification {
NSLog(@"applicationWillTerminate"); NSLog(@"applicationWillTerminate notification sender: %@", notification);
}
// --------------------------------------------------------------------------}}}
// Application Active Status ------------------------------------------------{{{
- (void)applicationWillBecomeActive:(NSNotification *)notification {
NSLog(@"applicationWillBecomeActive notification: %@", notification);
}
- (void)applicationDidBecomeActive:(NSNotification *)notification {
NSLog(@"applicationDidBecomeActive notification: %@", notification);
}
- (void)applicationWillResignActive:(NSNotification *)notification {
NSLog(@"applicationWillResignActive notification: %@", notification);
}
- (void)applicationDidResignActive:(NSNotification *)notification {
NSLog(@"applicationDidResignActive notification: %@", notification);
}
// --------------------------------------------------------------------------}}}
// Application Hide Status --------------------------------------------------{{{
- (void)applicationWillHide:(NSNotification *)notification {
NSLog(@"applicationWillHide notification: %@", notification);
}
- (void)applicationDidHide:(NSNotification *)notification {
NSLog(@"applicationDidHide notification: %@", notification);
}
- (void)applicationWillUnhide:(NSNotification *)notification {
NSLog(@"applicationWillUnhide notification: %@", notification);
}
- (void)applicationDidUnhide:(NSNotification *)notification {
NSLog(@"applicationDidUnhide notification: %@", notification);
}
// --------------------------------------------------------------------------}}}
// Application Update Status ------------------------------------------------{{{
- (void)applicationWillUpdate:(NSNotification *)notification {
// NSLog(@"applicationWillUpdate notification: %@", notification);
}
- (void)applicationDidUpdate:(NSNotification *)notification {
// NSLog(@"applicationDidUpdate notification: %@", notification);
}
// --------------------------------------------------------------------------}}}
// Menu Bar -----------------------------------------------------------------{{{
- (void) createMenuBar {
NSLog(@"Will create menu bar here");
NSLog(@"creating menu bar. initial main menu bar: %@", [NSApp mainMenu]);
id mainMenu = [NSMenu alloc];
[mainMenu initWithTitle:@"Main Menu"];
[NSApp setMainMenu:mainMenu];
id appMenuItem = [NSMenuItem alloc];
[appMenuItem initWithTitle:@"dws" action:NULL keyEquivalent:@""];
[mainMenu addItem:appMenuItem];
id appMenu = [NSMenu alloc];
[appMenu initWithTitle:@"dws"];
[appMenuItem setSubmenu:appMenu];
id quitMenuItem = [NSMenuItem alloc];
[quitMenuItem initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"];
[appMenu addItem:quitMenuItem];
NSLog(@"assigned to main menu: %@", [NSApp mainMenu]);
} }
// --------------------------------------------------------------------------}}}
@end @end

@ -1,6 +1,7 @@
package ui package ui
import ( import (
"log"
"runtime" "runtime"
) )
@ -13,6 +14,7 @@ import "C"
func NewDesktop() (UI, error) { func NewDesktop() (UI, error) {
runtime.LockOSThread() runtime.LockOSThread()
log.Println("Creating new cocoaUI")
return new(cocoaUI), nil return new(cocoaUI), nil
} }

@ -1,37 +1,30 @@
#include <Cocoa/Cocoa.h> #include <Cocoa/Cocoa.h>
#include "AppDelegate.h" #include "AppDelegate.h"
void id defaultAutoreleasePool;
Initialize(void) { id appDelegate;
[NSAutoreleasePool new];
void Initialize(void) {
NSLog(@"Initializing with processInfo: %@", [[NSProcessInfo processInfo] arguments]);
NSLog(@"Creating Autorelease Pool");
defaultAutoreleasePool = [NSAutoreleasePool new];
[NSApplication sharedApplication]; [NSApplication sharedApplication];
[NSApp setDelegate: [AppDelegate new]]; NSLog(@"Setting App Delegate");
appDelegate = [AppDelegate new];
[appDelegate createMenuBar];
[NSApp setDelegate: appDelegate];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
NSLog(@"Initialization complete");
} }
int
Run(void) {
id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem new] autorelease];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
id appMenu = [[NSMenu new] autorelease];
id appName = [[NSProcessInfo processInfo] processName];
id quitTitle = [@"Quit " stringByAppendingString:appName];
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:quitTitle
action:@selector(terminate:) keyEquivalent:@"q"]
autorelease];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];
id window = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 200) int Run(void) {
styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO] NSLog(@"Entered Run");
autorelease]; NSLog(@"Activating App");
[window cascadeTopLeftFromPoint:NSMakePoint(20,20)]; NSLog(@"Running App Event Loop");
[window setTitle:appName];
[window makeKeyAndOrderFront:nil];
[NSApp activateIgnoringOtherApps:YES];
[NSApp run]; [NSApp run];
NSLog(@"App Event Loop finished. Draining pool.");
[defaultAutoreleasePool drain];
NSLog(@"Leaving Run");
return 0; return 0;
} }

Loading…
Cancel
Save