Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Saving a Selection (Read 2236 times)
Alex
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 60
Joined: Nov 21st, 2006
Saving a Selection
Sep 6th, 2007 at 8:21am
Print Post  
Hello,

in my application I need support for some type of library of predefined groups (a previously saved Selection of items maybe). Is there any support for this implemented, or do I have to save this all manually?

Best regards,

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Saving a Selection
Reply #1 - Sep 6th, 2007 at 8:25am
Print Post  
Hello,

Check how the Export Selection and Import Selection commands are implemented in the CopyPaste example. Will that work for you?

Best regards,
Stoyan
  
Back to top
 
IP Logged
 
Alex
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 60
Joined: Nov 21st, 2006
Re: Saving a Selection
Reply #2 - Sep 6th, 2007 at 10:12am
Print Post  
Hi,

just checked and it worked partially. I think the way over the DiagramView with CopyToClipBoard is a little bit more persistent, or am I wrong?

Code
Select All
            if (diagram.Selection.Items.Count == 0)
            {
                MessageBox.Show("Select items to export");
                return;
            }
            SaveFileDialog sfd = new SaveFileDialog();
            DiagramView exportHelper = new DiagramView();
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                diagramView.CopyToClipboard(true, true);
                exportHelper.PasteFromClipboard(0,0);
                exportHelper.SaveToXml(sfd.FileName);
            }
 



And pasting it back in ...

Code
Select All
            OpenFileDialog ofd = new OpenFileDialog();
            DiagramView exportHelper = new DiagramView();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                exportHelper.LoadFromXml(ofd.FileName);
                try
                {
                    foreach (DiagramItem item in exportHelper.Diagram.Items)
                    {
                        exportHelper.Diagram.Selection.AddItem(item);
                    }
                    exportHelper.CopyToClipboard(true, true);
                    diagramView.PasteFromClipboard(0,0);

                }
                catch (FileLoadException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
 



Am I missing something? Maybe there are things not copied at all, but eventually you can help me with that, since AnchorPatterns and the links between grouped items are not stored.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Saving a Selection
Reply #3 - Sep 6th, 2007 at 11:33am
Print Post  
Yes, you could use CopyToClipboard if you don't mind clearing whatever the users have stored in the clipboard. Otherwise you will need to add some code the clone the Group objects as well.

Only the Id of AnchorPattern objects is saved if it's different than "", and an AnchorPattern with the same Id must be defined when loading the file.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Saving a Selection
Reply #4 - Sep 10th, 2007 at 12:15pm
Print Post  
Actually in version 5 the clipboard operations are implemented by calling public methods of the Diagram class that you could use in your situation. Use the

public SelectionCopy CopySelection(
     Diagram source, bool unconnectedLinks, bool copyGroups)

and

public bool PasteSelection(
     Diagram doc, SelectionCopy data, CompositeCmd cmd, float dx, float dy)

to copy the selected items and groups to a second Diagram, which you can save to a file.

Stoyan
  
Back to top
 
IP Logged
 
Alex
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 60
Joined: Nov 21st, 2006
Re: Saving a Selection
Reply #5 - Sep 19th, 2007 at 6:32am
Print Post  
Hi,

very nice. Thank you for the hint!

Alex
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint