diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpContextActionWrapper.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpContextActionWrapper.cs index 5662c0672f..49fef4fef3 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpContextActionWrapper.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpContextActionWrapper.cs @@ -47,6 +47,11 @@ namespace CSharpBinding.Refactoring get { return description; } } + public string GetDisplayName(EditorRefactoringContext context) + { + return DisplayName; + } + public void Execute(EditorRefactoringContext context) { SD.AnalyticsMonitor.TrackFeature(provider.ID); diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/MoveTypeToFileContextAction.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/MoveTypeToFileContextAction.cs index 00ce53d9f7..6966d54b38 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/MoveTypeToFileContextAction.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/MoveTypeToFileContextAction.cs @@ -41,7 +41,30 @@ namespace CSharpBinding.Refactoring return false; return identifier.Parent is TypeDeclaration || identifier.Parent is DelegateDeclaration; } - + + public override string DisplayName + { + get { + return "Move type to file"; + } + } + + public override string GetDisplayName(EditorRefactoringContext context) + { + CSharpFullParseInformation parseInformation = context.GetParseInformation() as CSharpFullParseInformation; + if (parseInformation != null) { + SyntaxTree st = parseInformation.SyntaxTree; + Identifier identifier = (Identifier) st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier); + if (identifier == null) + return DisplayName; + + return StringParser.Parse("${res:SharpDevelop.Refactoring.MoveClassToFile}", + new StringTagPair("FileName", MakeValidFileName(identifier.Name))); + } + + return DisplayName; + } + public override async void Execute(EditorRefactoringContext context) { SyntaxTree st = await context.GetSyntaxTreeAsync().ConfigureAwait(false); @@ -131,9 +154,5 @@ namespace CSharpBinding.Refactoring return name.RemoveAny(Path.GetInvalidFileNameChars()) + ".cs"; return name + ".cs"; } - - public override string DisplayName { - get { return "Move type to file"; } - } } } diff --git a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/RenameFileToMatchTypeNameContextAction.cs b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/RenameFileToMatchTypeNameContextAction.cs index e800c08362..e7a6637e16 100644 --- a/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/RenameFileToMatchTypeNameContextAction.cs +++ b/src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/RenameFileToMatchTypeNameContextAction.cs @@ -52,13 +52,29 @@ namespace CSharpBinding.Refactoring } } - public override string DisplayName { + public override string DisplayName + { get { - // TODO Use the string from resource file! But this needs to become GetDisplayName(context) first. return "Rename file to match type name"; } } + public override string GetDisplayName(EditorRefactoringContext context) + { + CSharpFullParseInformation parseInformation = context.GetParseInformation() as CSharpFullParseInformation; + if (parseInformation != null) { + SyntaxTree st = parseInformation.SyntaxTree; + Identifier identifier = (Identifier) st.GetNodeAt(context.CaretLocation, node => node.Role == Roles.Identifier); + if (identifier == null) + return DisplayName; + + return StringParser.Parse("${res:SharpDevelop.Refactoring.RenameFileTo}", + new StringTagPair("FileName", MakeValidFileName(identifier.Name))); + } + + return DisplayName; + } + string MakeValidFileName(string name) { if (name == null) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionViewModel.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionViewModel.cs index bca66229ee..c26e0fe8df 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionViewModel.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionViewModel.cs @@ -33,7 +33,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions } public string Name { - get { return this.action != null ? this.action.DisplayName : string.Empty; } + get { return this.action != null ? this.action.GetDisplayName(context) : string.Empty; } } public string Comment { get; set; } diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/GoToEntityAction.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/GoToEntityAction.cs index a139a55533..2721d2f0d0 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/GoToEntityAction.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/GoToEntityAction.cs @@ -25,10 +25,16 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions ChildActions = childActions }; } - + public string DisplayName { get; private set; } + public IEntity Entity { get; private set; } + public string GetDisplayName(EditorRefactoringContext context) + { + return DisplayName; + } + public GoToEntityAction(IEntity entity, string displayName) { if (entity == null) diff --git a/src/Main/Base/Project/Refactoring/ContextAction.cs b/src/Main/Base/Project/Refactoring/ContextAction.cs index 7343e3040c..836356b1c5 100644 --- a/src/Main/Base/Project/Refactoring/ContextAction.cs +++ b/src/Main/Base/Project/Refactoring/ContextAction.cs @@ -22,6 +22,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring public abstract string DisplayName { get; } + public virtual string GetDisplayName(EditorRefactoringContext context) + { + return DisplayName; + } + public virtual string Category { get { return string.Empty; } } diff --git a/src/Main/Base/Project/Refactoring/IContextAction.cs b/src/Main/Base/Project/Refactoring/IContextAction.cs index 0cdc85852a..562417b9c0 100644 --- a/src/Main/Base/Project/Refactoring/IContextAction.cs +++ b/src/Main/Base/Project/Refactoring/IContextAction.cs @@ -18,9 +18,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring IContextActionProvider Provider { get; } /// - /// Name displayed in the context actions popup. + /// Name displayed in the context action's popup. /// - string DisplayName { get; } + /// Refactoring context that can be used by the context action to create the display name. + /// + string GetDisplayName(EditorRefactoringContext context); /// /// Executes this action. Called when this action is selected from the context actions popup.