Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

Save and load MDI state

Last post 07-24-2008 12:29 by [Infragistics] Mike Dour. 24 replies.
Page 1 of 2 (25 items) 1 2 Next >
Sort Posts: Previous Next
  • 05-21-2008 10:53

    • mike2008
    • Top 500 Contributor
    • Joined on 05-15-2008
    • Points 330

    Save and load MDI state

    I am trying to save the MDI state when closing the application and load it when opening.
    Like FireFox, it opens all the web pages last time when you close the application.

    I've noticed that UltraTabbedMdiManager have methods like SaveAsXml and LoadFromXml.
    What is contained in the saved XML file?

    What do I need to do if I want to open the last visited pages like FireFox?

    Thanks.
    Mike
     

    • Post Points: 20
  • 05-22-2008 8:35 In reply to

    Re: Save and load MDI state

    The XML file will contain all properties and values which are publicly exposed in the tabbed mdi manager. It is intended to save customizations the user might have made, through both the default UI, as well as any additional UI you have added to your application to give the user control over certain aspects of the tabbed mdi manager.  One of the reasons to save and load this file would be to maintain the tab groups into which the user has organized the mdi child forms. However, loading the XML file will not open the forms which were previously opened. You must keep track of which forms were open when the XML file was saved and re-open them before loading the XML file.

    • Post Points: 20
  • 05-22-2008 9:00 In reply to

    • mike2008
    • Top 500 Contributor
    • Joined on 05-15-2008
    • Points 330

    Re: Save and load MDI state

    >You must keep track of which forms were open when the XML file was saved and re-open them before loading the XML file.

    So i guess i should save the open forms into a separate file, instead of messing this XML file.

    In fact, all I want to save for each form is the file name to initialize it.
    Is it possible to tag objects (e.g., the list of file names in this case) to the UltraTabbedMdiManager? Is it worth doing that? 

    >to maintain the tab groups into which the user has organized the mdi child forms
    The only think i can think of is to switch between normal MDI and tabbed MDI. Anything else user acn do to organize child forms?

    Thanks!

    • Post Points: 20
  • 05-22-2008 9:33 In reply to

    Re: Save and load MDI state

    mike2008:
    In fact, all I want to save for each form is the file name to initialize it.
    Is it possible to tag objects (e.g., the list of file names in this case) to the UltraTabbedMdiManager? Is it worth doing that? 

    No, because the load operation would load in the tag values and try to find the mdi child forms all before returning. There would be no way to intervene after the tag values were loaded to open the forms before the load operation attempted to find them.  I would recommend using a separate file for this. 

    mike2008:
    >to maintain the tab groups into which the user has organized the mdi child forms
    The only think i can think of is to switch between normal MDI and tabbed MDI. Anything else user acn do to organize child forms?

    Just like in VS, the user can drag the tabs down or to the side to form new tab groups. They can also form new tab groups by right-clicking the tab and selecting 'New Horizontal Tab Group' or 'New Vertical Tab Group'

    • Post Points: 20
  • 05-27-2008 8:34 In reply to

    • mike2008
    • Top 500 Contributor
    • Joined on 05-15-2008
    • Points 330

    Re: Save and load MDI state

    I tried to save child MDI forms in a separate file and successfully load them within MainForm's OnLoad method.
    But the LoadTabbedMdiLayout does not seems to work, even if i put it after loading all the child MDI forms. Even worse, it messes up the layout.
    I also tried to put LoadTabbedMdiLayout in OnLayout method in the MainForm, and it behaves the same. 

    Do you have any idea what is going wrong? and how can i make this work?

    Thanks. 

    • Post Points: 20
  • 05-27-2008 10:13 In reply to

    Re: Save and load MDI state

    I must apologize: I was thinking about how the dock manager loads the layout and I assumed the tabbed mdi manager worked the same way, so I am sorry for giving bad advice. I have checked with someone more familiar with this component, and there are properties and events built in specifically for what you are trying to do. Handle the StoreTab event on the tabbed mdi manager. When a tab is going to be serialized to the XML file, this event will be fired for each tab. In your case, when you handle this event, set the PersistedInfo of the tab for which the event is being fired to the file name associated with the tab. For deserialization, handle the RestoreTab event. This event will be fired for each tab which was serialized. In the handler, you can get the PersistedInfo for the tab and create a Form (or use an existing Form) to use for the tab. Set the Form on the Form property of the event arguments.

    • Post Points: 50
  • 05-27-2008 11:36 In reply to

    • mike2008
    • Top 500 Contributor
    • Joined on 05-15-2008
    • Points 330

    Re: Save and load MDI state

    So LoadTabbedMdiLayout would work properly if I create handler for StoreTab and RestoreTab?

    The reason LoadTabbedMdiLayout does not work for me is because I save the mdi child forms in a separate file?

    Thanks.

    • Post Points: 5
  • 05-28-2008 12:32 In reply to

    • mike2008
    • Top 500 Contributor
    • Joined on 05-15-2008
    • Points 330

    Re: Save and load MDI state

    Another question:
    Our application uses different managers (Toolbar, Dock, and MDI), is it possible to save the setting in a single file instead of multiple ones.
    What is the industrial standard to do that? 

    Thanks. 

    • Post Points: 20
  • 05-28-2008 15:57 In reply to

    Re: Save and load MDI state

    Its possible, but it would need to be done manually. You could create an XML file where you store each configuration stream as a base 64 value in the file. Here is one way you could accomplish this for a toolbars manager and dock manager:

    private void Form1_Load( object sender, EventArgs e )
    {
     if ( File.Exists( "config.xml" ) == false )
      return;

     using ( XmlTextReader reader = new XmlTextReader( "config.xml" ) )
     {
      reader.ReadStartElement( "Config" );

      using ( MemoryStream stream = new MemoryStream( this.ReadBase64( reader ) ) )
       this.ultraToolbarsManager1.LoadFromBinary( stream );

      using ( MemoryStream stream = new MemoryStream( this.ReadBase64( reader ) ) )
       this.ultraToolbarsManager1.LoadFromBinary( stream );
     }
    }

    private void Form1_FormClosed( object sender, FormClosedEventArgs e )
    {
     using ( XmlTextWriter writer = new XmlTextWriter( "config.xml", Encoding.Default ) )
     {
      writer.WriteStartElement( "Config" );
      writer.WriteStartElement( "ToolbarsConfig" );

      using ( MemoryStream stream = new MemoryStream() )
      {
       this.ultraToolbarsManager1.SaveAsBinary( stream, true );

       byte[ buffer = stream.GetBuffer();
       writer.WriteBase64( buffer, 0, buffer.Length );
      }

      writer.WriteEndElement();

      writer.WriteStartElement( "DockConfig" );

      using ( MemoryStream stream = new MemoryStream() )
      {
       this.ultraDockManager1.SaveAsBinary( stream );

       byte[ buffer = stream.GetBuffer();
       writer.WriteBase64( buffer, 0, buffer.Length );
      }

      writer.WriteEndElement();
      writer.WriteEndElement();
     }
    }

    private byte[ ReadBase64( XmlTextReader reader )
    {
     List<byte> finalBuffer = new List<byte>();
     byte[ buffer = new byte[ 1000 ];

     while ( true )
     {
      int bytesRead = reader.ReadBase64( buffer, 0, buffer.Length );

      if ( bytesRead < buffer.Length )
      {
       byte[ retValue = new byte[ finalBuffer.Count + bytesRead ];

       Buffer.BlockCopy( finalBuffer.ToArray(), 0, retValue, 0, finalBuffer.Count );
       Buffer.BlockCopy( buffer, 0, retValue, finalBuffer.Count, bytesRead );

       return retValue;
      }
      else
      {
       finalBuffer.AddRange( buffer );
      }
     }
    }

    • Post Points: 35
  • 06-09-2008 7:24 In reply to

    • mike2008
    • Top 500 Contributor
    • Joined on 05-15-2008
    • Points 330

    Re: Save and load MDI state

    I tried to add StoreTab and RestoreTab event handler, and they were called when SaveAsXml and LoadFromXml.

    All the MDI child forms were loaded successfully, but the MDI layout does not.

    For example, if i create a new horizontal Tab group, the group dissapears when loading next time.
    If i am not use tab, the sizes and positions of child forms were not loaded propertly next time.

    The only difference it can tell is whether the layout is tabbed or not, and this was loaded properly.

    Any idea what's going wrong? 

    Thanks! 

    • Post Points: 20
  • 06-09-2008 9:53 In reply to

    Re: Save and load MDI state

    It could be a bug. I would recommend submitting a sample which reproduces the issue to the support group: http://www.infragistics.com/gethelp.

    • Post Points: 20
  • 06-10-2008 13:28 In reply to

    • mike2008
    • Top 500 Contributor
    • Joined on 05-15-2008
    • Points 330

    Re: Save and load MDI state

    I managed to find out the cause of the problem, but i do not understand why.

    In my OnLoad method in the MainForm,  if i do  LoadTabbedMdiLayout("TabbedMdi.xml"), everything was fine, including the tab group or mdi child position.

    But if i add the following line, the tab group and mdi child position would fail to work. All tabs will be added into one group.
       this.Visible = false;

    Can you think of any reason why?

    The  reason I added this line is because it takes some time to LoadTabbedMdiLayout, and I do not want to show some blank screen while it is loading. 

    Thanks! 

    • Post Points: 20
  • 06-10-2008 17:00 In reply to

    Re: Save and load MDI state

    I can't think of any reason why it wouldn't work but I wouldn't be surprised if there was some timing issue occuring because Visible is changing in the OnLoad. If you must load the layout in the OnLoad because that is the earliest point at which you can access the mdi children, report the issue to the support group. They may find a workaround or a bug with the tabbed mdi manager which can be fixed. Otherwise, I would recommend trying to load the layout in the constructor so you don't need to worry about setting Visible to False.

    • Post Points: 5
  • 06-12-2008 9:04 In reply to

    • mike2008
    • Top 500 Contributor
    • Joined on 05-15-2008
    • Points 330

    Re: Save and load MDI state

    That saves all the layout settings in one XML file.
    However, there is a limitation: the individual layout is saved as Binary, and therefore unreadable.
    The ReadBase64 method is reading each binary block in the XML file. 

    Is it possible to use SaveAsXml on individual layout and combine them into the final XML file? and how can I read it back?

    Thanks!

    • Post Points: 20
  • 06-12-2008 10:55 In reply to

    Re: Save and load MDI state

    I'm not sure I understand the question. Do you want to be able to read the layout file in an editor or do you want to have all layout files for different components stored in one file? If you want to open the layout file in an xml editor and be able to read it, you can use SaveAsXML and try to write string values insted of base 64 values in elements. You would need to wrap the serialized stream with a StreamReader to get the text value written to the stream. Similarly, when you read the text from the xml file, you would need to create a new MemoryStream, wrap it in a StreamWriter and write the text value to the writer. However, if you want to know how to combine the layout files into one layout file, the code posted originally will do that.

    • Post Points: 20
Page 1 of 2 (25 items) 1 2 Next >
Powered by Community Server (Commercial Edition), by Telligent Systems