/// <summary> /// Reorganizes the specified document. /// </summary> /// <param name="document">The document for reorganizing.</param> internal void Reorganize(Document document) { if (!_codeReorganizationAvailabilityLogic.CanReorganize(document, true)) { return; } new UndoTransactionHelper(_package, $"CodeMaid Reorganize for '{document.Name}'").Run( delegate { OutputWindowHelper.DiagnosticWriteLine($"CodeReorganizationManager.Reorganize started for '{document.FullName}'"); _package.IDE.StatusBar.Text = $"CodeMaid is reorganizing '{document.Name}'..."; // Retrieve all relevant code items (excluding using statements). var rawCodeItems = _codeModelManager.RetrieveAllCodeItems(document).Where(x => !(x is CodeItemUsingStatement)); // Build the code tree based on the current file sort order. var codeItems = new SetCodeItems(rawCodeItems); var codeTree = CodeTreeBuilder.RetrieveCodeTree(new CodeTreeRequest(document, codeItems, CodeSortOrder.File)); // Recursively reorganize the code tree. RecursivelyReorganize(codeTree); _package.IDE.StatusBar.Text = $"CodeMaid reorganized '{document.Name}'."; OutputWindowHelper.DiagnosticWriteLine($"CodeReorganizationManager.Reorganize completed for '{document.FullName}'"); }); }
/// <summary> /// Reorganizes the specified document. /// </summary> /// <param name="document">The document for reorganizing.</param> /// <param name="isAutoSave">A flag indicating if occurring due to auto-save.</param> internal void Reorganize(Document document, bool isAutoSave) { if (!CanReorganize(document)) { return; } _undoTransactionHelper.Run( () => !(isAutoSave && Settings.Default.General_SkipUndoTransactionsDuringAutoCleanupOnSave), delegate { OutputWindowHelper.DiagnosticWriteLine( string.Format("CodeReorderManager.Reorganize started for '{0}'", document.FullName)); _package.IDE.StatusBar.Text = string.Format("CodeMaid is reorganizing '{0}'...", document.Name); // Retrieve all relevant code items (excluding using statements). var rawCodeItems = _codeModelManager.RetrieveAllCodeItems(document).Where(x => !(x is CodeItemUsingStatement)); // Build the code tree based on the current file layout. var codeItems = new SetCodeItems(rawCodeItems); var codeTree = CodeTreeBuilder.RetrieveCodeTree(new CodeTreeRequest(document, codeItems, TreeLayoutMode.FileLayout)); // Recursively reorganize the code tree. RecursivelyReorganize(codeTree); _package.IDE.StatusBar.Text = string.Format("CodeMaid reorganized '{0}'.", document.Name); OutputWindowHelper.DiagnosticWriteLine( string.Format("CodeReorderManager.Reorganize completed for '{0}'", document.FullName)); }, delegate(Exception ex) { OutputWindowHelper.ExceptionWriteLine( string.Format("Stopped reorganizing '{0}'", document.Name), ex); _package.IDE.StatusBar.Text = string.Format("CodeMaid stopped reorganizing '{0}'. See output window for more details.", document.Name); }); }
/// <summary> /// Reorganizes the specified document. /// </summary> /// <param name="document">The document for reorganizing.</param> internal void Reorganize(Document document) { if (!_codeReorganizationAvailabilityLogic.CanReorganize(document)) { return; } _undoTransactionHelper.Run( delegate { OutputWindowHelper.DiagnosticWriteLine( string.Format("CodeReorganizationManager.Reorganize started for '{0}'", document.FullName)); _package.IDE.StatusBar.Text = string.Format("CodeMaid is reorganizing '{0}'...", document.Name); // Retrieve all relevant code items (excluding using statements). var rawCodeItems = _codeModelManager.RetrieveAllCodeItems(document).Where(x => !(x is CodeItemUsingStatement)); // Build the code tree based on the current file sort order. var codeItems = new SetCodeItems(rawCodeItems); var codeTree = CodeTreeBuilder.RetrieveCodeTree(new CodeTreeRequest(document, codeItems, CodeSortOrder.File)); // Recursively reorganize the code tree. RecursivelyReorganize(codeTree); _package.IDE.StatusBar.Text = string.Format("CodeMaid reorganized '{0}'.", document.Name); OutputWindowHelper.DiagnosticWriteLine( string.Format("CodeReorganizationManager.Reorganize completed for '{0}'", document.FullName)); }, delegate(Exception ex) { OutputWindowHelper.ExceptionWriteLine( string.Format("Stopped reorganizing '{0}'", document.Name), ex); _package.IDE.StatusBar.Text = string.Format("CodeMaid stopped reorganizing '{0}'. See output window for more details.", document.Name); }); }