private void showDrawingBoard(object sender, EventArgs e) { MenuItem mi = sender as MenuItem; if (mi != null) { DrawingPage page = mi.Tag as DrawingPage; if (page != null) { IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (host != null) { HostSurface surface = host.GetService(typeof(DesignSurface)) as HostSurface; if (surface != null) { ClassPointer root = surface.Loader.GetRootId(); DrawingLayerCollection layers = page.ShowDrawingsEditor(); if (layers != null) { //layers0 is the existing layer collections DrawingLayerCollection layers0 = page.DrawingLayers; //for layers0 if a drawing object's guid does not exist in layers then //the object has been deleted List <DrawingItem> deleted = new List <DrawingItem>(); foreach (DrawingLayer l0 in layers0) { DrawingItem d = null; for (int i = 0; i < l0.Count; i++) { DrawingItem d0 = l0[i]; d = layers.GetDrawingItemById(d0.DrawingId); if (d != null) { d0.Copy(d); //not deleted //move and resize the IDrawDesignControl foreach (Control c in page.Controls) { IDrawDesignControl dc0 = c as IDrawDesignControl; if (dc0 != null) { if (dc0.Item == d0) { c.Location = d0.Location; c.Size = d0.Bounds.Size; break; } } } } else { deleted.Add(d0); //deleted } } } if (deleted.Count > 0) { //check to see if each deleted item has usages List <DrawingItem> ls = new List <DrawingItem>(); foreach (DrawingItem d0 in deleted) { for (int i = 0; i < page.Controls.Count; i++) { IDrawDesignControl dc = page.Controls[i] as IDrawDesignControl; if (dc != null) { if (dc.DrawingId == d0.DrawingId) { uint id = root.ObjectList.GetObjectID(dc); if (id == 0) { DesignUtil.WriteToOutputWindow("id not found on deleting component {0}", dc.Name); } else { List <ObjectTextID> list = root.GetComponentUsage(id); if (list.Count > 0) { dlgObjectUsage dlg = new dlgObjectUsage(); dlg.LoadData("Cannot delete this component. It is being used by the following objects", string.Format("Component - {0}", dc.Name), list); dlg.ShowDialog(); ls.Add(d0); } } break; } } } } if (ls.Count > 0) { foreach (DrawingItem d0 in ls) { deleted.Remove(d0); } } foreach (DrawingItem d0 in deleted) { for (int i = 0; i < page.Controls.Count; i++) { IDrawDesignControl dc = page.Controls[i] as IDrawDesignControl; if (dc != null) { if (dc.DrawingId == d0.DrawingId) { surface.Loader.DeleteComponent(page.Controls[i]); break; } } } } } //for a drawing object in layers if its guid does not exist in layers0 then //it is a new object //reset zorder according to the new layers List <Control> ctrls = new List <Control>(); foreach (DrawingLayer l in layers) { int zOrder = 0; foreach (DrawingItem d in l) { DrawingItem d0 = layers0.GetDrawingItemById(d.DrawingId); if (d0 == null) { //add a new drawing string name = d.Name + Guid.NewGuid().GetHashCode().ToString("x"); Type designerType = TypeMappingAttribute.GetMappedType(d.GetType()); if (designerType == null) { throw new DesignerException("Drawing type {0} does not have a designer", d.GetType()); } Control dc = (Control)surface.Loader.CreateComponent(designerType, name); IDrawDesignControl ddc = (IDrawDesignControl)dc; ddc.Item = d; dc.Location = d.Location; dc.Size = d.Bounds.Size; ctrls.Add(dc); ddc.ZOrder = zOrder; } else { for (int k = 0; k < page.Controls.Count; k++) { IDrawDesignControl dc = page.Controls[k] as IDrawDesignControl; if (dc != null) { if (dc.Item == d0) { dc.ZOrder = zOrder; break; } } } } zOrder += 10; } } if (ctrls.Count > 0) { page.Controls.AddRange(ctrls.ToArray()); } page.LoadData(layers, false); page.Refresh(); surface.SetModified(); surface.Loader.NotifyChanges(); } } } } } }
void miDelete_Click(object sender, EventArgs e) { LocalVariable lv = this.ClassPointer as LocalVariable; List <IAction> acts = lv.RootPointer.GetRelatedActions(lv.MemberId); bool bOK = (acts.Count == 0); if (bOK) { MethodDesignerHolder mdh = MethodViewer; if (mdh != null) { BranchList bl = mdh.ActionList; if (bl != null) { Dictionary <UInt32, IAction> actions = new Dictionary <uint, IAction>(); bl.GetActionsUseLocalVariable(lv.MemberId, actions); if (actions.Count > 0) { foreach (KeyValuePair <UInt32, IAction> kv in actions) { acts.Add(kv.Value); } bOK = false; } } } } if (!bOK) { List <ObjectTextID> objs = new List <ObjectTextID>(); foreach (IAction a in acts) { objs.Add(new ObjectTextID("Action", "", a.Display)); } dlgObjectUsage dlg = new dlgObjectUsage(); dlg.LoadData("There are actions using this object. These actions must be removed before this object can be removed.", "Remove object", objs); //currently no OK will be returned bOK = (dlg.ShowDialog(this.FindForm()) == DialogResult.OK); if (bOK) { IList <MethodDiagramViewer> l = MethodViewer.GetViewer(); foreach (MethodDiagramViewer mv in l) { //remove local/constructor actions belong to it List <IComponent> avList = new List <IComponent>(); for (int i = 0; i < mv.Controls.Count; i++) { ActionViewer av = mv.Controls[i] as ActionViewer; if (av != null) { foreach (IAction a in acts) { if (av.ActionObject.ContainsActionId(a.ActionId)) { avList.Add(av); } } } } if (avList.Count > 0) { mv.DeleteComponents(avList.ToArray()); } } } } if (bOK) { MethodViewer.RemoveLocalVariable(this); RemoveLabel(); Control p = this.Parent; if (p != null) { p.Controls.Remove(this); } MethodViewer.Changed = true; } }