コード例 #1
0
        private void FormatSelection(ITextView textView, ITextBuffer buffer)
        {
            if (!Options.Instance.FormatOnMoveLine)
            {
                return;
            }

            MoveCaretIfNeeded(textView);

            if (!_formatQueued)
            {
                _formatQueued = true;

                ThreadHelper.JoinableTaskFactory.RunAsync(async() =>
                {
                    await Task.Delay(1);

                    IEditorCommandHandlerService service = _commandService.GetService(textView);
                    var cmd = new FormatSelectionCommandArgs(textView, buffer);
                    service.Execute((v, b) => cmd, null);

                    _formatQueued = false;
                }).FileAndForget(nameof(FormatOnMoveLine));
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void InsertAtCaret(Document document)
        {
            var textView = document.GetContent <ITextView> ();

            textView.Properties.AddProperty(typeof(ExpansionTemplate), Template);
            try {
                commandDispatchFactory.GetService(textView).Execute((t, b) => new InsertSnippetCommandArgs(t, b), null);
            } finally {
                textView.Properties.RemoveProperty(typeof(ExpansionTemplate));
            }
            ((ICocoaTextView)textView).VisualElement.Window?.MakeKeyWindow();
        }
コード例 #4
0
        /// <summary>
        /// Creates a new key processor provider for the given WPF text view host
        /// </summary>
        /// <param name="wpfTextView">WPF-based text view to create key processor for</param>
        /// <returns>A valid key processor</returns>
        public KeyProcessor GetAssociatedProcessor(IWpfTextView wpfTextView)
        {
            if (wpfTextView == null)
            {
                throw new ArgumentNullException("wpfTextView");
            }

            return(new DefaultKeyProcessor(
                       wpfTextView,
                       editorOperationsProvider.GetEditorOperations(wpfTextView),
                       textUndoHistoryRegistry,
                       editorCommandHandlerServiceFactory.GetService(wpfTextView)));
        }
コード例 #5
0
        public bool ExecuteCommand(SaveCommandArgs args, CommandExecutionContext executionContext)
        {
            try
            {
                var service = _editorCommandHandlerServiceFactory.GetService(args.TextView);
                Debug.WriteLine($"I am executing something on save with {service.GetType()}");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            return(true);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public bool ExecuteCommand(FormatDocumentCommandArgs args, CommandExecutionContext executionContext)
        {
            if (!Options.Instance.RunCodeCleanupOnFormat)
            {
                return(false);
            }

            try
            {
                IEditorCommandHandlerService service = _commandService.GetService(args.TextView);

                var cmd = new CodeCleanUpDefaultProfileCommandArgs(args.TextView, args.SubjectBuffer);
                service.Execute((v, b) => cmd, null);
            }
            catch (Exception ex)
            {
                Trace.Write(ex);
            }

            return(false);
        }
コード例 #8
0
 protected internal void RefreshCommandFilters()
 {
     this.CurrentHandlers = _commandHandlerServiceFactory.GetService(WpfTextView);
 }