Skip to content

@nesteruk /GeneratorWorkflowNoUI.cs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
ReSharper generator workflow that shows no UI
namespace ChangeThis
{
using System;
using JetBrains.Application;
using JetBrains.Application.DataContext;
using JetBrains.Application.Progress;
using JetBrains.ReSharper.Feature.Services.ActionsMenu;
using JetBrains.ReSharper.Feature.Services.Generate;
using JetBrains.ReSharper.Feature.Services.Generate.Actions;
using JetBrains.ReSharper.Psi;
using JetBrains.UI.Icons;
using JetBrains.UI.RichText;
using DataConstants = JetBrains.ProjectModel.DataContext.DataConstants;
public abstract class GenerateWorkflowNoUI : IGenerateActionWorkflow, IWorkflow<GenerateActionGroup>
{
private readonly GenerateActionGroup myActionGroup;
private readonly string myActionId;
private readonly string myDescription;
private readonly IconId myIcon;
private readonly string myKind;
private readonly RichText myMenuText;
private readonly string myWindowTitle;
private IGeneratorWorkflow myWorkflow;
protected GenerateWorkflowNoUI(string kind, IconId icon, string menuText, GenerateActionGroup actionGroup,
string windowTitle, string description, string actionId)
{
myDescription = description;
myActionId = actionId;
myKind = kind;
myIcon = icon;
myMenuText = (RichText) menuText;
myActionGroup = actionGroup;
myWindowTitle = windowTitle;
}
public abstract double Order { get; }
public string Title
{
get { return (string) myMenuText; }
}
public string ShortActionId { get; private set; }
public GenerateActionGroup ActionGroup
{
get { return myActionGroup; }
}
public string ActionId
{
get { return myActionId; }
}
public IconId Icon
{
get { return myIcon; }
}
public virtual bool IsAvailable(IDataContext dataContext)
{
var data = dataContext.GetData(DataConstants.SOLUTION);
if (data == null)
return false;
GeneratorManager instance = GeneratorManager.GetInstance(data);
if (instance == null)
return false;
PsiLanguageType languageFromContext = instance.GetPsiLanguageFromContext(dataContext);
return languageFromContext != null && LanguageManager.Instance.TryGetService<IGeneratorContextFactory>(languageFromContext) != null;
}
public bool IsEnabled(IDataContext context)
{
if (context.GetData(DataConstants.SOLUTION) == null)
throw new InvalidOperationException("solution should be available from data context");
myWorkflow = GeneratorWorkflowFactory.CreateWorkflow(myKind, context);
return myWorkflow != null;
}
public void Execute(IDataContext context)
{
if (myWorkflow == null)
myWorkflow = GeneratorWorkflowFactory.CreateWorkflow(myKind, context);
if (myWorkflow == null)
return;
using (ReadLockCookie.Create())
{
myWorkflow.BuildInputOptions();
myWorkflow.GenerateAndFinish(myWindowTitle, (IProgressIndicator) NullProgressIndicator.Instance);
}
}
public override string ToString()
{
return string.Format("Title: {0}", (object) myWindowTitle);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.