private void OnImport() { logger.Info("Importing JSON"); try { // Deserialize JSON into Preset object. ImportedHotkey = JsonConvert.DeserializeObject <Models.Hotkey>(ImportText); // Checking validity purely by the name being specified. Could use a more robust check but this is good enough. if (ImportedHotkey.Name == null || ImportedHotkey.Name.Trim() == string.Empty) { MessageBox.Show("This does not resemble a valid preset. Could not import successfully.", "Paisley Park", MessageBoxButton.OK, MessageBoxImage.Error); return; } MessageBox.Show("Imported Preset " + ImportedHotkey.Name + "!", "Paisley Park", MessageBoxButton.OK, MessageBoxImage.Exclamation); DialogResult = true; } // Likely not a JSON string. catch (Exception ex) { logger.Error(ex, "Error trying to import JSON\n{0}", ImportText); MessageBox.Show("Invalid input, this is not valid JSON. Could not import preset.", "Paisley Park", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Adding new hotkey. /// </summary> private void OnAddHotkey() { // Can't do unless game is loaded. //if (!CheckCanDo()) // return; try { // Create window for add hotkey. var win = new NewHotkey { // Owner set to MainWindow. Owner = Application.Current.MainWindow }; // Get the VM for this window. var vm = win.DataContext as NewHotkeyViewModel; // Show the dialog for the hotkey window. if (win.ShowDialog() == true) { // Initialize the creation of our hotkey with the hotkey name. var p = new Models.Hotkey() { Name = vm.Name, preset = GetPresetByName(vm.Preset), Key = (System.Windows.Forms.Keys)Enum.GetValues(typeof(System.Windows.Forms.Keys)).GetValue(vm.Hotkey) }; // Add the hotkey. Hotkeys.Add(p); } } catch (Exception ex) { MessageBox.Show("Something happened while creating your hotkey!", "Paisley Park", MessageBoxButton.OK, MessageBoxImage.Error); logger.Error(ex, "Exception while adding a new hotkey."); } }