using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Shapes; using static QuikDawEditor.EDITING.ShorcutKeys; using static QuikDawEditor.EDITING.StaticProperties; namespace QuikDawEditor; public partial class PreferencesWindow : Window { public PreferencesWindow(EditorWindow edwin) { InitializeComponent(); this.Owner = edwin; } private void PrefWindow_Loaded(object sender, RoutedEventArgs e) { currentUserCommandKeyPairs.Clear(); foreach (UserCommandKeyPair uckp in userCommandKeyPairs) currentUserCommandKeyPairs.Add(uckp); cp16.PreviewMouseDown += Cp16_PreviewMouseDown; } public ObservableCollection currentUserCommandKeyPairs { get; set; } = new ObservableCollection(); private void ChangeKeyGestureBut(object sender, RoutedEventArgs e) { Button thisBut = (Button)sender; UserCommandKeyPair thisuckp = (UserCommandKeyPair)thisBut.DataContext; HotKeysDisabled = true; KeyInputWindow kiwin = new KeyInputWindow(thisuckp, this) { Owner = this }; kiwin.ShowDialog(); if (kiwin.UserCommandKeyPairSet) { UserCommandKeyPair findUCKP = currentUserCommandKeyPairs.Where(uckp => uckp.CommandName == kiwin.thisUserCommandKeyPair.CommandName).FirstOrDefault(); if (findUCKP != null) { int findex = currentUserCommandKeyPairs.IndexOf(findUCKP); currentUserCommandKeyPairs[findex] = new UserCommandKeyPair(kiwin.thisUserCommandKeyPair.GetSettingString); } shortcutKeysWereChanged = true; ShortcutKeysLV.Items.Refresh(); } HotKeysDisabled = false; } bool shortcutKeysWereChanged = false; private void SaveBut_Click(object sender, RoutedEventArgs e) { if (shortcutKeysWereChanged) { userCommandKeyPairs.Clear(); Properties.Settings.Default.ShortcutKeys.Clear(); foreach (UserCommandKeyPair uckp in currentUserCommandKeyPairs) { string settingString = uckp.GetSettingString; userCommandKeyPairs.Add(new UserCommandKeyPair(settingString)); Properties.Settings.Default.ShortcutKeys.Add(settingString); } } Properties.Settings.Default.Save(); this.Close(); } private void CancelBut_Click(object sender, RoutedEventArgs e) { this.Close(); } private void ClearKeyGestureBut(object sender, RoutedEventArgs e) { Button thisBut = (Button)sender; UserCommandKeyPair thisuckp = (UserCommandKeyPair)thisBut.DataContext; thisuckp.shortcutKey = Key.None; thisuckp.modifierKeys.Clear(); shortcutKeysWereChanged = true; ShortcutKeysLV.Items.Refresh(); } ColorPicker16 cp16 = new ColorPicker16(); Window cpWin; private void Cp16_PreviewMouseDown(object sender, MouseButtonEventArgs e) { cpWin.Close(); } private void CpWin_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) cpWin.Close(); } private void CreateColorPickWindow() { cpWin = new Window() { Width = 150, Height = 150, WindowStartupLocation = WindowStartupLocation.CenterOwner, Owner = this, Content = cp16, WindowStyle = WindowStyle.ToolWindow, ResizeMode = ResizeMode.NoResize, ShowInTaskbar = false }; cp16.SelectedBrush = null; cpWin.PreviewKeyDown += CpWin_PreviewKeyDown; cpWin.ShowDialog(); } private void DefAudioRectangle_MouseDown(object sender, MouseButtonEventArgs e) { CreateColorPickWindow(); if (cp16.SelectedBrush != null) { Rectangle thisRect = (Rectangle)sender; thisRect.Fill = cp16.SelectedBrush; Properties.Settings.Default.DefaultAudioTrackColor = cp16.SelectedBrush.Color.ToString(); } } private void DefMidiRectangle_MouseDown(object sender, MouseButtonEventArgs e) { CreateColorPickWindow(); if (cp16.SelectedBrush != null) { Rectangle thisRect = (Rectangle)sender; thisRect.Fill = cp16.SelectedBrush; Properties.Settings.Default.DefaultMidiTrackColor = cp16.SelectedBrush.Color.ToString(); } } private void DefSubmixRectangle_MouseDown(object sender, MouseButtonEventArgs e) { CreateColorPickWindow(); if (cp16.SelectedBrush != null) { Rectangle thisRect = (Rectangle)sender; thisRect.Fill = cp16.SelectedBrush; Properties.Settings.Default.DefaultSubmixTrackColor = cp16.SelectedBrush.Color.ToString(); } } }