/////////////////////////////////////////////////////////////////////////////
// Name:        proppanel_xmlsource.cpp
// Purpose:     wxPackagePropertiesPanel
//              (stuff for handling the "xml source" page)
// Author:      Francesco Montorsi
// Modified by:
// Created:     28/06/2006 19:22:47
// RCS-ID:      $Id: proppanel_xmlsource.cpp,v 1.7 2007/01/31 13:01:22 frm Exp $
// Copyright:   (c) 2006 Julian Smart, Francesco Montorsi
// Licence:     wxWidgets license
/////////////////////////////////////////////////////////////////////////////


// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include <wx/sstream.h>

#include "guipkg/proppanel.h"
#include "guipkg/sourceeditctrl.h"

#include "wxp/package.h"
#include "wxp/wxp.h"
#include "wxp/packagewxp.h"



// ----------------------------------------------------------------------------
// wxPackagePropertiesPanel - xml source stuff
// ----------------------------------------------------------------------------

void wxPackagePropertiesPanel::InitXMLSourcePage()
{
    m_pEditor = new wxPackageSourceEditCtrl(m_pXMLPanel, -1);
    m_pXMLSizer->Add(m_pEditor, 1, wxGROW|wxALL, 5);

    m_pEditor->SetToolTip(_("This is the read-only XML source for the package description file (WXP) which will be created when you use the 'Save' command."));
}

void wxPackagePropertiesPanel::UpdateXML()
{
    // use updated data
    TransferDataFromWindow();

    // save XML description to a wxString
    wxStringOutputStream out;
    m_xmlDescriptor.SetPackageInfo(GetPackageInfo());
    if (!m_xmlDescriptor.Save(out))
    {
        wxLogError(wxT("Could not create an XML description for this package!"));
        return;
    }

    // update XML source page
    m_pEditor->UpdateSource(out.GetString());
}



// ----------------------------------------------------------------------------
// wxPackagePropertiesPanel - event handlers
// ----------------------------------------------------------------------------

void wxPackagePropertiesPanel::OnPageChanged(wxNotebookEvent &ev)
{
    // we are only interested to this event when the user
    // selects the XML source page
    if (ev.GetSelection() != wxPROPPANEL_XMLSOURCE_PAGE_INDEX)
        return;

    UpdateXML();
}
