Down inside the GoSelection class, where it is adding an object to the selection, it adds the new object to the selection, and raises the OnObjectSelected for that object.
but then... what WAS the primary select may not be anymore, so GoSelection does:
It does this because primary selection handles may appear different than secondary handles, and it's telling the object... you've lost primary selection, but you are now part of the secondary selection.
Are you trying to always avoid having a child selected if the parent SubGraph is, or just in the case where the child is selected, then the parent?
ok… the code below handles the first case (selecting child, then parent) but not the reverse.
using System; using System.Collections.Generic; using System.Text;
using Northwoods.Go;
namespace SubGraphApp {
[Serializable] class GoToolSelectingSubGraph : GoToolSelecting {
public GoToolSelectingSubGraph(GoView v) : base(v) { }
private void DeselectChildren(GoSubGraph subG) { foreach (GoObject o in subG) { View.Selection.Remove(o); GoSubGraph sg = o as GoSubGraph; if (sg != null) { // make sure children aren't selected. DeselectChildren(sg); } } }
public override void DoSelect(GoInputEventArgs evt) { base.DoSelect(evt); if (this.CurrentObject != null && evt.Control) { GoSubGraph sg = this.CurrentObject as GoSubGraph; if (sg != null) { // make sure children aren't selected. DeselectChildren(sg); } } }
}
}
use this tool via
goView1.ReplaceMouseTool(typeof(GoToolSelecting), new GoToolSelectingSubGraph(goView1));
I can finish this in the morning if you need me to... but you may have it worked out by then.
using System; using System.Collections.Generic; using System.Text;
using Northwoods.Go;
namespace SubGraphApp {
[Serializable] class GoToolSelectingSubGraph : GoToolSelecting {
public GoToolSelectingSubGraph(GoView v) : base(v) { }
private void DeselectChildren(GoSubGraph subG) { foreach (GoObject o in subG) { View.Selection.Remove(o); GoSubGraph sg = o as GoSubGraph; if (sg != null) { // make sure children aren't selected. DeselectChildren(sg); } } }
private void DeselectParents(GoObject obj) { GoSubGraph parent = obj.Parent as GoSubGraph; while (parent != null) { View.Selection.Remove(parent); parent = parent.Parent as GoSubGraph; } }
public override void DoSelect(GoInputEventArgs evt) { base.DoSelect(evt); if (this.CurrentObject != null && evt.Control) { GoSubGraph sg = this.CurrentObject as GoSubGraph; if (sg != null) { // make sure children aren't selected. DeselectChildren(sg); } DeselectParents(this.CurrentObject); } }
actually, you said “Ctrl-mouse” in your first note… but looking at this again, I think you get into “bad states” (by your definition) with the shift-key as well. Removing the evt.Control above fixes that.