📄 visualjava.cpp
字号:
}
}
else
{
TRACE0("Error: Can not find a view for document to activate.\n");
}return ;
}
if(pBestTemplate == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_OPEN_DOC);
return ;
}
CVisualJavaDoc* pDoc = (CVisualJavaDoc*)pBestTemplate->CreateNewDocument();
pDoc->m_bAutoDelete = FALSE;
CChildFrame* pChildFrm = (CChildFrame*)pBestTemplate->CreateNewFrame(pDoc,NULL);
pDoc->m_bAutoDelete = TRUE;
if(!pChildFrm)
{
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
delete pDoc;
}
else
{
//make document connection
pBuf->m_pOwnerDoc = pDoc;
pDoc->init(pBuf);
CWaitCursor wait;
if(!pDoc->OnOpenDocument(szPath))
{
// user has be alerted to what failed in OnOpenDocument
TRACE0("CDocument::OnOpenDocument returned FALSE.\n");
pChildFrm->DestroyWindow();return;
}
pDoc->SetPathName(szPath);
pBestTemplate->InitialUpdateFrame(pChildFrm,pDoc,TRUE);
}*/
}
void CVisualJavaApp::CreateProject(CString strAppName,CString szpPath,
BOOL bCreateWorkSpc,UINT nProjectType,UINT nAppType /*=0*/,
UINT nFrmType /*=0*/)
{
CString strPath;
if(int pos = szpPath.Find(':') >-1)//remove drive letter for generalization
{
++pos;
strPath = szpPath.Right(szpPath.GetLength()-pos);
}
if(bCreateWorkSpc)//if a new workspace was asked to be created, then close current workspace
{
if(CVisualJavaApp::m_pCurWorkSpace != NULL)
{
//close current workspace
//CVisualJavaApp::m_pCurWorkSpace
CMainFrame *pFrm = (CMainFrame*)AfxGetApp()->GetMainWnd();
pFrm->CloseWorkSpace();
CVisualJavaApp::m_pCurWorkSpace = NULL;
}
}
//create workspace if one is needed or requested
if(CVisualJavaApp::m_pCurWorkSpace == NULL)
{
#define CREATE_PROJECT TRUE
CWorkSpace wsp;
wsp.CreateWorkSpc(strAppName,strPath,CREATE_PROJECT);
}
else
{
CVisualJavaApp::m_pCurWorkSpace->CreateProject(strAppName,strPath);
}
//now load the necessary application template code
//create main java file associated with new project
CString szpMainFile = strPath+strAppName+".java";
//insert approprite code template
if(nProjectType == PRO_CONSOLE)
{
//when resource are included exclude resource support for this kinda app
m_pCodeTemplates->WriteTemplate(CT_CONSOLE_APP,strAppName,szpMainFile);
}
else
if(nProjectType == PRO_AWT)//use old abstract window toolkit
{
if(nAppType == APP_FRAME)
{
if(nFrmType == FRM_EDITOR)//simple text editor
m_pCodeTemplates->WriteTemplate(CT_FRAME_APP_EDITOR_AWT,strAppName,szpMainFile);
else
if(nFrmType == FRM_MENUBAR)//just menu support
m_pCodeTemplates->WriteTemplate(CT_FRAME_APP_MENUBAR_AWT,strAppName,szpMainFile);
else
if(nFrmType == FRM_TOOLBAR)//toolbar support
m_pCodeTemplates->WriteTemplate(CT_FRAME_APP_TOOLBAR_AWT,strAppName,szpMainFile);
}
else
if(nAppType == APP_DIALOG)
m_pCodeTemplates->WriteTemplate(CT_DIALOG_APP_AWT,strAppName,szpMainFile);
else
if(nAppType == APP_APPLET)
m_pCodeTemplates->WriteTemplate(CT_APPLET_APP,strAppName,szpMainFile);
}
else
if(nProjectType == PRO_SWING)//use the swing api
{
if(nAppType == APP_FRAME)
{
if(nFrmType == FRM_EDITOR)//simple text editor
m_pCodeTemplates->WriteTemplate(CT_FRAME_APP_EDITOR_SWING,strAppName,szpMainFile);
else
if(nFrmType == FRM_MENUBAR)//just menu support
m_pCodeTemplates->WriteTemplate(CT_FRAME_APP_MENUBAR_SWING,strAppName,szpMainFile);
else
if(nFrmType == FRM_TOOLBAR)//toolbar support
m_pCodeTemplates->WriteTemplate(CT_FRAME_APP_TOOLBAR_SWING,strAppName,szpMainFile);
}
else
if(nAppType == APP_DIALOG)
m_pCodeTemplates->WriteTemplate(CT_DIALOG_APP_SWING,strAppName,szpMainFile);
else
if(nAppType == APP_APPLET)
m_pCodeTemplates->WriteTemplate(CT_APPLET_APP,strAppName,szpMainFile);
}
//open newly created project
if(CVisualJavaApp::m_pCurWorkSpace == NULL)
{
CVisualJavaApp::m_pCurWorkSpace = new CWorkSpace;
if(CVisualJavaApp::m_pCurWorkSpace->OpenWorkSpc(strPath+strAppName+"Workspace.xml",(CTreeCtrl*)CWorkSpaceBar::m_pwndFileView))
{
}
else
{
delete CVisualJavaApp::m_pCurWorkSpace;
CVisualJavaApp::m_pCurWorkSpace = NULL;
}
}
else
CVisualJavaApp::m_pCurWorkSpace->OpenProject(strPath+strAppName+"Project.xml",(CTreeCtrl*)CWorkSpaceBar::m_pwndFileView);
}
void CVisualJavaApp::CreateNewFile(CString szpName,CString szpPath,
CString szpProject,CString szpExt)
{
CString strPathName = szpPath;
strPathName += szpName+szpExt;
//strPathName += szpName
CStdioFile reader_writer;
if(reader_writer.Open(strPathName,CFile::modeCreate))
{
reader_writer.Close();
OpenDocumentFile(strPathName);
//CProject* pProj = m_pCurWorkSpace->getProject(szpProject);
//if(pProj != NULL)
{
//pProj->AddFile(szpName,szpPath,
}
}
}
//create empty workspace
void CVisualJavaApp::CreateWorkSpc(CString szpName,CString szpPath)
{
CVisualJavaApp::m_pCurWorkSpace = new CWorkSpace;
CVisualJavaApp::m_pCurWorkSpace->CreateWorkSpc(szpName,szpPath);
//CVisualJavaApp::m_pCurWorkSpace->OpenWorkSpc(szpPath+"\\"+szpName+".dsw",&CWorkSpcBase::m_wndFileView);
}
CVisualJavaDoc* CVisualJavaApp::GetDocument(CString szpPath,
CDocTemplate* pTemplate /*=NULL*/)
{
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate *pTempl, *pBestTemplate = NULL;
CDocument *pOpenDocument = NULL;
CDocTemplate::Confidence match;
int nIndex = 0;
while(pos)
{
pTempl = GetNextDocTemplate (pos);
ASSERT_KINDOF(CDocTemplate, pTempl);
ASSERT (pOpenDocument == NULL);
match = pTempl->MatchDocType (szpPath, pOpenDocument);
if(match == CDocTemplate::yesAlreadyOpen)
break;
if (nIndex++ == 0)
pBestTemplate = pTempl;
}
/*
CDocTemplate* pTmp = GetNextDocTemplate(nPos);
for(nPos = pTmp->GetFirstDocPosition();nPos != NULL;)
{
CDocument* pDoc = pTmp->GetNextDoc(nPos);
CString strFile = pDoc->GetPathName();
//remove drive letter
int p = strFile.Find(':');
if(p != -1)
strFile = strFile.Mid(p+1,strFile.GetLength()-(p+1));
if(strFile.Compare(szpPath) == 0)
{
//if(pTemplate != NULL)//not yet...
pTemplate = pTmp;
return (CVisualJavaDoc*)pDoc;
}
}*/return (CVisualJavaDoc*)pOpenDocument;
}
void CVisualJavaApp::LoadJavaApi()
{
//m_pJavaApiTool->loadPackages(&m_lPackages);
}
void CVisualJavaApp::Tokenize(CStringList* plOutPut,CString strString,
char nDelim)
{
CString strText(strString);
int nLen = strText.GetLength();
CString strToken;
for(int I=0; I<nLen; I++)
{
if(strText[I] == nDelim)
{
if(!strToken.IsEmpty())
{
plOutPut->AddTail(strToken);
strToken.Empty();
}
}
else
strToken += strText[I];
}
if(!strToken.IsEmpty())
plOutPut->AddTail(strToken);
}
void CVisualJavaApp::LoadXML(CString strPath,XMLELEMENT_LIST* pOutList)
{
// Line allocation granularity
#define CHAR_ALIGN 16
#define ALIGN_BUF_SIZE(size) ((size) / CHAR_ALIGN) * CHAR_ALIGN + CHAR_ALIGN;
static long bufsize = 0;
CStdioFile reader;
if(!reader.Open(strPath,CFile::modeRead))
return;
bufsize = reader.GetLength();
bufsize = ALIGN_BUF_SIZE(bufsize);
TCHAR* pBuf = new TCHAR[bufsize];
memset(pBuf,'\0',bufsize);
TCHAR* pBufSave = pBuf;
CString strLine;
while(reader.ReadString(strLine))
{
strLine.TrimLeft();strLine.TrimRight();
int count = strLine.GetLength();
LPSTR lszpBuf = strLine.GetBuffer(count);
memcpy(pBuf,lszpBuf,count*sizeof(TCHAR));
pBuf += (count*sizeof(TCHAR));
strLine.ReleaseBuffer();
}
reader.Close();
CMiniXMLParser xmlParser(pBufSave,_tcslen(pBufSave));
if(xmlParser.parse())
{
XMLELEMENT_LIST *pList = xmlParser.getXmlTree();
for(POSITION pos = pList->GetHeadPosition(); pos !=NULL;)
pOutList->AddTail(pList->GetNext(pos));
pList->RemoveAll();
}
free(pBufSave);
}
void CVisualJavaApp::DestroyXML(XMLELEMENT_LIST* pList)
{
for(POSITION pos = pList->GetHeadPosition(); pos !=NULL;)
delete pList->GetNext(pos);
}
void CVisualJavaApp::OnFileNewproject()
{
CFileNewDlg sheet("New");
sheet.AddPages();
sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
sheet.DoModal();
}
void CVisualJavaApp::OnUpdateFileNewproject(CCmdUI* pCmdUI)
{
pCmdUI->Enable();
}
void CVisualJavaApp::AddJavaDocToTemplate(CDocument* pDoc)
{
GetJavaDocTemplate()->AddDocument(pDoc);
}
CDocTemplate* CVisualJavaApp::GetJavaDocTemplate()
{
POSITION pos = this->GetFirstDocTemplatePosition();
return this->GetNextDocTemplate(pos);
}
CJavaDeclManager* CVisualJavaApp::findDeclMgr(CString strSrcFile)
{
for(POSITION nPos = CVisualJavaApp::m_lGlobalDeclarationList.GetHeadPosition(); nPos != NULL;)
{
CJavaDeclManager *pDeclMgr = CVisualJavaApp::m_lGlobalDeclarationList.GetNext(nPos);
if(pDeclMgr->GetPathName().Compare(strSrcFile) == 0)
return pDeclMgr;
}return NULL;
}
void CVisualJavaApp::addDeclMgr(CJavaDeclManager *pDeclMgr)
{
CVisualJavaApp::findAndFree(pDeclMgr->getSourceFile());//if a declaration manager already exist
//remove it in preference to a dynamic one
CVisualJavaApp::m_lGlobalDeclarationList.AddTail(pDeclMgr);
}
void CVisualJavaApp::findAndFree(CString strSource)
{
for(POSITION nPos = CVisualJavaApp::m_lGlobalDeclarationList.GetHeadPosition(); nPos != NULL;)
{
POSITION nCurPos = nPos;
CJavaDeclManager *pDeclMgr = CVisualJavaApp::m_lGlobalDeclarationList.GetNext(nPos);
if(pDeclMgr->getSourceFile().Compare(strSource) == 0)
{
DECL_PTRLIST* pExportList = pDeclMgr->getExportList();
for(POSITION xPos = pExportList->GetHeadPosition(); xPos != NULL;)
pExportList->GetNext(xPos)->removeImport(pDeclMgr);
/**delete pDeclMgr;**/
CVisualJavaApp::m_lGlobalDeclarationList.RemoveAt(nCurPos);
return;
}
}
}
void CVisualJavaApp::removeDeclMgr(CJavaDeclManager* pDeclMgr)
{
POSITION nPos = CVisualJavaApp::m_lGlobalDeclarationList.Find(pDeclMgr);
if(nPos != NULL)
{
DECL_PTRLIST* pExportList = pDeclMgr->getExportList();
for(POSITION xPos = pExportList->GetHeadPosition(); xPos != NULL;)
pExportList->GetNext(xPos)->removeImport(pDeclMgr);
CVisualJavaApp::m_lGlobalDeclarationList.RemoveAt(nPos);
}
}
void CVisualJavaApp::OnAddDeclMgr(DWORD pdata)
{
CVisualJavaApp::addDeclMgr((CJavaDeclManager*)pdata);
}
BOOL BuildTypePath(CJavaDeclManager* pDeclMgr,CString strBasePath,CString &strType)
{
//presume ,fully qualified typename, meaning:
//"PackageName_0.PackageName_1.PackageName_n.TypeName";
if(strType.Find('.') >-1)
{
CString strName = strType;
strName.Replace('.','\\');
strName = strBasePath+"\\"+strName+".java";
strType = strName;return TRUE;
}
DECL_LIST* pList = pDeclMgr->getDeclList();
for(POSITION pos = pList->GetHeadPosition(); pos !=NULL;)
{
__CBaseDecl* pDecl = pList->GetNext(pos);
if(pDecl->getKind() == IMPORT_DECL)
{
CImportDecl* pImport = (CImportDecl*)pDecl;
CString strName = pImport->getDeclName();
CString strImportedType;
for(int i = strName.GetLength()-1;i>=0; i--)
{
if(strName[i] == '.')break;
strImportedType.Insert(0,strName[i]);
}
if(strName[strName.GetLength()-1] == '*')
{
strName.Remove('*');
strName.Replace('.','\\');
strName = strBasePath+"\\"+strName+"\\"+strType+".java";
CFileFind finder;
if(finder.FindFile(strName))
{
strType = strName;return TRUE;
}
}
else
if(strImportedType.Compare(strType) == 0)
{
strName.Replace('.','\\');
strName = strBasePath+"\\"+strName+".java";
CFileFind finder;
if(finder.FindFile(strName))
{
strType = strName;return TRUE;
}
}
}else break;
}return FALSE;
}
void CVisualJavaApp::AddBFmap(back_to_front_map* pMap)
{
m_lParsingMap.AddTail(pMap);
}
void CVisualJavaApp::RemoveBFmap(back_to_front_map* pMap)
{
m_lParsingMap.RemoveAt(m_lParsingMap.Find(pMap));
}
//////////////////////////////////////////////////////////////////////////////////
//Description: //
// this function searches for the map associated with the file being //
// edited. It allows for a really neat separation between back-end //
// parsing and front-end veiw. Files can be opened,closed,relaoded, and//
// edited without any further colaboration with back-end. //
//////////////////////////////////////////////////////////////////////////////////
void CVisualJavaApp::SendEditMsg(CString strFile,const UINT msgID
,__CEditContext* pEditContext)
{
int p = strFile.Find(':');
if(p != -1)
strFile = strFile.Mid(p+1,strFile.GetLength()-(p+1));
DWORD idThread = 0;
for(POSITION pos = m_lParsingMap.GetHeadPosition(); pos != NULL;)
{
back_to_front_map* pMap = (back_to_front_map*)m_lParsingMap.GetNext(pos);
if(pMap->m_strFile.Compare(strFile) == 0)
idThread = pMap->m_nThreadID;
}
if(idThread)
::PostThreadMessage(idThread,msgID,(WPARAM)pEditContext,0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -