Exemplo n.º 1
0
        /// <summary>
        /// Called before a document is saved in order to potentially run code cleanup.
        /// </summary>
        /// <param name="document">The document about to be saved.</param>
        internal void OnBeforeDocumentSave(Document document)
        {
            if (!Settings.Default.Cleaning_AutoCleanupOnFileSave)
            {
                return;
            }
            if (!CodeCleanupAvailabilityLogic.CanCleanupDocument(document))
            {
                return;
            }

            try
            {
                Package.IsAutoSaveContext = true;

                using (new ActiveDocumentRestorer(Package))
                {
                    CodeCleanupManager.Cleanup(document);
                }
            }
            finally
            {
                Package.IsAutoSaveContext = false;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CleanupActiveCodeCommand"/> class.
 /// </summary>
 /// <param name="package">The hosting package.</param>
 internal CleanupActiveCodeCommand(EditorConfigPackage package)
     : base(package,
            new CommandID(Guids.GuidEditorConfigCommandCleanupActiveCode, (int)PkgCmdIDList.CmdIDEditorConfigCleanupActiveCode))
 {
     CodeCleanupAvailabilityLogic = CodeCleanupAvailabilityLogic.GetInstance(Package);
     CodeCleanupManager           = CodeCleanupManager.GetInstance(Package);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CleanupActiveCodeCommand" /> class.
 /// </summary>
 /// <param name="package">The hosting package.</param>
 internal CleanupActiveCodeCommand(CodeMaidPackage package)
     : base(package,
            new CommandID(PackageGuids.GuidCodeMaidCommandCleanupActiveCode, PackageIds.CmdIDCodeMaidCleanupActiveCode))
 {
     CodeCleanupAvailabilityLogic = CodeCleanupAvailabilityLogic.GetInstance(Package);
     CodeCleanupManager           = CodeCleanupManager.GetInstance(Package);
 }
        /// <summary>
        /// Default constructor of the package. Inside this method you can place any initialization
        /// code that does not require any Visual Studio service because at this point the package
        /// object is created but not sited yet inside Visual Studio environment. The place to do
        /// all the other initialization is the Initialize method.
        /// </summary>
        public CodeMaidPackage()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this));

            CodeCleanupAvailabilityLogic = CodeCleanupAvailabilityLogic.GetInstance(this);
            CodeCleanupManager           = CodeCleanupManager.GetInstance(this);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CleanupOpenCodeCommand" /> class.
 /// </summary>
 /// <param name="package">The hosting package.</param>
 internal CleanupOpenCodeCommand(CodeMaidPackage package)
     : base(package,
            new CommandID(GuidList.GuidCodeMaidCommandCleanupOpenCode, (int)PkgCmdIDList.CmdIDCodeMaidCleanupOpenCode))
 {
     CodeCleanupAvailabilityLogic = CodeCleanupAvailabilityLogic.GetInstance(Package);
     CodeCleanupManager           = CodeCleanupManager.GetInstance(Package);
 }
        /// <summary>
        /// Called to execute the command.
        /// </summary>
        protected override void OnExecute()
        {
            var textBuffer = GetCurrentTextBuffer();

            if (textBuffer != null)
            {
                CodeCleanupManager.Cleanup(ActiveDocument, textBuffer);
            }
        }
        /// <summary>
        /// Called before a document is saved in order to potentially run code cleanup.
        /// </summary>
        /// <param name="document">The document about to be saved.</param>
        internal void OnBeforeDocumentSave(Document document)
        {
            if (!CodeCleanupAvailabilityLogic.ShouldCleanup(document))
            {
                return;
            }

            using (new ActiveDocumentRestorer(this))
            {
                CodeCleanupManager.Cleanup(document);
            }
        }
        /// <summary>
        /// Called before a document is saved in order to potentially run code cleanup.
        /// </summary>
        /// <param name="document">The document about to be saved.</param>
        internal void OnBeforeDocumentSave(Document document)
        {
            try
            {
                EditorConfigPackage.IsAutoSaveContext = true;

                using (new ActiveDocumentRestorer(Package))
                {
                    CodeCleanupManager.Cleanup(document);
                }
            }
            finally
            {
                EditorConfigPackage.IsAutoSaveContext = false;
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Called before a document is saved in order to potentially run code cleanup.
        /// </summary>
        /// <param name="document">The document about to be saved.</param>
        internal void OnBeforeDocumentSave(Document document)
        {
            if (!Settings.Default.Cleaning_AutoCleanupOnFileSave)
            {
                return;
            }
            if (!CodeCleanupAvailabilityLogic.CanCleanup(document))
            {
                return;
            }

            using (new ActiveDocumentRestorer(Package))
            {
                CodeCleanupManager.Cleanup(document, true);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Handles the DoWork event of the backgroundWorker control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">
        /// The <see cref="System.ComponentModel.DoWorkEventArgs" /> instance containing the event data.
        /// </param>
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var bw    = (BackgroundWorker)sender;
            var items = (IEnumerable <object>)e.Argument;
            int i     = 0;

            foreach (dynamic item in items)
            {
                if (bw.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }

                bw.ReportProgress(++i, item);

                CodeCleanupManager.Cleanup(item);
            }
        }
Exemplo n.º 11
0
        /// <summary 该方法调用路径CleanupSelectedCodeCommand->CodeCleanupAvailabilityLogic->CleanupProgressViewModel>
        /// 该方法清理选中项目的代码
        /// Initializes a new instance of the <see cref="CleanupProgressViewModel" /> class.
        /// </summary>
        /// <param name="package">The hosting package.</param>
        /// <param name="items">The items to cleanup.</param>
        public CleanupProgressViewModel(CodeMaidPackage package, IEnumerable <object> items)
        {
            CodeCleanupManager = CodeCleanupManager.GetInstance(package);

            // Initialize UI elements.
            CountTotal = items.Count();

            // Initialize background worker.
            _backgroundWorker = new BackgroundWorker
            {
                WorkerReportsProgress      = true,
                WorkerSupportsCancellation = true
            };
            //异步调用数据处理
            _backgroundWorker.DoWork             += backgroundWorker_DoWork;
            _backgroundWorker.ProgressChanged    += backgroundWorker_ProgressChanged;
            _backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;

            _backgroundWorker.RunWorkerAsync(items);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Called to execute the command.
        /// </summary>
        protected override void OnExecute()
        {
            base.OnExecute();

            CodeCleanupManager.Cleanup(Package.ActiveDocument);
        }
 /// <summary>
 /// Called to execute the command.
 /// </summary>
 protected override void OnExecute()
 {
     CodeCleanupManager.Cleanup(ActiveDocument);
 }
 /// <summary>
 /// Called before a document is saved in order to potentially run code cleanup.
 /// </summary>
 /// <param name="document">The document about to be saved.</param>
 internal void OnBeforeDocumentSave(Document document)
 {
     CodeCleanupManager.Cleanup(document);
 }