private void OnUserPresetClicked(object sender, EventArgs eventArgs) { try { string presetName = ((ToolStripItem)sender).Text; if (Savefilehandler.GetSavedPresetNamesList().Contains(presetName)) { List <int> presetValues = Savefilehandler.GetPresetValuesFromName(presetName); if (presetValues.Count == 4) { this.CurrentPreset = new Preset(true, presetName, presetValues[0], presetValues[1], presetValues[2], presetValues[3]); this.presetSwitchHotkeyIndex = 6 + Savefilehandler.GetSavedPresetNamesList().IndexOf(presetName); //6=number of default presets+1 toolStripStatusLabel1.Text = $"Loaded preset {this.CurrentPreset.PresetName}"; } else { if (!Savefilehandler.DeletePreset(presetName)) { throw new Exception($"Cannot delete preset {presetName}"); } } } else { toolStripStatusLabel1.Text = $"Preset {presetName} not found"; } } catch (Exception ex) { Debug.Print(ex.Message); } }
private void LoadUserPresetsNames() { try { List <string> savedPresetNames = Savefilehandler.GetSavedPresetNamesList(); if (savedPresetNames.Count > 0) { userPresetsMenuItem = new ToolStripMenuItem("User presets"); toolStripMenuItemPresets.DropDownItems.Add(userPresetsMenuItem); foreach (var presetName in savedPresetNames) { ToolStripItem newPreset = new ToolStripMenuItem(presetName); newPreset.Click += OnUserPresetClicked; userPresetsMenuItem.DropDownItems.Add(newPreset); } } } catch (Exception ex) { Debug.Print("Exception in loading presets."); } }