/// <summary></summary> /// <param name="parentPane"></param> /// <param name="paneData"></param> /// <param name="fullUri"></param> public PpsGenericWpfChildPane(PpsGenericWpfWindowPane parentPane, object paneData, Uri fullUri) : base(parentPane) { if (parentPane == null) { throw new ArgumentNullException("parentPane"); } // create a new request object for this child pane Request = parentPane.Shell.CreateHttp(new Uri(fullUri, ".")); // create the control if (paneData is XDocument xamlCode) { Control = PpsXamlParser.LoadAsync <FrameworkElement>(PpsXmlPosition.CreateLinePositionReader(xamlCode.CreateReader()), new PpsXamlReaderSettings() { Code = this, CloseInput = true, ServiceProvider = (IServiceProvider)Parent }).AwaitTask(); } else if (paneData is LuaChunk luaCode) // run the chunk on the current table { luaCode.Run(this, this); } else { throw new ArgumentException(); // todo: } Control.DataContext = this; CallMemberDirect("OnControlCreated", Array.Empty <object>(), rawGet: true, ignoreNilFunction: true); } // ctor
} // func CompileLambdaAsync /// <summary></summary> /// <typeparam name="T"></typeparam> /// <param name="xSource"></param> /// <param name="throwException"></param> /// <param name="argumentNames"></param> /// <returns></returns> public Task <T> CompileLambdaAsync <T>(XElement xSource, bool throwException, params string[] argumentNames) where T : class { var code = xSource.Value; var pos = PpsXmlPosition.GetXmlPositionFromAttributes(xSource); return(CompileLambdaAsync <T>(code, pos.LineInfo ?? "dummy.lua", throwException, argumentNames)); } // func CompileAsync
/// <summary>Load the content of the panel</summary> /// <param name="arguments"></param> /// <returns></returns> protected virtual async Task LoadInternAsync(LuaTable arguments) { // save the arguments this.Arguments = arguments; // prepare the base var paneUri = GetPaneUri(arguments, true); Request = Shell.CreateHttp(new Uri(paneUri, ".")); // Load the xaml file and code var paneData = await this.LoadPaneDataAsync(arguments, paneUri); // Create the Wpf-Control if (paneData is XDocument xamlCode) { //PpsXamlParser.DebugTransform = true; Control = await PpsXamlParser.LoadAsync <PpsGenericWpfControl>(PpsXmlPosition.CreateLinePositionReader(xamlCode.CreateReader()), new PpsXamlReaderSettings() { BaseUri = paneUri, Code = this, ServiceProvider = this, ParserServices = GetRootParserServices() } ); //PpsXamlParser.DebugTransform = false; Control.Resources[PpsShellWpf.CurrentWindowPaneKey] = this; OnControlCreated(); } else if (paneData is LuaChunk luaCode) // run the code to initalize control, setControl should be called. { Shell.RunScript(luaCode, this, true, this); } if (Control == null) { throw new ArgumentException("No control created."); } // init bindings Control.DataContext = this; DependencyPropertyDescriptor.FromProperty(PpsGenericWpfControl.TitleProperty, typeof(PpsGenericWpfControl)).AddValueChanged(Control, ControlTitleChanged); DependencyPropertyDescriptor.FromProperty(PpsGenericWpfControl.SubTitleProperty, typeof(PpsGenericWpfControl)).AddValueChanged(Control, ControlSubTitleChanged); DependencyPropertyDescriptor.FromProperty(PpsGenericWpfControl.HasSideBarProperty, typeof(PpsGenericWpfControl)).AddValueChanged(Control, ControlHasSideBarChanged); // notify changes on control OnPropertyChanged(nameof(Control)); OnPropertyChanged(nameof(Title)); OnPropertyChanged(nameof(SubTitle)); OnPropertyChanged(nameof(IPpsWindowPane.HasSideBar)); OnPropertyChanged(nameof(Commands)); } // proc LoadInternAsync
} // func CompileAsync /// <summary>Compiles a chunk in the background.</summary> /// <param name="xSource">Source element of the chunk. The Value is the source code, and the positions encoded in the tag (see GetXmlPositionFromAttributes).</param> /// <param name="throwException">If the compile fails, should be raised a exception.</param> /// <param name="arguments">Argument definition for the chunk.</param> /// <returns>Compiled chunk</returns> public Task <LuaChunk> CompileAsync(XElement xSource, bool throwException, params KeyValuePair <string, Type>[] arguments) { if (xSource == null) { throw new ArgumentNullException(nameof(xSource)); } var code = xSource.Value; var pos = PpsXmlPosition.GetXmlPositionFromAttributes(xSource); return(CompileAsync(code, pos.LineInfo ?? "dummy.lua", throwException, arguments)); } // func CompileAsync
} // func OpenXmlDocumentAsync private async Task RefreshDefaultResourcesAsync() { // update the resources, load a server site resource dictionary using (var xml = PpsXmlPosition.CreateLinePositionReader(await OpenXmlDocumentAsync("wpf/styles.xaml", true, true))) { if (xml == null) { return; // no styles found } // move to "theme" await xml.ReadStartElementAsync(StuffUI.xnTheme); // parse resources await xml.ReadStartElementAsync(StuffUI.xnResources); await UpdateResourcesAsync(xml); await xml.ReadEndElementAsync(); // resource await xml.ReadEndElementAsync(); // theme } } // proc RefreshDefaultResourcesAsync
} // proc RefreshDefaultResourcesAsync private async Task RefreshTemplatesAsync() { var priority = 1; using (var xml = PpsXmlPosition.CreateLinePositionReader(await OpenXmlDocumentAsync("wpf/templates.xaml", true, true))) { if (xml == null) { return; // no templates found } // read root await xml.ReadStartElementAsync(StuffUI.xnTemplates); while (xml.NodeType != XmlNodeType.EndElement) { if (xml.NodeType == XmlNodeType.Element) { if (xml.IsName(StuffUI.xnResources)) { if (!await xml.ReadAsync()) { break; // fetch element } // check for a global resource dictionary, and update the main resources await UpdateResourcesAsync(xml); await xml.ReadEndElementAsync(); // resource } else if (xml.IsName(StuffUI.xnTemplate)) { var key = xml.GetAttribute("key", String.Empty); if (String.IsNullOrEmpty(key)) { xml.Skip(); break; } var templateDefinition = templateDefinitions[key]; if (templateDefinition == null) { templateDefinition = new PpsDataTemplateDefinition(this, key); templateDefinitions.AppendItem(templateDefinition); } priority = await templateDefinition.AppendTemplateAsync(xml, priority); await xml.ReadEndElementAsync(); await xml.SkipAsync(); } else { await xml.SkipAsync(); } } else { await xml.ReadAsync(); } } await xml.ReadEndElementAsync(); // templates } // using xml // remove unused templates // todo: } // proc RefreshTemplatesAsync