Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build in suggested actions base classes
- Loading branch information
1 parent
a978fef
commit d31d78d
Showing
3 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
EditorExtensions/HTML/LightBulbs/Actions/HtmlSuggestedActionBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.Html.Core.Tree.Nodes; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MadsKristensen.EditorExtensions.Html | ||
{ | ||
internal abstract class HtmlSuggestedActionBase : SuggestedActionBase | ||
{ | ||
public ElementNode Element { get; private set; } | ||
public AttributeNode Attribute { get; private set; } | ||
|
||
protected HtmlSuggestedActionBase(ITextView textView, ITextBuffer textBuffer, ElementNode element, string displayText) | ||
: this(textView, textBuffer, element, null, displayText) | ||
{ | ||
} | ||
|
||
protected HtmlSuggestedActionBase(ITextView textView, ITextBuffer textBuffer, ElementNode element, AttributeNode attribute, string displayText) | ||
: base(textBuffer, textView, displayText) | ||
{ | ||
Element = element; | ||
Attribute = attribute; | ||
} | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
EditorExtensions/HTML/LightBulbs/Actions/SuggestedActionBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using Microsoft.VisualStudio.Imaging.Interop; | ||
using Microsoft.VisualStudio.Language.Intellisense; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace MadsKristensen.EditorExtensions.Html | ||
{ | ||
/// <summary> | ||
/// Base class for suggested action implementations. Actions can derive from this type and specialize as necessary for their appropriate | ||
/// language context (e.g. HTML, JSON, etc). | ||
/// </summary> | ||
public abstract class SuggestedActionBase : ISuggestedAction | ||
{ | ||
public SuggestedActionBase(ITextBuffer buffer, ITextView view, string displayText) | ||
{ | ||
TextBuffer = buffer; | ||
TextView = view; | ||
DisplayText = displayText; | ||
} | ||
|
||
public ITextBuffer TextBuffer | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
public ITextView TextView | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
#region ISuggestedAction members | ||
|
||
/// <summary> | ||
/// By default, nested actions are not supported. | ||
/// </summary> | ||
public virtual bool HasActionSets | ||
{ | ||
get | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// By default, nested actions are not supported. | ||
/// </summary> | ||
public virtual Task<IEnumerable<SuggestedActionSet>> GetActionSetsAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult<IEnumerable<SuggestedActionSet>>(null); | ||
} | ||
|
||
public string DisplayText | ||
{ | ||
get; | ||
private set; | ||
} | ||
|
||
public string IconAutomationText | ||
{ | ||
get; | ||
protected set; | ||
} | ||
|
||
public ImageMoniker IconMoniker | ||
{ | ||
get; | ||
protected set; | ||
} | ||
|
||
public string InputGestureText | ||
{ | ||
get; | ||
protected set; | ||
} | ||
|
||
/// <summary> | ||
/// By default, Preview is not supported. | ||
/// </summary> | ||
public virtual bool HasPreview | ||
{ | ||
get | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// By default, Preview is not supported. | ||
/// </summary> | ||
public virtual Task<object> GetPreviewAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.FromResult<object>(null); | ||
} | ||
|
||
public abstract void Invoke(CancellationToken cancellationToken); | ||
|
||
/// <summary> | ||
/// By default, telemetry is not supported. | ||
/// </summary> | ||
public virtual bool TryGetTelemetryId(out Guid telemetryId) | ||
{ | ||
telemetryId = Guid.Empty; | ||
return false; | ||
} | ||
|
||
#region IDisposable Support | ||
protected virtual void Dispose(bool disposing) | ||
{ | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
} | ||
#endregion | ||
|
||
#endregion | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters