/// <summary>Edits the item(s) currently selected in the view</summary> public static DialogResult Display(StaticView view) { Transaction transaction = new Transaction(); List <Item> items = new List <Item>(); List <Scriptable> scriptables = new List <Scriptable>(); // probably selected items are scriptables, but this is written to cope with all cases (eg naked Items not inside a Scriptable) foreach (Shape selected in view.CurrentPage.SelectedShapes) { if (selected is Item item) { items.Add(item); if (item.Parent is Scriptable scriptable) { scriptables.Add(scriptable); } } else if (selected is Scriptable s) { scriptables.Add(s); if (s.Element is Item item1) { items.Add(item1); } } } foreach (Scriptable s in scriptables) { transaction.Edit(s); } foreach (Item i in items) { transaction.Edit(i); i.BeingEdited = true; } // there must always be at least one item, but not necessarily scriptables Globals.StoreEvent("Log " + items.Count + " items, " + scriptables.Count + " scriptable, first ID=" + (scriptables?.First()?.SAWID ?? 0)); using (var frm = new frmSAWItem(items, scriptables, transaction)) { // deselect it, so that we get a better preview of what it looks like: frm.m_Page.SelectOnly((Shape)null); Shape beside = scriptables.Any() ? (Shape)scriptables.First() : items.First(); GUIUtilities.PositionNewFormBeside(frm, view.ShapeBounds(beside, true)); bool ok = frm.ShowDialog() == DialogResult.OK; foreach (Item i in items) { i.BeingEdited = false; } frm.SetPreviewState(ButtonShape.States.Normal); view.CurrentPage.SelectOnly(scriptables.Cast <Shape>().ToList()); if (ok) { Globals.Root.StoreNewTransaction(transaction); return(DialogResult.OK); } transaction.Cancel(); return(DialogResult.Cancel); } }