コード例 #1
0
        private void LoadThemes()
        {
            tsmiTheme.DropDownItems.Clear();

            if (!Directory.Exists("themes"))
            {
                Directory.CreateDirectory("themes");
            }
            string[] themeParents = Directory.GetDirectories("themes");

            foreach (string themeParent in themeParents)
            {
                string ThemeName = Path.GetFileName(themeParent);
                try
                {
                    string themeMetaFile = Path.Combine(themeParent, "theme.json");
                    if (File.Exists(themeMetaFile))
                    {
                        ThemeDesc desc = JsonConvert.DeserializeObject <ThemeDesc>(File.ReadAllText(themeMetaFile));
                        if (!string.IsNullOrWhiteSpace(desc.name))
                        {
                            ThemeName = desc.name;
                        }
                    }
                }
                catch { }

                ToolStripMenuItem itmTop = new ToolStripMenuItem(ThemeName);
                tsmiTheme.DropDownItems.Add(itmTop);

                string[] themeFiles = Directory.GetFiles(themeParent, "*.json", SearchOption.TopDirectoryOnly);
                foreach (string themeFile in themeFiles)
                {
                    string ThemeFileName = Path.GetFileNameWithoutExtension(themeFile);

                    if (ThemeFileName.ToLowerInvariant() == "theme")
                    {
                        continue;
                    }

                    string DisplayName = ThemeFileName;

                    try
                    {
                        ThemeSubDesc desc = JsonConvert.DeserializeObject <ThemeSubDesc>(File.ReadAllText(themeFile));
                        if (!string.IsNullOrWhiteSpace(desc.name))
                        {
                            DisplayName = desc.name;
                        }
                    }
                    catch { }

                    ToolStripItem itm = new ToolStripMenuItem(DisplayName, null, LoadTheme);
                    itm.Tag = themeFile;
                    itmTop.DropDownItems.Add(itm);
                }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Nielk1/VSCView
        private void LoadThemes()
        {
            tsmiTheme.DropDownItems.Clear();
            ThemeMenuItems.Clear();

            if (!Directory.Exists("themes"))
            {
                Directory.CreateDirectory("themes");
            }
            IEnumerable <string> themeParents = Directory.EnumerateFiles("themes", "theme.json", SearchOption.AllDirectories)
                                                .OrderBy(dr => dr.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).Skip(1).FirstOrDefault())
                                                .ThenBy(dr => (dr.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).Skip(2).FirstOrDefault()?.ToLowerInvariant() ?? string.Empty) == "default" ? 0 : 1)
                                                .ThenBy(dr => dr);

            themeParents = themeParents.Select(dr => Path.GetDirectoryName(dr)).Distinct().ToArray();

            foreach (string themeParent in themeParents)
            {
                string[] PathMiddleParts = themeParent.Split(Path.DirectorySeparatorChar).Reverse().Skip(1).Reverse().Skip(1).ToArray();

                ToolStripMenuItem parentMenuItem = tsmiTheme;
                for (int j = 0; j < PathMiddleParts.Length; j++)
                {
                    string dir_key = string.Join(Path.DirectorySeparatorChar.ToString(), PathMiddleParts.Take(j + 1).ToArray());
                    if (!ThemeMenuItems.ContainsKey(dir_key))
                    {
                        string nameFile  = Path.Combine("themes", dir_key, "name.txt");
                        string icon_file = Path.Combine("themes", dir_key, "icon.png");
                        string name      = File.Exists(nameFile) ? File.ReadAllText(nameFile).Trim() : null;
                        if (string.IsNullOrWhiteSpace(name))
                        {
                            name = PathMiddleParts.Skip(j).First();
                        }
                        ThemeMenuItems[dir_key] = new ToolStripMenuItem(name);
                        if (File.Exists(icon_file))
                        {
                            ThemeMenuItems[dir_key].Image        = Image.FromFile(icon_file);
                            ThemeMenuItems[dir_key].ImageScaling = ToolStripItemImageScaling.None;
                        }
                        parentMenuItem.DropDownItems.Add(ThemeMenuItems[dir_key]);
                    }
                    parentMenuItem = ThemeMenuItems[dir_key];
                }

                string ThemeName = Path.GetFileName(themeParent);
                try
                {
                    string themeMetaFile = Path.Combine(themeParent, "theme.json");
                    if (File.Exists(themeMetaFile))
                    {
                        ThemeDesc desc = JsonConvert.DeserializeObject <ThemeDesc>(File.ReadAllText(themeMetaFile));
                        if (!string.IsNullOrWhiteSpace(desc.name))
                        {
                            ThemeName = desc.name;
                        }
                    }
                }
                catch { }

                ToolStripMenuItem itmTop        = new ToolStripMenuItem(ThemeName);
                string            themeIconFile = Path.Combine(themeParent, "icon.png");
                if (File.Exists(themeIconFile))
                {
                    itmTop.Image        = Image.FromFile(themeIconFile);
                    itmTop.ImageScaling = ToolStripItemImageScaling.None;
                }
                parentMenuItem.DropDownItems.Add(itmTop);

                IEnumerable <string> themeFiles = Directory.EnumerateFiles(themeParent, "*.json", SearchOption.TopDirectoryOnly);
                foreach (string themeFile in themeFiles)
                {
                    string ThemeFileName = Path.GetFileNameWithoutExtension(themeFile);

                    if (ThemeFileName.ToLowerInvariant() == "theme")
                    {
                        continue;
                    }

                    string DisplayName = ThemeFileName;

                    try
                    {
                        ThemeSubDesc desc = JsonConvert.DeserializeObject <ThemeSubDesc>(File.ReadAllText(themeFile));
                        if (!string.IsNullOrWhiteSpace(desc.name))
                        {
                            DisplayName = desc.name;
                        }
                    }
                    catch { }

                    ToolStripItem itm = new ToolStripMenuItem(DisplayName, null, LoadTheme);
                    itm.Tag = themeFile;
                    itmTop.DropDownItems.Add(itm);
                }
            }
        }
コード例 #3
0
        public About()
        {
            InitializeComponent();
            this.Text = String.Format("About {0}", AssemblyTitle);
            this.labelProductName.Text   = AssemblyProduct;
            this.labelVersion.Text       = String.Format("Version {0}", AssemblyVersion);
            this.labelCopyright.Text     = AssemblyCopyright;
            this.labelCompanyName.Text   = AssemblyCompany;
            this.textBoxDescription.Text = AssemblyDescription;

            {
                if (!Directory.Exists("themes"))
                {
                    Directory.CreateDirectory("themes");
                }
                string[] themeParents = Directory.GetDirectories("themes");

                foreach (string themeParent in themeParents)
                {
                    string ThemeName = Path.GetFileName(themeParent);
                    List <ThemeDescAuthors> authors = null;
                    try
                    {
                        string themeMetaFile = Path.Combine(themeParent, "theme.json");
                        if (File.Exists(themeMetaFile))
                        {
                            ThemeDesc desc = JsonConvert.DeserializeObject <ThemeDesc>(File.ReadAllText(themeMetaFile));
                            if (!string.IsNullOrWhiteSpace(desc.name))
                            {
                                ThemeName = desc.name;
                            }
                            authors = desc.authors;
                        }
                        authors?.ForEach(dr =>
                        {
                            if (string.IsNullOrWhiteSpace(dr.name))
                            {
                                if (string.IsNullOrWhiteSpace(dr.url))
                                {
                                    dr.name = null;
                                    dr.url  = null;
                                }
                                else
                                {
                                    dr.name = dr.url;
                                }
                            }
                            else if (string.IsNullOrWhiteSpace(dr.url))
                            {
                                dr.url = null;
                            }
                        });
                        authors = authors?.Where(dr => dr.name != null).ToList();
                        if (authors?.Any(dr => dr.url != null) ?? false) // at least one url
                        {
                            LinkLabel label = new LinkLabel();
                            label.Text             = ThemeName;
                            label.LinkColor        = Color.Yellow;
                            label.ActiveLinkColor  = Color.GreenYellow;
                            label.VisitedLinkColor = Color.DarkGreen;
                            foreach (var author in authors)
                            {
                                label.Text += " - ";
                                if (author.url != null)
                                {
                                    label.Links.Add(label.Text.Length, author.name.Length, author.url);
                                }
                                label.Text += author.name;
                            }
                            label.LinkClicked += Label_LinkClicked;
                            label.Padding      = new Padding(0, 0, 0, 5);
                            label.AutoSize     = true;
                            pnlThemes.Controls.Add(label);
                        }
                        else if ((authors?.Count ?? 0) > 0)
                        {
                            Label label = new Label();
                            label.Font     = LinkLabel.DefaultFont;
                            label.Text     = ThemeName + " - " + string.Join(" - ", authors.Select(dr => dr.name));
                            label.Padding  = new Padding(0, 0, 0, 5);
                            label.AutoSize = true;
                            pnlThemes.Controls.Add(label);
                        }
                        else
                        {
                            Label label = new Label();
                            label.Font     = LinkLabel.DefaultFont;
                            label.Text     = ThemeName;
                            label.Padding  = new Padding(0, 0, 0, 5);
                            label.AutoSize = true;
                            pnlThemes.Controls.Add(label);
                        }
                    }
                    catch { }
                }
            }
        }
コード例 #4
0
ファイル: About.cs プロジェクト: Nielk1/VSCView
        public About()
        {
            InitializeComponent();
            this.Text = String.Format("About {0}", AssemblyTitle);
            this.labelProductName.Text   = AssemblyProduct;
            this.labelVersion.Text       = String.Format("Version {0}", AssemblyVersion);
            this.labelCopyright.Text     = AssemblyCopyright;
            this.labelCompanyName.Text   = AssemblyCompany;
            this.textBoxDescription.Text = AssemblyDescription;

            {
                if (!Directory.Exists("themes"))
                {
                    Directory.CreateDirectory("themes");
                }
                string[] themeParents = Directory.GetFiles("themes", "theme.json", SearchOption.AllDirectories);
                themeParents = themeParents.Select(dr => Path.GetDirectoryName(dr)).Distinct().ToArray();

                foreach (string themeParent in themeParents)
                {
                    string[]      PathMiddleParts = themeParent.Split(Path.DirectorySeparatorChar).Reverse().Skip(1).Reverse().Skip(1).ToArray();
                    List <string> PathBits        = new List <string>();
                    for (int j = 0; j < PathMiddleParts.Length; j++)
                    {
                        string dir_key  = string.Join(Path.DirectorySeparatorChar.ToString(), PathMiddleParts.Take(j + 1).ToArray());
                        string nameFile = Path.Combine("themes", dir_key, "name.txt");
                        string name     = File.Exists(nameFile) ? File.ReadAllText(nameFile).Trim() : null;
                        if (string.IsNullOrWhiteSpace(name))
                        {
                            name = PathMiddleParts.Skip(j).First();
                        }
                        PathBits.Add(name);
                    }
                    string ParentBits = string.Join(Path.DirectorySeparatorChar.ToString(), PathBits.ToArray());

                    string ThemeName = Path.GetFileName(themeParent);
                    List <ThemeDescAuthors> authors = null;
                    try
                    {
                        string themeMetaFile = Path.Combine(themeParent, "theme.json");
                        if (File.Exists(themeMetaFile))
                        {
                            ThemeDesc desc = JsonConvert.DeserializeObject <ThemeDesc>(File.ReadAllText(themeMetaFile));
                            if (!string.IsNullOrWhiteSpace(desc.name))
                            {
                                ThemeName = desc.name;
                            }
                            authors = desc.authors;
                        }
                        authors?.ForEach(dr =>
                        {
                            if (string.IsNullOrWhiteSpace(dr.name))
                            {
                                if (string.IsNullOrWhiteSpace(dr.url))
                                {
                                    dr.name = null;
                                    dr.url  = null;
                                }
                                else
                                {
                                    dr.name = dr.url;
                                }
                            }
                            else if (string.IsNullOrWhiteSpace(dr.url))
                            {
                                dr.url = null;
                            }
                        });
                        authors   = authors?.Where(dr => dr.name != null).ToList();
                        ThemeName = string.IsNullOrWhiteSpace(ParentBits) ? ThemeName : ParentBits + Path.DirectorySeparatorChar + ThemeName;
                        if (authors?.Any(dr => dr.url != null) ?? false) // at least one url
                        {
                            LinkLabel label = new LinkLabel();
                            label.Text             = ThemeName;
                            label.LinkColor        = Color.Yellow;
                            label.ActiveLinkColor  = Color.GreenYellow;
                            label.VisitedLinkColor = Color.DarkGreen;
                            foreach (var author in authors)
                            {
                                label.Text += " - ";
                                if (author.url != null)
                                {
                                    label.Links.Add(label.Text.Length, author.name.Length, author.url);
                                }
                                label.Text += author.name;
                            }
                            label.LinkClicked += Label_LinkClicked;
                            label.Padding      = new Padding(0, 0, 0, 5);
                            label.AutoSize     = true;
                            pnlThemes.Controls.Add(label);
                        }
                        else if ((authors?.Count ?? 0) > 0)
                        {
                            Label label = new Label();
                            label.Font     = LinkLabel.DefaultFont;
                            label.Text     = ThemeName + " - " + string.Join(" - ", authors.Select(dr => dr.name));
                            label.Padding  = new Padding(0, 0, 0, 5);
                            label.AutoSize = true;
                            pnlThemes.Controls.Add(label);
                        }
                        else
                        {
                            Label label = new Label();
                            label.Font     = LinkLabel.DefaultFont;
                            label.Text     = ThemeName;
                            label.Padding  = new Padding(0, 0, 0, 5);
                            label.AutoSize = true;
                            pnlThemes.Controls.Add(label);
                        }
                    }
                    catch { }
                }
            }
        }