Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Working with clipboard (Read 3502 times)
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Working with clipboard
Dec 24th, 2009 at 4:07pm
Print Post  
I have a question. I want to add into my application Copy/Paste functionality. And I want to create the corresponding menu items. But me menu item for paste for example need to be able only if user already copied some nodes into clipboard. I found the next method in MSDN:
Code
Select All
bool IsHTMLDataOnClipboard = Clipboard.ContainsData(DataFormats.Html);
 


But what data format can I use for detect that there are some nodes into the clipboard present?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Working with clipboard
Reply #1 - Dec 26th, 2009 at 7:50am
Print Post  
Try with Clipboard.ContainsData(typeof(MemoryStream)).

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Working with clipboard
Reply #2 - Dec 28th, 2009 at 7:09am
Print Post  
Ok. I try it. But I found the another problem. When I call PastFromClipboard I see 2 exceptions in your example FCDemo and the same exceptions I catch in my code. The difference is in your example nodes are pasted succeed. In my code they are not pasted. May be I define copy-constructor and Clone() incorrect
Code
Select All
   /// <summary>
    /// Class represents nodes which are using in the diagram with some additional
    /// properties
    /// </summary>
    public class CustomNode: ShapeNode
    {
        #region Data
        NodeType m_nNodeType = NodeType.Bus;
        int m_nInpNum = 0;
        int m_nOutNum = 0;
        #endregion //Data

        #region Constructor and Helper functions
        /// <summary>
        /// Default constructor. Creates an empty object
        /// </summary>
        /// <param name="a_nNodeType">Sets the type of the node</param>
        public CustomNode(NodeType a_nNodeType): base()
        {
            m_nNodeType = a_nNodeType;
        }
        /// <summary>
        /// Copy-constructor. Creates a clone of the prototype
        /// </summary>
        /// <param name="a_Prototype"></param>
        public CustomNode(CustomNode a_Prototype): base(a_Prototype)
        {
            m_nNodeType = a_Prototype.Type;
        }
        #endregion //Constructor and Helper functions

        #region Properties
        /// <value>
        /// Gets or sets type of the Node according to enum <see cref="NodeType"/>
        /// </value>
        public NodeType Type
        {
            get { return m_nNodeType; }
            set { m_nNodeType = value; }
        }
        /// <value>
        /// Gets or sets number of inputs of the node
        /// </value>
        public int InputNumber
        {
            set { m_nInpNum = value; }
            get { return m_nInpNum; }
        }
        /// <value>
        /// Gets or sets number of outputs of the node
        /// </value>
        public int OutputNumber
        {
            set { m_nOutNum = value; }
            get { return m_nOutNum; }
        }
        #endregion //Properties

        #region Overrides
        public override DiagramItem Clone(bool clipboard)
        {
            CustomNode node = base.Clone(clipboard) as CustomNode;
            if (node != null)
            {
                node.OutputNumber = OutputNumber;
                node.Type = Type;
                node.InputNumber = InputNumber;
            }
            return node;
        }
        #endregion //Overrides
    }
 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Working with clipboard
Reply #3 - Dec 28th, 2009 at 8:47am
Print Post  
You must also implement the SaveToXml and LoadFromXml serialization methods, and also call Diagram.RegisterItemClass.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Working with clipboard
Reply #4 - Dec 28th, 2009 at 8:58am
Print Post  
Can you show me examples for SaveToXml and LoadFromXml methods please?
Are these overrides correct:
Code
Select All
	  /// <summary>
	  /// Saves the item content into an XML element
	  /// </summary>
	  /// <param name="xmlElement">An XmlElement the item's data should be stored into</param>
	  /// <param name="context">An XmlPersistContext object providing contextual information about the serialization process and some helper serialization methods</param>
	  protected override void SaveToXml(System.Xml.XmlElement xmlElement, XmlPersistContext context)
	  {
		base.SaveToXml(xmlElement, context);
		context.WriteInt(OutputNumber, "OutputNumber", xmlElement);
		context.WriteInt(InputNumber, "InputNumber", xmlElement);
		context.WriteEnum(Type, "ElementType", xmlElement);
	  }
	  /// <summary>
	  /// Loads the item content from an XML element
	  /// </summary>
	  /// <param name="xmlElement">An XmlElement containing the item's data</param>
	  /// <param name="context">An XmlPersistContext object providing contextual information about the serialization process and some helper serialization methods</param>
	  protected override void LoadFromXml(System.Xml.XmlElement xmlElement, XmlPersistContext context)
	  {
		base.LoadFromXml(xmlElement, context);
		OutputNumber = context.ReadInt("OutputNumber", xmlElement);
		InputNumber = context.ReadInt("InputNumber", xmlElement);
		Type = (NodeType)context.ReadEnum("ElementType", xmlElement);
	  } 

  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Working with clipboard
Reply #5 - Dec 28th, 2009 at 9:33am
Print Post  
The SaveToXml methods calls each time when I copy to the clipboard. But when I try to paste the LoadFromXml method is not called. In the constructor of my main window I call
Code
Select All
Diagram.RegisterItemClass(typeof(CustomNode), "CustomNode", 1);
 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Working with clipboard
Reply #6 - Dec 28th, 2009 at 9:56am
Print Post  
We are getting closer Wink For deserialization to work, you must either add a no-args constructor, or one that takes a Diagram argument.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Hunter
Full Member
***
Offline



Posts: 194
Location: Sevastopol
Joined: Dec 1st, 2009
Re: Working with clipboard
Reply #7 - Dec 28th, 2009 at 11:16am
Print Post  
Yeeeees! It at last works! Smiley Thank you very much!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint