protected override Widget GetElementWidget(T obj) { Cell cell; cell = new Cell(context, obj); if (editable) { MyDragDrop.SetFailAction(cell, delegate { parent.Remove(obj); DependencyManager.TriggerAllFlags(); }); MyDragDrop.SetFailAction(cell.frame.LabelWidget, delegate { parent.Remove(obj); DependencyManager.TriggerAllFlags(); }); } // Rationale for removing only if drag had no target ("fails") // - If cellObject is dragged from an aggregative list to another aggregative list, // the Add() function on the second automatically removes it from the first, so calling Remove() is unnecessary. // - If cellObject is dragged from an associative list to an aggregative list or vice versa, // We reasonably assume that user doesn't want it removed from the first list since the concept of "moving" doesn't apply in this context. // - Only if the user has dragged cellObject from any list to *nothing* can it be assumed that they need it manually removed by us. return(cell); }
public override Widget GetCellContents(Context context) { bool editable = UIFactory.EditAuthorized(this, "structures"); //Creates the cell contents VBox structureBox = new VBox(false, 0) { BorderWidth = 3 }; foreach (Structure structure in structures) { InspectableBox header = (InspectableBox)structure.GetHeader(context.butInUIContext(this)); if (editable) { MyDragDrop.SetFailAction(header, delegate { Remove(structure); DependencyManager.TriggerAllFlags(); }); } structureBox.PackStart(header, false, false, 0); } if (editable) { //Set up dropping EventBox eventBox = new EventBox { Child = structureBox, VisibleWindow = false }; MyDragDrop.DestSet(eventBox, "Structure"); MyDragDrop.DestSetDropAction(eventBox, delegate { if (Accepts(MyDragDrop.currentDragged)) { Add(MyDragDrop.currentDragged); DependencyManager.TriggerAllFlags(); } }); return(new Gtk.Alignment(0, 0, 1, 0) { Child = eventBox, BorderWidth = 7 }); } else { structureBox.BorderWidth += 7; return(structureBox); } //For some reason drag/drop highlights include BorderWidth. //The Alignment makes the highlight actually appear at the 3:7 point in the margin. }