Build custom columns support with Makefile
[git-cheetah/kirill.git] / menuengine.c
blobb6eb60fda0760b46649b84c1707bc660c6e32d0a
2 #include "cache.h"
3 #include "menuengine.h"
5 struct menu_item *active_menu;
6 unsigned int next_active_item;
8 void reset_active_menu()
10 if (active_menu) {
11 do {
12 struct menu_item item;
13 next_active_item--;
15 item = active_menu[next_active_item];
16 if (MENU_ITEM_CLEANUP == item.selection) {
17 if (item.string)
18 free(item.string);
19 if (item.helptext)
20 free(item.helptext);
23 } while (next_active_item);
25 free(active_menu);
28 active_menu = 0;
29 next_active_item = 0;
32 void append_active_menu(const struct menu_item item)
34 active_menu = realloc(active_menu,
35 (next_active_item + 1) * sizeof(struct menu_item));
36 active_menu[next_active_item] = item;
37 next_active_item++;
40 void build_menu_items(struct git_data *data,
41 selection_to_mask *mask_builder,
42 const struct menu_item menu_def[],
43 const unsigned int menu_def_count,
44 void *platform)
46 unsigned int i = 0;
47 const unsigned int selection = mask_builder(data);
49 reset_active_menu();
51 if (MENU_ITEM_LAST == selection)
52 return;
54 for (i = 0;
55 i < menu_def_count && MENU_ITEM_LAST != menu_def[i].selection;
56 i++)
57 if ((menu_def[i].selection & selection) ==
58 menu_def[i].selection) {
59 if (menu_def[i].builder(data, &menu_def[i], platform))
60 append_active_menu(menu_def[i]);
64 char *get_menu_item_text(unsigned int id)
66 if (id > next_active_item)
67 return NULL;
69 return active_menu[id].helptext;
72 void handle_menu_item(void *data, unsigned int id)
74 if (id > next_active_item)
75 return;
77 (active_menu[id].handler)(data, id);