public IPYConsole(CommandLine commandLine) { waitHandles = new WaitHandle[] { lineReceivedEvent, disposedEvent }; this.commandLine = commandLine; dispatcherThread = new Thread(new ThreadStart(DispatcherThreadStartingPoint)); dispatcherThread.SetApartmentState(ApartmentState.STA); dispatcherThread.IsBackground = true; dispatcherThread.Start(); // Only required when running outside REP loop. prompt = ">>> "; CodeContext codeContext = DefaultContext.Default; // Set dispatcher to run on a UI thread independent of both the Control UI thread and thread running the REPL. ClrModule.SetCommandDispatcher(codeContext, DispatchCommand); }
public PythonConsole(PythonTextEditor textEditor, CommandLine commandLine) : this() { _waitHandles = new WaitHandle[] { _lineReceivedEvent, _disposedEvent }; _commandLine = commandLine; _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: _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) { _textEditor.TextArea.CommandBindings.Remove(pasteBinding); } if (copyBinding != null) { _textEditor.TextArea.CommandBindings.Remove(copyBinding); } if (cutBinding != null) { _textEditor.TextArea.CommandBindings.Remove(cutBinding); } if (undoBinding != null) { _textEditor.TextArea.CommandBindings.Remove(undoBinding); } if (deleteBinding != null) { _textEditor.TextArea.CommandBindings.Remove(deleteBinding); } _textEditor.TextArea.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, OnPaste, CanPaste)); _textEditor.TextArea.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, OnCopy, PythonEditingCommandHandler.CanCutOrCopy)); _textEditor.TextArea.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, PythonEditingCommandHandler.OnCut, CanCut)); _textEditor.TextArea.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, OnUndo, CanUndo)); _textEditor.TextArea.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, PythonEditingCommandHandler.OnDelete(ApplicationCommands.NotACommand), CanDeleteCommand)); })); CodeContext codeContext = DefaultContext.Default; // Set dispatcher to run on a UI thread independent of both the Control UI thread and thread running the REPL. ClrModule.SetCommandDispatcher(codeContext, DispatchCommand); }