From 399edc2a0e582857afc71efb61fd934e976930b1 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Wed, 14 Dec 2016 14:17:59 -0800 Subject: [PATCH] Set an appropriate title on the FindRefs window in response to new editor change. --- .../Core/EditorFeaturesResources.Designer.cs | 27 +++++++++++++++++++ .../Core/EditorFeaturesResources.resx | 9 +++++++ .../AbstractFindReferencesService.cs | 7 +---- .../FindUsages/AbstractFindUsagesService.cs | 13 ++++----- .../Core/FindUsages/FindUsagesContext.cs | 2 +- .../Core/FindUsages/FindUsagesHelpers.cs | 3 +++ .../Core/FindUsages/IFindUsagesContext.cs | 2 +- .../FindUsages/SimpleFindUsagesContext.cs | 4 +++ .../GoToDefinition/GoToDefinitionHelpers.cs | 8 ++++-- .../GoToImplementationCommandHandler.cs | 2 +- ...senter.TableDataSourceFindUsagesContext.cs | 20 +++++++++++--- 11 files changed, 74 insertions(+), 23 deletions(-) diff --git a/src/EditorFeatures/Core/EditorFeaturesResources.Designer.cs b/src/EditorFeatures/Core/EditorFeaturesResources.Designer.cs index aff44ef6087..b271086368f 100644 --- a/src/EditorFeatures/Core/EditorFeaturesResources.Designer.cs +++ b/src/EditorFeatures/Core/EditorFeaturesResources.Designer.cs @@ -69,6 +69,15 @@ internal class EditorFeaturesResources { } } + /// + /// Looks up a localized string similar to '{0}' declarations. + /// + internal static string _0_declarations { + get { + return ResourceManager.GetString("_0_declarations", resourceCulture); + } + } + /// /// Looks up a localized string similar to '{0}' does not support the '{1}' operation. However, it may contain nested '{2}'s (see '{2}.{3}') that support this operation.. /// @@ -79,6 +88,15 @@ internal class EditorFeaturesResources { } } + /// + /// Looks up a localized string similar to '{0}' implementations. + /// + internal static string _0_implementations { + get { + return ResourceManager.GetString("_0_implementations", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} - (Line {1}). /// @@ -88,6 +106,15 @@ internal class EditorFeaturesResources { } } + /// + /// Looks up a localized string similar to '{0}' references. + /// + internal static string _0_references { + get { + return ResourceManager.GetString("_0_references", resourceCulture); + } + } + /// /// Looks up a localized string similar to {0} unresolvable conflict(s). /// diff --git a/src/EditorFeatures/Core/EditorFeaturesResources.resx b/src/EditorFeatures/Core/EditorFeaturesResources.resx index ba4c253ed00..ca8aacef83d 100644 --- a/src/EditorFeatures/Core/EditorFeaturesResources.resx +++ b/src/EditorFeatures/Core/EditorFeaturesResources.resx @@ -745,4 +745,13 @@ Do you want to proceed? Suggestion ellipses (…) + + '{0}' references + + + '{0}' implementations + + + '{0}' declarations + \ No newline at end of file diff --git a/src/EditorFeatures/Core/FindReferences/AbstractFindReferencesService.cs b/src/EditorFeatures/Core/FindReferences/AbstractFindReferencesService.cs index fe99c7858e4..5846075a5be 100644 --- a/src/EditorFeatures/Core/FindReferences/AbstractFindReferencesService.cs +++ b/src/EditorFeatures/Core/FindReferences/AbstractFindReferencesService.cs @@ -44,7 +44,7 @@ internal abstract partial class AbstractFindReferencesService : var symbol = symbolAndProject?.symbol; var project = symbolAndProject?.project; - var displayName = GetDisplayName(symbol); + var displayName = FindUsagesHelpers.GetDisplayName(symbol); waitContext.Message = string.Format( EditorFeaturesResources.Finding_references_of_0, displayName); @@ -54,11 +54,6 @@ internal abstract partial class AbstractFindReferencesService : return Tuple.Create(result, project.Solution); } - public static string GetDisplayName(ISymbol symbol) - { - return symbol.IsConstructor() ? symbol.ContainingType.Name : symbol.Name; - } - public bool TryFindReferences(Document document, int position, IWaitContext waitContext) { var cancellationToken = waitContext.CancellationToken; diff --git a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.cs b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.cs index 337952e0126..c03f1c0eaeb 100644 --- a/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.cs +++ b/src/EditorFeatures/Core/FindUsages/AbstractFindUsagesService.cs @@ -1,12 +1,7 @@ // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.FindReferences; -using Microsoft.CodeAnalysis.Editor.GoToImplementation; using Microsoft.CodeAnalysis.FindSymbols; using Microsoft.CodeAnalysis.FindUsages; @@ -32,8 +27,10 @@ public async Task FindImplementationsAsync(Document document, int position, IFin return; } - var project = tuple.Value.project; + context.SetSearchTitle(string.Format(EditorFeaturesResources._0_implementations, + FindUsagesHelpers.GetDisplayName(tuple.Value.symbol))); + var project = tuple.Value.project; foreach (var implementation in tuple.Value.implementations) { var definitionItem = implementation.ToDefinitionItem( @@ -79,8 +76,8 @@ public async Task FindImplementationsAsync(Document document, int position, IFin var symbol = symbolAndProject?.symbol; var project = symbolAndProject?.project; - var displayName = AbstractFindReferencesService.GetDisplayName(symbol); - context.SetSearchLabel(displayName); + context.SetSearchTitle(string.Format(EditorFeaturesResources._0_references, + FindUsagesHelpers.GetDisplayName(symbol))); var progressAdapter = new ProgressAdapter(project.Solution, context); diff --git a/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs b/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs index e64900c8c16..f1a386e56e7 100644 --- a/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs +++ b/src/EditorFeatures/Core/FindUsages/FindUsagesContext.cs @@ -19,7 +19,7 @@ public virtual void ReportMessage(string message) { } - public virtual void SetSearchLabel(string displayName) + public virtual void SetSearchTitle(string title) { } diff --git a/src/EditorFeatures/Core/FindUsages/FindUsagesHelpers.cs b/src/EditorFeatures/Core/FindUsages/FindUsagesHelpers.cs index e28f739a0db..f141c8d7e0a 100644 --- a/src/EditorFeatures/Core/FindUsages/FindUsagesHelpers.cs +++ b/src/EditorFeatures/Core/FindUsages/FindUsagesHelpers.cs @@ -14,6 +14,9 @@ namespace Microsoft.CodeAnalysis.Editor.FindUsages { internal static class FindUsagesHelpers { + public static string GetDisplayName(ISymbol symbol) + => symbol.IsConstructor() ? symbol.ContainingType.Name : symbol.Name; + /// /// Common helper for both the synchronous and streaming versions of FAR. /// It returns the symbol we want to search for and the solution we should diff --git a/src/EditorFeatures/Core/FindUsages/IFindUsagesContext.cs b/src/EditorFeatures/Core/FindUsages/IFindUsagesContext.cs index 35f34ab9c11..aafc38c79e7 100644 --- a/src/EditorFeatures/Core/FindUsages/IFindUsagesContext.cs +++ b/src/EditorFeatures/Core/FindUsages/IFindUsagesContext.cs @@ -17,7 +17,7 @@ internal interface IFindUsagesContext /// /// Set the title of the window that results are displayed in. /// - void SetSearchLabel(string displayName); + void SetSearchTitle(string title); Task OnDefinitionFoundAsync(DefinitionItem definition); Task OnReferenceFoundAsync(SourceReferenceItem reference); diff --git a/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs b/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs index 23a18382587..c35cb4255b7 100644 --- a/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs +++ b/src/EditorFeatures/Core/FindUsages/SimpleFindUsagesContext.cs @@ -29,10 +29,14 @@ public SimpleFindUsagesContext(CancellationToken cancellationToken) } public string Message { get; private set; } + public string SearchTitle { get; private set; } public override void ReportMessage(string message) => Message = message; + public override void SetSearchTitle(string title) + => SearchTitle = title; + public ImmutableArray GetDefinitions() { lock (_gate) diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs index eb3ac4f8ea3..d5f26eb9b7a 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs @@ -5,6 +5,8 @@ using System.Linq; using System.Runtime.InteropServices; using System.Threading; +using Microsoft.CodeAnalysis.Editor.FindReferences; +using Microsoft.CodeAnalysis.Editor.FindUsages; using Microsoft.CodeAnalysis.Editor.Host; using Microsoft.CodeAnalysis.FindSymbols; using Microsoft.CodeAnalysis.FindUsages; @@ -69,9 +71,11 @@ internal static class GoToDefinitionHelpers definitions.Add(symbol.ToDefinitionItem(solution, includeHiddenLocations: true)); var presenter = GetFindUsagesPresenter(streamingPresenters); + var title = string.Format(EditorFeaturesResources._0_declarations, + FindUsagesHelpers.GetDisplayName(symbol)); + return presenter.TryNavigateToOrPresentItemsAsync( - EditorFeaturesResources.Go_to_Definition, - definitions.ToImmutableAndFree(), + title, definitions.ToImmutableAndFree(), alwaysShowDeclarations: true).WaitAndGetResult(cancellationToken); } diff --git a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs index 061a065bbfd..29f937a1e35 100644 --- a/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs +++ b/src/EditorFeatures/Core/GoToImplementation/GoToImplementationCommandHandler.cs @@ -125,7 +125,7 @@ private void ExecuteCommand(Document document, int caretPosition) var definitionItems = goToImplContext.GetDefinitions(); streamingPresenter.TryNavigateToOrPresentItemsAsync( - EditorFeaturesResources.Go_To_Implementation, definitionItems, + goToImplContext.SearchTitle, definitionItems, alwaysShowDeclarations: true).Wait(cancellationToken); } diff --git a/src/VisualStudio/Core/Next/FindReferences/StreamingFindUsagesPresenter.TableDataSourceFindUsagesContext.cs b/src/VisualStudio/Core/Next/FindReferences/StreamingFindUsagesPresenter.TableDataSourceFindUsagesContext.cs index 22fb0972156..8e2cae33578 100644 --- a/src/VisualStudio/Core/Next/FindReferences/StreamingFindUsagesPresenter.TableDataSourceFindUsagesContext.cs +++ b/src/VisualStudio/Core/Next/FindReferences/StreamingFindUsagesPresenter.TableDataSourceFindUsagesContext.cs @@ -5,6 +5,7 @@ using System.Collections.Immutable; using System.Diagnostics; using System.Linq; +using System.Reflection; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis; @@ -197,12 +198,23 @@ public IDisposable Subscribe(ITableDataSink sink) #region FindUsagesContext overrides. - public override void SetSearchLabel(string displayName) + public override void SetSearchTitle(string title) { - var labelProperty = _findReferencesWindow.GetType().GetProperty("Label"); - if (labelProperty != null) + try + { + // Editor renamed their property from Label to Title, and made it public. + // However, we don't have access to that property yet until they publish + // their next SDK. In the meantime, use reflection to get at the right + // property. + var titleProperty = _findReferencesWindow.GetType().GetProperty( + "Title", BindingFlags.Public | BindingFlags.Instance); + if (titleProperty != null) + { + titleProperty.SetValue(_findReferencesWindow, title); + } + } + catch (Exception) { - labelProperty.SetValue(_findReferencesWindow, displayName); } } -- GitLab