예제 #1
0
 /// <summary>
 /// Initialization of the package; this method is called right after the package is sited, so this is the place
 /// where you can put all the initialization code that rely on services provided by VisualStudio.
 /// </summary>
 protected override void Initialize()
 {
     base.Initialize();
     ToggleComment.Initialize(this);
     ExpandSelection.Initialize(this);
     FormatCode.Initialize(this);
     DuplicateSelection.Initialize(this);
     MoveMemberUp.Initialize(this);
     MoveMemberDown.Initialize(this);
 }
예제 #2
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            ToggleComment.Initialize(this);
            ExpandSelection.Initialize(this);
            FormatCode.Initialize(this);
            DuplicateSelection.Initialize(this);
            MoveMemberUp.Initialize(this);
            MoveMemberDown.Initialize(this);
            await GoToLastEditLocation.Initialize(this);
        }
예제 #3
0
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            // Command handling
            if (pguidCmdGroup == Constants.HotCommandsGuid)
            {
                // Dispatch to the correct command handler
                switch (nCmdID)
                {
                case Constants.ToggleCommentCmdId:
                    return(ToggleComment.Instance.HandleCommand(textView, classifier, GetShellCommandDispatcher(), editorOperations));

                case Constants.ExpandSelectionCmdId:
                    return(ExpandSelection.Instance.HandleCommand(textView, true));

                case Constants.ShrinkSelectionCmdId:
                    return(ExpandSelection.Instance.HandleCommand(textView, false));

                case Constants.FormatCodeCmdId:
                    return(FormatCode.Instance.HandleCommand(textView, GetShellCommandDispatcher()));

                case Constants.DuplicateSelectionCmdId:
                    return(DuplicateSelection.HandleCommand(textView, classifier, GetShellCommandDispatcher(), editorOperations));

                case Constants.DuplicateSelectionReverseCmdId:
                    return(DuplicateSelection.HandleCommand(textView, classifier, GetShellCommandDispatcher(), editorOperations, true));

                case Constants.JoinLinesCmdId:
                    return(JoinLines.HandleCommand(textView, classifier, GetShellCommandDispatcher(), editorOperations));

                case Constants.MoveMemberUpCmdId:
                    return(MoveMemberUp.Instance.HandleCommand(textView, GetShellCommandDispatcher(), editorOperations));

                case Constants.MoveMemberDownCmdId:
                    return(MoveMemberDown.Instance.HandleCommand(textView, GetShellCommandDispatcher(), editorOperations));

                case Constants.GoToPreviousMemberCmdId:
                    return(MoveCursorToAdjacentMember.MoveToPreviousMember(textView, editorOperations));

                case Constants.GoToNextMemberCmdId:
                    return(MoveCursorToAdjacentMember.MoveToNextMember(textView, editorOperations));
                }
            }

            // No commands called. Pass to next command handler.
            if (Next != null)
            {
                return(Next.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }
            return((int)OLEConstants.OLECMDERR_E_UNKNOWNGROUP);
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            // Command handling
            if (pguidCmdGroup == Constants.HotCommandsGuid)
            {
                // Due to Async initialization, some Instances might be uninitialized and will return null.
                // Safely catch the NullReferenceException and report a message to the status bar
                try
                {
                    // Dispatch to the correct command handler
                    switch (nCmdID)
                    {
                    case Constants.ToggleCommentCmdId:
                        return(ToggleComment.Instance.HandleCommand(textView, classifier, GetShellCommandDispatcher(), editorOperations));

                    case Constants.ExpandSelectionCmdId:
                        return(ExpandSelection.Instance.HandleCommand(textView, true));

                    case Constants.ShrinkSelectionCmdId:
                        return(ExpandSelection.Instance.HandleCommand(textView, false));

                    case Constants.FormatCodeCmdId:
                        return(FormatCode.Instance.HandleCommand(textView, GetShellCommandDispatcher()));

                    case Constants.DuplicateSelectionCmdId:
                        return(DuplicateSelection.HandleCommand(textView, classifier, GetShellCommandDispatcher(), editorOperations));

                    case Constants.DuplicateSelectionReverseCmdId:
                        return(DuplicateSelection.HandleCommand(textView, classifier, GetShellCommandDispatcher(), editorOperations, true));

                    case Constants.JoinLinesCmdId:
                        return(JoinLines.HandleCommand(textView, classifier, GetShellCommandDispatcher(), editorOperations));

                    case Constants.MoveMemberUpCmdId:
                        return(MoveMemberUp.Instance.HandleCommand(textView, GetShellCommandDispatcher(), editorOperations));

                    case Constants.MoveMemberDownCmdId:
                        return(MoveMemberDown.Instance.HandleCommand(textView, GetShellCommandDispatcher(), editorOperations));

                    case Constants.GoToPreviousMemberCmdId:
                        return(MoveCursorToAdjacentMember.MoveToPreviousMember(textView, editorOperations));

                    case Constants.GoToNextMemberCmdId:
                        return(MoveCursorToAdjacentMember.MoveToNextMember(textView, editorOperations));
                    }
                    // Clear the Status Bar text
                    StatusBarService.Clear();
                }
                catch (NullReferenceException)
                {
                    // Most likely exception: System.NullReferenceException: 'Object reference not set to an instance of an object.'
                    // Resulting from the command being called before Async loading has taken place.
                    // Swallow the exception and hope it works the next time the user tries it.
                    // Print a message to the StatusBar
                    StatusBarService.SetText("HotCommands is still loading. Please try again soon.");
                }
            }

            // No commands called. Pass to next command handler.
            if (Next != null)
            {
                return(Next.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut));
            }
            return((int)OLEConstants.OLECMDERR_E_UNKNOWNGROUP);
        }