public void Execute(ISolution solution, ITextControl textControl)
        {
            Shell.Instance.GetComponent <UITaskExecutor>().SingleThreaded.ExecuteTask("Cleanup file", TaskCancelable.No, progress =>
            {
                progress.TaskName = _profile.Name;
                progress.Start(1);

                using (Shell.Instance.GetComponent <ICommandProcessor>().UsingBatchTextChange("Code Cleanup"))
                {
                    using (var cookie = solution.GetComponent <SolutionDocumentTransactionManager>().CreateTransactionCookie(DefaultAction.Rollback, "Code cleanup"))
                    {
                        var progressIndicator = NullProgressIndicator.Create();

                        CodeCleanup instance = CodeCleanup.GetInstance(solution);

                        int caret = -1;
                        instance.Run(this._dataProvider.SourceFile, DocumentRange.InvalidRange, ref caret, _profile, NullProgressIndicator.Create());

                        cookie.Commit(progressIndicator);
                    }
                }

                progress.Stop();
            });
        }
示例#2
0
 private string GetTextAfterFormatting([NotNull] IDocument document, [NotNull] ITextControl textControl)
 {
     using (Solution.GetComponent <DocumentTransactionManager>()
            .CreateTransactionCookie(DefaultAction.Rollback, "Temporary change"))
     {
         var file                = document.GetPsiSourceFile(Solution);
         var codeCleanup         = CodeCleanup.GetInstance(Solution);
         var codeCleanupSettings = Shell.Instance.GetComponent <CodeCleanupSettingsComponent>();
         var profile             = codeCleanupSettings.GetDefaultProfile(CodeCleanup.DefaultProfileType.REFORMAT);
         var selectionRange      = textControl.Selection.OneDocRangeWithCaret();
         codeCleanup.Run(file, selectionRange.Length > 0
                                 ? new DocumentRange(textControl.Document, selectionRange)
                                 : DocumentRange.InvalidRange, profile, NullProgressIndicator.Create());
         return(document.GetText());
     }
 }