public bool ExecuteCommand(SaveCommandArgs args, CommandExecutionContext executionContext) { if (!GeneralOptions.Instance.Enabled) { return(true); } try { IEditorCommandHandlerService service = _commandService.GetService(args.TextView); // Profile 1 if (GeneralOptions.Instance.Profile == GeneralOptions.CodeCleanupProfile.Profile1) { var cmd = new CodeCleanUpDefaultProfileCommandArgs(args.TextView, args.SubjectBuffer); service.Execute((v, b) => cmd, null); } // Profile 2 else if (GeneralOptions.Instance.Profile == GeneralOptions.CodeCleanupProfile.Profile2) { var cmd = new CodeCleanUpCustomProfileCommandArgs(args.TextView, args.SubjectBuffer); service.Execute((v, b) => cmd, null); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } return(true); }
public bool ExecuteCommand(SaveCommandArgs args, CommandExecutionContext executionContext) { ThreadHelper.ThrowIfNotOnUIThread(); // Check if file is part of a project first. if (args.SubjectBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument textDoc)) { var filePath = textDoc.FilePath; var dte = Package.GetGlobalService(typeof(DTE)) as DTE2; ProjectItem item = dte.Solution?.FindProjectItem(filePath); if (string.IsNullOrEmpty(item?.ContainingProject?.FullName)) { return(true); } } // Then check if it's been enabled in the options. if (!GeneralOptions.Instance.Enabled) { return(true); } try { IEditorCommandHandlerService service = _commandService.GetService(args.TextView); // Profile 1 if (GeneralOptions.Instance.Profile == GeneralOptions.CodeCleanupProfile.Profile1) { var cmd = new CodeCleanUpDefaultProfileCommandArgs(args.TextView, args.SubjectBuffer); service.Execute((v, b) => cmd, null); } // Profile 2 else if (GeneralOptions.Instance.Profile == GeneralOptions.CodeCleanupProfile.Profile2) { var cmd = new CodeCleanUpCustomProfileCommandArgs(args.TextView, args.SubjectBuffer); service.Execute((v, b) => cmd, null); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } return(true); }