ui/cocoa/menu.m

changeset 15
7a36f91c22f7
parent 14
e2fd132ab781
child 19
f8f22eb0b575
equal deleted inserted replaced
14:e2fd132ab781 15:7a36f91c22f7
171 [item->item setState: item->state]; 171 [item->item setState: item->state];
172 return 0; 172 return 0;
173 } 173 }
174 174
175 int ui_update_item_list(UiCocoaWindow *window, void *data) { 175 int ui_update_item_list(UiCocoaWindow *window, void *data) {
176 printf("update list\n");
177
178 UiMenuItemList *itemList = data; 176 UiMenuItemList *itemList = data;
179 UiList *list = itemList->list; 177 UiList *list = itemList->list;
180 178
181 printf("oldcount: %d\n", itemList->oldcount);
182 for(int r=0;r<itemList->oldcount;r++) { 179 for(int r=0;r<itemList->oldcount;r++) {
183 [itemList->menu removeItemAtIndex:itemList->index]; 180 [itemList->menu removeItemAtIndex:itemList->index];
184 } 181 }
185 182
186 char *str = ui_list_first(list); 183 char *str = ui_list_first(list);
187 int i = itemList->index; 184 int i = itemList->index;
188 [itemList->menu insertItem: [NSMenuItem separatorItem] atIndex: i]; 185 [itemList->menu insertItem: [NSMenuItem separatorItem] atIndex: i];
189 i++; 186 i++;
190 do { 187 while(str) {
188 EventWrapper *event = [[EventWrapper alloc]initWithData:itemList->data callback:itemList->callback];
189 [event setIntval: i - itemList->index - 1];
190
191 NSString *title = [[NSString alloc] initWithUTF8String:str]; 191 NSString *title = [[NSString alloc] initWithUTF8String:str];
192 NSMenuItem *item = [[NSMenuItem alloc]initWithTitle:title action:@selector(handleStateEvent:) keyEquivalent:@""]; 192 NSMenuItem *item = [[NSMenuItem alloc]initWithTitle:title action:@selector(handleEvent:) keyEquivalent:@""];
193 [item setTarget:event];
193 194
194 [itemList->menu insertItem:item atIndex:i]; 195 [itemList->menu insertItem:item atIndex:i];
196
197 str = ui_list_next(list);
195 i++; 198 i++;
196 } while ((str = ui_list_next(list))); 199 }
197 200
198 itemList->oldcount = i - itemList->index; 201 itemList->oldcount = i - itemList->index;
199 202
200 return 0; 203 return 0;
201 } 204 }

mercurial