private void PowershellExecuted(object sender, RoutedEventArgs e) { #if POWERSHELL var shell = new WpfTerminalControl(); shell.BeginInit(); shell.ForegroundColor = ConsoleColor.Black; shell.BackgroundColor = ConsoleColor.White; shell.Background = Brushes.White; ; shell.Foreground = Brushes.Black; ; shell.AutoResize = true; shell.CursorBrush = Brushes.Orange; shell.EndInit(); var wrapped = new WrappedPowerShell(); wrapped.BeginInit(); wrapped.Terminal = shell; wrapped.EndInit(); wrapped.CoerceValue(WrappedPowerShell.InitialSessionStateProperty); wrapped.CoerceValue(WrappedPowerShell.RunspaceProperty); shell.TextEntryComplete += (o, args) => JTF.RunAsync(async() => { await wrapped.ExecuteAsync(args.Text); }); Tabs.Items.Add(new TabItem() { Header = "PowerShell", Content = shell }); Tabs.SelectedIndex = Tabs.Items.Count - 1; #endif }
private void OnDocumentChanged(Document oldValue, Document newValue) { if (newValue == null) { return; } if (DiagramPanel == null) { return; } JTF.RunAsync(() => SetupDocumentAsync(newValue)); }
private void OpenFile(object sender, RoutedEventArgs e) { var d = new OpenFileDialog { Filter = "CSharp Source|*.cs" }; if (!d.ShowDialog().GetValueOrDefault()) { return; } Filename = d.FileName; JTF.RunAsync(() => ViewModel.LoadFileOrProjectAsync(this, this.Filename)); }
private void OnOpen(object sender, ExecutedRoutedEventArgs e) { switch (e.Parameter) { case Document d: Document = d; JTF.RunAsync(SetupCodeControlAsync); return; case Project p: Project = p; return; } }
public void Test6() { var roslynCodeControl = CodeControl; roslynCodeControl.JTF2 = _f.JTF2; // c.JTF = new JoinableTaskFactory(new JoinableTaskContext()); var path = "C:\\Users\\mccor.LAPTOP-T6T0BN1K\\source\\repos\\KayMcCormick.Dev\\src\\RoslynCodeControls\\src\\XUnitTestProject1\\UnitTest1.cs"; roslynCodeControl.SourceText = File.ReadAllText(path); var w = new Window(); _window = w; w.Content = roslynCodeControl; var StartTime = DateTime.MinValue; roslynCodeControl.AddHandler(RoslynCodeBase.RenderStartEvent, new RoutedEventHandler((sender, args) => { StartTime = DateTime.Now; Debug.WriteLine("render start"); })); List <TimeSpan> timings = new List <TimeSpan>(); TimeSpan? span = null; roslynCodeControl.AddHandler(RoslynCodeBase.RenderCompleteEvent, new RoutedEventHandler((sender, args) => { span = DateTime.Now - StartTime; timings.Add(span.Value); var msg1 = "render complete " + span; Debug.WriteLine(msg1); OutputHelper.WriteLine(msg1); })); _closeWindow = true; w.Loaded += (sender1, args1) => JTF.RunAsync(() => TestHelper.OnLoadedAsync(this.CodeControl, this.CloseWindow, this.Window)); w.ShowDialog(); int i = 0; foreach (var timeSpan in timings) { var message = $"{i}: {timeSpan}"; OutputHelper.WriteLine(message); ProtoLogger.Instance.LogAction(message); } var info = new TimeSpan(0, 0, 0, 0, (int)timings.Average(z => z.TotalMilliseconds)).ToString(); ProtoLogger.Instance.LogAction("Average is " + info); }
private void Compile(object sender, RoutedEventArgs e) { JTF.RunAsync(() => ViewModel.CompileAsync(Project, this)); }
private void OnLoaded(object sender, RoutedEventArgs e) { JTF.RunAsync(OnLoadedAsync); }
/// <inheritdoc /> public async Task UpdateFormattedTextAsync() { var codeView = (ICodeView)this; _debugFn?.Invoke($"Entering {nameof(UpdateFormattedTextAsync)} {codeView.PerformingUpdate}"); if (codeView.PerformingUpdate) { _debugFn?.Invoke("Already performing update"); } else { JTF.RunAsync(ReaderListenerAsync); codeView.PerformingUpdate = true; codeView.Status = CodeControlStatus.Rendering; codeView.Reset(); codeView.RaiseEvent(new RoutedEventArgs(RenderStartEvent, this)); var text = await SyntaxTree.GetTextAsync(); var o = new Point(double.NaN, 0); for (var i = 0; i < text.Lines.Count; i++) { DrawLineNumber(i, o); o.Y += LineHeight; } var textStorePosition = 0; var linePosition = new Point(codeView.XOffset, 0); codeView.TextDestination.Children.Clear(); var line = 0; _debugFn?.Invoke("Calling inner update"); // ScrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; var fontFamilyFamilyName = codeView.FontFamily.FamilyNames[XmlLanguage.GetLanguage("en-US")]; _debugFn?.Invoke(fontFamilyFamilyName); _debugFn?.Invoke("OutputWidth " + codeView.OutputWidth); // not sure what to do here !! // Rectangle.Width = OutputWidth + Rectangle.StrokeThickness * 2; var emSize = codeView.FontSize; var fontWeight = codeView.FontWeight; var customTextSource4Parameters = codeView.CreateDefaultTextSourceArguments(); var mainUpdateParameters = new MainUpdateParameters(textStorePosition, line, linePosition, CommonText.Formatter, codeView.OutputWidth, codeView.PixelsPerDip, emSize, fontFamilyFamilyName, codeView.UpdateChannel.Writer, fontWeight, null, customTextSource4Parameters, _debugFn); await JTF2.SwitchToMainThreadAsync(); SecondaryThreadTasks(); var source = codeView.InnerUpdate(mainUpdateParameters, customTextSource4Parameters); await JTF.SwitchToMainThreadAsync(); codeView.CustomTextSource = source; _debugFn?.Invoke("Return from await inner update"); codeView.PerformingUpdate = false; codeView.InitialUpdate = false; codeView.RaiseEvent(new RoutedEventArgs(RenderCompleteEvent, this)); codeView.Status = CodeControlStatus.Rendered; codeView.InsertionPoint = 0; codeView.InsertionLineNode = codeView.FindLine(0); #if false foreach (var x1 in codeView.FindLine(0).List) { for (var ci1 = x1.FirstCharInfo; ci1 != null && ci1.Value.Index < x1.Offset + x1.Length; ci1 = ci1.Next) { Debug.WriteLine($"{x1.LineNumber:D4},{ci1.Value.LineIndex:D3},{ci1.Value.Index:D6}"); } } #endif #if false var #if av = codeView.FindLine(0).Value.FirstCharInfo.List.Average(c => c.AdvanceWidth); foreach (var x1 in codeView.FindLine(0).Value.FirstCharInfo.List.GroupBy(c => c.AdvanceWidth) .Select(z => new { Width = z.Key, Count = z.Count() })) { var msg = $"{x1.Width} - {x1.Count}"; DebugFn(msg); Debug.WriteLine(msg); } Debug.WriteLine($"Average related to font size is {av/FontSize}"); #endif await UpdateRoslynPropertiesAsync(); ScrollViewer.InvalidateScrollInfo(); } }
private void Paste(object sender, ExecutedRoutedEventArgs e) { JTF.RunAsync(DoPasteAsync); }