Beispiel #1
0
 private static ITextUndoTransaction CreateTransaction(IEmacsCommandMetadata metadata, ITextUndoHistory history)
 {
     if (string.IsNullOrEmpty(metadata.UndoName))
     {
         return(null);
     }
     return(history.CreateTransaction(metadata.UndoName));
 }
        public void Execute(ITextView view, EmacsCommandID commandId, bool evaluateUniversalArgument = true)
        {
            IEmacsCommandMetadata commandMetadata = GetCommandMetadata(commandId);

            if (commandMetadata == null)
            {
                return;
            }
            Execute(view, commandMetadata, evaluateUniversalArgument);
        }
Beispiel #3
0
        private EmacsCommand CreateCommand(IEmacsCommandMetadata metadata)
        {
            if (metadata == null)
            {
                return(null);
            }

            var command = this.Commands.FirstOrDefault(export => export.Metadata.Command == metadata.Command && export.Metadata.CommandGroup == metadata.CommandGroup);

            if (command != null)
            {
                return(command.Value);
            }

            return(null);
        }
Beispiel #4
0
 public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
 {
     if (manager.IsEnabled)
     {
         IEmacsCommandMetadata commandMetadata = manager.GetCommandMetadata((int)nCmdID, pguidCmdGroup);
         if (commandMetadata != null)
         {
             if (commandMetadata != null)
             {
                 try
                 {
                     manager.Execute(view, commandMetadata, true);
                     manager.AfterSearch = false;
                 }
                 catch (Exception ex)
                 {
                     manager.UpdateStatus(ex.Message, false);
                     return(1);
                 }
             }
             return(0);
         }
         if (pguidCmdGroup == VSConstants.VSStd2K && (int)nCmdID == 1 && manager.UniversalArgument.HasValue &&
             manager.UniversalArgument.Value > 1)
         {
             int num1 = manager.UniversalArgument.Value;
             while (num1-- > 0)
             {
                 int num2 = router.ExecuteCommand(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
                 if (num2 != 0)
                 {
                     return(num2);
                 }
             }
             return(0);
         }
         if (pguidCmdGroup == VSConstants.VSStd2K && ((int)nCmdID == 122 || (int)nCmdID == 123))
         {
             MarkSession.GetSession(view).PushMark(true);
             manager.AfterSearch = true;
         }
     }
     return(1);
 }
        private EmacsCommand CreateCommand(IEmacsCommandMetadata metadata)
        {
            if (metadata == null)
            {
                return(null);
            }
            Lazy <EmacsCommand, IEmacsCommandMetadata> lazy = Commands.FirstOrDefault(export =>
            {
                if (export.Metadata.Command == metadata.Command)
                {
                    return(export.Metadata.CommandGroup == metadata.CommandGroup);
                }
                return(false);
            });

            if (lazy != null)
            {
                return(lazy.Value);
            }
            return(null);
        }
Beispiel #6
0
        /// <summary>
        /// Executes the emacs command
        /// </summary>
        /// <param name="view"></param>
        /// <param name="metadata"></param>
        public void Execute(ITextView view, IEmacsCommandMetadata metadata, bool evaluateUniversalArgument = true)
        {
            using (BufferMonitor bufferMonitor = BufferMonitor.Create(view.TextBuffer))
            {
                try
                {
                    EmacsCommand          command                = CreateCommand(metadata);
                    EmacsCommand          inverseCommand         = null;
                    IEmacsCommandMetadata inverseCommandMetadata = null;

                    var context = new EmacsCommandContext(
                        this, this.TextStructureNavigatorSelectorService,
                        this.EditorOperationsFactoryService.GetEditorOperations(view),
                        view, CommandRouterProvider.GetCommandRouter(view));

                    if (command != null)
                    {
                        var history = this.TextUndoHistoryRegistry.GetHistory(context.TextBuffer);
                        using (var transaction = CreateTransaction(metadata, history))
                        {
                            var  repeatCount          = 1;
                            bool shouldExecuteInverse = false;

                            if (evaluateUniversalArgument)
                            {
                                // Check if we should execute the inverse logic of the command by checking if the universal argument is lower than 0
                                shouldExecuteInverse = GetUniversalArgumentOrDefault() < 0;
                                if (shouldExecuteInverse)
                                {
                                    // Search the inverse command using the metadata
                                    inverseCommandMetadata = GetCommandMetadata(metadata.InverseCommand);
                                    inverseCommand         = CreateCommand(inverseCommandMetadata);
                                }

                                // If the command specifies that can be repeated use the universal argument as the counter, otherwise execute the command only once.
                                if (metadata.CanBeRepeated)
                                {
                                    repeatCount = Math.Abs(GetUniversalArgumentOrDefault(1));
                                }
                            }

                            for (; repeatCount > 0; repeatCount--)
                            {
                                if (shouldExecuteInverse)
                                {
                                    // Execute the inverse logic
                                    if (inverseCommand != null)
                                    {
                                        inverseCommand.Execute(context);
                                    }
                                    else
                                    {
                                        command.ExecuteInverse(context);
                                    }
                                }
                                else
                                {
                                    // Execute the normal logic
                                    command.Execute(context);
                                }
                            }

                            // TODO: Check command error and rollback the transaction
                            if (transaction != null)
                            {
                                transaction.Complete();
                            }

                            // If the command executed was a kill command, then we want to append the text that was cut
                            // to any currently text cut for the view.
                            // If the command is not a kill command and we have had some cut commands executed previously
                            // that accumulated deleted text, then we want to put the data on the clipboard and reset
                            // the accumulated text.
                            if (metadata.IsKillCommand)
                            {
                                view.AppendKillString(bufferMonitor.BufferChanges);
                            }
                            else
                            {
                                view.FlushKillSring(this.ClipboardRing);
                            }

                            this.LastExecutedCommand = shouldExecuteInverse ? inverseCommandMetadata : metadata;
                        }
                    }
                }
                catch (NoOperationException)
                {
                    // Do nothing
                }
            }
        }
 public void Execute(ITextView view, IEmacsCommandMetadata metadata, bool evaluateUniversalArgument = true)
 {
     try
     {
         changes = new StringBuilder();
         view.TextBuffer.Changed += OnTextBufferChanged;
         EmacsCommand          command      = CreateCommand(metadata);
         EmacsCommand          emacsCommand = null;
         IEmacsCommandMetadata metadata1    = null;
         var context = new EmacsCommandContext(this, TextStructureNavigatorSelectorService,
                                               EditorOperationsFactoryService.GetEditorOperations(view), view,
                                               CommandRouterProvider.GetCommandRouter(view));
         if (ClipboardRing.Count == 0 || ClipboardRing.Last() != Clipboard.GetText())
         {
             ClipboardRing.Add(Clipboard.GetText());
         }
         if (command == null)
         {
             return;
         }
         ITextUndoHistory history = TextUndoHistoryRegistry.GetHistory(context.TextBuffer);
         using (ITextUndoTransaction transaction = CreateTransaction(metadata, history))
         {
             int  num  = 1;
             bool flag = false;
             if (evaluateUniversalArgument)
             {
                 flag = GetUniversalArgumentOrDefault(0) < 0;
                 if (flag)
                 {
                     metadata1    = GetCommandMetadata(metadata.InverseCommand);
                     emacsCommand = CreateCommand(metadata1);
                 }
                 if (metadata.CanBeRepeated)
                 {
                     num = Math.Abs(GetUniversalArgumentOrDefault(1));
                 }
             }
             for (; num > 0; --num)
             {
                 if (flag)
                 {
                     if (emacsCommand != null)
                     {
                         emacsCommand.Execute(context);
                     }
                     else
                     {
                         command.ExecuteInverse(context);
                     }
                 }
                 else
                 {
                     command.Execute(context);
                 }
             }
             if (transaction != null)
             {
                 transaction.Complete();
             }
             if (context.Clipboard.Length > 0)
             {
                 ClipboardRing.Add(context.Clipboard.ToString());
                 Clipboard.SetText(context.Clipboard.ToString());
             }
             else if (changes.Length > 0 && metadata.CopyDeletedTextToTheClipboard)
             {
                 ClipboardRing.Add(changes.ToString());
                 Clipboard.SetText(changes.ToString());
             }
             LastExecutedCommand = flag ? metadata1 : metadata;
         }
     }
     catch (NoOperationException ex)
     {
     }
     finally
     {
         view.TextBuffer.Changed -= OnTextBufferChanged;
     }
 }
        /// <summary>
        /// Executes the emacs command
        /// </summary>
        /// <param name="view"></param>
        /// <param name="metadata"></param>
        public void Execute(ITextView view, IEmacsCommandMetadata metadata, bool evaluateUniversalArgument = true)
        {
            using (BufferMonitor bufferMonitor = BufferMonitor.Create(view.TextBuffer))
            {
                try
                {
                    EmacsCommand command = CreateCommand(metadata);
                    EmacsCommand inverseCommand = null;
                    IEmacsCommandMetadata inverseCommandMetadata = null;

                    var context = new EmacsCommandContext(
                        this, this.TextStructureNavigatorSelectorService,
                        this.EditorOperationsFactoryService.GetEditorOperations(view),
                        view, CommandRouterProvider.GetCommandRouter(view));

                    if (command != null)
                    {
                        var history = this.TextUndoHistoryRegistry.GetHistory(context.TextBuffer);
                        using (var transaction = CreateTransaction(metadata, history))
                        {
                            var repeatCount = 1;
                            bool shouldExecuteInverse = false;

                            if (evaluateUniversalArgument)
                            {
                                // Check if we should execute the inverse logic of the command by checking if the universal argument is lower than 0
                                shouldExecuteInverse = GetUniversalArgumentOrDefault() < 0;
                                if (shouldExecuteInverse)
                                {
                                    // Search the inverse command using the metadata
                                    inverseCommandMetadata = GetCommandMetadata(metadata.InverseCommand);
                                    inverseCommand = CreateCommand(inverseCommandMetadata);
                                }

                                // If the command specifies that can be repeated use the universal argument as the counter, otherwise execute the command only once.
                                if (metadata.CanBeRepeated)
                                    repeatCount = Math.Abs(GetUniversalArgumentOrDefault(1));
                            }

                            for (; repeatCount > 0; repeatCount--)
                            {
                                if (shouldExecuteInverse)
                                {
                                    // Execute the inverse logic
                                    if (inverseCommand != null)
                                        inverseCommand.Execute(context);
                                    else
                                        command.ExecuteInverse(context);
                                }
                                else
                                {
                                    // Execute the normal logic
                                    command.Execute(context);
                                }
                            }

                            // TODO: Check command error and rollback the transaction     
                            if (transaction != null)
                            {
                                transaction.Complete();
                            }

                            // If the command executed was a kill command, then we want to append the text that was cut
                            // to any currently text cut for the view.
                            // If the command is not a kill command and we have had some cut commands executed previously
                            // that accumulated deleted text, then we want to put the data on the clipboard and reset
                            // the accumulated text.
                            if (metadata.IsKillCommand)
                            {
                                view.AppendKillString(bufferMonitor.BufferChanges);
                            }
                            else
                            {
                                view.FlushKillSring(this.ClipboardRing);
                            }

                            this.LastExecutedCommand = shouldExecuteInverse ? inverseCommandMetadata : metadata;
                        }
                    }
                }
                catch (NoOperationException)
                {
                    // Do nothing
                }
            }
        }
        private EmacsCommand CreateCommand(IEmacsCommandMetadata metadata)
        {
            if (metadata == null)
                return null;

            var command = this.Commands.FirstOrDefault(export => export.Metadata.Command == metadata.Command && export.Metadata.CommandGroup == metadata.CommandGroup);

            if (command != null)
                return command.Value;

            return null;
        }
 private static ITextUndoTransaction CreateTransaction(IEmacsCommandMetadata metadata, ITextUndoHistory history)
 {
     if (string.IsNullOrEmpty(metadata.UndoName))
     {
         return null;
     }
     return history.CreateTransaction(metadata.UndoName);
 }