private void Save() { this.SaveOutput = true; var lay = MdSessionData.CurrentLayout; var dataCont = new MacroDataContainer(); var hasData = false; foreach (var ele in lay.AddonDatas) { if (ele.GetType() == MacroDataContainer.DATA_TYPE) { hasData = true; dataCont = ele as MacroDataContainer; } } if (!hasData) { lay.AddonDatas.Add(dataCont); } var data = this.Data; hasData = false; var oldDataIndex = 0; if (dataCont != null) { foreach (var ele in dataCont.MacroKeys) { if (ele.Index == this.Data.Index) { hasData = true; break; } oldDataIndex++; } if (hasData) { dataCont.MacroKeys[oldDataIndex] = data; } else { dataCont.MacroKeys.Add(data); } } MdSessionData.CurrentKeyboardUI.DisplayUnsavedChangeSignal(); Close(); }
private void OpenMacroMenu() { var lst = new List <string> { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; var fm = new FmSelectTextDialog(lst, lst.Select(ele => "macro" + ele).ToList(), "Select a macro key to edit"); fm.ShowModal(); var outputInd = fm.OutputIndex; if (outputInd >= 0) { if (!MdSessionData.OpenedMacroEdit) { if (MdSessionData.CurrentLayout.KeyDatas.Count == 0) { MessageBox.Show("Error: You must first select a device"); } else { MdSessionData.OpenedMacroEdit = true; var lay = MdSessionData.CurrentLayout; var dataCont = new MacroDataContainer(); var hasData = false; foreach (var ele in lay.AddonDatas) { if (ele.GetType() == MacroDataContainer.DATA_TYPE) { hasData = true; dataCont = ele as MacroDataContainer; } } if (!hasData) { lay.AddonDatas.Add(dataCont); } var data = new MacroData(); data.Index = outputInd; hasData = false; if (dataCont != null) { foreach (var ele in dataCont.MacroKeys) { if (ele.Index == outputInd) { hasData = true; data = ele; } } if (!hasData) { dataCont.MacroKeys.Add(data); } } var mdialog = new FmMacroEdit(new MacroData(data)); mdialog.Show(); } } else { MessageBox.Show("Error: Macro editor already opened"); } } }