/// <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); } }
/// <summary> /// Initializes a new instance of the <see cref="WhereAmI"/> class. /// Creates a square image and attaches an event handler to the layout changed event that /// adds the the square in the upper right-hand corner of the TextView via the adornment layer /// </summary> /// <param name="view">The <see cref="IWpfTextView"/> upon which the adornment will be drawn</param> public WhereAmI(IWpfTextView view, IWhereAmISettings settings) { _view = view; _settings = settings; _fileName = new TextBlock(); _folderStructure = new TextBlock(); _projectName = new TextBlock(); ITextDocument textDoc; object obj; if (view.TextBuffer.Properties.TryGetProperty <ITextDocument>(typeof(ITextDocument), out textDoc)) { // Retrieved the ITextDocument from the first level } else if (view.TextBuffer.Properties.TryGetProperty <object>("IdentityMapping", out obj)) { // Try to get the ITextDocument from the second level (e.g. Razor files) if ((obj as ITextBuffer) != null) { (obj as ITextBuffer).Properties.TryGetProperty <ITextDocument>(typeof(ITextDocument), out textDoc); } } // If I found an ITextDocument, access to its FilePath prop to retrieve informations about Proj if (textDoc != null) { string fileName = System.IO.Path.GetFileName(textDoc.FilePath); Project proj = GetContainingProject(textDoc.FilePath); if (proj != null) { string projectName = proj.Name; if (_settings.ViewFilename) { _fileName.Text = fileName; Brush fileNameBrush = new SolidColorBrush(Color.FromArgb(_settings.FilenameColor.A, _settings.FilenameColor.R, _settings.FilenameColor.G, _settings.FilenameColor.B)); _fileName.FontFamily = new FontFamily("Consolas"); _fileName.FontSize = _settings.FilenameSize; _fileName.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; _fileName.TextAlignment = System.Windows.TextAlignment.Right; _fileName.Foreground = fileNameBrush; _fileName.Opacity = _settings.Opacity; } if (_settings.ViewFolders) { _folderStructure.Text = GetFolderDiffs(textDoc.FilePath, proj.FullName); Brush foldersBrush = new SolidColorBrush(Color.FromArgb(_settings.FoldersColor.A, _settings.FoldersColor.R, _settings.FoldersColor.G, _settings.FoldersColor.B)); _folderStructure.FontFamily = new FontFamily("Consolas"); _folderStructure.FontSize = _settings.FoldersSize; _folderStructure.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; _folderStructure.TextAlignment = System.Windows.TextAlignment.Right; _folderStructure.Foreground = foldersBrush; _folderStructure.Opacity = _settings.Opacity; } if (_settings.ViewProject) { _projectName.Text = projectName; Brush projectNameBrush = new SolidColorBrush(Color.FromArgb(_settings.ProjectColor.A, _settings.ProjectColor.R, _settings.ProjectColor.G, _settings.ProjectColor.B)); _projectName.FontFamily = new FontFamily("Consolas"); _projectName.FontSize = _settings.ProjectSize; _projectName.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; _projectName.TextAlignment = System.Windows.TextAlignment.Right; _projectName.Foreground = projectNameBrush; _projectName.Opacity = _settings.Opacity; } } } // Force to have an ActualWidth System.Windows.Rect finalRect = new System.Windows.Rect(); _fileName.Arrange(finalRect); _folderStructure.Arrange(finalRect); _projectName.Arrange(finalRect); //Grab a reference to the adornment layer that this adornment should be added to _adornmentLayer = view.GetAdornmentLayer(Constants.AdornmentLayerName); _view.ViewportHeightChanged += delegate { this.onSizeChange(); }; _view.ViewportWidthChanged += delegate { this.onSizeChange(); }; }
/// <summary> /// Initializes a new instance of the <see cref="WhereAmI"/> class. /// Creates a square image and attaches an event handler to the layout changed event that /// adds the the square in the upper right-hand corner of the TextView via the adornment layer /// </summary> /// <param name="view">The <see cref="IWpfTextView"/> upon which the adornment will be drawn</param> /// <param name="settings">The <see cref="IWhereAmISettings"/> injected by the provider</param> public WhereAmI(IWpfTextView view, IWhereAmISettings settings) { _view = view; _settings = settings; _fileName = new TextBlock(); _folderStructure = new TextBlock(); _projectName = new TextBlock(); ITextDocument textDoc; object obj; if (view.TextBuffer.Properties.TryGetProperty<ITextDocument>(typeof(ITextDocument), out textDoc)) { // Retrieved the ITextDocument from the first level } else if (view.TextBuffer.Properties.TryGetProperty<object>("IdentityMapping", out obj)) { // Try to get the ITextDocument from the second level (e.g. Razor files) if ((obj as ITextBuffer) != null) { (obj as ITextBuffer).Properties.TryGetProperty<ITextDocument>(typeof(ITextDocument), out textDoc); } } // If I found an ITextDocument, access to its FilePath prop to retrieve informations about Proj if (textDoc != null) { string fileName = System.IO.Path.GetFileName(textDoc.FilePath); Project proj = GetContainingProject(fileName); if (proj != null) { string projectName = proj.Name; if (_settings.ViewFilename) { _fileName.Text = fileName; Brush fileNameBrush = new SolidColorBrush(Color.FromArgb(_settings.FilenameColor.A, _settings.FilenameColor.R, _settings.FilenameColor.G, _settings.FilenameColor.B)); _fileName.FontFamily = new FontFamily("Consolas"); _fileName.FontSize = _settings.FilenameSize; _fileName.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; _fileName.TextAlignment = System.Windows.TextAlignment.Right; _fileName.Foreground = fileNameBrush; _fileName.Opacity = _settings.Opacity; } if (_settings.ViewFolders) { _folderStructure.Text = GetFolderDiffs(textDoc.FilePath, proj.FullName); Brush foldersBrush = new SolidColorBrush(Color.FromArgb(_settings.FoldersColor.A, _settings.FoldersColor.R, _settings.FoldersColor.G, _settings.FoldersColor.B)); _folderStructure.FontFamily = new FontFamily("Consolas"); _folderStructure.FontSize = _settings.FoldersSize; _folderStructure.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; _folderStructure.TextAlignment = System.Windows.TextAlignment.Right; _folderStructure.Foreground = foldersBrush; _folderStructure.Opacity = _settings.Opacity; } if (_settings.ViewProject) { _projectName.Text = projectName; Brush projectNameBrush = new SolidColorBrush(Color.FromArgb(_settings.ProjectColor.A, _settings.ProjectColor.R, _settings.ProjectColor.G, _settings.ProjectColor.B)); _projectName.FontFamily = new FontFamily("Consolas"); _projectName.FontSize = _settings.ProjectSize; _projectName.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; _projectName.TextAlignment = System.Windows.TextAlignment.Right; _projectName.Foreground = projectNameBrush; _projectName.Opacity = _settings.Opacity; } } } // Force to have an ActualWidth System.Windows.Rect finalRect = new System.Windows.Rect(); _fileName.Arrange(finalRect); _folderStructure.Arrange(finalRect); _projectName.Arrange(finalRect); //Grab a reference to the adornment layer that this adornment should be added to _adornmentLayer = view.GetAdornmentLayer("WhereAmIAdornment"); _view.ViewportHeightChanged += delegate { this.onSizeChange(); }; _view.ViewportWidthChanged += delegate { this.onSizeChange(); }; }