/// <summary>
        /// Permite abrir un fichero xml en el que esta almacenada la base de
        /// datos.
        /// </summary>
        /// <param name="path">
        /// La ruta del archivo que queremos cargar.
        /// </param>
        public static MathTextDatabase Load(string path)
        {
            XmlSerializer serializer =
                new XmlSerializer(typeof(MathTextDatabase),
                                  MathTextDatabase.GetXmlAttributeOverrides());

            MathTextDatabase db = null;
            StreamReader     r  = null;


            try
            {
                r = new StreamReader(path);
            }
            catch (Exception)
            {
                return(null);
            }


            try
            {
                db = (MathTextDatabase)serializer.Deserialize(r);
            }
            catch (System.Xml.XmlException)
            {
                // Nada.
            }

            r.Close();

            return(db);
        }
		/// <summary>
		/// Sets the appropiate labels based on the database.
		/// </summary>
		/// <param name="database">
		/// The database which info we want to be showed.
		/// </param>
		public void SetDatabase(MathTextDatabase database)
		{
			shortDescLabel.Markup = String.Format("<i>{0}</i>", 
			                                    database.ShortDescription);
			
			longDescLabel.Text = database.Description;
			
			typeLabel.Text = database.DatabaseTypeShortDescription;
		}
        /// <summary>
        /// Este metodo almacena la base de datos en el disco duro.
        /// </summary>
        /// <param name="path">
        /// La ruta del archivo en la que se guardara la base de datos.
        /// </param>
        public void Save(string path)
        {
            XmlSerializer serializer =
                new XmlSerializer(typeof(MathTextDatabase),
                                  MathTextDatabase.GetXmlAttributeOverrides());

            using (StreamWriter w = new StreamWriter(path))
            {
                serializer.Serialize(w, this);
                w.Close();
            }
        }
		private MathTextDatabase CreateDatabase()
		{
			MathTextDatabase mtd = new MathTextDatabase();
			
			mtd.Database = databaseStep.Database;
			mtd.Processes = processesStep.Processes;
			mtd.Description = propertiesStep.LongDescription;
			mtd.ShortDescription = propertiesStep.ShortDescription;
			
			return mtd;
		}
		/// <summary>
		/// <c>MainLearnerWindow</c>'s parametriced constructor.
		/// </summary>
		/// <param name="parent">
		/// The windo's parent window. 
		/// </param>
		/// <param name="inputDatabase">
		/// A database to be loaded upon start.
		/// </param>
		/// <param name="inputDatabasePath">
		/// The path of the input database.
		/// </param>
		/// <param name="inputImage">
		/// An image to be learned upon start.
		/// </param>
		public MainLearnerWindow(Gtk.Window parent,
		                         MathTextDatabase inputDatabase, 
		                         string inputDatabasePath,
		                         Pixbuf inputImage,
		                         string inputImageName)
		{			
			
			Glade.XML gxml = new Glade.XML (null,
			                                "mathtextlearner.glade", 
			                                "mainWindow", 
			                                null);
				
			gxml.Autoconnect (this);
			
			Initialize();
			
			if (parent !=null)
			{
				mainWindow.Modal = true;
				mainWindow.TransientFor = parent;
			}
			
			// We try loading the image.
			
			if(inputDatabase!=null)
			{
				// We have to load a database.
				SetDatabase(inputDatabase);	
				
				SetTitle(inputDatabasePath);
				
				if (inputImage != null)
				{
					LoadNewImage(inputImage);
				}				
			}
			else if(inputImage!=null)
			{
				// We haven't specified a database, but want to learn and image,
				// so we launch the new database wizard, and add that image.
				NewDatabaseAsisstant assistant = 
					new NewDatabaseAsisstant(mainWindow,
					                         inputImage, 
					                         inputImageName);
				
				ResponseType res  = assistant.Run();
				if(res == ResponseType.Ok)
				{
					SetDatabase(assistant.Database);
					
					LoadNewImages(assistant.Images);
				}				
				
				assistant.Destroy();
			}
			
			mainWindow.Icon = ImageResources.LoadPixbuf("mathtextlearner16");
		
		}
		/// <summary>
		/// Sets the database the symbols will be learned into, and makes the
		/// proper interface elementents (un)sensitive.
		/// </summary>
		/// <param name="database">
		/// A <see cref="MathTextDatabase"/>
		/// </param>
		private void SetDatabase(MathTextDatabase database)
		{
			this.database = database; 
			
			database.StepDone +=
				new ProcessingStepDoneHandler(OnLearningStepDone);
			
			messageInfoHB.Visible = false;
			
			mtb = null;
			

			toolSaveAs.Sensitive = true;
			menuSaveAs.Sensitive = true;
			
			imagesHB.Sensitive = true;			
			imagesVB.Sensitive = true;
			
			imagesStore.Clear();
			
			hboxSymbolWidgets.Sensitive = false;
			nextButtonsHB.Sensitive =false;
			
			editPropertiesBtn.Sensitive = true;
			
			symbolLabelEditor.Label = "";
			
			SetDatabaseInfo();
			
			
		}