Started the stub menu code.
This commit is contained in:
parent
b7272f680f
commit
855bca9b0c
|
@ -55,65 +55,7 @@ NSMenuItem *makeMenu(const char *name, const uiMenuItem *items, struct menuConfi
|
|||
return menubarItem;
|
||||
}
|
||||
|
||||
// Cocoa constructs the default application menu by hand for each program; that's what MainMenu.[nx]ib does
|
||||
// TODO investigate setAppleMenu:
|
||||
static void buildApplicationMenu(NSMenu *menubar)
|
||||
{
|
||||
NSString *appName;
|
||||
NSMenuItem *appMenuItem;
|
||||
NSMenu *appMenu;
|
||||
NSMenuItem *item;
|
||||
NSString *title;
|
||||
|
||||
appName = [[NSProcessInfo processInfo] processName];
|
||||
appMenuItem = [[NSMenuItem alloc] initWithTitle:appName action:NULL keyEquivalent:@""];
|
||||
appMenu = [[NSMenu alloc] initWithTitle:appName];
|
||||
[appMenuItem setSubmenu:appMenu];
|
||||
[menubar addItem:appMenuItem];
|
||||
|
||||
// first is About
|
||||
title = [@"About " stringByAppendingString:appName];
|
||||
item = [[NSMenuItem alloc] initWithTitle:title action:NULL keyEquivalent:@""];
|
||||
[item setEnabled:NO];
|
||||
[appMenu addItem:item];
|
||||
aboutItem = item;
|
||||
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
// next is Preferences
|
||||
item = [[NSMenuItem alloc] initWithTitle:@"Preferences…" action:NULL keyEquivalent:@","];
|
||||
[item setEnabled:NO];
|
||||
[appMenu addItem:item];
|
||||
preferencesItem = item;
|
||||
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
// next is Services
|
||||
item = [[NSMenuItem alloc] initWithTitle:@"Services" action:NULL keyEquivalent:@""];
|
||||
// TODO build this part
|
||||
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
// next are the three hiding options
|
||||
title = [@"Hide " stringByAppendingString:appName];
|
||||
item = [[NSMenuItem alloc] initWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
|
||||
// TODO set target for all three of these? the .xib file says they go to -1 ("First Responder", which sounds wrong...)
|
||||
[appMenu addItem:item];
|
||||
item = [[NSMenuItem alloc] initWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
|
||||
[item setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask)];
|
||||
[appMenu addItem:item];
|
||||
item = [[NSMenuItem alloc] initWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
|
||||
[appMenu addItem:item];
|
||||
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
// and finally Quit
|
||||
// DON'T use @selector(terminate:) as the action; we handle termination ourselves (TODO figure out how)
|
||||
title = [@"Quit " stringByAppendingString:appName];
|
||||
item = [[NSMenuItem alloc] initWithTitle:title action:NULL keyEquivalent:@"q"];
|
||||
[appMenu addItem:item];
|
||||
quitItem = item;
|
||||
}
|
||||
|
||||
NSMenu *makeMenubar(void)
|
||||
{
|
||||
|
|
|
@ -21,10 +21,7 @@
|
|||
|
||||
@end
|
||||
|
||||
@interface uiAppDelegate : NSObject <NSApplicationDelegate>
|
||||
@end
|
||||
|
||||
@implementation uiAppDelegate
|
||||
@implementation appDelegate
|
||||
|
||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app
|
||||
{
|
||||
|
@ -54,10 +51,11 @@ const char *uiInit(uiInitOptions *o)
|
|||
// don't check for a NO return; something (launch services?) causes running from application bundles to always return NO when asking to change activation policy, even if the change is to the same activation policy!
|
||||
// see https://github.com/andlabs/ui/issues/6
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||
[NSApp setDelegate:[uiAppDelegate new]];
|
||||
[NSApp setDelegate:[appDelegate new]];
|
||||
|
||||
// always do this so we always have an application menu
|
||||
[NSApp setMainMenu:makeMenubar()];
|
||||
appDelegate().menuManager = [menuManager new];
|
||||
[NSApp setMainMenu:[appDelegate().menuManager makeMenubar]];
|
||||
|
||||
// we can use a stock NSView for this
|
||||
destroyedControlsView = [[NSView alloc] initWithFrame:NSZeroRect];
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
// 28 april 2015
|
||||
#import "uipriv_darwin.h"
|
||||
|
||||
@implementation menuManager
|
||||
|
||||
// TODO allocation logger
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
self->items = [NSMutableDictionary new];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self->items release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (IBAction)onClicked:(id)sender
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Cocoa constructs the default application menu by hand for each program; that's what MainMenu.[nx]ib does
|
||||
// TODO investigate setAppleMenu:
|
||||
- (void)buildApplicationMenu:(NSMenu *)menubar
|
||||
{
|
||||
NSString *appName;
|
||||
NSMenuItem *appMenuItem;
|
||||
NSMenu *appMenu;
|
||||
NSMenuItem *item;
|
||||
NSString *title;
|
||||
|
||||
appName = [[NSProcessInfo processInfo] processName];
|
||||
appMenuItem = [[NSMenuItem alloc] initWithTitle:appName action:NULL keyEquivalent:@""];
|
||||
appMenu = [[NSMenu alloc] initWithTitle:appName];
|
||||
[appMenuItem setSubmenu:appMenu];
|
||||
[menubar addItem:appMenuItem];
|
||||
|
||||
// first is About
|
||||
title = [@"About " stringByAppendingString:appName];
|
||||
item = [[NSMenuItem alloc] initWithTitle:title action:@selector(onClicked:) keyEquivalent:@""];
|
||||
[item setTarget:self];
|
||||
[item setEnabled:NO];
|
||||
[appMenu addItem:item];
|
||||
self.aboutItem = item;
|
||||
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
// next is Preferences
|
||||
item = [[NSMenuItem alloc] initWithTitle:@"Preferences…" action:@selector(onClicked:) keyEquivalent:@","];
|
||||
[item setTarget:self];
|
||||
[item setEnabled:NO];
|
||||
[appMenu addItem:item];
|
||||
self.preferencesItem = item;
|
||||
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
// next is Services
|
||||
item = [[NSMenuItem alloc] initWithTitle:@"Services" action:NULL keyEquivalent:@""];
|
||||
// TODO build this part
|
||||
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
// next are the three hiding options
|
||||
title = [@"Hide " stringByAppendingString:appName];
|
||||
item = [[NSMenuItem alloc] initWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
|
||||
// TODO set target for all three of these? the .xib file says they go to -1 ("First Responder", which sounds wrong...)
|
||||
[appMenu addItem:item];
|
||||
item = [[NSMenuItem alloc] initWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
|
||||
[item setKeyEquivalentModifierMask:(NSAlternateKeyMask | NSCommandKeyMask)];
|
||||
[appMenu addItem:item];
|
||||
item = [[NSMenuItem alloc] initWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
|
||||
[appMenu addItem:item];
|
||||
|
||||
[appMenu addItem:[NSMenuItem separatorItem]];
|
||||
|
||||
// and finally Quit
|
||||
// DON'T use @selector(terminate:) as the action; we handle termination ourselves (TODO figure out how)
|
||||
title = [@"Quit " stringByAppendingString:appName];
|
||||
item = [[NSMenuItem alloc] initWithTitle:title action:@selector(onClicked:) keyEquivalent:@"q"];
|
||||
[item setTarget:self];
|
||||
[appMenu addItem:item];
|
||||
self.quitItem = item;
|
||||
}
|
||||
|
||||
- (NSMenu *)makeMenubar
|
||||
{
|
||||
NSMenu *menubar;
|
||||
|
||||
menubar = [[NSMenu alloc] initWithTitle:@""];
|
||||
[self buildApplicationMenu:menubar];
|
||||
return menubar;
|
||||
}
|
||||
|
||||
@end
|
|
@ -24,23 +24,31 @@
|
|||
fprintf(stderr, "%p free\n", self); \
|
||||
}
|
||||
|
||||
#define VIEW(c) uiControlHandle(uiControl(c))
|
||||
|
||||
// init.m
|
||||
extern NSView *destroyedControlsView;
|
||||
|
||||
// util.m
|
||||
extern void setStandardControlFont(NSControl *);
|
||||
extern void disableAutocorrect(NSTextView *);
|
||||
|
||||
// parent.m
|
||||
// These are based on measurements from Interface Builder.
|
||||
// These seem to be based on Auto Layout constants, but I don't see an API that exposes these...
|
||||
#define macXMargin 20
|
||||
#define macYMargin 20
|
||||
|
||||
// menu.m
|
||||
@interface menuManager : NSObject {
|
||||
NSMutableDictionary *items;
|
||||
}
|
||||
@property NSMenuItem *quitItem;
|
||||
@property NSMenuItem *preferencesItem;
|
||||
@property NSMenuItem *aboutItem;
|
||||
- (IBAction)onMenuItemClicked:(id)sender;
|
||||
- (NSMenu *)makeMenubar;
|
||||
@end
|
||||
|
||||
// init.m
|
||||
@interface appDelegate : NSObject <NSApplicationDelegate>
|
||||
@property menuManager *menuManager;
|
||||
@end
|
||||
#define appDelegate() ((appDelegate *) [NSApp delegate])
|
||||
|
||||
// util.m
|
||||
extern void setStandardControlFont(NSControl *);
|
||||
extern void disableAutocorrect(NSTextView *);
|
||||
|
||||
// entry.m
|
||||
extern void finishNewTextField(NSTextField *, BOOL);
|
||||
|
||||
// menu.m
|
||||
extern NSMenu *makeMenubar(void);
|
||||
|
|
Loading…
Reference in New Issue