/// <summary> /// Delete variables /// </summary> /// <param name="list">variable list</param> /// <param name="po">printer object</param> /// <returns>if at least one item removed</returns> public static bool DeleteVariables(ListBox list, PrinterObject po) { bool atLeastOne = false; for (int index = list.SelectedIndices.Count - 1; index >= 0; --index) { PrinterVariable pv = list.SelectedItems[index] as PrinterVariable; int pos = list.SelectedIndices[index]; po.DeleteVariable(pv.Name); list.Items.RemoveAt(pos); hasModified = true; atLeastOne = true; } list.Refresh(); return(atLeastOne); }
/// <summary> /// Edit a variable /// </summary> /// <param name="list">variable list</param> /// <param name="po">printer object</param> /// <returns>added variable</returns> public static bool EditVariable(ListBox list, PrinterObject po) { if (list.SelectedIndices.Count == 1) { PrinterVariable pv = list.SelectedItems[0] as PrinterVariable; Variable var = new Variable(); var.IsIndented = pv.Indent; var.Controls["txtName"].Text = pv.Name; if (pv.Include) { (var.IncludePage.Controls["rbInclude"] as RadioButton).Checked = true; var.IncludePage.Controls["txtFile"].Text = pv.Value; FillVars(var.IncludePage.Controls["vars"] as ListBox, pv); var.IncludePage.Controls["txtSource"].Text = pv.ToString(); } else { (var.ValuePage.Controls["rbValue"] as RadioButton).Checked = true; var.ValuePage.Controls["txtValue"].Text = pv.Value; } DialogResult dr = var.ShowDialog(); if (dr == DialogResult.OK) { if (!String.IsNullOrEmpty(pv.Name) && pv.Name != var.Controls["txtName"].Text) { po.DeleteVariable(pv.Name); list.Items.RemoveAt(list.SelectedIndices[0]); } pv.Indent = var.IsIndented; pv.Include = (var.IncludePage.Controls["rbInclude"] as RadioButton).Checked; if (pv.Include) { pv.Value = var.IncludePage.Controls["txtFile"].Text; foreach (PrinterVariable subpv in (var.IncludePage.Controls["vars"] as ListBox).Items) { pv.AddVariable(subpv.Name, subpv); } } else { pv.Value = var.ValuePage.Controls["txtValue"].Text; } pv.Name = var.Controls["txtName"].Text; if (po.ExistTestVariable(pv.Name)) { po.EditVariable(pv.Name, pv); for (int index = 0; index < list.Items.Count; ++index) { if ((list.Items[index] as PrinterVariable).Name == pv.Name) { list.Items.RemoveAt(index); list.Items.Insert(index, pv); list.SelectedIndices.Add(index); break; } } } else { po.AddVariable(pv.Name, pv); int pos = list.Items.Add(pv); list.SelectedIndices.Add(pos); } list.Refresh(); hasModified = true; return(true); } return(false); } return(false); }