/// <summary> /// Event function. Called when selected in DiagnosticListView item has changed. /// Select line in source code depending on currently selected item. /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Arguments</param> private void DiagnosticListView_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count > 0 && e.AddedItems[0] is DiagnosticHelper selectedItem && selectedItem.Location.Location == CodeLocation.LocationType.InSource) { DocumentLine line = SourceCodeTextBox.Document .GetLineByNumber(selectedItem.Location.Line); SourceCodeTextBox.Select(line.Offset, line.Length); FixButton.IsEnabled = selectedItem.Refactor != null; }
/// <summary> /// Constructor. Initialize all components and sets basic fields. /// </summary> /// <param name="currentLesson">Specyfic <see cref="Lesson"/> object for current lesson</param> public SourceCode(Lesson currentLesson) { InitializeComponent(); // Initialize with defaults CurrentLesson = currentLesson; TitleTextBox.Text = CurrentLesson.Title; LessonInfoTextBlock.Text = CurrentLesson.Info; SourceCodeTextBox.Text = CurrentLesson.DefaultCode; DiagnosticListView.ItemsSource = lastDiagnostics_; CurrentResultTextBlock.Text = CurrentLesson.CurrentResultsStars; // Create marker service textMarkerService_ = new TextMarkerService(SourceCodeTextBox.Document); SourceCodeTextBox.TextArea.TextView.BackgroundRenderers.Add(textMarkerService_); SourceCodeTextBox.TextArea.TextView.LineTransformers.Add(textMarkerService_); // Add service to document ((IServiceContainer)SourceCodeTextBox.Document .ServiceProvider .GetService(typeof(IServiceContainer))) ?.AddService(typeof(ITextMarkerService), textMarkerService_); SourceCodeTextBox.TextArea.TextEntered += SourceCodeTextBox_TextArea_TextEntered; SourceCodeTextBox.TextArea.SelectionChanged += SourceCodeTextBox_TextArea_SelectionChanged; SourceCodeTextBox.Focus(); // Handle real-time diagnostic updation dispacherTimer_.Tick += (sender, args) => { if (timer_.Elapsed >= TimeSpan.FromSeconds(1)) { UpdateDiagnostic(); timer_.Reset(); } }; dispacherTimer_.Interval = TimeSpan.FromSeconds(2); dispacherTimer_.Start(); UpdateDiagnostic(); EnbleAllButtons(); }
public MainWindow() { InitializeComponent(); SourceCodeTextBox.Options.ConvertTabsToSpaces = false; SourceCodeTextBox.Options.IndentationSize = 10; //var vd = new VirtualDisk(); //vd.AddFile(System.IO.File.ReadAllBytes(@"c:\q\file1.bas"), "faa.bas", FileTypes.Basic, FileModes.Ascii); //vd.AddFile(@"C:\q\file1.bas", "faa.bas", FileTypes.Basic, FileModes.Ascii); //vd.AddFile(@"C:\q\file2.bas", "zebra.bas", FileTypes.Basic, FileModes.Ascii); //vd.WriteVirtualDiskToFile(@"C:\q\test.dsk"); string program = "DOG\tEQU\t$15+2*4\nCAT\tEQU\tDOG-10\nMOUSE\tEQU\t-32\nSTART\tLDA\t#10\n\tEND\tSTART"; program = "\tORG\t$3F00\nSTART\tLDX\t#1054\n\tLDA\t#65\n\tSTA\t-$585,X\n\tRTS\n\tEND\tSTART"; SourceCodeTextBox.AppendText(program); }