Profile Picture

NDrawingDocument Undo not reverting the Tag.

Posted By Steve Warner 14 Years Ago
Author
Message
Steve Warner
Posted 14 Years Ago
View Quick Profile
Junior Member

Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)

Group: Forum Members
Last Active: 10 Years Ago
Posts: 15, Visits: 1
I have an event that changes the Tag associated with my NDrawingDocument, but when I undo the Event it doesn't revert the Tag to it's previous state. Is there something I am missing?

I ask because I have Shapes that are utilizing this behavior properly using the NShape.Drawing.StartTransaction/HistoryService.Commit paradigm.

Is there something I should be doing differently?

Here is my code snippet.


_form.document.StartTransaction("UpdateFormatProperties");
_form.document.Tag = object.Clone();
//Do some other stuff to the document.
_form.document.HistoryService.Commit();

Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Steve,

The objects assigned to the Tag property need to comply with the following requiresments in order to operate with history and be serialized for drag/drop, clipboard and preview purposes. These requiresments are:

1. Default constructor
2. Implement ICloneable
3. Be marked as serializable

Following is a sample code that demonstrates a custom Tag object:


private void Form1_Load(object sender, EventArgs e)
{
   // create a dummy document, shape and tag
   NDrawingDocument doc = new NDrawingDocument();

   NShape shape = new NRectangleShape();
   doc.ActiveLayer.AddChild(shape);

   MyTag t1 = new MyTag();
   t1.BoolValue = false;
   shape.Tag = t1;
   
   // start a transaction
   doc.StartTransaction("My Transaction");

   // modify the tag
   MyTag t2 = new MyTag();
   t2.BoolValue = true;
   shape.Tag = t2;

   // commit the transaction
   doc.Commit();

   // at this point the value of the tag is t2, so BoolValue is true
   Debug.Assert(((MyTag)shape.Tag).BoolValue == true);

   // perform an undo
   doc.HistoryService.Undo();

   // at this point the history applied a clone of t1, so the value of BoolValue is false
   Debug.Assert(((MyTag)shape.Tag).BoolValue == false);
}

///
/// Must implement ICloneable and be marked as [Serializable]
///

[Serializable]
public class MyTag : ICloneable
{
   ///
   /// Must have a default contructor
   ///

   public MyTag()
   {
      BoolValue = false;
   }
   ///
   /// Must implement ICloneable
   ///

   ///
   public object Clone()
   {
      MyTag clone = new MyTag();
      clone.BoolValue = this.BoolValue;
      return clone;
   }
   public bool BoolValue;
}


Best Regards,
Nevron Support Team



Steve Warner
Posted 14 Years Ago
View Quick Profile
Junior Member

Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)Junior Member (15 reputation)

Group: Forum Members
Last Active: 10 Years Ago
Posts: 15, Visits: 1
My problem is not with the Tags on the shapes in the document. My issue is with the Tag for the document itself.

I have the following code.

document.StartTransaction("My Transaction");
document.Tag = new MyTag();
document.Commit();

yet, nothing gets placed in the history so there is no undo available.

Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009
Hi Steve,

Yes indeed this appears to be a bug in the diagram, because the Tag property setter of NDocument (base for NDrawingDocument and NLibraryDocument) is actually not recording the property change. The fix will appear in the next service pack or release.



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic