we have a menu bar

master
Jordan Orelli 8 years ago
parent 1c3612e33f
commit e4d9a1a47f

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

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

@ -2,29 +2,110 @@
@implementation AppDelegate
// Application Startup ------------------------------------------------------{{{
- (void) applicationWillFinishLaunching:(NSNotification *)notification {
NSLog(@"applicationWillFinishLaunching");
NSLog(@"applicationWillFinishLaunching notification: %@", notification);
NSLog(@"Main Menu in applicationWillFinishLaunching: %@", [NSApp mainMenu]);
}
- (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 {
NSLog(@"applicationShouldTerminate");
NSLog(@"applicationShouldTerminate sender: %@", sender);
return NSTerminateNow;
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
NSLog(@"applicationShouldTerminateAfterLastWindowClosed");
NSLog(@"applicationShouldTerminateAfterLastWindowClosed sender: %@", sender);
return YES;
}
- (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

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

@ -1,37 +1,30 @@
#include <Cocoa/Cocoa.h>
#include "AppDelegate.h"
void
Initialize(void) {
[NSAutoreleasePool new];
id defaultAutoreleasePool;
id appDelegate;
void Initialize(void) {
NSLog(@"Initializing with processInfo: %@", [[NSProcessInfo processInfo] arguments]);
NSLog(@"Creating Autorelease Pool");
defaultAutoreleasePool = [NSAutoreleasePool new];
[NSApplication sharedApplication];
[NSApp setDelegate: [AppDelegate new]];
NSLog(@"Setting App Delegate");
appDelegate = [AppDelegate new];
[appDelegate createMenuBar];
[NSApp setDelegate: appDelegate];
[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)
styleMask:NSTitledWindowMask backing:NSBackingStoreBuffered defer:NO]
autorelease];
[window cascadeTopLeftFromPoint:NSMakePoint(20,20)];
[window setTitle:appName];
[window makeKeyAndOrderFront:nil];
[NSApp activateIgnoringOtherApps:YES];
int Run(void) {
NSLog(@"Entered Run");
NSLog(@"Activating App");
NSLog(@"Running App Event Loop");
[NSApp run];
NSLog(@"App Event Loop finished. Draining pool.");
[defaultAutoreleasePool drain];
NSLog(@"Leaving Run");
return 0;
}

Loading…
Cancel
Save