For anyone who stumbles on this thread, here's my kludgy "solution" for avoiding the "dirty" flag getting set when the user selects a node:
// Copy of the "dirty flag", saved when the Diagram.NodeSelecting event was fired, and a time
// stamp as a kludge solution of detecting if this is happening
private bool _savedDirtyFlag = false;
private int _nodeSelectionTimestamp = 0;
...
// Following two event handlers are used to suppress MindFusion's setting of the "dirty flag"
// for just selecting a node.
private void Diagram_NodeSelecting(object sender, NodeValidationEventArgs e)
{
_savedDirtyFlag = _diagramView.Diagram.Dirty;
_nodeSelectionTimestamp = Environment.TickCount;
}
private void Diagram_DirtyChanged(object sender, EventArgs e)
{
if (Environment.TickCount - _nodeSelectionTimestamp < 100) // 100 ms.
_diagramView.Diagram.Dirty = _savedDirtyFlag;
}
And to be consistent with my principle that selection should not be considered to be a part of the Diagram object that should be persisted, I deselect everything before saving the diagram:
List<DiagramItem> savedSelection =
new List<DiagramItem>(_diagramView.Diagram.Selection.Items);
_diagramView.Diagram.Selection.Clear();
_diagramView.Diagram.SaveToStream(memoryStream, true);
foreach (DiagramItem diagramItem in savedSelection)
_diagramView.Diagram.Selection.AddItem(diagramItem);
(I know that it would be simpler to just deselect everything after loading a saved diagram, but this somehow seems to be more correct.)
On reflection, I think the best solution would be for MindFusion to add a "selection should be persisted" option, and when that option is set to false then
a) changes in selection do not turn the dirty flag on
b) saving the Diagram object should not save selection info