Exemplo n.º 1
0
        /// <summary>
        /// Attempts to run code cleanup on the specified document.
        /// </summary>
        /// <param name="document">The document for cleanup.</param>
        /// <param name="isAutoSave">A flag indicating if occurring due to auto-save.</param>
        internal void Cleanup(Document document, bool isAutoSave = false)
        {
            if (!_codeCleanupAvailabilityLogic.ShouldCleanup(document, true))
            {
                return;
            }

            // Make sure the document to be cleaned up is active, required for some commands like
            // format document.
            document.Activate();

            if (_package.ActiveDocument != document)
            {
                OutputWindowHelper.WarningWriteLine(
                    string.Format("Activation was not completed before cleaning began for '{0}'", document.Name));
            }

            // Conditionally start cleanup with reorganization.
            if (Settings.Default.Reorganizing_RunAtStartOfCleanup)
            {
                _codeReorderManager.Reorganize(document, isAutoSave);
            }

            _undoTransactionHelper.Run(
                () => !(isAutoSave && Settings.Default.General_SkipUndoTransactionsDuringAutoCleanupOnSave),
                delegate
            {
                var cleanupMethod = FindCodeCleanupMethod(document);
                if (cleanupMethod != null)
                {
                    OutputWindowHelper.DiagnosticWriteLine(
                        string.Format("CodeCleanupManager.Cleanup started for '{0}'", document.FullName));

                    _package.IDE.StatusBar.Text = string.Format("CodeMaid is cleaning '{0}'...", document.Name);

                    // Perform the set of configured cleanups based on the language.
                    cleanupMethod(document, isAutoSave);

                    _package.IDE.StatusBar.Text = string.Format("CodeMaid cleaned '{0}'.", document.Name);

                    OutputWindowHelper.DiagnosticWriteLine(
                        string.Format("CodeCleanupManager.Cleanup completed for '{0}'", document.FullName));
                }
            },
                delegate(Exception ex)
            {
                OutputWindowHelper.ExceptionWriteLine(
                    string.Format("Stopped cleaning '{0}'", document.Name), ex);
                _package.IDE.StatusBar.Text = string.Format("CodeMaid stopped cleaning '{0}'.  See output window for more details.", document.Name);
            });
        }
Exemplo n.º 2
0
 private static void RunReorganize(Document document)
 {
     _codeReorderManager.Reorganize(document, false);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Called to execute the command.
        /// </summary>
        protected override void OnExecute()
        {
            base.OnExecute();

            CodeReorderManager.Reorganize(Package.ActiveDocument, false);
        }