protected override void Run() { var document = IdeApp.Workbench.ActiveDocument; if (!StylerOptionsConfiguration.IsFormatableDocument(document)) { return; } var stylerOptions = StylerOptionsConfiguration.GetOptionsForDocument(document.FileName, document.Owner as Project); var styler = new StylerService(stylerOptions); if (document.Editor is null) { var textBuffer = document.TextBuffer; var currentSnapshot = textBuffer.CurrentSnapshot; var rawText = currentSnapshot.GetText(); var styledText = styler.StyleDocument(rawText); var replaceSpan = new Span(0, rawText.Length); textBuffer.Replace(replaceSpan, styledText); } else { var editor = document.Editor; using (editor.OpenUndoGroup()) { var styledText = styler.StyleDocument(editor.Text); editor.Text = styledText; } } document.IsDirty = true; }
protected override void Update(CommandInfo info) { var document = IdeApp.Workbench.ActiveDocument; var isDocumentFormattable = StylerOptionsConfiguration.IsFormatableDocument(document); info.Enabled = isDocumentFormattable; info.Visible = isDocumentFormattable; }
protected override void Run() { var options = StylerOptionsConfiguration.ReadFromUserProfile(); var styler = new StylerService(options); var item = IdeApp.ProjectOperations.CurrentSelectedItem; if (item is Solution sln) { BatchProcessSolution(sln, styler); return; } if (item is Project prj) { BatchProcessProject(prj, styler); } }
private void ProcessFileInPlace(ProjectFile file) { var options = StylerOptionsConfiguration.GetOptionsForDocument(file.Name, file.Project); var styler = new StylerService(options); LoggingService.LogDebug($"Processing {file.FilePath} in-place"); var content = System.IO.File.ReadAllText(file.FilePath); var styledXaml = styler.StyleDocument(content); System.IO.File.WriteAllText(file.FilePath, styledXaml); var openedFile = IdeApp.Workbench.Documents.FirstOrDefault(f => f.FileName.FullPath == file.FilePath); if (openedFile != null) { LoggingService.LogDebug($"Reloading {file.FilePath} in editor window"); openedFile.Reload(); } }
protected override void Run() { var options = StylerOptionsConfiguration.ReadFromUserProfile(); var styler = new StylerService(options); var doc = IdeApp.Workbench.ActiveDocument; var edit = doc.Editor; if (edit != null) { var styledXaml = styler.StyleDocument(edit.Text); using (edit.OpenUndoGroup()) { edit.RemoveText(0, edit.Text.Length); edit.InsertText(0, styledXaml); } doc.IsDirty = true; } }
protected override void Run() { var document = IdeApp.Workbench.ActiveDocument; if (!StylerOptionsConfiguration.IsFormatableDocument(document)) { return; } var stylerOptions = StylerOptionsConfiguration.GetOptionsForDocument(document.FileName, document.Owner as Project); var styler = new StylerService(stylerOptions); var editor = document.Editor; using (editor.OpenUndoGroup()) { var styledText = styler.StyleDocument(editor.Text); editor.Text = styledText; } document.IsDirty = true; }