private void FillList() { SigButDefs.Refresh(); SigButDefElements.Refresh(); if (listComputers.SelectedIndex == -1) //although I don't know how this could happen { listComputers.SelectedIndex = 0; } if (listComputers.SelectedIndex == 0) { SubList = SigButDefs.GetByComputer(""); } else { //remember, defaults are mixed into this list unless overridden: SubList = SigButDefs.GetByComputer(Computers.List[listComputers.SelectedIndex - 1].CompName); } int selected = listButtons.SelectedIndex; listButtons.Items.Clear(); SigButDef button; SigButDefElement[] elements; string s; for (int i = 0; i < 20; i++) { button = SigButDefs.GetByIndex(i, SubList); if (button == null) { listButtons.Items.Add("-" + (i + 1).ToString() + "-"); } else { s = button.ButtonText; elements = SigButDefElements.GetForButton(button.SigButDefNum); for (int e = 0; e < elements.Length; e++) { if (e == 0) { s += " ("; } else { s += ", "; } s += SigElementDefs.GetElement(elements[e].SigElementDefNum).SigText; if (e == elements.Length - 1) { s += ")"; } } if (button.ComputerName == "" && listComputers.SelectedIndex != 0) { s += " " + Lan.g(this, "(all)"); } listButtons.Items.Add(s); } } }
private void butDown_Click(object sender, EventArgs e) { if (listButtons.SelectedIndex == -1) { MsgBox.Show(this, "Please select an item first."); return; } int selected = listButtons.SelectedIndex; if (selected == listButtons.Items.Count - 1) { return; } SigButDef button = SigButDefs.GetByIndex(selected, _arraySigButDefs); if (button == null) { return; } if (button.ButtonIndex == _maxNumButtonsInList - 1) { MsgBox.Show(this, $"No more than {_maxNumButtonsInList} buttons are allowed."); return; } _arraySigButDefs = SigButDefs.MoveDown(button, _arraySigButDefs); FillList(); listButtons.SelectedIndex = selected + 1; }
private void listButtons_DoubleClick(object sender, EventArgs e) { if (listButtons.SelectedIndex == -1) //should never happen { return; } //Save any changes to the cache because the item order could have changed. if (SigButDefs.UpdateButtonIndexIfChanged(_arraySigButDefs)) { DataValid.SetInvalid(InvalidType.SigMessages); } int selected = listButtons.SelectedIndex; SigButDef sigButDef = SigButDefs.GetByIndex(selected, _arraySigButDefs); //Keep track of the currently selected computer name so we know what computer buttons to refresh after making changes. string computerNameSelected = (listComputers.SelectedIndex > 0) ? _listComputers[listComputers.SelectedIndex - 1].CompName : ""; //Now create a new computer name variable that will represent the computer name for the SigButDef. string computerNameSigButDef = ""; if (sigButDef == null) //Add { sigButDef = new SigButDef(); sigButDef.ButtonIndex = selected; if (listComputers.SelectedIndex != 0) { computerNameSigButDef = _listComputers[listComputers.SelectedIndex - 1].CompName; } sigButDef.ComputerName = computerNameSigButDef; FormSigButDefEdit FormS = new FormSigButDefEdit(sigButDef.Copy()); FormS.IsNew = true; FormS.ShowDialog(); } else if (sigButDef.ComputerName == "" && listComputers.SelectedIndex != 0) { //create a copy of the default, and treat it as a new sigButDef.ComputerName = _listComputers[listComputers.SelectedIndex - 1].CompName; FormSigButDefEdit FormS = new FormSigButDefEdit(sigButDef.Copy()); FormS.IsNew = true; FormS.ShowDialog(); } else //edit { if (listComputers.SelectedIndex > 0) //If "All" is selected, the computerName will already be blank, so it only needs reset if it isn't "All". { computerNameSigButDef = _listComputers[listComputers.SelectedIndex - 1].CompName; } FormSigButDefEdit FormS = new FormSigButDefEdit(sigButDef.Copy()); FormS.ShowDialog(); } //Refresh our local list to match the cache in case the user edited or added a new button item. _arraySigButDefs = SigButDefs.GetByComputer(computerNameSelected); FillList(); }
private void listButtons_DoubleClick(object sender, EventArgs e) { if (listButtons.SelectedIndex == -1) //should never happen { return; } int selected = listButtons.SelectedIndex; SigButDef button = SigButDefs.GetByIndex(selected, SubList); if (button == null) //Add { FormSigButDefEdit FormS = new FormSigButDefEdit(); FormS.IsNew = true; button = new SigButDef(); button.ElementList = new SigButDefElement[0]; button.ButtonIndex = selected; if (listComputers.SelectedIndex == 0) { button.ComputerName = ""; } else { button.ComputerName = Computers.List[listComputers.SelectedIndex - 1].CompName; } FormS.ButtonCur = button.Copy(); FormS.ShowDialog(); } else if (button.ComputerName == "" && listComputers.SelectedIndex != 0) { //create a copy of the default, and treat it as a new FormSigButDefEdit FormS = new FormSigButDefEdit(); FormS.IsNew = true; button.ComputerName = Computers.List[listComputers.SelectedIndex - 1].CompName; FormS.ButtonCur = button.Copy(); FormS.ShowDialog(); } else //edit { FormSigButDefEdit FormS = new FormSigButDefEdit(); FormS.ButtonCur = button.Copy(); FormS.ShowDialog(); } FillList(); }
private void butUp_Click(object sender, EventArgs e) { if (listButtons.SelectedIndex == -1) { MsgBox.Show(this, "Please select an item first."); return; } int selected = listButtons.SelectedIndex; if (selected == 0) { return; } SigButDef button = SigButDefs.GetByIndex(selected, _arraySigButDefs); if (button == null) { return; } _arraySigButDefs = SigButDefs.MoveUp(button, _arraySigButDefs); FillList(); listButtons.SelectedIndex = selected - 1; }
private void butDown_Click(object sender, EventArgs e) { if (listButtons.SelectedIndex == -1) { MsgBox.Show(this, "Please select an item first."); return; } int selected = listButtons.SelectedIndex; if (selected == listButtons.Items.Count - 1) { return; } SigButDef button = SigButDefs.GetByIndex(selected, SubList); if (button == null) { return; } SigButDefs.MoveDown(button, SubList); FillList(); listButtons.SelectedIndex = selected + 1; }
private void FillList() { if (listComputers.SelectedIndex == -1) //although I don't know how this could happen { listComputers.SelectedIndex = 0; } int selected = listButtons.SelectedIndex; listButtons.Items.Clear(); SigButDef sigButDef; List <SigElementDef> listSigElementDefs; string buttonText; for (int i = 0; i < _maxNumButtonsInList; i++) { sigButDef = SigButDefs.GetByIndex(i, _arraySigButDefs); if (sigButDef == null) { listButtons.Items.Add("-" + (i + 1).ToString() + "-"); } else { buttonText = sigButDef.ButtonText; listSigElementDefs = SigElementDefs.GetElementsForButDef(sigButDef); if (listSigElementDefs.Count > 0) { buttonText += " (" + string.Join(",", listSigElementDefs.Select(x => x.SigText)) + ")"; } if (sigButDef.ComputerName == "" && listComputers.SelectedIndex != 0) { buttonText += " " + Lan.g(this, "(all)"); } listButtons.Items.Add(buttonText); } } }