예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        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 = Guid.Parse(visualStudioThemeId.Split('*')[2]).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);
            }
        }