added menu accelerators (Cocoa)

Wed, 02 Apr 2014 13:21:11 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 02 Apr 2014 13:21:11 +0200
changeset 19
f8f22eb0b575
parent 18
06be29a56f8b
child 20
2dda1ad6dc7a

added menu accelerators (Cocoa)

application/main.c file | annotate | diff | comparison | revisions
resource/template.app/Contents/Resources/English.lproj/MainMenu.nib file | annotate | diff | comparison | revisions
ui/cocoa/menu.m file | annotate | diff | comparison | revisions
ui/cocoa/stock.h file | annotate | diff | comparison | revisions
ui/cocoa/stock.m file | annotate | diff | comparison | revisions
--- 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);
Binary file resource/template.app/Contents/Resources/English.lproj/MainMenu.nib has changed
--- 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++;
 }
 
--- 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);
--- 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);

mercurial