using System; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Text.Json; using System.Text.RegularExpressions; using System.Windows; using System.Windows.Controls; namespace QuikDawEditor; public partial class ViewJsonWindow : Window, INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged([CallerMemberName] String propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public string _JsonText; public string JsonText { get { return _JsonText; } set { int firstLinePoint = value.IndexOf(Environment.NewLine); //string beatsPerMinute = Double.Parse(value.Substring(0, firstLinePoint)); JsonDocument jdoc = JsonDocument.Parse(value.Substring(firstLinePoint)); _JsonText = JsonSerializer.Serialize(jdoc, new JsonSerializerOptions { WriteIndented = true }); NotifyPropertyChanged(nameof(JsonText)); } } public ViewJsonWindow(string jsonText) { InitializeComponent(); JsonText = jsonText; } MatchCollection trackMatches; MatchCollection clipMatches; bool addingClips = false; private void GoToTrackCB_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (GoToTrackCB.SelectedIndex == -1) return; int trackTextStart = trackMatches[GoToTrackCB.SelectedIndex].Index; asdfTB.Select(trackTextStart, 10); asdfTB.ScrollToLine(asdfTB.GetLineIndexFromCharacterIndex(trackTextStart) - 2); asdfTB.Focus(); int trackTextEnd = GoToTrackCB.SelectedIndex == GoToTrackCB.Items.Count - 1 ? JsonText.Length : trackMatches[GoToTrackCB.SelectedIndex + 1].Index; string trackText = JsonText.Substring(trackMatches[GoToTrackCB.SelectedIndex].Index, trackTextEnd - trackTextStart); clipMatches = Regex.Matches(trackText, "\"ClipSourceFileName\""); addingClips = true; GoToClipCB.Items.Clear(); for (int clipid = 0; clipid < clipMatches.Count; clipid++) GoToClipCB.Items.Add("ClipNo " + clipid.ToString()); addingClips = false; } private void GoToClipCB_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (addingClips) return; int selCharIdx = trackMatches[GoToTrackCB.SelectedIndex].Index + clipMatches[GoToClipCB.SelectedIndex].Index; asdfTB.Select(selCharIdx, 10); asdfTB.ScrollToLine(asdfTB.GetLineIndexFromCharacterIndex(selCharIdx) - 3); asdfTB.Focus(); } private void JsonWindow_ContentRendered(object sender, EventArgs e) { trackMatches = Regex.Matches(JsonText, "\"trackIndex\""); for (int trkid = 0; trkid < trackMatches.Count; trkid++) GoToTrackCB.Items.Add("TrackNo " + trkid.ToString()); } }