static void remove_menu(struct menu_priv *item, int recursive) { if (recursive) { struct menu_priv *next,*child=item->child; while (child) { next=child->sibling; remove_menu(child, recursive); child=next; } } if (item->action) { gtk_ui_manager_remove_ui(item->gui->menu_manager, item->merge_id); gtk_action_group_remove_action(item->gui->dyn_group, item->action); #if 0 if (item->callback) g_signal_handler_disconnect(item->action, item->handler_id); #endif g_object_unref(item->action); } g_free(item->path); g_free(item); }
void file_menu( void ) { static saved = 1; char *buff, ans[2] = "y"; static char *menu[] = { "Main Menu", " 1.load screen font", " 2.load italic screen font", " 3.load 9 pins font", " 4.load italic 9 pins font", " 5.load 24 pins font", " 6.load italic 24 pins font", " 7.load super&subscript font", " 8.load italic superscript", " 9.load .FED file", "10.save font file", "11.continue working", "12.exit", 0 }; while ( 1 ) { switch ( popup_menu( menu, &buff ) ) { case 0: new_load = SCR_FONT; break; case 1: new_load = ITALIC_SCR_FONT; break; case 2: new_load = PRN_FONT; break; case 3: new_load = ITALIC_PRN_FONT; break; case 4: new_load = LQ_FONT; break; case 5: new_load = ITALIC_LQ_FONT; break; case 6: new_load = SUP_SUB_LQ_FONT; break; case 7: new_load = ITALIC_SUP_SUB_LQ_FONT; break; case 8: new_load = FED_FONT; break; case 9: if ( loaded ) { if ( save_font( ) ) { saved = !0; } } else { error_message( "You haven't load font yet!" ); } remove_menu( &buff ); continue; case 10: if ( first_file ) { error_message( "You haven't load font yet!" ); remove_menu( &buff ); continue; } remove_menu( &buff ); new_load = 0; first_file = 0; return; case 11: if ( !saved ) { switch ( immediatebox( 40, 10, NOTSAVEPROMPT, ans ) ) { case 1: if ( save_font( ) ) { terminate( ); exit( 0 ); } else { remove_menu( &buff ); continue; } case 0: terminate( ); exit( 0 ); case -1: remove_menu( &buff ); return; } } else { terminate( ); exit( 0 ); } } if ( new_load ) { if ( !saved ) { switch ( immediatebox( 40, 10, NOTSAVEPROMPT, ans ) ) { case 1: if ( save_font( ) ) { saved = !0; } else { remove_menu( &buff ); new_load = 0; continue; } break; case 0: break; case -1:remove_menu( &buff ); new_load = 0; continue; } } if ( load_font( ) ) { clearworkarea( ); print_table( 0 ); loaded = new_load; new_load = 0; first_file = 0; saved = 0; free( buff ); return; } else { remove_menu( &buff ); continue; } } } }
/* * Do the :menu command and relatives. */ void ex_menu ( exarg_T *eap /* Ex command arguments */ ) { char_u *menu_path; int modes; char_u *map_to; int noremap; int silent = FALSE; int special = FALSE; int unmenu; char_u *map_buf; char_u *arg; char_u *p; int i; int pri_tab[MENUDEPTH + 1]; int enable = MAYBE; /* TRUE for "menu enable", FALSE for "menu * disable */ vimmenu_T menuarg; modes = get_menu_cmd_modes(eap->cmd, eap->forceit, &noremap, &unmenu); arg = eap->arg; for (;; ) { if (STRNCMP(arg, "<script>", 8) == 0) { noremap = REMAP_SCRIPT; arg = skipwhite(arg + 8); continue; } if (STRNCMP(arg, "<silent>", 8) == 0) { silent = TRUE; arg = skipwhite(arg + 8); continue; } if (STRNCMP(arg, "<special>", 9) == 0) { special = TRUE; arg = skipwhite(arg + 9); continue; } break; } /* Locate an optional "icon=filename" argument. */ if (STRNCMP(arg, "icon=", 5) == 0) { arg += 5; while (*arg != NUL && *arg != ' ') { if (*arg == '\\') STRMOVE(arg, arg + 1); mb_ptr_adv(arg); } if (*arg != NUL) { *arg++ = NUL; arg = skipwhite(arg); } } /* * Fill in the priority table. */ for (p = arg; *p; ++p) if (!VIM_ISDIGIT(*p) && *p != '.') break; if (vim_iswhite(*p)) { for (i = 0; i < MENUDEPTH && !vim_iswhite(*arg); ++i) { pri_tab[i] = getdigits_int(&arg); if (pri_tab[i] == 0) pri_tab[i] = 500; if (*arg == '.') ++arg; } arg = skipwhite(arg); } else if (eap->addr_count && eap->line2 != 0) { pri_tab[0] = eap->line2; i = 1; } else i = 0; while (i < MENUDEPTH) pri_tab[i++] = 500; pri_tab[MENUDEPTH] = -1; /* mark end of the table */ /* * Check for "disable" or "enable" argument. */ if (STRNCMP(arg, "enable", 6) == 0 && vim_iswhite(arg[6])) { enable = TRUE; arg = skipwhite(arg + 6); } else if (STRNCMP(arg, "disable", 7) == 0 && vim_iswhite(arg[7])) { enable = FALSE; arg = skipwhite(arg + 7); } /* * If there is no argument, display all menus. */ if (*arg == NUL) { show_menus(arg, modes); return; } menu_path = arg; if (*menu_path == '.') { EMSG2(_(e_invarg2), menu_path); goto theend; } map_to = menu_translate_tab_and_shift(arg); /* * If there is only a menu name, display menus with that name. */ if (*map_to == NUL && !unmenu && enable == MAYBE) { show_menus(menu_path, modes); goto theend; } else if (*map_to != NUL && (unmenu || enable != MAYBE)) { EMSG(_(e_trailing)); goto theend; } if (enable != MAYBE) { /* * Change sensitivity of the menu. * For the PopUp menu, remove a menu for each mode separately. * Careful: menu_nable_recurse() changes menu_path. */ if (STRCMP(menu_path, "*") == 0) /* meaning: do all menus */ menu_path = (char_u *)""; if (menu_is_popup(menu_path)) { for (i = 0; i < MENU_INDEX_TIP; ++i) if (modes & (1 << i)) { p = popup_mode_name(menu_path, i); menu_nable_recurse(root_menu, p, MENU_ALL_MODES, enable); free(p); } } menu_nable_recurse(root_menu, menu_path, modes, enable); } else if (unmenu) { /* * Delete menu(s). */ if (STRCMP(menu_path, "*") == 0) /* meaning: remove all menus */ menu_path = (char_u *)""; /* * For the PopUp menu, remove a menu for each mode separately. */ if (menu_is_popup(menu_path)) { for (i = 0; i < MENU_INDEX_TIP; ++i) if (modes & (1 << i)) { p = popup_mode_name(menu_path, i); remove_menu(&root_menu, p, MENU_ALL_MODES, TRUE); free(p); } } /* Careful: remove_menu() changes menu_path */ remove_menu(&root_menu, menu_path, modes, FALSE); } else { /* * Add menu(s). * Replace special key codes. */ if (STRICMP(map_to, "<nop>") == 0) { /* "<Nop>" means nothing */ map_to = (char_u *)""; map_buf = NULL; } else if (modes & MENU_TIP_MODE) map_buf = NULL; /* Menu tips are plain text. */ else map_to = replace_termcodes(map_to, &map_buf, FALSE, TRUE, special); menuarg.modes = modes; menuarg.noremap[0] = noremap; menuarg.silent[0] = silent; add_menu_path(menu_path, &menuarg, pri_tab, map_to ); /* * For the PopUp menu, add a menu for each mode separately. */ if (menu_is_popup(menu_path)) { for (i = 0; i < MENU_INDEX_TIP; ++i) if (modes & (1 << i)) { p = popup_mode_name(menu_path, i); // Include all modes, to make ":amenu" work menuarg.modes = modes; add_menu_path(p, &menuarg, pri_tab, map_to); free(p); } } free(map_buf); } theend: ; }
/* * Remove the (sub)menu with the given name from the menu hierarchy * Called recursively. */ static int remove_menu ( vimmenu_T **menup, char_u *name, int modes, int silent /* don't give error messages */ ) { vimmenu_T *menu; vimmenu_T *child; char_u *p; if (*menup == NULL) return OK; /* Got to bottom of hierarchy */ /* Get name of this element in the menu hierarchy */ p = menu_name_skip(name); /* Find the menu */ while ((menu = *menup) != NULL) { if (*name == NUL || menu_name_equal(name, menu)) { if (*p != NUL && menu->children == NULL) { if (!silent) EMSG(_(e_notsubmenu)); return FAIL; } if ((menu->modes & modes) != 0x0) { #if defined(FEAT_GUI_W32) & defined(FEAT_TEAROFF) /* * If we are removing all entries for this menu,MENU_ALL_MODES, * Then kill any tearoff before we start */ if (*p == NUL && modes == MENU_ALL_MODES) { if (IsWindow(menu->tearoff_handle)) DestroyWindow(menu->tearoff_handle); } #endif if (remove_menu(&menu->children, p, modes, silent) == FAIL) return FAIL; } else if (*name != NUL) { if (!silent) EMSG(_(e_othermode)); return FAIL; } /* * When name is empty, we are removing all menu items for the given * modes, so keep looping, otherwise we are just removing the named * menu item (which has been found) so break here. */ if (*name != NUL) break; /* Remove the menu item for the given mode[s]. If the menu item * is no longer valid in ANY mode, delete it */ menu->modes &= ~modes; if (modes & MENU_TIP_MODE) free_menu_string(menu, MENU_INDEX_TIP); if ((menu->modes & MENU_ALL_MODES) == 0) free_menu(menup); else menup = &menu->next; } else menup = &menu->next; } if (*name != NUL) { if (menu == NULL) { if (!silent) EMSG2(_(e_nomenu), name); return FAIL; } /* Recalculate modes for menu based on the new updated children */ menu->modes &= ~modes; #if defined(FEAT_GUI_W32) & defined(FEAT_TEAROFF) if ((s_tearoffs) && (menu->children != NULL)) /* there's a tear bar.. */ child = menu->children->next; /* don't count tearoff bar */ else #endif child = menu->children; for (; child != NULL; child = child->next) menu->modes |= child->modes; if (modes & MENU_TIP_MODE) { free_menu_string(menu, MENU_INDEX_TIP); #if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32) \ && (defined(FEAT_BEVAL) || defined(FEAT_GUI_GTK)) /* Need to update the menu tip. */ if (gui.in_use) gui_mch_menu_set_tip(menu); #endif } if ((menu->modes & MENU_ALL_MODES) == 0) { /* The menu item is no longer valid in ANY mode, so delete it */ #if defined(FEAT_GUI_W32) & defined(FEAT_TEAROFF) if (s_tearoffs && menu->children != NULL) /* there's a tear bar.. */ free_menu(&menu->children); #endif *menup = menu; free_menu(menup); } } return OK; }
int teacher_menu(char *database){ int i, c, n, choice = 0; teacher *xteacher; WINDOW *win; ITEM **items; MENU *menu; n = teacher_number(database); start_color(); cbreak(); noecho(); keypad(stdscr, TRUE); xteacher = (teacher *)malloc(sizeof(teacher) * (n + 1)); items = (ITEM **)calloc(n + 3, sizeof(ITEM *)); for(i = 0; i < n; ++i) { xteacher[i] = get_teacher(database,i); items[i] = new_item(xteacher[i].name, NULL); } menu = new_menu((ITEM **)items); win = newwin(0, 0, 0, 0); int y,x; getmaxyx(win,y,x); keypad(win, TRUE); set_menu_win(menu, win); set_menu_sub(menu, derwin(win, y - 5, 38, 5, 0.4*x)); set_menu_format(menu,x - 4, 1); set_menu_mark(menu, " * "); set_menu_spacing(menu, 0, 2, 0); box(win, 0, 0); print_in_middle(win, 1, 0, x, "Teachers" , COLOR_PAIR(1)); mvwaddch(win, 2, 0, ACS_LTEE); mvwhline(win, 2, 1, ACS_HLINE, x - 2); mvwaddch(win, 2, x - 1, ACS_RTEE); mvwaddch(win, y - 3, 0, ACS_LTEE); mvwhline(win, y - 3, 1, ACS_HLINE, x - 2); mvwaddch(win, y - 3, x - 1, ACS_RTEE); refresh(); if(n) { if(n > 1) mvwprintw(win,y - 2, 2,"N:New Teacher\t\tR:Remove Teacher\tS:Sort\t\tB:Back\tQ:Quit"); else mvwprintw(win,y - 2, 2,"N:New Teacher\t\tR:Remove Teacher\tB:Back\tQ:Quit"); for(i = 0; i < choice; i++) menu_driver(menu, REQ_DOWN_ITEM); post_menu(menu); wrefresh(win); while((c = wgetch(win))){ switch(c) { case KEY_DOWN: menu_driver(menu, REQ_DOWN_ITEM); if(choice != n -1) choice++; break; case KEY_UP: menu_driver(menu, REQ_UP_ITEM); if(choice != 0) choice--; break; case 10: /* Enter */ remove_menu(menu,items,n); return choice; case 'R': case 'r': remove_teacher(database, choice); remove_menu(menu,items,n); return -1; case 'B': case 'b': remove_menu(menu,items,n); return n + 1; case 'N': case 'n': remove_menu(menu,items,n); return n + 2; case 'Q': case 'q': remove_menu(menu,items,n); return INT_MIN; default: break; } wrefresh(win); } } else { mvwprintw(win,y - 2, 2,"N:New Teacher\t\tB:Back\t\tQ:Quit"); mvwprintw(win,5,3*x/7,"No Teachers found :(\n"); wrefresh(win); curs_set(0); while((c = wgetch(win))) { switch(c) { case 'n': case 'N': remove_menu(menu,items,n); curs_set(1); return n+2; case 'b': case 'B': remove_menu(menu,items,n); curs_set(1); return n+1; case 'Q': case 'q': remove_menu(menu,items,n); curs_set(1); return INT_MIN; default: break; } wrefresh(win); } } free(xteacher); return -1; }
/* * Remove the (sub)menu with the given name from the menu hierarchy * Called recursively. */ static int remove_menu ( vimmenu_T **menup, char_u *name, int modes, bool silent /* don't give error messages */ ) { vimmenu_T *menu; vimmenu_T *child; char_u *p; if (*menup == NULL) return OK; /* Got to bottom of hierarchy */ /* Get name of this element in the menu hierarchy */ p = menu_name_skip(name); /* Find the menu */ while ((menu = *menup) != NULL) { if (*name == NUL || menu_name_equal(name, menu)) { if (*p != NUL && menu->children == NULL) { if (!silent) EMSG(_(e_notsubmenu)); return FAIL; } if ((menu->modes & modes) != 0x0) { if (remove_menu(&menu->children, p, modes, silent) == FAIL) return FAIL; } else if (*name != NUL) { if (!silent) EMSG(_(e_othermode)); return FAIL; } /* * When name is empty, we are removing all menu items for the given * modes, so keep looping, otherwise we are just removing the named * menu item (which has been found) so break here. */ if (*name != NUL) break; /* Remove the menu item for the given mode[s]. If the menu item * is no longer valid in ANY mode, delete it */ menu->modes &= ~modes; if (modes & MENU_TIP_MODE) free_menu_string(menu, MENU_INDEX_TIP); if ((menu->modes & MENU_ALL_MODES) == 0) free_menu(menup); else menup = &menu->next; } else menup = &menu->next; } if (*name != NUL) { if (menu == NULL) { if (!silent) EMSG2(_(e_nomenu), name); return FAIL; } /* Recalculate modes for menu based on the new updated children */ menu->modes &= ~modes; child = menu->children; for (; child != NULL; child = child->next) menu->modes |= child->modes; if (modes & MENU_TIP_MODE) { free_menu_string(menu, MENU_INDEX_TIP); } if ((menu->modes & MENU_ALL_MODES) == 0) { /* The menu item is no longer valid in ANY mode, so delete it */ *menup = menu; free_menu(menup); } } return OK; }
static void popup_deactivate(GtkWidget *widget, struct menu_priv *menu) { g_signal_handler_disconnect(widget, menu->handler_id); remove_menu(menu, 1); }