protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) { var projectFile = (IProjectFile)_highlight.OffendingProjectItem; using (var cookie = solution.CreateTransactionCookie(DefaultAction.Rollback, this.GetType().Name, progress)) { IProjectFolder newFolder = (IProjectFolder)_highlight.TargetProject.FindProjectItemByLocation(_highlight.TargetFolder) ?? _highlight.TargetProject.GetOrCreateProjectFolder(_highlight.TargetFolder, cookie); var workflow = new MoveToFolderWorkflow(solution, "ManualMoveToFolderQuickFix"); IProjectFolder targetFolder = newFolder ?? _highlight.TargetProject; var dataProvider = new MoveToFolderDataProvider(true, false, targetFolder, new List <string>(), new List <string>()); workflow.SetDataProvider(dataProvider); Lifetimes.Using( (lifetime => WorkflowExecuter.ExecuteWithCustomHost( Shell.Instance.GetComponent <IActionManager>() .DataContexts.CreateWithoutDataRules(lifetime , DataRules.AddRule(DataRules.AddRule("ManualMoveToFolderQuickFix" , JetBrains.ProjectModel.DataContext.ProjectModelDataConstants.PROJECT_MODEL_ELEMENTS, new IProjectModelElement[] { projectFile }) , "ManualMoveToFolderQuickFix" , JetBrains.ProjectModel.DataContext.ProjectModelDataConstants.SOLUTION, solution)) , workflow, new SimpleWorkflowHost()))); cookie.Commit(progress); } return(null); }
private static void ExecuteRefactoring([NotNull] ITextControl textControl, [NotNull] ICSharpExpression expression, [CanBeNull] Action executeAfter = null) { const string actionId = IntroVariableAction.ACTION_ID; var solution = expression.GetSolution(); var document = textControl.Document; var expressionRange = expression.GetDocumentRange().TextRange; textControl.Selection.SetRange(expressionRange); var rules = DataRules .AddRule(actionId, ProjectModel.DataContext.DataConstants.SOLUTION, solution) .AddRule(actionId, DocumentModel.DataContext.DataConstants.DOCUMENT, document) .AddRule(actionId, TextControl.DataContext.DataConstants.TEXT_CONTROL, textControl); var settingsStore = expression.GetSettingsStore(); var multipleOccurrences = settingsStore.GetValue(PostfixSettingsAccessor.SearchVarOccurrences); var definition = Lifetimes.Define(EternalLifetime.Instance, actionId); try // note: uber ugly code down here { var dataContexts = solution.GetComponent <DataContexts>(); var dataContext = dataContexts.CreateWithDataRules(definition.Lifetime, rules); if (multipleOccurrences && !Shell.Instance.IsTestShell) { var introduceAction = new IntroVariableAction(); if (introduceAction.Update(dataContext, new ActionPresentation(), () => false)) { introduceAction.Execute(dataContext, delegate { }); if (executeAfter != null) { SubscribeAfterExecute(executeAfter); } } } else { var workflow = new IntroduceVariableWorkflow(solution, actionId); WorkflowExecuter.ExecuteBatch(dataContext, workflow); #if RESHARPER8 if (executeAfter != null) { SubscribeAfterExecute(executeAfter); } #elif RESHARPER9 var finishedAction = executeAfter; if (finishedAction != null) { workflow.SuccessfullyFinished += delegate { finishedAction(); } } ; #endif } } finally { definition.Terminate(); } }
private static void ExecuteRefactoring([NotNull] ITextControl textControl, [NotNull] ICSharpExpression expression, [CanBeNull] Action executeAfter = null) { const string actionId = IntroVariableAction.ACTION_ID; var solution = expression.GetSolution(); var document = textControl.Document; var expressionRange = expression.GetDocumentRange().TextRange; textControl.Selection.SetRange(expressionRange); var rules = DataRules .AddRule(actionId, ProjectModel.DataContext.DataConstants.SOLUTION, solution) .AddRule(actionId, DocumentModel.DataContext.DataConstants.DOCUMENT, document) .AddRule(actionId, TextControl.DataContext.DataConstants.TEXT_CONTROL, textControl); var settingsStore = expression.GetSettingsStore(); var multipleOccurrences = settingsStore.GetValue(PostfixTemplatesSettingsAccessor.SearchVarOccurrences); // note: uber ugly code down here using (var definition = Lifetimes.Define(EternalLifetime.Instance, actionId)) { var dataContexts = solution.GetComponent <DataContexts>(); var dataContext = dataContexts.CreateWithDataRules(definition.Lifetime, rules); // todo: introduce normal way to execute refactorings with occurences search if (multipleOccurrences && !Shell.Instance.IsTestShell) { var introduceAction = new IntroVariableAction(); if (introduceAction.Update(dataContext, new ActionPresentation(), () => false)) { introduceAction.Execute(dataContext, delegate { }); if (executeAfter != null) { IntroduceVariableTemplate.SubscribeAfterExecute(executeAfter); } } } else { var workflow = new IntroduceVariableWorkflow(solution, actionId); WorkflowExecuter.ExecuteBatch(dataContext, workflow); var finishedAction = executeAfter; if (finishedAction != null) { var currentSession = HotspotSessionExecutor.Instance.CurrentSession; if (currentSession != null) // ugly hack { currentSession.HotspotSession.Closed.Advise(EternalLifetime.Definition, (e) => { if (e.TerminationType == TerminationType.Finished) { finishedAction(); } }); } else { finishedAction(); } } } } }