Exemplo n.º 1
0
 /// <summary>
 /// Initialize the option
 /// </summary>
 /// <param name="cap">Text to show in the menu for this option</param>
 /// <param name="key">Text for hotkey to show to the right of the text</param>
 /// <param name="tt">Tooltip to show in footer when this option is highlighted</param>
 /// <param name="close">If true, close the menu after activation, otherwise keep it open</param>
 /// <param name="exec">Function to call if the user chooses this option</param>
 /// <param name="radio">If set, this option is a radio button, and this function returns its value</param>
 /// <param name="submenu">Submenu to open for this option</param>
 public ConsoleMenuOption(string cap, string key, string tt, bool close,
                          Func <bool> exec = null, Func <bool> radio = null, ConsolePopupMenu submenu = null)
 {
     Caption     = cap;
     Key         = key;
     Tooltip     = tt;
     CloseParent = close;
     OnExec      = exec;
     SubMenu     = submenu;
     RadioActive = radio;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Return a popup menu representing the sort options for this list box
 /// </summary>
 public ConsolePopupMenu SortMenu()
 {
     if (sortMenu == null)
     {
         List <ConsoleMenuOption> opts = new List <ConsoleMenuOption>()
         {
             new ConsoleMenuOption(
                 "Ascending", "",
                 "Sort the list in ascending order",
                 true,
                 () => { SortDirection = ListSortDirection.Ascending; return(true); },
                 () => { return(sortDir == ListSortDirection.Ascending); }
                 ),
             new ConsoleMenuOption(
                 "Descending", "",
                 "Sort the list in descending order",
                 true,
                 () => { SortDirection = ListSortDirection.Descending; return(true); },
                 () => { return(sortDir == ListSortDirection.Descending); }
                 ),
             null
         };
         for (int i = 0; i < columns.Count; ++i)
         {
             // Our menus' lambas will share 'i' unless we capture it
             int newIndex = i;
             opts.Add(new ConsoleMenuOption(
                          string.IsNullOrEmpty(columns[i].Header)
                     ? $"Column #{i+1}"
                     : columns[i].Header,
                          "",
                          string.IsNullOrEmpty(columns[i].Header)
                     ? $"Sort the list by column #{i+1}"
                     : $"Sort the list by the {columns[i].Header} column",
                          true,
                          () => { SortColumnIndex = newIndex; return(true); },
                          () => { return(sortColIndex == newIndex); }
                          ));
         }
         sortMenu = new ConsolePopupMenu(opts);
     }
     return(sortMenu);
 }