Inheritance: ICloneable, INotifyPropertyChanged
Beispiel #1
0
        public static void SaveThemes(BindingList <ThemeInfo> themes)
        {
            var themesArray = new ThemeInfo[themes.Count - 1 + 1];

            themes.CopyTo(themesArray, 0);
            SaveThemes(themesArray);
        }
Beispiel #2
0
        /// <summary>
        /// Takes a theme in memory and update the color values that the user might have changed
        /// </summary>
        /// <param name="themeToUpdate"></param>
        public static void UpdateThemeXMLValues(ThemeInfo themeToUpdate)
        {
            var bytesIn     = File.ReadAllBytes(themeToUpdate.URI);
            var manipulator = new MremoteNGPaletteManipulator(bytesIn, themeToUpdate.ExtendedPalette);
            var bytesOut    = manipulator.mergePalette(themeToUpdate.ExtendedPalette);

            File.WriteAllBytes(themeToUpdate.URI, bytesOut);
        }
Beispiel #3
0
        public static void SaveToXmlFile(ThemeInfo themeInfo, string filename)
        {
            var themeList = new List <ThemeInfo> {
                themeInfo
            };

            SaveToXmlFile(themeList, filename);
        }
Beispiel #4
0
        /// <summary>
        /// Save the theme to file, name property is used as filename
        /// The baseTheme is used as a template, by copy that file and rewrite the extpalette values
        /// </summary>
        /// <param name="themeToSave"></param>
        /// <param name="baseTheme"></param>
        public static void SaveToXmlFile(ThemeInfo themeToSave, ThemeInfo baseTheme)
        {
            var oldURI        = baseTheme.URI;
            var directoryName = Path.GetDirectoryName(oldURI);
            var toSaveURI     = directoryName + Path.DirectorySeparatorChar + themeToSave.Name + ".vstheme";

            File.Copy(baseTheme.URI, toSaveURI);
            themeToSave.URI = toSaveURI;
        }
Beispiel #5
0
        public static List <ThemeInfo> LoadFromXmlFile(string filename)
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.Load(filename);

            var fileInfoNode    = xmlDocument.SelectSingleNode("/mRemoteNG/FileInfo");
            var fileInfoVersion = new Version(fileInfoNode.Attributes["Version"].Value);

            if (fileInfoVersion > new Version(1, 0))
            {
                throw (new FileFormatException($"Unsupported FileInfo version ({fileInfoVersion})."));
            }

            var fileTypeNode = fileInfoNode.SelectSingleNode("./FileType");
            var fileType     = fileTypeNode.InnerText;

            if (fileType != "Theme")
            {
                throw (new FileFormatException($"Incorrect FileType ({fileType}). Expected \"Theme\"."));
            }

            var fileTypeVersion = new Version(fileInfoNode.SelectSingleNode("./FileTypeVersion").InnerText);

            if (fileTypeVersion > new Version(1, 0))
            {
                throw (new FileFormatException($"Unsupported FileTypeVersion ({fileTypeVersion})."));
            }

            var themeNodes = xmlDocument.SelectNodes("/mRemoteNG/Theme");
            var themes     = new List <ThemeInfo>();
            var themeType  = (new ThemeInfo()).GetType();
            var colorType  = (new Color()).GetType();

            foreach (XmlNode themeNode in themeNodes)
            {
                var themeInfo = new ThemeInfo {
                    Name = themeNode.Attributes?["Name"].Value
                };
                foreach (XmlNode colorNode in themeNode.SelectNodes("./Color"))
                {
                    var colorName    = colorNode.Attributes?["Name"].Value;
                    var colorValue   = colorNode.Attributes?["Value"].Value;
                    var propertyInfo = themeType.GetProperty(colorName);
                    if (propertyInfo == null || !(propertyInfo.PropertyType == colorType))
                    {
                        continue;
                    }
                    propertyInfo.SetValue(themeInfo, DecodeColorName(colorValue), null);
                }
                themes.Add(themeInfo);
            }

            return(themes);
        }
Beispiel #6
0
 //Delete a theme from memory and disk
 public void deleteTheme(ThemeInfo themeToDelete)
 {
     if (!themes.Contains(themeToDelete.Name))
     {
         return;
     }
     if (ActiveTheme == themeToDelete)
     {
         ActiveTheme = DefaultTheme;
     }
     themes.Remove(themeToDelete.Name);
     ThemeSerializer.DeleteFile(themeToDelete);
 }
Beispiel #7
0
        public override void LoadSettings()
        {
            base.SaveSettings();

            _themeList = new BindingList<ThemeInfo>(ThemeManager.LoadThemes());
            cboTheme.DataSource = _themeList;
            cboTheme.SelectedItem = ThemeManager.ActiveTheme;
            cboTheme_SelectionChangeCommitted(this, new EventArgs());

            ThemePropertyGrid.PropertySort = PropertySort.Categorized;

            _originalTheme = ThemeManager.ActiveTheme;
        }
Beispiel #8
0
        /// <summary>
        /// Add a new theme based on an existing one by cloning and renaming, the theme is saved to disk
        /// </summary>
        /// <param name="baseTheme"></param>
        /// <param name="newThemeName"></param>
        /// <returns></returns>
        public ThemeInfo addTheme(ThemeInfo baseTheme, string newThemeName)
        {
            if (themes.Contains(newThemeName))
            {
                return(null);
            }
            var modifiedTheme = (ThemeInfo)baseTheme.Clone();

            modifiedTheme.Name         = newThemeName;
            modifiedTheme.IsExtendable = true;
            modifiedTheme.IsThemeBase  = false;
            ThemeSerializer.SaveToXmlFile(modifiedTheme, baseTheme);
            themes.Add(newThemeName, modifiedTheme);
            return(modifiedTheme);
        }
Beispiel #9
0
        public static List<ThemeInfo> LoadFromXmlFile(string filename)
        {
            var xmlDocument = new XmlDocument();
            xmlDocument.Load(filename);

            var fileInfoNode = xmlDocument.SelectSingleNode("/mRemoteNG/FileInfo");
            var fileInfoVersion = new Version(fileInfoNode.Attributes["Version"].Value);
            if (fileInfoVersion > new Version(1, 0))
            {
                throw (new FileFormatException($"Unsupported FileInfo version ({fileInfoVersion})."));
            }

            var fileTypeNode = fileInfoNode.SelectSingleNode("./FileType");
            var fileType = fileTypeNode.InnerText;
            if (fileType != "Theme")
            {
                throw (new FileFormatException($"Incorrect FileType ({fileType}). Expected \"Theme\"."));
            }

            var fileTypeVersion = new Version(fileInfoNode.SelectSingleNode("./FileTypeVersion").InnerText);
            if (fileTypeVersion > new Version(1, 0))
            {
                throw (new FileFormatException($"Unsupported FileTypeVersion ({fileTypeVersion})."));
            }

            var themeNodes = xmlDocument.SelectNodes("/mRemoteNG/Theme");
            var themes = new List<ThemeInfo>();
            var themeType = (new ThemeInfo()).GetType();
            var colorType = (new Color()).GetType();
            foreach (XmlNode themeNode in themeNodes)
            {
                var themeInfo = new ThemeInfo {Name = themeNode.Attributes?["Name"].Value};
                foreach (XmlNode colorNode in themeNode.SelectNodes("./Color"))
                {
                    var colorName = colorNode.Attributes?["Name"].Value;
                    var colorValue = colorNode.Attributes?["Value"].Value;
                    var propertyInfo = themeType.GetProperty(colorName);
                    if (propertyInfo == null || !(propertyInfo.PropertyType == colorType))
                    {
                        continue;
                    }
                    propertyInfo.SetValue(themeInfo, DecodeColorName(colorValue), null);
                }
                themes.Add(themeInfo);
            }

            return themes;
        }
Beispiel #10
0
        public object Clone()
        {
            var extPalette = new ExtendedColorPalette
            {
                ExtColorPalette =
                    _extendedPalette.ExtColorPalette.ToDictionary(entry => entry.Key, entry => entry.Value),
                DefaultColorPalette = _extendedPalette.DefaultColorPalette
            };
            var clonedObj = new ThemeInfo(_name, _theme, _URI, _version, extPalette)
            {
                IsExtendable = IsExtendable,
                IsThemeBase  = IsThemeBase
            };

            return(clonedObj);
        }
Beispiel #11
0
        /// <summary>
        /// Load a theme form an xml file
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="defaultTheme"></param>
        /// <returns></returns>
        public static ThemeInfo LoadFromXmlFile(string filename, ThemeInfo defaultTheme = null)
        {
            var bytes = File.ReadAllBytes(filename);
            //Load the dockpanel part
            var themeBaseLoad = new MremoteNGThemeBase(bytes);
            //Load the mremote part
            //Cause we cannot default the theme for the default theme
            var extColorLoader = new MremoteNGPaletteManipulator(bytes, defaultTheme?.ExtendedPalette);
            var loadedTheme    = new ThemeInfo(Path.GetFileNameWithoutExtension(filename), themeBaseLoad, filename, VisualStudioToolStripExtender.VsVersion.Vs2015, extColorLoader.getColors());

            if (new[] { "darcula", "vs2015blue", "vs2015dark", "vs2015light" }.Contains(Path.GetFileNameWithoutExtension(filename)))
            {
                loadedTheme.IsThemeBase = true;
            }
            loadedTheme.IsExtendable = true;
            return(loadedTheme);
        }
Beispiel #12
0
        public static ThemeInfo LoadTheme(string themeName, bool setActive = true)
        {
            ThemeInfo loadedTheme = DefaultTheme;

            if (!string.IsNullOrEmpty(themeName))
            {
                foreach (ThemeInfo theme in LoadThemes())
                {
                    if (theme.Name == themeName)
                    {
                        loadedTheme = theme;
                        break;
                    }
                }
            }

            if (setActive)
            {
                ActiveTheme = loadedTheme;
            }
            return(loadedTheme);
        }
Beispiel #13
0
		public override bool Equals(object obj)
		{
			ThemeInfo otherTheme = obj as ThemeInfo;
			if (otherTheme == null)
			{
				return false;
			}
				
			Type themeInfoType = (new ThemeInfo()).GetType();
			object myProperty = null;
			object otherProperty = null;
			foreach (System.Reflection.PropertyInfo propertyInfo in themeInfoType.GetProperties())
			{
				myProperty = propertyInfo.GetValue(this, null);
				otherProperty = propertyInfo.GetValue(otherTheme, null);
				if (!myProperty.Equals(otherProperty))
				{
					return false;
				}
			}
				
			return true;
		}
Beispiel #14
0
 private static void SaveThemes(ThemeInfo[] themes)
 {
     SaveThemes(new List<ThemeInfo>(themes));
 }
Beispiel #15
0
 public static void SaveToXmlFile(ThemeInfo themeInfo, string filename)
 {
     var themeList = new List<ThemeInfo> {themeInfo};
     SaveToXmlFile(themeList, filename);
 }
Beispiel #16
0
 public static void DeleteFile(ThemeInfo themeToDelete)
 {
     File.Delete(themeToDelete.URI);
 }
Beispiel #17
0
 //Synchronize the theme XML values from memory to disk
 public void updateTheme(ThemeInfo themeToUpdate)
 {
     ThemeSerializer.UpdateThemeXMLValues(themeToUpdate);
 }
Beispiel #18
0
 public static void SaveThemes(BindingList<ThemeInfo> themes)
 {
     var themesArray = new ThemeInfo[themes.Count - 1 + 1];
     themes.CopyTo(themesArray, 0);
     SaveThemes(themesArray);
 }
Beispiel #19
0
        //The manager precharges all the themes at once
        public List <ThemeInfo> LoadThemes()
        {
            if (themes != null)
            {
                return(themes.Values.OfType <ThemeInfo>().ToList());
            }
            themes = new Hashtable();

            if (themePath == null)
            {
                return(themes.Values.OfType <ThemeInfo>().ToList());
            }
            try
            {
                //Check that theme folder exist before trying to load themes
                if (ThemeDirExists())
                {
                    var themeFiles = Directory.GetFiles(themePath, "*.vstheme");

                    //First we load the default base theme, its vs2015lightNG
                    var defaultTheme = LoadDefaultTheme();
                    themes.Add(defaultTheme.Name, defaultTheme);
                    //Then the rest
                    foreach (var themeFile in themeFiles)
                    {
                        // Skip the default theme here, since it will get loaded again without the *NG below...
                        if (themeFile.Contains("vs2015light.vstheme"))
                        {
                            continue;
                        }
                        //filter default one
                        var extTheme = ThemeSerializer.LoadFromXmlFile(themeFile, defaultTheme);
                        if (extTheme.Theme == null || themes.ContainsKey(extTheme.Name))
                        {
                            continue;
                        }

                        if (extTheme.Name.Equals("darcula") || extTheme.Name.Equals("vs2015blue") ||
                            extTheme.Name.Equals("vs2015dark"))
                        {
                            extTheme.Name = $"{extTheme.Name}NG";
                        }

                        themes.Add(extTheme.Name, extTheme);
                    }

                    //Load the embedded themes, extended palettes are taken from the vs2015 themes, trying to match the color theme

                    // 2003
                    var vs2003 = new ThemeInfo("vs2003", new VS2003Theme(), "",
                                               VisualStudioToolStripExtender.VsVersion.Vs2003,
                                               ((ThemeInfo)themes["vs2015lightNG"]).ExtendedPalette);
                    themes.Add(vs2003.Name, vs2003);

                    // 2005
                    var vs2005 = new ThemeInfo("vs2005", new VS2005Theme(), "",
                                               VisualStudioToolStripExtender.VsVersion.Vs2005,
                                               ((ThemeInfo)themes["vs2015lightNG"]).ExtendedPalette);
                    themes.Add(vs2005.Name, vs2005);

                    // 2012
                    var vs2012Light = new ThemeInfo("vs2012Light", new VS2012LightTheme(), "",
                                                    VisualStudioToolStripExtender.VsVersion.Vs2012,
                                                    ((ThemeInfo)themes["vs2015lightNG"]).ExtendedPalette);
                    themes.Add(vs2012Light.Name, vs2012Light);
                    var vs2012Dark = new ThemeInfo("vs2012Dark", new VS2012DarkTheme(), "",
                                                   VisualStudioToolStripExtender.VsVersion.Vs2012,
                                                   ((ThemeInfo)themes["vs2015darkNG"]).ExtendedPalette);
                    themes.Add(vs2012Dark.Name, vs2012Dark);
                    var vs2012Blue = new ThemeInfo("vs2012Blue", new VS2012BlueTheme(), "",
                                                   VisualStudioToolStripExtender.VsVersion.Vs2012,
                                                   ((ThemeInfo)themes["vs2015blueNG"]).ExtendedPalette);
                    themes.Add(vs2012Blue.Name, vs2012Blue);

                    // 2013
                    var vs2013Light = new ThemeInfo("vs2013Light", new VS2013LightTheme(), "",
                                                    VisualStudioToolStripExtender.VsVersion.Vs2013,
                                                    ((ThemeInfo)themes["vs2015lightNG"]).ExtendedPalette);
                    themes.Add(vs2013Light.Name, vs2013Light);
                    var vs2013Dark = new ThemeInfo("vs2013Dark", new VS2013DarkTheme(), "",
                                                   VisualStudioToolStripExtender.VsVersion.Vs2013,
                                                   ((ThemeInfo)themes["vs2015darkNG"]).ExtendedPalette);
                    themes.Add(vs2013Dark.Name, vs2013Dark);
                    var vs2013Blue = new ThemeInfo("vs2013Blue", new VS2013BlueTheme(), "",
                                                   VisualStudioToolStripExtender.VsVersion.Vs2013,
                                                   ((ThemeInfo)themes["vs2015blueNG"]).ExtendedPalette);
                    themes.Add(vs2013Blue.Name, vs2013Blue);

                    // 2015
                    var vs2015Light = new ThemeInfo("vs2015Light", new VS2015LightTheme(), "",
                                                    VisualStudioToolStripExtender.VsVersion.Vs2015,
                                                    ((ThemeInfo)themes["vs2015lightNG"]).ExtendedPalette);
                    themes.Add(vs2015Light.Name, vs2015Light);
                    var vs2015Dark = new ThemeInfo("vs2015Dark", new VS2015DarkTheme(), "",
                                                   VisualStudioToolStripExtender.VsVersion.Vs2015,
                                                   ((ThemeInfo)themes["vs2015darkNG"]).ExtendedPalette);
                    themes.Add(vs2015Dark.Name, vs2015Dark);
                    var vs2015Blue = new ThemeInfo("vs2015Blue", new VS2015BlueTheme(), "",
                                                   VisualStudioToolStripExtender.VsVersion.Vs2015,
                                                   ((ThemeInfo)themes["vs2015blueNG"]).ExtendedPalette);
                    themes.Add(vs2015Blue.Name, vs2015Blue);
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionStackTrace("Error loading themes", ex);
            }

            return(themes.Values.OfType <ThemeInfo>().ToList());
        }
        //THe manager precharges all the themes at once
        public List <ThemeInfo> LoadThemes()
        {
            if (themes != null)
            {
                return(themes.Values.OfType <ThemeInfo>().ToList());
            }
            themes = new Hashtable();

            //Load the files in theme folder first, to incluide vstheme light as default
            var themePath = App.Info.SettingsFileInfo.ThemeFolder;

            if (themePath == null)
            {
                return(themes.Values.OfType <ThemeInfo>().ToList());
            }
            try
            {
                //In install mode first time is necesary to copy the themes folder
                if (!Directory.Exists(themePath))
                {
                    Directory.CreateDirectory(themePath);
                }
                var orig  = new DirectoryInfo(App.Info.SettingsFileInfo.InstalledThemeFolder);
                var files = orig.GetFiles();
                foreach (var file in files)
                {
                    if (!File.Exists(Path.Combine(themePath, file.Name)))
                    {
                        file.CopyTo(Path.Combine(themePath, file.Name), true);
                    }
                }



                //Check that theme folder exist before trying to load themes
                if (Directory.Exists(themePath))
                {
                    var themeFiles      = Directory.GetFiles(themePath, "*.vstheme");
                    var defaultThemeURL = Directory.GetFiles(themePath, "vs2015light" + ".vstheme")[0];
                    //First we load the default theme, its vs2015light
                    var defaultTheme = ThemeSerializer.LoadFromXmlFile(defaultThemeURL);
                    themes.Add(defaultTheme.Name, defaultTheme);
                    //Then the rest
                    foreach (var themeFile in themeFiles)
                    {
                        //filter default one
                        var extTheme = ThemeSerializer.LoadFromXmlFile(themeFile, defaultTheme);
                        if (extTheme.Theme != null && !themes.ContainsKey(extTheme.Name))
                        {
                            themes.Add(extTheme.Name, extTheme);
                        }
                    }


                    //Load the embedded themes, extended palettes are taken from the vs2015 themes, trying to match the color theme
                    var vs2003 = new ThemeInfo("Vs2003", new VS2003Theme(), "", VisualStudioToolStripExtender.VsVersion.Vs2003, ((ThemeInfo)themes["vs2015light"]).ExtendedPalette);
                    themes.Add(vs2003.Name, vs2003);
                    var vs2005 = new ThemeInfo("Vs2005", new VS2005Theme(), "", VisualStudioToolStripExtender.VsVersion.Vs2005, ((ThemeInfo)themes["vs2015light"]).ExtendedPalette);
                    themes.Add(vs2005.Name, vs2005);
                    var vs2012Light = new ThemeInfo("vs2012Light", new VS2012LightTheme(), "", VisualStudioToolStripExtender.VsVersion.Vs2012, ((ThemeInfo)themes["vs2015light"]).ExtendedPalette);
                    themes.Add(vs2012Light.Name, vs2012Light);
                    var vs2012Dark = new ThemeInfo("vs2012Dark", new VS2012DarkTheme(), "", VisualStudioToolStripExtender.VsVersion.Vs2012, ((ThemeInfo)themes["vs2015dark"]).ExtendedPalette);
                    themes.Add(vs2012Dark.Name, vs2012Dark);
                    var vs2012Blue = new ThemeInfo("vs2012Blue", new VS2012BlueTheme(), "", VisualStudioToolStripExtender.VsVersion.Vs2012, ((ThemeInfo)themes["vs2015blue"]).ExtendedPalette);
                    themes.Add(vs2012Blue.Name, vs2012Blue);
                    var vs2013Light = new ThemeInfo("vs2013Light", new VS2013LightTheme(), "", VisualStudioToolStripExtender.VsVersion.Vs2013, ((ThemeInfo)themes["vs2015light"]).ExtendedPalette);
                    themes.Add(vs2013Light.Name, vs2013Light);
                    var vs2013Dark = new ThemeInfo("vs2013Dark", new VS2013DarkTheme(), "", VisualStudioToolStripExtender.VsVersion.Vs2013, ((ThemeInfo)themes["vs2015dark"]).ExtendedPalette);
                    themes.Add(vs2013Dark.Name, vs2013Dark);
                    var vs2013Blue = new ThemeInfo("vs2013Blue", new VS2013BlueTheme(), "", VisualStudioToolStripExtender.VsVersion.Vs2013, ((ThemeInfo)themes["vs2015blue"]).ExtendedPalette);
                    themes.Add(vs2013Blue.Name, vs2013Blue);
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, "Error loading themes" + Environment.NewLine + ex.Message, true);
            }
            return(themes.Values.OfType <ThemeInfo>().ToList());
        }