Click here to Skip to main content
15,896,557 members
Articles / Desktop Programming / ATL

CM_ConfigBuilder 1.2g: Visual Studio 6/Visual Studio 2005/Visual Studio 2008 Code Generator for Application Settings Graphic Management

Rate me:
Please Sign up or sign in to vote.
4.94/5 (126 votes)
12 Feb 2008CPOL17 min read 698.5K   9.8K   262  
CM_ConfigBuilder generates and compiles the required files to manage your application's settings/preferences and to store/retrieve them in XML format.
// ProjectDoc.cpp : implementation of the CProjectDoc class
//

#include "stdafx.h"
#include "AsCfgBuilder.h"

#include "ProjectDoc.h"
#include "XmlClassInfo.h"
#include "XmlBaseElement.h"
#include "XmlElementsFactory.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CProjectDoc

IMPLEMENT_DYNCREATE(CProjectDoc, CDocument)

BEGIN_MESSAGE_MAP(CProjectDoc, CDocument)
	//{{AFX_MSG_MAP(CProjectDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CProjectDoc construction/destruction

CProjectDoc::CProjectDoc():
	displayRootNode_(true)
{
	// TODO: add one-time construction code here

}

CProjectDoc::~CProjectDoc()
{
}

BOOL CProjectDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	CXmlElementsFactory::ResetIdCounter();
	project_.Clear();
	selectedItemId_ = project_.GetRootElement()->GetId();

	UpdateAllViews(NULL, enUpdateViewReason_DocLoaded);

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CProjectDoc serialization

void CProjectDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CProjectDoc diagnostics

#ifdef _DEBUG
void CProjectDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CProjectDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CProjectDoc commands

BOOL CProjectDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	
	bool ret;
	cmString tmp;

	tmp = lpszPathName;
	CoInitialize(NULL);
	project_.Clear();
	ret = project_.LoadFromXmlFile(tmp);
	CoUninitialize();
	if (ret) {
		selectedItemId_ = project_.GetRootElement()->GetId();
		UpdateAllViews(NULL, enUpdateViewReason_DocLoaded);
	} else {
		::MessageBox(NULL, project_.ParseErrorToString(), _T("Project Parse Error"), MB_OK);
	}
	
	return ret;
}

BOOL CProjectDoc::OnSaveDocument(LPCTSTR lpszPathName) 
{
	UpdateAllViews(NULL, enUpdateViewReason_BeforeSaveDoc);

	CoInitialize(NULL);
	cmString tmp;

	tmp = lpszPathName;
	project_.SaveToXmlFile(tmp);
	CoUninitialize();

	return TRUE;
}

void CProjectDoc::SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CDocument::SetPathName(lpszPathName, bAddToMRU);
}

void CProjectDoc::SetTitle(LPCTSTR lpszTitle) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	CDocument::SetTitle(lpszTitle);
}

void CProjectDoc::SetDisplayRootNode(bool displayRootNode)
{
	displayRootNode_ = displayRootNode;
}

bool CProjectDoc::GetDisplayRootNode() const
{
	return displayRootNode_;
}

void CProjectDoc::SetSelectedItemId(const cmString& id)
{
	selectedItemId_ = id;
}
	
cmString CProjectDoc::GetSelectedItemId() const
{
	return selectedItemId_;
}

CXmlBaseElement* CProjectDoc::GetElementById(const cmString& id)
{
	if (project_.GetRootElement()->GetId() == id)
		return project_.GetRootElement();

	return project_.GetRootElement()->GetMemberById(id);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Italy Italy
For all Stefano's latest code, binaries and tutorials visit www.codemachines.com

Comments and Discussions