📄 wxsproject.cpp
字号:
#include "wxsheaders.h"
#include "wxsproject.h"
#include "widget.h"
#include "defwidgets/wxsstdmanager.h"
#include "defwidgets/wxsdialog.h"
#include "resources/wxswindowres.h"
#include "wxswidgetfactory.h"
#include "wxsmith.h"
#include <wx/string.h>
#define XML_DIALOG_STR "dialog"
#define XML_FRAME_STR "frame"
#define XML_PANEL_STR "panel"
#define XML_FNAME_STR "wxs_file"
#define XML_CNAME_STR "class"
#define XML_SFILE_STR "src_file"
#define XML_HFILE_STR "header_file"
#define XML_XRCFILE_STR "xrc_file"
#define XML_EDITMODE_STR "edit_mode"
wxsProject::wxsProject(): Integration(NotBinded), Project(NULL), DuringClear(false)
{}
wxsProject::~wxsProject()
{
Clear();
}
wxsProject::IntegrationState wxsProject::BindProject(cbProject* Proj)
{
Clear();
/* creating new node in resource tree */
wxTreeCtrl* ResTree = wxsTREE();
ResTree->Expand(ResTree->GetRootItem());
TreeItem = ResTree->AppendItem(ResTree->GetRootItem(),Proj->GetTitle());
/* Binding project object */
if ( Proj && !Proj->IsLoaded() )
{
Proj = NULL;
}
Project = Proj;
if ( !Proj )
{
return Integration = NotBinded;
}
/* Checkign association of C::B project with wxS project */
ProjectPath.Assign(Proj->GetFilename());
WorkingPath = ProjectPath;
WorkingPath.AppendDir(wxSmithSubDirectory);
WorkingPath.SetName(wxSmithMainConfigFile);
WorkingPath.SetExt(_T(""));
WorkingPath.Assign(WorkingPath.GetFullPath()); // Reparsing path
if ( ! WorkingPath.FileExists() )
{
return Integration = NotWxsProject;
}
/* Trying to read configuration data */
TiXmlDocument Doc(WorkingPath.GetFullPath().mb_str());
if ( !Doc.LoadFile() )
{
return Integration = NotWxsProject;
}
TiXmlNode* MainNode = Doc.FirstChild("wxsmith");
if ( MainNode == NULL || ! LoadFromXml(MainNode) )
{
return Integration = NotWxsProject;
}
BuildTree(ResTree,TreeItem);
return Integration = Integrated;
}
inline void wxsProject::Clear()
{
DuringClear = true;
Integration = NotBinded;
WorkingPath.Clear();
ProjectPath.Clear();
for ( DialogListI i = Dialogs.begin(); i!=Dialogs.end(); ++i )
{
if ( *i )
{
delete *i;
*i = NULL;
}
}
for ( FrameListI i = Frames.begin(); i!=Frames.end(); ++i )
{
if ( *i )
{
delete *i;
*i = NULL;
}
}
for ( PanelListI i = Panels.begin(); i!=Panels.end(); ++i )
{
if ( *i )
{
delete *i;
*i = NULL;
}
}
Dialogs.clear();
Frames.clear();
Panels.clear();
if ( Project ) wxsTREE()->Delete(TreeItem);
Project = NULL;
wxsTREE()->Refresh();
DuringClear = false;
}
void wxsProject::BuildTree(wxTreeCtrl* Tree,wxTreeItemId WhereToAdd)
{
DialogId = Tree->AppendItem(WhereToAdd,_("Dialog resources"));
FrameId = Tree->AppendItem(WhereToAdd,_("Frame resources"));
PanelId = Tree->AppendItem(WhereToAdd,_("Panel resources"));
for ( DialogListI i = Dialogs.begin(); i!=Dialogs.end(); ++i )
{
(*i)->BuildTree(Tree,DialogId,true);
}
for ( FrameListI i = Frames.begin(); i!=Frames.end(); ++i )
{
(*i)->BuildTree(Tree,FrameId,true);
}
for ( PanelListI i = Panels.begin(); i!=Panels.end(); ++i )
{
(*i)->BuildTree(Tree,PanelId,true);
}
Tree->Refresh();
}
bool wxsProject::LoadFromXml(TiXmlNode* MainNode)
{
TiXmlElement* Elem;
// Loading dialog resources
for ( Elem = MainNode->FirstChildElement(XML_DIALOG_STR);
Elem;
Elem = Elem->NextSiblingElement(XML_DIALOG_STR) )
{
wxString Mode = wxString(Elem->Attribute(XML_EDITMODE_STR),wxConvUTF8);
wxString Xrc = ( Mode == _T("Source") ) ? _T("") : wxString ( Elem->Attribute(XML_XRCFILE_STR), wxConvUTF8 );
AddDialogResource(
wxString ( Elem->Attribute(XML_FNAME_STR), wxConvUTF8 ),
wxString ( Elem->Attribute(XML_CNAME_STR), wxConvUTF8 ),
wxString ( Elem->Attribute(XML_SFILE_STR), wxConvUTF8 ),
wxString ( Elem->Attribute(XML_HFILE_STR), wxConvUTF8 ),
Xrc );
}
// Loading frame resources
for ( Elem = MainNode->FirstChildElement(XML_FRAME_STR);
Elem;
Elem = Elem->NextSiblingElement(XML_FRAME_STR) )
{
wxString Mode = wxString(Elem->Attribute(XML_EDITMODE_STR),wxConvUTF8);
wxString Xrc = ( Mode == _T("Source") ) ? _T("") : wxString ( Elem->Attribute(XML_XRCFILE_STR), wxConvUTF8 );
AddFrameResource(
wxString ( Elem->Attribute(XML_FNAME_STR), wxConvUTF8 ),
wxString ( Elem->Attribute(XML_CNAME_STR), wxConvUTF8 ),
wxString ( Elem->Attribute(XML_SFILE_STR), wxConvUTF8 ),
wxString ( Elem->Attribute(XML_HFILE_STR), wxConvUTF8 ),
Xrc );
}
// Loading panel resources
for ( Elem = MainNode->FirstChildElement(XML_PANEL_STR);
Elem;
Elem = Elem->NextSiblingElement(XML_PANEL_STR) )
{
wxString Mode = wxString(Elem->Attribute(XML_EDITMODE_STR),wxConvUTF8);
wxString Xrc = ( Mode == _T("Source") ) ? _T("") : wxString ( Elem->Attribute(XML_XRCFILE_STR), wxConvUTF8 );
AddPanelResource(
wxString ( Elem->Attribute(XML_FNAME_STR), wxConvUTF8 ),
wxString ( Elem->Attribute(XML_CNAME_STR), wxConvUTF8 ),
wxString ( Elem->Attribute(XML_SFILE_STR), wxConvUTF8 ),
wxString ( Elem->Attribute(XML_HFILE_STR), wxConvUTF8 ),
Xrc );
}
SetModified(false);
return true;
}
void wxsProject::AddDialogResource( const wxString& FileName, const wxString& ClassName, const wxString& SourceName, const wxString& HeaderName, const wxString& XrcName)
{
AddWindowResource(FileName,ClassName,SourceName,HeaderName,XrcName,_T("Dialog"));
}
void wxsProject::AddFrameResource( const wxString& FileName, const wxString& ClassName, const wxString& SourceName, const wxString& HeaderName, const wxString& XrcName)
{
AddWindowResource(FileName,ClassName,SourceName,HeaderName,XrcName,_T("Frame"));
}
void wxsProject::AddPanelResource(const wxString& FileName, const wxString& ClassName, const wxString& SourceName, const wxString& HeaderName, const wxString& XrcName)
{
AddWindowResource(FileName,ClassName,SourceName,HeaderName,XrcName,_T("Panel"));
}
void wxsProject::AddWindowResource(
const wxString& FileName,
const wxString& ClassName,
const wxString& SourceName,
const wxString& HeaderName,
const wxString& XrcName,
const wxString& Type)
{
if ( !FileName || !ClassName || !SourceName || !HeaderName )
return;
if ( !CheckProjFileExists(SourceName) )
{
Manager::Get()->GetMessageManager()->Log(_("Couldn't find source file '%s'"),SourceName.c_str());
Manager::Get()->GetMessageManager()->Log(_("Not all resources will be loaded"));
return;
}
if ( !CheckProjFileExists(HeaderName) )
{
Manager::Get()->GetMessageManager()->Log(_("Couldn't find header file '%s'"),HeaderName.c_str());
Manager::Get()->GetMessageManager()->Log(_("Not all resources will be loaded"));
return;
}
/* Creating resource */
wxString RealFileName = GetInternalFileName(FileName);
wxsWindowRes* Res = NULL;
int EditMode = !XrcName ? wxsResSource : (wxsResSource | wxsResFile);
if ( Type == _T("Dialog") )
{
Res = new wxsDialogRes(this,EditMode,ClassName,RealFileName,SourceName,HeaderName,XrcName);
}
else if ( Type == _T("Panel") )
{
Res = new wxsPanelRes(this,EditMode,ClassName,RealFileName,SourceName,HeaderName,XrcName);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -