public static IWhereAmISettings LightThemeDefaults() { WhereAmISettings settings = new WhereAmISettings(); settings.FilenameSize = 60; settings.FoldersSize = settings.ProjectSize = 52; settings.FilenameColor = Color.FromArgb(234, 234, 234); settings.FoldersColor = settings.ProjectColor = Color.FromArgb(243, 243, 243); settings.Position = AdornmentPositions.TopRight; settings.Opacity = 1; settings.ViewFilename = true; settings.ViewFolders = true; settings.ViewProject = true; settings.Theme = Theme.Light; return(settings); }
private void LoadSettings() { // Default values var lightTheme = WhereAmISettings.LightThemeDefaults(); FilenameSize = lightTheme.FilenameSize; FoldersSize = ProjectSize = lightTheme.FoldersSize; FilenameColor = lightTheme.FilenameColor; FoldersColor = ProjectColor = lightTheme.FoldersColor; Position = lightTheme.Position; Opacity = lightTheme.Opacity; ViewFilename = ViewFolders = ViewProject = lightTheme.ViewFilename; Theme = lightTheme.Theme; try { // Retrieve the Id of the current theme used in VS from user's settings, this is changed a lot in VS2015 string visualStudioThemeId = VSRegistry.RegistryRoot(Microsoft.VisualStudio.Shell.Interop.__VsLocalRegistryType.RegType_UserSettings).OpenSubKey("ApplicationPrivateSettings").OpenSubKey("Microsoft").OpenSubKey("VisualStudio").GetValue("ColorTheme", "de3dbbcd-f642-433c-8353-8f1df4370aba", Microsoft.Win32.RegistryValueOptions.DoNotExpandEnvironmentNames).ToString(); string parsedThemeId = ""; if (visualStudioThemeId.Contains("*")) { parsedThemeId = Guid.Parse(visualStudioThemeId.Split('*')[2]).ToString(); } else { parsedThemeId = Guid.Parse(visualStudioThemeId).ToString(); } switch (parsedThemeId) { case Constants.VisualStudioLightThemeId: // Light case Constants.VisualStudioBlueThemeId: // Blue default: // Just use the defaults break; case Constants.VisualStudioDarkThemeId: // Dark var darkTheme = WhereAmISettings.DarkThemeDefaults(); FilenameSize = darkTheme.FilenameSize; FoldersSize = ProjectSize = darkTheme.FoldersSize; FilenameColor = darkTheme.FilenameColor; FoldersColor = ProjectColor = darkTheme.FoldersColor; Position = darkTheme.Position; Opacity = darkTheme.Opacity; ViewFilename = ViewFolders = ViewProject = darkTheme.ViewFilename; Theme = darkTheme.Theme; break; } // Tries to retrieve the configurations if previously saved if (writableSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "FilenameColor")) { this.FilenameColor = Color.FromArgb(writableSettingsStore.GetInt32(Constants.SettingsCollectionPath, "FilenameColor", this.FilenameColor.ToArgb())); } if (writableSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "FoldersColor")) { this.FoldersColor = Color.FromArgb(writableSettingsStore.GetInt32(Constants.SettingsCollectionPath, "FoldersColor", this.FoldersColor.ToArgb())); } if (writableSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "ProjectColor")) { this.ProjectColor = Color.FromArgb(writableSettingsStore.GetInt32(Constants.SettingsCollectionPath, "ProjectColor", this.ProjectColor.ToArgb())); } if (writableSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "ViewFilename")) { bool b = this.ViewFilename; if (Boolean.TryParse(writableSettingsStore.GetString(Constants.SettingsCollectionPath, "ViewFilename"), out b)) { this.ViewFilename = b; } } if (writableSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "ViewFolders")) { bool b = this.ViewFolders; if (Boolean.TryParse(writableSettingsStore.GetString(Constants.SettingsCollectionPath, "ViewFolders"), out b)) { this.ViewFolders = b; } } if (writableSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "ViewProject")) { bool b = this.ViewProject; if (Boolean.TryParse(writableSettingsStore.GetString(Constants.SettingsCollectionPath, "ViewProject"), out b)) { this.ViewProject = b; } } if (writableSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "FilenameSize")) { double d = this.FilenameSize; if (Double.TryParse(writableSettingsStore.GetString(Constants.SettingsCollectionPath, "FilenameSize"), out d)) { this.FilenameSize = d; } } if (writableSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "FoldersSize")) { double d = this.FoldersSize; if (Double.TryParse(writableSettingsStore.GetString(Constants.SettingsCollectionPath, "FoldersSize"), out d)) { this.FoldersSize = d; } } if (writableSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "ProjectSize")) { double d = this.ProjectSize; if (Double.TryParse(writableSettingsStore.GetString(Constants.SettingsCollectionPath, "ProjectSize"), out d)) { this.ProjectSize = d; } } if (writableSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "Position")) { AdornmentPositions p = this.Position; if (Enum.TryParse <AdornmentPositions>(writableSettingsStore.GetString(Constants.SettingsCollectionPath, "Position"), out p)) { this.Position = p; } } if (writableSettingsStore.PropertyExists(Constants.SettingsCollectionPath, "Opacity")) { double d = this.Opacity; if (Double.TryParse(writableSettingsStore.GetString(Constants.SettingsCollectionPath, "Opacity"), out d)) { this.Opacity = d; } } } catch (Exception ex) { Debug.Fail(ex.Message); } }
public override bool Equals(object obj) { WhereAmISettings o = obj as WhereAmISettings; return(o.GetHashCode() == this.GetHashCode()); }
/// <summary> /// Handles "apply" messages from the Visual Studio environment. /// </summary> /// <devdoc> /// This method is called when VS wants to save the user's /// changes (for example, when the user clicks OK in the dialog). /// </devdoc> protected override void OnApply(PageApplyEventArgs e) { IWhereAmISettings storedValues = settings; IWhereAmISettings currentValues = new WhereAmISettings() { FilenameColor = FilenameColor, FoldersColor = FoldersColor, ProjectColor = ProjectColor, FilenameSize = FilenameSize, FoldersSize = FoldersSize, ProjectSize = ProjectSize, ViewFilename = ViewFilename, ViewFolders = ViewFolders, ViewProject = ViewProject, Position = Position, Opacity = Opacity }; int result = (int)VSConstants.MessageBoxResult.IDOK; if (!storedValues.Equals(currentValues)) { result = VsShellUtilities.ShowMessageBox(Site, Resources.MessageOnApplyEntered, Resources.Confirm, OLEMSGICON.OLEMSGICON_QUERY, OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } if (result == (int)VSConstants.MessageBoxResult.IDCANCEL) { e.ApplyBehavior = ApplyKind.Cancel; } else if (e.ApplyBehavior == ApplyKind.Apply) { settings.FilenameColor = currentValues.FilenameColor; settings.FoldersColor = currentValues.FoldersColor; settings.ProjectColor = currentValues.ProjectColor; settings.FilenameSize = currentValues.FilenameSize; settings.FoldersSize = currentValues.FoldersSize; settings.ProjectSize = currentValues.ProjectSize; settings.ViewFilename = currentValues.ViewFilename; settings.ViewFolders = currentValues.ViewFolders; settings.ViewProject = currentValues.ViewProject; settings.Position = currentValues.Position; settings.Opacity = currentValues.Opacity; if (WhereAmISettings.DarkThemeDefaults().Equals(currentValues)) { settings.Theme = Theme.Dark; } else if (WhereAmISettings.LightThemeDefaults().Equals(currentValues)) { settings.Theme = Theme.Light; } else { settings.Theme = Theme.Custom; } settings.Store(); base.OnApply(e); } }