/// <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
        /// <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
Exemplo n.º 3
0
        }         // 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
Exemplo n.º 4
0
        }                                        // 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