Skip to content

Commit

Permalink
Build in suggested actions base classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mlorbetske committed Jun 23, 2016
1 parent a978fef commit d31d78d
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
@@ -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 EditorExtensions/HTML/LightBulbs/Actions/SuggestedActionBase.cs
@@ -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
}
}

2 changes: 2 additions & 0 deletions EditorExtensions/WebEssentials2015.csproj
Expand Up @@ -483,9 +483,11 @@
<Compile Include="HTML\LightBulbs\Actions\AngularControllerLightBulbAction.cs" />
<Compile Include="HTML\LightBulbs\Actions\Base64DecodeLightBulbAction.cs" />
<Compile Include="HTML\LightBulbs\Actions\ExtractLightBulbAction.cs" />
<Compile Include="HTML\LightBulbs\Actions\HtmlSuggestedActionBase.cs" />
<Compile Include="HTML\LightBulbs\Actions\IntegrityLightBulbAction.cs" />
<Compile Include="HTML\LightBulbs\Actions\MinifyLightBulbAction.cs" />
<Compile Include="HTML\LightBulbs\Actions\RemoveElementLightBulbAction.cs" />
<Compile Include="HTML\LightBulbs\Actions\SuggestedActionBase.cs" />
<Compile Include="HTML\LightBulbs\Providers\AngularControllerLightBulbProvider.cs" />
<Compile Include="HTML\LightBulbs\Providers\ImageLightBulbProvider.cs" />
<Compile Include="HTML\LightBulbs\Providers\RemoveElementLightBulbProvider.cs" />
Expand Down

0 comments on commit d31d78d

Please sign in to comment.