Beispiel #1
0
        private void HandleTemplateDirectories(DirectoryInfo directory, CTTreeViewItem parent)
        {
            if (directory == null)
            {
                return;
            }

            //Read directory metainfos:
            var         dirName  = directory.Name;
            Inline      tooltip  = null;
            ImageSource dirImage = null;
            var         metainfo = directory.GetFiles("dir.xml");
            var         order    = -1;

            if (metainfo.Length > 0)
            {
                XElement metaXML = XElement.Load(metainfo[0].FullName);
                if (metaXML.Attribute("order") != null)
                {
                    order = int.Parse(metaXML.Attribute("order").Value);
                }

                var dirNameEl = XMLHelper.GetGlobalizedElementFromXML(metaXML, "name");
                if (dirNameEl.Value != null)
                {
                    dirName = dirNameEl.Value;
                }

                if (metaXML.Element("icon") != null && metaXML.Element("icon").Attribute("file") != null)
                {
                    var iconFile = Path.Combine(directory.FullName, metaXML.Element("icon").Attribute("file").Value);
                    if (File.Exists(iconFile))
                    {
                        dirImage = ImageLoader.LoadImage(new Uri(iconFile));
                    }
                }

                var summaryElement = XMLHelper.GetGlobalizedElementFromXML(metaXML, "summary");
                if (summaryElement != null)
                {
                    tooltip = XMLHelper.ConvertFormattedXElement(summaryElement);
                }
            }

            CTTreeViewItem item = new CTTreeViewItem(dirName, order, tooltip, dirImage);

            parent.Items.Add(item);

            foreach (var subDirectory in directory.GetDirectories())
            {
                HandleTemplateDirectories(subDirectory, item);
            }

            MakeTemplateInformation(directory, item);
        }
Beispiel #2
0
        private void FillTemplatesNavigationPane(DirectoryInfo templateDir, TreeView treeView)
        {
            var rootItem = new CTTreeViewItem(templateDir.Name);

            if (templateDir.Exists)
            {
                foreach (var subDirectory in templateDir.GetDirectories())
                {
                    HandleTemplateDirectories(subDirectory, rootItem);
                }

                MakeTemplateInformation(templateDir, rootItem);

                // sort listbox entries alphabetically
                TemplatesListBox.Items.SortDescriptions.Add(new SortDescription("Tag.Value", ListSortDirection.Ascending));
            }

            //Add root directory entries to the treeview based on their order number:
            var counter = 0;
            var items   = rootItem.Items.Cast <CTTreeViewItem>().ToList();

            rootItem.Items.Clear();
            while (items.Count > 0)
            {
                var item = items.FirstOrDefault(x => x.Order == counter);
                if (item != null)
                {
                    items.Remove(item);
                    treeView.Items.Add(item);
                }
                else
                {
                    treeView.Items.Add(new TreeViewItem()
                    {
                        Style = (Style)FindResource("SeparatorStyle")
                    });

                    if (items.All(x => x.Order < 0))
                    {
                        foreach (var it in items)
                        {
                            treeView.Items.Add(it);
                        }
                        return;
                    }
                }
                counter++;
            }
        }
Beispiel #3
0
        private void MakeTemplateInformation(DirectoryInfo info, CTTreeViewItem parent)
        {
            SolidColorBrush bg = Brushes.Transparent;

            foreach (var file in info.GetFiles().Where(x => (x.Extension.ToLower() == ".cwm") || (x.Extension.ToLower() == ".component")))
            {
                if (file.Name.StartsWith("."))
                {
                    continue;
                }
                bool   component = (file.Extension.ToLower() == ".component");
                string title     = null;
                Span   summary1  = new Span();
                Span   summary2  = new Span();
                string xmlFile   = Path.Combine(file.Directory.FullName, Path.GetFileNameWithoutExtension(file.Name) + ".xml");
                string iconFile  = null;
                Dictionary <string, List <string> > internationalizedKeywords = new Dictionary <string, List <string> >();
                if (File.Exists(xmlFile))
                {
                    try
                    {
                        XElement xml          = XElement.Load(xmlFile);
                        var      titleElement = XMLHelper.GetGlobalizedElementFromXML(xml, "title");
                        if (titleElement != null)
                        {
                            title = titleElement.Value;
                        }

                        var summaryElement     = XMLHelper.GetGlobalizedElementFromXML(xml, "summary");
                        var descriptionElement = XMLHelper.GetGlobalizedElementFromXML(xml, "description");
                        if (summaryElement != null)
                        {
                            summary1.Inlines.Add(new Bold(XMLHelper.ConvertFormattedXElement(summaryElement)));
                            summary2.Inlines.Add(new Bold(XMLHelper.ConvertFormattedXElement(summaryElement)));
                        }
                        if (descriptionElement != null && descriptionElement.Value.Length > 1)
                        {
                            summary1.Inlines.Add(new LineBreak());
                            summary1.Inlines.Add(new LineBreak());
                            summary1.Inlines.Add(XMLHelper.ConvertFormattedXElement(descriptionElement));
                            summary2.Inlines.Add(new LineBreak());
                            summary2.Inlines.Add(new LineBreak());
                            summary2.Inlines.Add(XMLHelper.ConvertFormattedXElement(descriptionElement));
                        }

                        if (xml.Element("icon") != null && xml.Element("icon").Attribute("file") != null)
                        {
                            iconFile = Path.Combine(file.Directory.FullName, xml.Element("icon").Attribute("file").Value);
                        }

                        foreach (var keywordTag in xml.Elements("keywords"))
                        {
                            var    langAtt = keywordTag.Attribute("lang");
                            string lang    = "en";
                            if (langAtt != null)
                            {
                                lang = langAtt.Value;
                            }
                            var keywords = keywordTag.Value;
                            if (keywords != null || keywords != "")
                            {
                                foreach (var keyword in keywords.Split(','))
                                {
                                    if (!internationalizedKeywords.ContainsKey(lang))
                                    {
                                        internationalizedKeywords.Add(lang, new List <string>());
                                    }
                                    internationalizedKeywords[lang].Add(keyword.Trim());
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        //we do nothing if the loading of an description xml fails => this is not a hard error
                    }
                }

                if ((title == null) || (title.Trim() == ""))
                {
                    title = component ? file.Name : Path.GetFileNameWithoutExtension(file.Name).Replace("-", " ").Replace("_", " ");
                }

                if (summary1.Inlines.Count == 0)
                {
                    string desc = component ? Properties.Resources.This_is_a_standalone_component_ : Properties.Resources.This_is_a_WorkspaceManager_file_;
                    summary1.Inlines.Add(new Run(desc));
                    summary2.Inlines.Add(new Run(desc));
                }

                if (iconFile == null || !File.Exists(iconFile))
                {
                    iconFile = Path.Combine(file.Directory.FullName, Path.GetFileNameWithoutExtension(file.Name) + ".png");
                }
                ImageSource image = null;
                if (File.Exists(iconFile))
                {
                    try
                    {
                        image = ImageLoader.LoadImage(new Uri(iconFile));
                    }
                    catch (Exception)
                    {
                        image = null;
                    }
                }
                else
                {
                    var ext = file.Extension.Remove(0, 1);
                    if (!component && ComponentInformations.EditorExtension.ContainsKey(ext))
                    {
                        Type editorType = ComponentInformations.EditorExtension[ext];
                        image = editorType.GetImage(0).Source;
                    }
                }

                System.Collections.ArrayList list = new System.Collections.ArrayList();
                list.Add(new TabInfo()
                {
                    Filename = file,
                });

                ListBoxItem searchItem = CreateTemplateListBoxItem(file, title, summary1, image);

                if (internationalizedKeywords.Count > 0)
                {
                    list.Add(internationalizedKeywords);
                }

                ((StackPanel)searchItem.Content).Tag = list;
                TemplatesListBox.Items.Add(searchItem);

                CTTreeViewItem item = new CTTreeViewItem(file, title, summary2, image)
                {
                    Background = bg
                };
                ToolTipService.SetShowDuration(item, Int32.MaxValue);
                item.MouseDoubleClick += TemplateItemDoubleClick;
                parent.Items.Add(item);
            }
        }