public static IEnumerable <TemplateHeader> GetTemplates([NotNull] DatabaseUri databaseUri)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));

            var list = AppHost.Settings.Get(ControlsTemplateSelectorRecent, GetStorageKey(databaseUri), string.Empty) as string;

            if (string.IsNullOrEmpty(list))
            {
                return(Enumerable.Empty <TemplateHeader>());
            }

            var result = new List <TemplateHeader>();

            var items = list.Split('|');

            foreach (var item in items)
            {
                var parts = item.Split('^');

                var name   = parts[0];
                var itemId = new ItemId(new Guid(parts[1]));
                var path   = parts[2];

                var templateUri = new ItemUri(databaseUri, itemId);

                var template = new TemplateHeader(templateUri, name, string.Empty, path, Resources.Recent, false);

                result.Add(template);
            }

            return(result);
        }
Beispiel #2
0
        public void GetTemplates([NotNull] DatabaseUri databaseUri, [NotNull] GetItemsCompleted <TemplateHeader> completed, bool includeBranches)
        {
            Assert.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Assert.ArgumentNotNull(completed, nameof(completed));

            ExecuteCompleted callback = delegate(string response, ExecuteResult executeResult)
            {
                var root = response.ToXElement();
                if (root == null)
                {
                    completed(Enumerable.Empty <TemplateHeader>());
                    return;
                }

                var result = new List <TemplateHeader>();

                foreach (var child in root.Elements())
                {
                    var itemId  = new ItemId(new Guid(child.GetAttributeValue("id")));
                    var itemUri = new ItemUri(databaseUri, itemId);

                    var parentPath = (Path.GetDirectoryName(child.GetAttributeValue("path")) ?? string.Empty).Replace("\\", "/");
                    var template   = new TemplateHeader(itemUri, child.Value, child.GetAttributeValue("icon"), child.GetAttributeValue("path"), parentPath, child.Name == "branch");

                    result.Add(template);
                }

                completed(result);
            };

            databaseUri.Site.DataService.ExecuteAsync("Templates.GetTemplates", callback, databaseUri.DatabaseName.ToString(), includeBranches ? "true" : "false");
        }
        public static void AddToRecent([NotNull] TemplateHeader templateHeader)
        {
            Assert.ArgumentNotNull(templateHeader, nameof(templateHeader));

            var s = templateHeader.Name + @"^" + templateHeader.TemplateUri.ItemId + @"^" + templateHeader.Path;

            var entries = new List <string>();

            var list = AppHost.Settings.Get(ControlsTemplateSelectorRecent, GetStorageKey(templateHeader.TemplateUri.DatabaseUri), string.Empty) as string ?? string.Empty;

            if (!string.IsNullOrEmpty(list))
            {
                entries.AddRange(list.Split('|'));
            }

            entries.Remove(s);
            entries.Insert(0, s);

            while (entries.Count > 10)
            {
                entries.RemoveAt(10);
            }

            var result = string.Join("|", entries);

            AppHost.Settings.Set(ControlsTemplateSelectorRecent, GetStorageKey(templateHeader.TemplateUri.DatabaseUri), result);
        }
        public SetBaseTemplate([NotNull] TemplateHeader templateHeader)
        {
            TemplateHeader = templateHeader;
            Assert.ArgumentNotNull(templateHeader, nameof(templateHeader));

            Text         = "Set Base Template " + templateHeader.Name;
            Group        = "Template";
            SortingValue = 1000;
        }
        public void AddToRecent([NotNull] TemplateHeader template)
        {
            Assert.ArgumentNotNull(template, nameof(template));

            foreach (var source in TemplateSelectorFilters)
            {
                source.AddToRecent(template);
            }
        }
        private IEnumerable <TemplateHeader> ParseTemplates([NotNull] DatabaseUri databaseUri, [NotNull] XElement root)
        {
            Debug.ArgumentNotNull(databaseUri, nameof(databaseUri));
            Debug.ArgumentNotNull(root, nameof(root));

            var result = new List <TemplateHeader>();

            foreach (var child in root.Elements())
            {
                var itemId  = new ItemId(new Guid(child.GetAttributeValue("id")));
                var itemUri = new ItemUri(databaseUri, itemId);

                var parentPath = AppHost.Files.GetDirectoryName(child.GetAttributeValue("path")).Replace("\\", "/");
                var template   = new TemplateHeader(itemUri, child.Value, child.GetAttributeValue("icon"), child.GetAttributeValue("path"), parentPath, child.Name == "branch");

                result.Add(template);
            }

            return(result);
        }
        public override void AddToRecent(TemplateHeader templateHeader)
        {
            Assert.ArgumentNotNull(templateHeader, nameof(templateHeader));

            RecentTemplateManager.AddToRecent(templateHeader);
        }
        public void LoadTemplates(ContextMenuStrip templateMenu, ContextMenuStrip subTemplateMenu, esSettings settings)
        {
            try
            {
                this.Settings = settings;

                if (this.TreeViewNodeSorter == null)
                {
                    this.TreeViewNodeSorter = new NodeSorter();
                    InitializeComponent();

                    Template.SetTemplateCachePath(esSettings.TemplateCachePath);
                    Template.SetCompilerAssemblyPath(Settings.CompilerAssemblyPath);
                }

                this.Nodes.Clear();
                rootNode                    = this.Nodes.Add("Templates");
                rootNode.ImageIndex         = 2;
                rootNode.SelectedImageIndex = 2;
                rootNode.ContextMenuStrip   = this.folderMenu;

                this.currentUIControls.Clear();
                this.coll.Clear();

                string[] files = Directory.GetFiles(Settings.TemplatePath, "*.est", SearchOption.AllDirectories);

                foreach (string file in files)
                {
                    Template       template = new Template();
                    TemplateHeader header   = null;
                    string[]       nspace   = null;

                    try
                    {
                        // If this doesn't meet the criteria skip it and move on to the next file
                        template.Parse(file);

                        header = template.Header;
                        if (header.Namespace == string.Empty)
                        {
                            continue;
                        }

                        nspace = header.Namespace.Split('.');
                        if (nspace == null || nspace.Length == 0)
                        {
                            continue;
                        }
                    }
                    catch { continue; }

                    // Okay, we have a valid template with a namespace ...
                    TreeNode   node = rootNode;
                    TreeNode[] temp = null;

                    // This foreach loop adds all of the folder entries based on
                    // the namespace
                    foreach (string entry in nspace)
                    {
                        temp = node.Nodes.Find(entry, true);

                        if (temp == null || temp.Length == 0)
                        {
                            node      = node.Nodes.Add(entry);
                            node.Name = entry;
                        }
                        else
                        {
                            node = temp[0];
                        }

                        node.ImageIndex         = 2;
                        node.SelectedImageIndex = 2;
                        node.ContextMenuStrip   = this.folderMenu;
                    }

                    // Now we add the final node, with the template icon and stash the Template
                    // in the node's "Tag" property for later use when they execute it.
                    node             = node.Nodes.Add(template.Header.Title);
                    node.Tag         = template;
                    node.ToolTipText = header.Description + " : " + header.Author + " (" + header.Version + ")" + Environment.NewLine;


                    if (header.IsSubTemplate)
                    {
                        node.ImageIndex         = 0;
                        node.SelectedImageIndex = 0;
                        node.ContextMenuStrip   = subTemplateMenu;
                    }
                    else
                    {
                        node.ImageIndex         = 1;
                        node.SelectedImageIndex = 1;
                        node.ContextMenuStrip   = templateMenu;
                    }
                }

                // Now, let's sort it so it all makes sense ...
                this.Sort();
            }
            catch { }
        }
 public virtual void AddToRecent(TemplateHeader templateHeader)
 {
     Assert.ArgumentNotNull(templateHeader, nameof(templateHeader));
 }