# HG changeset patch # User Olaf Wintermann # Date 1396437671 -7200 # Node ID f8f22eb0b575b7a74c7e293011c6f4252802013f # Parent 06be29a56f8b0283107fb60122326b7e8c72aba9 added menu accelerators (Cocoa) diff -r 06be29a56f8b -r f8f22eb0b575 application/main.c --- a/application/main.c Wed Apr 02 09:59:38 2014 +0200 +++ b/application/main.c Wed Apr 02 13:21:11 2014 +0200 @@ -118,13 +118,18 @@ ui_menuitem("Dokument 1", action_doc1, NULL); ui_menuitem("Dokument 2", action_doc2, NULL); void ui_menuseparator(); - ui_menuseparator(); + ui_checkitem_nv("Check", "check1"); //ui_checkitem("Check", action_open, NULL); +<<<<<<< local + +======= ui_menuitem_st(UI_STOCK_CLOSE, action_close, NULL); +>>>>>>> other void ui_menuseparator(); ui_menuitem_list(list, action_document, list); - + ui_menuseparator(); + ui_menuitem("Close", action_close, NULL); ui_toolitem_st("new", UI_STOCK_NEW, action_new, NULL); diff -r 06be29a56f8b -r f8f22eb0b575 resource/template.app/Contents/Resources/English.lproj/MainMenu.nib Binary file resource/template.app/Contents/Resources/English.lproj/MainMenu.nib has changed diff -r 06be29a56f8b -r f8f22eb0b575 ui/cocoa/menu.m --- a/ui/cocoa/menu.m Wed Apr 02 09:59:38 2014 +0200 +++ b/ui/cocoa/menu.m Wed Apr 02 13:21:11 2014 +0200 @@ -32,6 +32,7 @@ #import "menu.h" #import "window.h" +#import "stock.h" @implementation UiMenuDelegate @@ -113,7 +114,17 @@ action:@selector(handleEvent:) keyEquivalent:@""]; [item setTarget:event]; - //[delegate addItem: item]; + currentItemIndex++; +} + +void ui_menuitem_st(char *stockid, ui_callback f, void *data) { + EventWrapper *event = [[EventWrapper alloc]initWithData:data callback:f]; + UiStockItem *si = ui_get_stock_item(stockid); + + NSMenuItem *item = [currentMenu addItemWithTitle:si->label + action:@selector(handleEvent:) keyEquivalent:si->keyEquivalent]; + [item setTarget:event]; + currentItemIndex++; } diff -r 06be29a56f8b -r f8f22eb0b575 ui/cocoa/stock.h --- a/ui/cocoa/stock.h Wed Apr 02 09:59:38 2014 +0200 +++ b/ui/cocoa/stock.h Wed Apr 02 13:21:11 2014 +0200 @@ -32,11 +32,12 @@ typedef struct UiStockItem { NSString *label; + NSString *keyEquivalent; NSImage *image; } UiStockItem; void ui_stock_init(); -void ui_add_stock_item(char *stock_id, NSString *label, NSImage *image); +void ui_add_stock_item(char *stock_id, NSString *label, NSString *keyEquivalent, NSImage *image); UiStockItem* ui_get_stock_item(char *stock_id); diff -r 06be29a56f8b -r f8f22eb0b575 ui/cocoa/stock.m --- a/ui/cocoa/stock.m Wed Apr 02 09:59:38 2014 +0200 +++ b/ui/cocoa/stock.m Wed Apr 02 13:21:11 2014 +0200 @@ -36,21 +36,22 @@ void ui_stock_init() { stock_items = ucx_map_new(64); - ui_add_stock_item(UI_STOCK_NEW, @"New", nil); - ui_add_stock_item(UI_STOCK_OPEN, @"Open", nil); - ui_add_stock_item(UI_STOCK_SAVE, @"Save", nil); - ui_add_stock_item(UI_STOCK_SAVE_AS, @"Save as ...", nil); - ui_add_stock_item(UI_STOCK_CLOSE, @"Close", nil); - ui_add_stock_item(UI_STOCK_UNDO, @"Undo", nil); - ui_add_stock_item(UI_STOCK_REDO, @"Redo", nil); + ui_add_stock_item(UI_STOCK_NEW, @"New", @"n", nil); + ui_add_stock_item(UI_STOCK_OPEN, @"Open", @"o", nil); + ui_add_stock_item(UI_STOCK_SAVE, @"Save", @"s", nil); + ui_add_stock_item(UI_STOCK_SAVE_AS, @"Save as ...", @"", nil); + ui_add_stock_item(UI_STOCK_CLOSE, @"Close", @"w", nil); + ui_add_stock_item(UI_STOCK_UNDO, @"Undo", @"z", nil); + ui_add_stock_item(UI_STOCK_REDO, @"Redo", @"", nil); - ui_add_stock_item(UI_STOCK_GO_BACK, @"Back", [NSImage imageNamed: NSImageNameGoLeftTemplate]); - ui_add_stock_item(UI_STOCK_GO_FORWARD, @"Forward", [NSImage imageNamed: NSImageNameGoRightTemplate]); + ui_add_stock_item(UI_STOCK_GO_BACK, @"Back", @"", [NSImage imageNamed: NSImageNameGoLeftTemplate]); + ui_add_stock_item(UI_STOCK_GO_FORWARD, @"Forward", @"", [NSImage imageNamed: NSImageNameGoRightTemplate]); } -void ui_add_stock_item(char *stock_id, NSString *label, NSImage *image) { +void ui_add_stock_item(char *stock_id, NSString *label, NSString *keyEquivalent, NSImage *image) { UiStockItem *i = malloc(sizeof(UiStockItem)); i->label = label; + i->keyEquivalent = keyEquivalent; i->image = image; ucx_map_cstr_put(stock_items, stock_id, i);