internal CommandPlayer(TextEditorControl control, ITextEditorCore core) { textEditorControl = control; textEditorCore = core; textEditorCore.SetCommandRecorder(null); textEditorCore.EnableRegularCommands = false; }
/// <summary> /// As an extension, information of the core and the control needs to be present in all extensions, therefore /// it is a protected base class member /// </summary> /// <param name="editor"> TextEditorControl object </param> /// <param name="core"> TextCore Singleton object </param> public void SetEditorCore(TextEditorControl editor, ITextEditorCore core) { textEditorControl = editor; textCore = core; textEditorCanvas = textEditorControl.FindName("textCanvas") as TextEditorCanvas; scrollViewer = textEditorControl.FindName("scrollViewer") as ScrollViewer; }
public void EnableLogging(bool enable) { // This is the single flag that "Logger.LogXxx" methods check. ITextEditorCore core = TextEditorControl.Instance.TextCore; core.TextEditorSettings.CollectFeedback = enable; }
/// <summary> /// This method is a static call made via reflection from the Caller of the Extensions. /// It instantiates all the IDE extensions and passes the list back to the caller, where /// different methods can be called for different visual behaviours from the controls. /// </summary> /// <param name="textEditorControl"> Main TextEditorControl object </param> /// <param name="textCore"> TextCore singleton </param> /// <returns></returns> public static List<EditorExtension> EnumerateExtensions(TextEditorControl textEditorControl, ITextEditorCore textCore) { ExtensionFactory.textEditorCore = textCore; List<EditorExtension> extensions = new List<EditorExtension>(); // Instantiate all popups FunctionSignatureExtension functionSignatureExt = new FunctionSignatureExtension(); AutoCompleteExtension autoCompleteExt = new AutoCompleteExtension(); NumericSliderExtension numericSliderExt = new NumericSliderExtension(); InspectionToolTipExtension inspectionToolTipExt = new InspectionToolTipExtension(); // Instantiate Core functionSignatureExt.SetEditorCore(textEditorControl, textCore); autoCompleteExt.SetEditorCore(textEditorControl, textCore); numericSliderExt.SetEditorCore(textEditorControl, textCore); inspectionToolTipExt.SetEditorCore(textEditorControl, textCore); // Add to main list extensions.Add(functionSignatureExt); extensions.Add(autoCompleteExt); extensions.Add(numericSliderExt); extensions.Add(inspectionToolTipExt); return extensions; }
private void OnPausePlaybackClicked(object sender, RoutedEventArgs e) { if (null == playbackSnapshot) { ITextEditorCore editorCore = TextEditorControl.Instance.TextCore; playbackSnapshot = new PlaybackSnapshot(); playbackSnapshot.Owner = Application.Current.MainWindow; playbackSnapshot.Initialize(editorCore.GetAssertableProperties()); } if (playbackSnapshot.Visibility != Visibility.Visible) { playbackSnapshot.RefreshProperties(); playbackSnapshot.Show(); TextEditorControl.Instance.PauseActionPlayback(true); } }
public Generator(string[] arguments, ITextEditorCore textCore, TextEditorControl textEditorControl) { textEditorCore = textCore; this.textEditorControl = textEditorControl; if (arguments.Length > 2 && arguments[1] == "/path") { filePath = arguments[2]; MadTypistBeingMad(); } else { currentFilePath = filePath; Start(); random = new Random((int)DateTime.Now.Ticks); } }
protected override DrawingVisual RenderCore(RenderParameters renderParams) { if (drawingVisual == null) { drawingVisual = new DrawingVisual(); } if (null == currentScript) { return(drawingVisual); // No active script yet! } System.Windows.Point linePosition = new System.Windows.Point( Configurations.CanvasMarginLeft, 0); ITextEditorCore textCore = textEditorCanvas.TextEditorCore; ITextBuffer textBuffer = currentScript.GetTextBuffer(); numberOfLines = textBuffer.GetLineCount(); int lastVisibleLine = renderParams.firstVisibleLine + renderParams.maxVisibleLines; if (lastVisibleLine >= numberOfLines) { lastVisibleLine = numberOfLines - 1; } // Retrieve the DrawingContext from the DrawingVisual. DrawingContext context = drawingVisual.RenderOpen(); int maxColumns = textEditorCanvas.MaxVisibelColumns + 1; double hiddenWidth = textEditorCanvas.FirstVisibleColumn * Configurations.FormatFontWidth; CharPosition converter = this.currentScript.CreateCharPosition(); Typeface font = new Typeface(Configurations.FontFace); for (int lineIndex = renderParams.firstVisibleLine; lineIndex <= lastVisibleLine; lineIndex++) { // A constant starting point on left edge. linePosition.X = Configurations.CanvasMarginLeft; int startColumn = converter.VisualToCharOffset(lineIndex, textEditorCanvas.FirstVisibleColumn); string lineContent = textBuffer.GetLineContent(lineIndex); int lineLength = (lineContent != null ? lineContent.Length : 0); if (lineLength <= startColumn) { linePosition.Y += Configurations.FontDisplayHeight; continue; } if (startColumn > 0) { string hiddenText = lineContent.Substring(0, startColumn); hiddenText = hiddenText.Replace("\t", Configurations.TabSpaces); // Accounting for the part that is hidden beyond the left of canvas. double hiddenTextWidth = hiddenText.Length * Configurations.FormatFontWidth; linePosition.X = linePosition.X + hiddenTextWidth - hiddenWidth; } int endColumn = startColumn + maxColumns; endColumn = ((endColumn >= lineLength) ? lineLength - 1 : endColumn); for (int charIndex = startColumn; charIndex <= endColumn; charIndex++) { CodeFragment fragment = null; int fragmentWidth = textCore.GetFragment( charIndex, lineIndex, out fragment); // We may be showing partial fragment now. if (null != fragment) { fragmentWidth -= (charIndex - fragment.ColStart); } int offsetToNextChar = fragmentWidth - 1; if ((charIndex + fragmentWidth) > (lineLength - 1)) { fragmentWidth = (lineLength - 1) - charIndex; offsetToNextChar = fragmentWidth - 1; } // Initialize the text store. string textContent = string.Empty; textContent = lineContent.Substring(charIndex, ((fragmentWidth == 0) ? 1 : fragmentWidth)); // Replace all TAB characters with actual spaces. textContent = textContent.Replace("\t", Configurations.TabSpaces); CodeFragment.Type fragmentType = CodeFragment.Type.None; if (null != fragment) { fragmentType = fragment.CodeType; } Color textColor = CodeFragment.GetFragmentColor(fragmentType); if ((textBuffer.ParsePending == true) && (fragmentType == CodeFragment.Type.None)) { textColor = Colors.Black; } FormattedText formattedText = new FormattedText( textContent, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, font, Configurations.FontHeight, new SolidColorBrush(textColor)); // Draw the formatted text into the drawing context. context.DrawText(formattedText, linePosition); if (lineContent[charIndex] == '\n') { break; } else { linePosition.X += formattedText.WidthIncludingTrailingWhitespace; } if (fragmentWidth > 0) { charIndex += offsetToNextChar; } } // Update the line position coordinate for the displayed line. linePosition.Y += Configurations.FontDisplayHeight; } // Persist the drawn text content. context.Close(); return(drawingVisual); }
public TextEditorControl(IHostApplication hostApplication) { Stopwatch launchWatch = new Stopwatch(); launchWatch.Start(); if (null != TextEditorControl.hostApplication) throw new InvalidOperationException("'TextEditorControl' should be a singleton!"); if (null != textEditorControl) throw new InvalidOperationException("'TextEditorControl' should be a singleton!"); textEditorControl = this; TextEditorControl.hostApplication = hostApplication; TextEditorControl.dialogProvider = new DialogProvider(); CoreInterfaceFactory.RegisterInterfaces(hostApplication, dialogProvider); textCore = CoreInterfaceFactory.CreateTextEditorCore(OnExecutionStateChanged); actionRecorder = new CommandRecorder(); textCore.SetCommandRecorder(actionRecorder); // Only for human users. InitializeComponent(); InitializeEditor(); startUpWorker = new StartUpWorker(); startUpWorker.InitializeStartUpWorker(); startUpWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(OnStartUpWorkerRunWorkerCompleted); startUpWorker.RunWorkerAsync(); EnumerateExtensions(); this.LayoutUpdated += new EventHandler(OnTextEditorLayoutUpdated); launchWatch.Stop(); Logger.LogPerf("TextEditorControl.ctor", launchWatch.ElapsedMilliseconds + " ms"); }
/// <summary> /// This method is a static call made via reflection from the Caller of the Extensions. /// It instantiates all the IDE extensions and passes the list back to the caller, where /// different methods can be called for different visual behaviours from the controls. /// </summary> /// <param name="textEditorControl"> Main TextEditorControl object </param> /// <param name="textCore"> TextCore singleton </param> /// <returns></returns> public static List <EditorExtension> EnumerateExtensions(TextEditorControl textEditorControl, ITextEditorCore textCore) { ExtensionFactory.textEditorCore = textCore; List <EditorExtension> extensions = new List <EditorExtension>(); // Instantiate all popups FunctionSignatureExtension functionSignatureExt = new FunctionSignatureExtension(); AutoCompleteExtension autoCompleteExt = new AutoCompleteExtension(); NumericSliderExtension numericSliderExt = new NumericSliderExtension(); InspectionToolTipExtension inspectionToolTipExt = new InspectionToolTipExtension(); // Instantiate Core functionSignatureExt.SetEditorCore(textEditorControl, textCore); autoCompleteExt.SetEditorCore(textEditorControl, textCore); numericSliderExt.SetEditorCore(textEditorControl, textCore); inspectionToolTipExt.SetEditorCore(textEditorControl, textCore); // Add to main list extensions.Add(functionSignatureExt); extensions.Add(autoCompleteExt); extensions.Add(numericSliderExt); extensions.Add(inspectionToolTipExt); return(extensions); }
internal AssertableProperties(ITextEditorCore textEditorCore) { this.textEditorCore = textEditorCore; }