|
/**********************************************************************
UML StateWizard provides its software under the LGPL License and
zlib/libpng License.
Email us at info@intelliwizard.com for any information, suggestions and
feature requestions.
Home Page: http://www.intelliwizard.com
*************************************************************************/
// CreateEventIdFileDlg.cpp : implementation file
//
#include "stdafx.h"
#include "StateTree.h"
#include "CreateEventIdFileDlg.h"
// CreateEventIdFileDlg.cpp : implementation file
//
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCreateEventIdFileDlg dialog
CCreateEventIdFileDlg::CCreateEventIdFileDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCreateEventIdFileDlg::IDD, pParent)
{
// m_pApplication = pApp;
//{{AFX_DATA_INIT(CCreateEventIdFileDlg)
m_eventIdFilename = _T("");
m_otherPrjSelSeq = -1;
//}}AFX_DATA_INIT
}
void CCreateEventIdFileDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCreateEventIdFileDlg)
DDX_Control(pDX, IDC_CUR_PRJ_STATIC, m_curPrjStatic);
DDX_Control(pDX, IDC_OTR_PRJ_LIST_BOX, m_otherPrjListBox);
DDX_Control(pDX, IDC_FILE_NAME_EDIT, m_filename_edit);
DDX_Text(pDX, IDC_FILE_NAME_EDIT, m_eventIdFilename);
DDX_CBIndex(pDX, IDC_OTR_PRJ_LIST_BOX, m_otherPrjSelSeq);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCreateEventIdFileDlg, CDialog)
//{{AFX_MSG_MAP(CCreateEventIdFileDlg)
ON_BN_CLICKED(IDC_NO_BUTTON, OnNoButton)
ON_BN_CLICKED(IDC_YES_BUTTON, OnYesButton)
ON_BN_CLICKED(IDC_CUR_PRJ_BUTTON, OnCurPrjButton)
ON_BN_CLICKED(IDC_OTR_PRJ_BUTTON, OnOtrPrjButton)
ON_EN_CHANGE(IDC_FILE_NAME_EDIT, OnChangeFileNameEdit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCreateEventIdFileDlg message handlers
void CCreateEventIdFileDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
if (((CButton*)GetDlgItem(IDC_YES_BUTTON))->GetCheck() == 1)
{
// Confirm event id file name is not empty
m_eventIdFilename.TrimLeft();
m_eventIdFilename.TrimRight();
// Confirm to get legal project name to contain event id file
CString sPrjName;
if (((CButton*)GetDlgItem(IDC_OTR_PRJ_BUTTON))->GetCheck() == 1)
{
if (m_otherPrjSelSeq == -1)
{
AfxMessageBox("Please choose a project to contain new event identifier file", MB_ICONERROR|MB_OK);
return;
}
m_otherPrjListBox.GetLBText(m_otherPrjSelSeq ,sPrjName);
}
else
m_curPrjStatic.GetWindowText(sPrjName);
// Check file list in the selected project to be sure the unique of event id file name
//!!! Update Interface
BSTR bstrPrjName = _com_util::ConvertStringToBSTR(sPrjName.GetBuffer());
m_pStateTree->Fire_GetProjectDir(bstrPrjName);
sPrjName.ReleaseBuffer();
char* lpszPrjPath = _com_util::ConvertBSTRToString(m_pStateTree->data.prjDir);
CString strPrjPath(lpszPrjPath);
delete[] lpszPrjPath;
CString sPrjFullPath;
sPrjFullPath = strPrjPath+"\\"+sPrjName+PRJ_FILE_SUF;
CStringArray PrjFileList;
PrjFileList.RemoveAll();
m_pStateTree->Fire_GetProjectFileList(bstrPrjName);
//!!! Update Interface
BSTR bstrPrjFullPath = _com_util::ConvertStringToBSTR(sPrjFullPath.GetBuffer());
sPrjFullPath.ReleaseBuffer();
//!!! From vector to CStringArray
m_pStateTree->data.Convert2StringArray(PrjFileList,m_pStateTree->data.prjFileList);
int nSeq = 0;
int nSize = (int)PrjFileList.GetSize();
BOOL bFileFound = FALSE;
// Check whether current file name is exsited in chosen project
while (true)
{
if (nSeq == nSize)
break;
int idx = PrjFileList[nSeq].ReverseFind('\\');
CString sPrjFileName = PrjFileList[nSeq].Right(PrjFileList[nSeq].GetLength()-idx-1);
if (m_eventIdFilename.CompareNoCase(sPrjFileName) == 0)
{
bFileFound = TRUE;
break;
}
nSeq++;
}
if (bFileFound == TRUE)
{
CString sWarning = "The file:";
sWarning += m_eventIdFilename;
sWarning += " has already existed in the project:";
sWarning += sPrjName;
sWarning += ".";
AfxMessageBox(sWarning, MB_ICONERROR|MB_OK);
return;
}
CString sEventIdFileFullPath = strPrjPath+"\\"+m_eventIdFilename;
CStdioFile EventIdHdrFile;
if (EventIdHdrFile.Open(LPCTSTR(sEventIdFileFullPath),CFile::modeRead| CFile::typeText ))
{
EventIdHdrFile.Close();
AfxMessageBox(_T("The file: "+(CString)sEventIdFileFullPath + " already exists."), MB_ICONERROR|MB_OK);
return;
}
CString sEventIdFileRelativePath = ".\\";
sEventIdFileRelativePath += m_eventIdFilename;
//!!! Update Interface
//!!! From LPCTSTR to BSTR
BSTR bstrEventIdFileFullPath=_com_util::ConvertStringToBSTR(sEventIdFileFullPath.GetBuffer());
m_pStateTree->Fire_CreateServiceFile(bstrEventIdFileFullPath);
sEventIdFileFullPath.ReleaseBuffer();
//!!! Update Interface
bstrPrjName=_com_util::ConvertStringToBSTR(sPrjName.GetBuffer());
m_pStateTree->Fire_AddSrcHdrFilesToPrj(bstrPrjName, CComBSTR(NULL), CComBSTR(NULL),CComBSTR(bstrEventIdFileFullPath));
sPrjName.ReleaseBuffer();
m_pStateTree->m_EventIdList.RemoveAll();
m_pStateTree->m_EventIdFilePath = sEventIdFileFullPath;
//!!! Update Interface
//!!! From CString to BSTR & From CStringArray to VARIANT pointer
CComVariant pEventIdList;
pEventIdList.puintVal=reinterpret_cast<UINT*>(&m_pStateTree->m_EventIdList);
m_pStateTree->Fire_GetEventIdList(bstrEventIdFileFullPath,pEventIdList);
m_pStateTree->data.Convert2StringArray(m_pStateTree->m_EventIdList, m_pStateTree->data.eventIdList);
}
CDialog::OnOK();
}
void CCreateEventIdFileDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
BOOL CCreateEventIdFileDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// Set check on check box for yes button
((CButton*)GetDlgItem(IDC_YES_BUTTON))->SetCheck(1);
((CButton*)GetDlgItem(IDC_NO_BUTTON))->SetCheck(0);
((CButton*)GetDlgItem(IDC_CUR_PRJ_BUTTON))->SetCheck(1);
((CButton*)GetDlgItem(IDC_OTR_PRJ_BUTTON))->SetCheck(0);
m_otherPrjListBox.EnableWindow(FALSE);
m_filename_edit.SetWindowText(EVENT_ID_FILE_NAME);
// Get the current project name
//!!! Update Interface
m_pStateTree->Fire_GetActiveProjectName();
//!!! From BSTR to _bstr_t
char* lpszCurPrjNam = _com_util::ConvertBSTRToString(m_pStateTree->data.activePrjName);
CString sCurPrjName = lpszCurPrjNam;
delete[] lpszCurPrjNam;
m_curPrjStatic.SetWindowText(sCurPrjName);
// Get project name list
CStringArray sPrjPathList;
sPrjPathList.RemoveAll();
// Get project full path list in the workspace/solution
//!!! Update Interface
m_pStateTree->Fire_GetProjectList();
//!!! From vector to CStringArray
m_pStateTree->data.Convert2StringArray(sPrjPathList,m_pStateTree->data.prjNameList);
long lPrjCount = (long)sPrjPathList.GetSize();
long nSeq;
CString sPrjName;
for (nSeq = 0; nSeq < lPrjCount; nSeq++)
{
sPrjName = sPrjPathList[nSeq];
/* Project name is not the full path file name.
int idx = sPrjName.ReverseFind('\\');
sPrjName = sPrjName.Right(sPrjName.GetLength()-idx-1);
sPrjName.Replace(PRJ_FILE_SUF, NULL);
sPrjName.TrimRight();
*/
if (sPrjName.CompareNoCase(sCurPrjName) != 0)
m_otherPrjListBox.InsertString(-1, (LPCTSTR)sPrjName);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCreateEventIdFileDlg::OnNoButton()
{
// TODO: Add your control notification handler code here
((CButton*)GetDlgItem(IDC_YES_BUTTON))->SetCheck(0);
((CButton*)GetDlgItem(IDC_NO_BUTTON))->SetCheck(1);
((CButton*)GetDlgItem(IDC_CUR_PRJ_BUTTON))->EnableWindow(FALSE);
((CButton*)GetDlgItem(IDC_OTR_PRJ_BUTTON))->EnableWindow(FALSE);
m_curPrjStatic.EnableWindow(FALSE);
m_filename_edit.EnableWindow(FALSE);
m_filename_edit.SetWindowText("");
m_otherPrjListBox.EnableWindow(FALSE);
m_otherPrjListBox.SetCurSel(-1);
((CStatic*)GetDlgItem(IDC_FILE_NAME_STATIC))->EnableWindow(FALSE);
((CStatic*)GetDlgItem(IDC_NEW_FILE_INFO))->EnableWindow(FALSE);
((CButton*)GetDlgItem(IDOK))->EnableWindow(TRUE);
}
void CCreateEventIdFileDlg::OnYesButton()
{
// TODO: Add your control notification handler code here
((CButton*)GetDlgItem(IDC_YES_BUTTON))->SetCheck(1);
((CButton*)GetDlgItem(IDC_NO_BUTTON))->SetCheck(0);
((CButton*)GetDlgItem(IDC_CUR_PRJ_BUTTON))->SetCheck(1);
((CButton*)GetDlgItem(IDC_CUR_PRJ_BUTTON))->EnableWindow(TRUE);
((CButton*)GetDlgItem(IDC_OTR_PRJ_BUTTON))->EnableWindow(TRUE);
m_curPrjStatic.EnableWindow(TRUE);
m_filename_edit.EnableWindow(TRUE);
m_filename_edit.SetWindowText(EVENT_ID_FILE_NAME".h");
m_otherPrjListBox.EnableWindow(FALSE);
((CStatic*)GetDlgItem(IDC_FILE_NAME_STATIC))->EnableWindow(TRUE);
((CStatic*)GetDlgItem(IDC_NEW_FILE_INFO))->EnableWindow(TRUE);
}
void CCreateEventIdFileDlg::OnCurPrjButton()
{
// TODO: Add your control notification handler code here
((CButton*)GetDlgItem(IDC_YES_BUTTON))->SetCheck(1);
((CButton*)GetDlgItem(IDC_CUR_PRJ_BUTTON))->SetCheck(1);
((CButton*)GetDlgItem(IDC_OTR_PRJ_BUTTON))->SetCheck(0);
m_otherPrjListBox.EnableWindow(FALSE);
}
void CCreateEventIdFileDlg::OnOtrPrjButton()
{
// TODO: Add your control notification handler code here
((CButton*)GetDlgItem(IDC_YES_BUTTON))->SetCheck(1);
((CButton*)GetDlgItem(IDC_CUR_PRJ_BUTTON))->SetCheck(0);
((CButton*)GetDlgItem(IDC_OTR_PRJ_BUTTON))->SetCheck(1);
m_otherPrjListBox.EnableWindow(TRUE);
}
void CCreateEventIdFileDlg::OnChangeFileNameEdit()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
static BOOL bAddSuffix = FALSE;
m_eventIdFilename.TrimLeft();
m_eventIdFilename.TrimRight();
if (m_eventIdFilename.IsEmpty())
bAddSuffix = FALSE;
int idx = m_eventIdFilename.Find(".h");
int len = m_eventIdFilename.GetLength();
if (idx == -1 || (m_eventIdFilename[len-1] != 'h' || m_eventIdFilename[len-2] != '.'))
bAddSuffix = FALSE;
if (bAddSuffix == FALSE)
{
CString sText = m_eventIdFilename+".h";
bAddSuffix = TRUE;
m_filename_edit.SetWindowText(sText);
m_filename_edit.SetSel(sText.GetLength()-2,sText.GetLength()-2); // Move cursor
}
if (m_eventIdFilename.CompareNoCase(".h") == 0)
{
((CButton*)GetDlgItem(IDOK))->EnableWindow(FALSE);
}
else
((CButton*)GetDlgItem(IDOK))->EnableWindow(TRUE);
}
|
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.