private void LoadPTTFromFile() { try { BindingBoys = new ObservableCollection <BindingBoy>(); string[] lines = File.ReadAllLines(PTTSavedSettingsFileName); int bindingcountmax = int.Parse(lines[0]) * 2; int i = -1 + 1; while (i < bindingcountmax) { BindingBoy boi = new BindingBoy() { WindowName = lines[++i], Binding = lines[++i] }; boi.BindingName = BindingBoy.GetBindingName(boi.Binding); BindingBoys.Add(boi); } BeginKeybindTextBox.Text = lines[++i]; EndKeybindTextBox.Text = lines[++i]; BindingDataGrid.ItemsSource = BindingBoys; } catch (Exception e) { Console.WriteLine(e.Message + "\r\n" + e.StackTrace); } }
public void ButtonClickBoy(object sender, object uselessboy) { Button b = (Button)sender; switch (b.Name) { case "KeyGrabber": mainwindowreference.sm_kp = MainWindow._sm_kp.GET_BINDING; break; case "WindowRefreshButton": populatewindowlist(); break; case "AddBindingButton": BindingBoy newboy = new BindingBoy() { WindowName = (string)(WindowNameComboBox.SelectedValue), Binding = KeyBindingTextBox.Text }; newboy.BindingName = BindingBoy.GetBindingName(newboy.Binding); BindingBoys.Add(newboy); BindingDataGrid.ItemsSource = BindingBoys; break; case "SaveButton": SavePTTToFile(); mainwindowreference.BindingBoys = BindingBoys.ToList(); break; case "CancelButton": LoadPTTFromFile(); if (mainwindowreference.sm_kp == MainWindow._sm_kp.GET_BINDING || mainwindowreference.sm_kp == MainWindow._sm_kp.GET_BINDING_BEGIN || mainwindowreference.sm_kp == MainWindow._sm_kp.GET_BINDING_END) { mainwindowreference.sm_kp = MainWindow._sm_kp.NORMAL; } this.Hide(); break; case "CloseButton": if (mainwindowreference.sm_kp == MainWindow._sm_kp.GET_BINDING || mainwindowreference.sm_kp == MainWindow._sm_kp.GET_BINDING_BEGIN || mainwindowreference.sm_kp == MainWindow._sm_kp.GET_BINDING_END) { mainwindowreference.sm_kp = MainWindow._sm_kp.NORMAL; } this.Hide(); break; case "BeginKeybindButton": mainwindowreference.sm_kp = MainWindow._sm_kp.GET_BINDING_BEGIN; break; case "EndKeybindButton": mainwindowreference.sm_kp = MainWindow._sm_kp.GET_BINDING_END; break; } }