Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private void ReadRecentFileList()
        {
            var recentFiles = _recentFileList.GetRecentFiles();

            _recentFileInfos.Clear();

            foreach (var rfile in recentFiles)
            {
                if (!File.Exists(rfile))
                {
                    continue; // ignore non-existing files
                }
                var file    = new FileInfo(rfile);
                var fileExt = file.Extension.ToLower().Substring(1);
                if (ComponentInformations.EditorExtension != null && ComponentInformations.EditorExtension.ContainsKey(fileExt))
                {
                    bool   cte         = (fileExt == "cte");
                    Type   editorType  = ComponentInformations.EditorExtension[fileExt];
                    string xmlFile     = Path.Combine(file.Directory.FullName, Path.GetFileNameWithoutExtension(file.Name) + ".xml");
                    string iconFile    = null;
                    Span   description = new Span();
                    string title       = null;

                    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)
                            {
                                description.Inlines.Add(new Bold(XMLHelper.ConvertFormattedXElement(summaryElement)));
                            }
                            if (descriptionElement != null && descriptionElement.Value.Length > 1)
                            {
                                description.Inlines.Add(new LineBreak());
                                description.Inlines.Add(new LineBreak());
                                description.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);
                            }
                        }
                        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 = Path.GetFileNameWithoutExtension(file.Name).Replace("-", " ").Replace("_", " ");
                    }
                    if (description.Inlines.Count == 0)
                    {
                        string desc;
                        if (cte)
                        {
                            desc = Properties.Resources.This_is_an_AnotherEditor_file_;
                        }
                        else
                        {
                            desc = Properties.Resources.This_is_a_WorkspaceManager_file_;
                        }
                        description.Inlines.Add(new Run(desc));
                    }

                    if (iconFile == null || !File.Exists(iconFile))
                    {
                        iconFile = Path.Combine(file.Directory.FullName, Path.GetFileNameWithoutExtension(file.Name) + ".png");
                    }
                    var image = File.Exists(iconFile) ? ImageLoader.LoadImage(new Uri(iconFile)) : editorType.GetImage(0).Source;

                    _recentFileInfos.Add(new RecentFileInfo()
                    {
                        File        = rfile,
                        Title       = title,
                        Description = new TextBlock(description)
                        {
                            MaxWidth = 400, TextWrapping = TextWrapping.Wrap
                        },
                        Icon       = image,
                        EditorType = editorType
                    });
                }
            }
            _recentFileInfos.Reverse();
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 4
0
        public TabInfo GenerateTabInfo(FileInfo file)
        {
            bool   component = (file.Extension.ToLower() == ".component");
            string title     = null;
            Span   summary   = new Span();
            string iconFile  = null;
            string xmlFile   = Path.Combine(file.Directory.FullName, Path.GetFileNameWithoutExtension(file.Name) + ".xml");

            if (File.Exists(xmlFile))
            {
                try
                {
                    XElement xml = XElement.Load(xmlFile);

                    var titleElement       = XMLHelper.GetGlobalizedElementFromXML(xml, "title");
                    var summaryElement     = XMLHelper.GetGlobalizedElementFromXML(xml, "summary");
                    var descriptionElement = XMLHelper.GetGlobalizedElementFromXML(xml, "description");

                    if (titleElement != null)
                    {
                        title = titleElement.Value;
                        if (title != null && title.Trim().Length > 0)
                        {
                            summary.Inlines.Add(new Bold(XMLHelper.ConvertFormattedXElement(titleElement)));
                        }
                    }

                    if (summaryElement != null)
                    {
                        if (summary.Inlines.Count > 0)
                        {
                            summary.Inlines.Add(new LineBreak());
                            summary.Inlines.Add(new LineBreak());
                        }
                        summary.Inlines.Add(new Bold(XMLHelper.ConvertFormattedXElement(summaryElement)));
                    }

                    if (descriptionElement != null && descriptionElement.Value.Length > 1)
                    {
                        if (summary.Inlines.Count > 0)
                        {
                            summary.Inlines.Add(new LineBreak());
                            summary.Inlines.Add(new LineBreak());
                        }
                        summary.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);
                    }

                    CopyText = (titleElement != null ? (titleElement.Value + Environment.NewLine + Environment.NewLine) : "") +
                               (summaryElement != null ? (summaryElement.Value + Environment.NewLine + Environment.NewLine) : "") +
                               (descriptionElement != null ? XMLHelper.ConvertFormattedXElementToString(descriptionElement) : "");
                }
                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 (summary.Inlines.Count == 0)
            {
                string desc = component ? Properties.Resources.This_is_a_standalone_component_ : Properties.Resources.This_is_a_WorkspaceManager_file_;
                summary.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 = ImageHelper.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;
                }
            }

            return(new TabInfo()
            {
                Tooltip = summary, Title = title, Icon = image, filename = file
            });
        }