Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

ReSharper generator workflow that shows no UI

View GeneratorWorkflowNoUI.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
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.