@@ -118,7 +118,8 @@ public class Canvas : DrawingArea {
118118 set_cursor( cursor );
119119 }
120120
121- /* Opens a new image and displays it in the drawing area */
121+ // -------------------------------------------------------------
122+ // Opens a new image and displays it in the drawing area.
122123 public bool open_image ( string filename ) {
123124
124125 try {
@@ -494,6 +495,38 @@ public class Canvas : DrawingArea {
494495
495496 }
496497
498+ /* ***************************************************************************/
499+ // SAVE/LOAD
500+ /* ***************************************************************************/
501+
502+ // -------------------------------------------------------------
503+ // Saves this canvas and all canvas items in XML format.
504+ public Xml . Node * save( string ? image_dir = null ) {
505+
506+ Xml . Node * node = new Xml .Node ( null , " canvas" );
507+
508+ node- > add_child( image. save( editor. filename, image_dir ) );
509+ node- > add_child( items. save( image_dir ) );
510+
511+ return ( node );
512+
513+ }
514+
515+ // -------------------------------------------------------------
516+ // Loads this canvas and the canvas items from XML format.
517+ public void load( Xml . Node * node ) {
518+
519+ for ( Xml . Node * it= node- > children; it!= null ; it= it- > next ) {
520+ if ( it- > type == Xml . ElementType . ELEMENT_NODE ) {
521+ switch ( it- > name ) {
522+ case " image" : image. load( it ); break ;
523+ case " items" : items. load( it ); break ;
524+ }
525+ }
526+ }
527+
528+ }
529+
497530 /* ***************************************************************************/
498531 // DRAWING FUNCTIONS
499532 /* ***************************************************************************/
0 commit comments