private void parseSingleBlockItem(IMyTerminalBlock Block, DasMenuItem Parent) { DasMenuBlockItem BlockItem = (new DasMenuItemFactory()).createBlockItem(Block); Parent.addChild(BlockItem); parseActions(BlockItem); }
public DasMenuItem runCommand(string cmd, DasMenuItem MenuItem, string args) { DasMenuItem Result = MenuItem; switch (cmd) { case CMD_ENTER: Result = getReturn(MenuItem, args); break; case CMD_ESC: Result = getEsc(MenuItem, args); break; case CMD_NEXT: Result = getCycle(MenuItem, args, 1); break; case CMD_PREV: Result = getCycle(MenuItem, args, -1); break; default: break; } return(Result); }
private string renderLine(DasMenuItem Item, DasMenuConfig Config, DasMenuItem Selected) { string content = Config.getFormat(); string indent = getIndent(Item, Config); content = content.Replace(DasMenuConfig.FORMAT_INDENT, indent); if (indent.Length > 0) { content = content.Replace(DasMenuConfig.FORMAT_INDENTSPACE, " "); } else { content = content.Replace(DasMenuConfig.FORMAT_INDENTSPACE, ""); } if (Item.Equals(Selected)) { content = content.Replace(DasMenuConfig.FORMAT_SELECTED, Config.getSelector()); } else { content = content.Replace(DasMenuConfig.FORMAT_SELECTED, ""); } content = content.Replace(DasMenuConfig.FORMAT_LABEL, Item.getLabel()); return(content); }
private DasMenuPathItem parsePathItem(string data, DasMenuItem Parent) { DasMenuPathItem PathItem = (new DasMenuItemFactory()).createPathItem(data); Parent.addChild(PathItem); return(PathItem); }
public void removeChild(DasMenuItem value) { if (getChilds().Contains(value)) { getChilds().Remove(value); value.setParent(null); } }
private DasMenuItem getCurrentItem(DasMenuArgs Args, DasMenuItem RootItem, string selected) { DasMenuCommand Cmd = new DasMenuCommand(); DasMenuItem Item; Item = Cmd.runCommand(Args.getCommand(), RootItem, selected); return(Item); }
private void parseBlockItems(string data, DasMenuItem Parent) { List <IMyTerminalBlock> Blocks = getBlocksFromDataSegment(data); for (int i_Blocks = 0; i_Blocks < Blocks.Count; i_Blocks++) { IMyTerminalBlock Block = Blocks[i_Blocks]; parseSingleBlockItem(Block, Parent); } }
public int getIndex(DasMenuItem Item) { int index = 0; if (Item.hasParent()) { index = Item.getParent().getChilds().IndexOf(Item); } return(index); }
public DasMenuItem getEsc(DasMenuItem RootItem, string currentSelection) { DasMenuItemRepository ItemRepository = new DasMenuItemRepository(); DasMenuItem CurrentItem = ItemRepository.getItemOrDefault(ItemRepository.findOneByUid(RootItem, currentSelection), RootItem); if (CurrentItem.hasParent()) { CurrentItem = CurrentItem.getParent(); } return(CurrentItem); }
private string getIndent(DasMenuItem Item, DasMenuConfig Config) { string indent = ""; int count = Item.countParents(); for (int i = 0; i < count; i++) { indent += Config.getIndent(); } return(indent); }
public void addChild(DasMenuItem value) { if (!getChilds().Contains(value)) { getChilds().Add(value); if (value.hasParent()) { value.getParent().removeChild(value); } value.setParent(this); } }
public string getContent(DasMenuItem RootItem, DasMenuConfig Config, DasMenuItem Selected) { StringBuilder content = new StringBuilder(); if (Config.getTitle().Length > 0) { content.AppendLine(Config.getTitle()); } content.Append(getContentChilds(RootItem, Config, Selected)); return(content.ToString()); }
public DasMenuItem getItemOrDefault(DasMenuItem Item, DasMenuItem RootItem) { DasMenuItem Result = Item; if (Result == null) { if (RootItem.hasChilds()) { Result = RootItem.getChilds()[0]; } } return(Result); }
public DasMenuItem getReturn(DasMenuItem RootItem, string currentSelection) { DasMenuItemRepository ItemRepository = new DasMenuItemRepository(); DasMenuItem CurrentItem = ItemRepository.getItemOrDefault(ItemRepository.findOneByUid(RootItem, currentSelection), RootItem); if (CurrentItem.hasChilds()) { CurrentItem = CurrentItem.getChilds()[0]; } else if (CurrentItem is DasMenuActionItem) { ApplyAction(CurrentItem as DasMenuActionItem); } return(CurrentItem); }
private StringBuilder getContentChilds(DasMenuItem RootItem, DasMenuConfig Config, DasMenuItem Selected) { List <DasMenuItem> Items = RootItem.getChilds(); StringBuilder content = new StringBuilder(); for (int i_Items = 0; i_Items < Items.Count; i_Items++) { DasMenuItem Item = Items[i_Items]; content.AppendLine(renderLine(Item, Config, Selected)); if (Item.hasChilds()) { content.Append(getContentChilds(Item, Config, Selected).ToString()); } } return(content); }
private void parseLine(string data, DasMenuRootItem RootItem) { List <string> dataSegments = new List <string>(); DasMenuItem Parent = RootItem; dataSegments = getSegments(data); for (int i_dataSegments = 0; i_dataSegments < dataSegments.Count; i_dataSegments++) { string dataSegment = dataSegments[i_dataSegments]; if (isLastOfCollection(dataSegments, i_dataSegments)) { parseBlockItems(dataSegment, Parent); Parent = RootItem; } else { Parent = parsePathItem(dataSegment, Parent); } } }
private void run(string args) { DasMenuArgs MenuArgs = new DasMenuArgs(args, ARGS_SPLIT); DasMenuTextPanelRepository TextPanelRepository = new DasMenuTextPanelRepository(GridTerminalSystem); DasMenuFactory MenuFactory = new DasMenuFactory(GridTerminalSystem); IMyTextPanel TextPanel = TextPanelRepository.findLcd(MenuArgs.getLcdPattern()); if (TextPanel != null) { string SelectedItemUid = TextPanelRepository.readStateFromTextPanel(TextPanel); DasMenuConfig MenuConfig = new DasMenuConfig(TextPanel.GetPrivateText()); DasMenuItem RootItem = MenuFactory.createFromConfig(MenuConfig); DasMenuView View = new DasMenuView(); DasMenuItem CurrentItem = getCurrentItem(MenuArgs, RootItem, SelectedItemUid); string content = View.getContent(RootItem, MenuConfig, CurrentItem); TextPanel.WritePublicText(content); Echo(content); TextPanelRepository.saveStateToTextPanel(TextPanel, CurrentItem.getUid()); } }
public DasMenuItem findOneByUid(DasMenuItem HaystackItem, string uid) { DasMenuItem Item = null; if (HaystackItem.getUid().Equals(uid)) { Item = HaystackItem; } else if (HaystackItem.hasChilds()) { for (int i = 0; i < HaystackItem.getChilds().Count; i++) { Item = findOneByUid(HaystackItem.getChilds()[i], uid); if (Item != null) { break; } } } return(Item); }
public DasMenuItem getCycle(DasMenuItem RootItem, string currentSelection, int steps) { DasMenuItemRepository ItemRepository = new DasMenuItemRepository(); DasMenuItem CurrentItem = ItemRepository.getItemOrDefault(ItemRepository.findOneByUid(RootItem, currentSelection), RootItem); if (CurrentItem.hasParent()) { int maxIndex = CurrentItem.getParent().getChilds().Count - 1; int currentIndex = ItemRepository.getIndex(CurrentItem); int newIndex = currentIndex + steps; if (newIndex < 0) { newIndex = maxIndex; } if (newIndex > maxIndex) { newIndex = 0; } CurrentItem = CurrentItem.getParent().getChilds()[newIndex]; } return(CurrentItem); }
public void setParent(DasMenuItem value) { Parent = value; }
private void parseSingleAction(ITerminalAction Action, DasMenuItem Parent) { DasMenuActionItem ActionItem = (new DasMenuItemFactory()).createActionItem(Action); Parent.addChild(ActionItem); }