fixed menu update

Tue, 01 Apr 2014 11:50:32 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 01 Apr 2014 11:50:32 +0200
changeset 15
7a36f91c22f7
parent 14
e2fd132ab781
child 16
a499c8a72c15

fixed menu update

application/main.c file | annotate | diff | comparison | revisions
ui/cocoa/menu.m file | annotate | diff | comparison | revisions
ui/cocoa/toolkit.h file | annotate | diff | comparison | revisions
ui/cocoa/toolkit.m file | annotate | diff | comparison | revisions
--- a/application/main.c	Mon Mar 31 20:22:16 2014 +0200
+++ b/application/main.c	Tue Apr 01 11:50:32 2014 +0200
@@ -98,6 +98,7 @@
 
 void action_document(UiEvent *event, void *data) {
     UiList *documents = data;
+    printf("selected document: %d\n", event->intval);
 }
 
 
--- a/ui/cocoa/menu.m	Mon Mar 31 20:22:16 2014 +0200
+++ b/ui/cocoa/menu.m	Tue Apr 01 11:50:32 2014 +0200
@@ -173,12 +173,9 @@
 }
 
 int ui_update_item_list(UiCocoaWindow *window, void *data) {
-    printf("update list\n");
-    
     UiMenuItemList *itemList = data;
     UiList *list = itemList->list;
     
-    printf("oldcount: %d\n", itemList->oldcount);
     for(int r=0;r<itemList->oldcount;r++) {
         [itemList->menu removeItemAtIndex:itemList->index];
     }
@@ -187,13 +184,19 @@
     int i = itemList->index;
     [itemList->menu insertItem: [NSMenuItem separatorItem] atIndex: i];
     i++;
-    do {
+    while(str) {
+        EventWrapper *event = [[EventWrapper alloc]initWithData:itemList->data callback:itemList->callback];
+        [event setIntval: i - itemList->index - 1];
+        
         NSString *title = [[NSString alloc] initWithUTF8String:str];
-        NSMenuItem *item = [[NSMenuItem alloc]initWithTitle:title action:@selector(handleStateEvent:) keyEquivalent:@""];
+        NSMenuItem *item = [[NSMenuItem alloc]initWithTitle:title action:@selector(handleEvent:) keyEquivalent:@""];
+        [item setTarget:event];
         
         [itemList->menu insertItem:item atIndex:i];
+        
+        str = ui_list_next(list);
         i++;
-    } while ((str = ui_list_next(list)));
+    }
     
     itemList->oldcount = i - itemList->index;
     
--- a/ui/cocoa/toolkit.h	Mon Mar 31 20:22:16 2014 +0200
+++ b/ui/cocoa/toolkit.h	Tue Apr 01 11:50:32 2014 +0200
@@ -34,15 +34,17 @@
 @interface EventWrapper : NSObject {
     void         *data;
     ui_callback  callback;
+    int          value;
 }
 
 - (EventWrapper*) initWithData: (void*)data callback:(ui_callback) f;
 
 - (void*) data;
 - (void) setData:(void*)d;
-
 - (ui_callback) callback;
 - (void) setCallback: (ui_callback)f;
+- (int) intval;
+- (void) setIntval:(int)i;
 
 - (BOOL)handleEvent:(id)sender;
 - (BOOL)handleStateEvent:(id)sender;
--- a/ui/cocoa/toolkit.m	Mon Mar 31 20:22:16 2014 +0200
+++ b/ui/cocoa/toolkit.m	Tue Apr 01 11:50:32 2014 +0200
@@ -80,6 +80,7 @@
 - (EventWrapper*) initWithData: (void*)d callback:(ui_callback) f {
     data = d;
     callback = f;
+    value = 0;
     return self;
 }
 
@@ -101,6 +102,14 @@
     callback = f;
 }
 
+- (int) intval {
+    return value;
+}
+
+- (void) setIntval:(int)i {
+    value = i;
+}
+
 
 - (BOOL)handleEvent:(id)sender {
     NSWindow *activeWindow = [NSApp keyWindow];
@@ -110,7 +119,7 @@
         event.obj = [(UiCocoaWindow*)activeWindow object];
         event.window = event.obj->window;
         event.document = event.obj->document;
-        event.intval = 0;
+        event.intval = value;
     }
     if(callback) {
         callback(&event, data);

mercurial