protected void CanDeleteCommand(object target, CanExecuteRoutedEventArgs args) { if (!CanDelete) { args.CanExecute = false; } else { PythonEditingCommandHandler.CanDelete(target, args); } }
private void CanCut(object target, CanExecuteRoutedEventArgs args) { if (!CanDelete) { args.CanExecute = false; } else { PythonEditingCommandHandler.CanCutOrCopy(target, args); } }
protected void OnCopy(object target, ExecutedRoutedEventArgs args) { if (target != textEditor.textArea) { return; } if (textEditor.SelectionLength == 0 && executing) { // Send the 'Ctrl-C' abort //if (!IsInReadOnlyRegion) //{ MoveToHomePosition(); //textEditor.Column = GetLastTextEditorLine().Length + 1; //textEditor.Write(Environment.NewLine); //} dispatcherThread.Abort(new Microsoft.Scripting.KeyboardInterruptException("")); args.Handled = true; } else { PythonEditingCommandHandler.OnCopy(target, args); } }
private void OnCopy(object target, ExecutedRoutedEventArgs args) { if (target != _textEditor.TextArea) { return; } if (_textEditor.SelectionLength == 0 && Executing) { // Send the 'Ctrl-C' abort //if (!IsInReadOnlyRegion) //{ MoveToHomePosition(); //textEditor.Column = GetLastTextEditorLine().Length + 1; //textEditor.Write(Environment.NewLine); //} AbortRunningScript(); args.Handled = true; } else { PythonEditingCommandHandler.OnCopy(target, args); } }
public PythonConsole(PythonTextEditor textEditor, CommandLine commandLine) { waitHandles = new WaitHandle[] { lineReceivedEvent, disposedEvent }; this.commandLine = commandLine; this.textEditor = textEditor; textEditor.CompletionProvider = new PythonConsoleCompletionDataProvider(commandLine) { ExcludeCallables = disableAutocompletionForCallables }; textEditor.PreviewKeyDown += textEditor_PreviewKeyDown; textEditor.TextEntering += textEditor_TextEntering; dispatcherThread = new Thread(new ThreadStart(DispatcherThreadStartingPoint)); dispatcherThread.SetApartmentState(ApartmentState.STA); dispatcherThread.IsBackground = true; dispatcherThread.Start(); // Only required when running outside REP loop. prompt = ">>> "; // Set commands: this.textEditor.textArea.Dispatcher.Invoke(new Action(delegate() { CommandBinding pasteBinding = null; CommandBinding copyBinding = null; CommandBinding cutBinding = null; CommandBinding undoBinding = null; CommandBinding deleteBinding = null; foreach (CommandBinding commandBinding in (this.textEditor.textArea.CommandBindings)) { if (commandBinding.Command == ApplicationCommands.Paste) { pasteBinding = commandBinding; } if (commandBinding.Command == ApplicationCommands.Copy) { copyBinding = commandBinding; } if (commandBinding.Command == ApplicationCommands.Cut) { cutBinding = commandBinding; } if (commandBinding.Command == ApplicationCommands.Undo) { undoBinding = commandBinding; } if (commandBinding.Command == ApplicationCommands.Delete) { deleteBinding = commandBinding; } } // Remove current bindings completely from control. These are static so modifying them will cause other // controls' behaviour to change too. if (pasteBinding != null) { this.textEditor.textArea.CommandBindings.Remove(pasteBinding); } if (copyBinding != null) { this.textEditor.textArea.CommandBindings.Remove(copyBinding); } if (cutBinding != null) { this.textEditor.textArea.CommandBindings.Remove(cutBinding); } if (undoBinding != null) { this.textEditor.textArea.CommandBindings.Remove(undoBinding); } if (deleteBinding != null) { this.textEditor.textArea.CommandBindings.Remove(deleteBinding); } this.textEditor.textArea.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, OnPaste, CanPaste)); this.textEditor.textArea.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopy, PythonEditingCommandHandler.CanCutOrCopy)); this.textEditor.textArea.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, PythonEditingCommandHandler.OnCut, CanCut)); this.textEditor.textArea.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, OnUndo, CanUndo)); this.textEditor.textArea.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, PythonEditingCommandHandler.OnDelete(ApplicationCommands.NotACommand), CanDeleteCommand)); })); // Set dispatcher to run on a UI thread independent of both the Control UI thread and thread running the REPL. WhenConsoleInitialized(delegate { SetCommandDispatcher(DispatchCommand); }); }