public static List <LogInfo> VisibleOp(EngineState s, CodeCommand cmd) { List <LogInfo> logs = new List <LogInfo>(8); Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_VisibleOp)); CodeInfo_VisibleOp infoOp = cmd.Info as CodeInfo_VisibleOp; Plugin p = cmd.Addr.Plugin; PluginSection iface = p.GetInterface(out string ifaceSecName); if (iface == null) { logs.Add(new LogInfo(LogState.Error, $"Plugin [{cmd.Addr.Plugin.ShortPath}] does not have section [{ifaceSecName}]")); return(logs); } List <UICommand> uiCodes = iface.GetUICodes(true); List <Tuple <string, bool> > prepArgs = new List <Tuple <string, bool> >(); foreach (CodeInfo_Visible info in infoOp.InfoList) { string visibilityStr = StringEscaper.Preprocess(s, info.Visibility); bool visibility = false; if (visibilityStr.Equals("True", StringComparison.OrdinalIgnoreCase)) { visibility = true; } else if (visibilityStr.Equals("False", StringComparison.OrdinalIgnoreCase) == false) { throw new ExecuteException($"Invalid boolean value [{visibilityStr}]"); } prepArgs.Add(new Tuple <string, bool>(info.InterfaceKey, visibility)); } List <UICommand> uiCmdList = new List <UICommand>(); foreach (Tuple <string, bool> args in prepArgs) { UICommand uiCmd = uiCodes.Find(x => x.Key.Equals(args.Item1, StringComparison.OrdinalIgnoreCase)); if (uiCmd == null) { logs.Add(new LogInfo(LogState.Error, $"Cannot find interface control [{args.Item1}] from section [{ifaceSecName}]")); continue; } uiCmd.Visibility = args.Item2; uiCmdList.Add(uiCmd); } UICommand.Update(uiCmdList); foreach (Tuple <string, bool> args in prepArgs) { logs.Add(new LogInfo(LogState.Success, $"Interface control [{args.Item1}]'s visibility set to [{args.Item2}]")); } // Re-render Plugin Application.Current.Dispatcher.Invoke(() => { MainWindow w = (Application.Current.MainWindow as MainWindow); if (w.CurMainTree.Plugin == cmd.Addr.Plugin) { w.DrawPlugin(cmd.Addr.Plugin); } }); return(logs); }
private static CodeCommand PackCommand(CodeType type, List <CodeCommand> cmds) { Debug.Assert(0 < cmds.Count); CodeType packType; CodeInfo packInfo; switch (type) { case CodeType.TXTAddLine: packType = CodeType.TXTAddLineOp; packInfo = new CodeInfo_TXTAddLineOp(cmds); break; case CodeType.TXTReplace: packType = CodeType.TXTReplaceOp; packInfo = new CodeInfo_TXTReplaceOp(cmds); break; case CodeType.TXTDelLine: packType = CodeType.TXTDelLineOp; packInfo = new CodeInfo_TXTDelLineOp(cmds); break; case CodeType.IniRead: packType = CodeType.IniReadOp; packInfo = new CodeInfo_IniReadOp(cmds); break; case CodeType.IniWrite: packType = CodeType.IniWriteOp; packInfo = new CodeInfo_IniWriteOp(cmds); break; case CodeType.IniDelete: packType = CodeType.IniDeleteOp; packInfo = new CodeInfo_IniDeleteOp(cmds); break; case CodeType.IniReadSection: packType = CodeType.IniReadSectionOp; packInfo = new CodeInfo_IniReadSectionOp(cmds); break; case CodeType.IniAddSection: packType = CodeType.IniAddSectionOp; packInfo = new CodeInfo_IniAddSectionOp(cmds); break; case CodeType.IniDeleteSection: packType = CodeType.IniDeleteSectionOp; packInfo = new CodeInfo_IniDeleteSectionOp(cmds); break; case CodeType.IniWriteTextLine: packType = CodeType.IniWriteTextLineOp; packInfo = new CodeInfo_IniWriteTextLineOp(cmds); break; case CodeType.Visible: packType = CodeType.VisibleOp; packInfo = new CodeInfo_VisibleOp(cmds); break; case CodeType.ReadInterface: packType = CodeType.ReadInterfaceOp; packInfo = new CodeInfo_ReadInterfaceOp(cmds); break; case CodeType.WriteInterface: packType = CodeType.WriteInterfaceOp; packInfo = new CodeInfo_WriteInterfaceOp(cmds); break; case CodeType.WimExtract: packType = CodeType.WimExtractOp; packInfo = new CodeInfo_WimExtractOp(cmds); break; case CodeType.WimPathAdd: // Use WimPathAdd as representative of WimPath* packType = CodeType.WimPathOp; packInfo = new CodeInfo_WimPathOp(cmds); break; default: throw new InternalException("Internal Logic Error at CodeOptimizer.InternalOptimize"); } return(new CodeCommand(MergeRawCodes(cmds), cmds[0].Section, packType, packInfo, cmds[0].LineIdx)); }