public bool doUndo(DiagramView view = null) { if (operations.Count() == 0) { return false; } int group = 0; bool result = false; do { UndoOperation operation = operations.First(); // first restore position where change occurred if (view != null && !view.isOnPosition(operation.position, operation.layer)) { view.goToShift(operation.position); view.goToLayer(operation.layer); view.Invalidate(); return false; } // process all operations in same group if (group != 0 && operation.group != group) { group = 0; break; } group = operation.group; if (operation.type == "delete") { this.doUndoDelete(operation); reverseOperations.Push(operation); } if (operation.type == "create") { this.doUndoCreate(operation); reverseOperations.Push(operation); } if (operation.type == "edit" || operation.type == "move" || operation.type == "changeLineColor" || operation.type == "changeLineWidth" || operation.type == "changeNodeColor" ) { Nodes nodes = new Nodes(); foreach (Node node in operation.nodes) { nodes.Add(this.diagram.GetNodeByID(node.id)); } Lines lines = new Lines(); foreach (Line line in operation.lines) { lines.Add(this.diagram.getLine(line.start, line.end)); } UndoOperation roperation = new UndoOperation( operation.type, nodes, lines, operation.group, operation.position, operation.layer ); reverseOperations.Push(roperation); this.doUndoEdit(operation); } operations.Pop(); result = true; } while (group != 0 && operations.Count() > 0); if (result) { this.saved--; if (!this.saveLost && this.saved == 0) { this.diagram.restoresave(); } else { this.diagram.unsave(); } } return result; }
/*************************************************************************************************************************/ // VIEW // open new view on diagram public DiagramView openDiagramView(DiagramView parent = null, Layer layer = null) { DiagramView diagramview = new DiagramView(main, this, parent); diagramview.setDiagram(this); this.DiagramViews.Add(diagramview); main.addDiagramView(diagramview); this.SetTitle(); diagramview.Show(); if (layer != null) { diagramview.goToLayer(layer.id); } return diagramview; }