Browse Source

Showing target file name in action menu of MoveTypeToFile/RenameFileToMatchTypeName context actions.

pull/48/head
Andreas Weizel 12 years ago
parent
commit
226fef0697
  1. 5
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpContextActionWrapper.cs
  2. 29
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/MoveTypeToFileContextAction.cs
  3. 20
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/RenameFileToMatchTypeNameContextAction.cs
  4. 2
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionViewModel.cs
  5. 8
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/GoToEntityAction.cs
  6. 5
      src/Main/Base/Project/Refactoring/ContextAction.cs
  7. 6
      src/Main/Base/Project/Refactoring/IContextAction.cs

5
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/CSharpContextActionWrapper.cs

@ -47,6 +47,11 @@ namespace CSharpBinding.Refactoring
get { return description; } get { return description; }
} }
public string GetDisplayName(EditorRefactoringContext context)
{
return DisplayName;
}
public void Execute(EditorRefactoringContext context) public void Execute(EditorRefactoringContext context)
{ {
SD.AnalyticsMonitor.TrackFeature(provider.ID); SD.AnalyticsMonitor.TrackFeature(provider.ID);

29
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/MoveTypeToFileContextAction.cs

@ -41,7 +41,30 @@ namespace CSharpBinding.Refactoring
return false; return false;
return identifier.Parent is TypeDeclaration || identifier.Parent is DelegateDeclaration; 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) public override async void Execute(EditorRefactoringContext context)
{ {
SyntaxTree st = await context.GetSyntaxTreeAsync().ConfigureAwait(false); SyntaxTree st = await context.GetSyntaxTreeAsync().ConfigureAwait(false);
@ -131,9 +154,5 @@ namespace CSharpBinding.Refactoring
return name.RemoveAny(Path.GetInvalidFileNameChars()) + ".cs"; return name.RemoveAny(Path.GetInvalidFileNameChars()) + ".cs";
return name + ".cs"; return name + ".cs";
} }
public override string DisplayName {
get { return "Move type to file"; }
}
} }
} }

20
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 { get {
// TODO Use the string from resource file! But this needs to become GetDisplayName(context) first.
return "Rename file to match type name"; 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) string MakeValidFileName(string name)
{ {
if (name == null) if (name == null)

2
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/ContextActionViewModel.cs

@ -33,7 +33,7 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
} }
public string Name { 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; } public string Comment { get; set; }

8
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/ContextActions/GoToEntityAction.cs

@ -25,10 +25,16 @@ namespace ICSharpCode.AvalonEdit.AddIn.ContextActions
ChildActions = childActions ChildActions = childActions
}; };
} }
public string DisplayName { get; private set; } public string DisplayName { get; private set; }
public IEntity Entity { get; private set; } public IEntity Entity { get; private set; }
public string GetDisplayName(EditorRefactoringContext context)
{
return DisplayName;
}
public GoToEntityAction(IEntity entity, string displayName) public GoToEntityAction(IEntity entity, string displayName)
{ {
if (entity == null) if (entity == null)

5
src/Main/Base/Project/Refactoring/ContextAction.cs

@ -22,6 +22,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring
public abstract string DisplayName { get; } public abstract string DisplayName { get; }
public virtual string GetDisplayName(EditorRefactoringContext context)
{
return DisplayName;
}
public virtual string Category { public virtual string Category {
get { return string.Empty; } get { return string.Empty; }
} }

6
src/Main/Base/Project/Refactoring/IContextAction.cs

@ -18,9 +18,11 @@ namespace ICSharpCode.SharpDevelop.Refactoring
IContextActionProvider Provider { get; } IContextActionProvider Provider { get; }
/// <summary> /// <summary>
/// Name displayed in the context actions popup. /// Name displayed in the context action's popup.
/// </summary> /// </summary>
string DisplayName { get; } /// <param name="context">Refactoring context that can be used by the context action to create the display name.</param>
/// <returns></returns>
string GetDisplayName(EditorRefactoringContext context);
/// <summary> /// <summary>
/// Executes this action. Called when this action is selected from the context actions popup. /// Executes this action. Called when this action is selected from the context actions popup.

Loading…
Cancel
Save