📄 visualjava.cpp
字号:
// VisualJava.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "VisualJava.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "VisualJavaDoc.h"
#include "VisualJavaView.h"
#include "editcmd.h"
#include "memcombo.h"
#include "registry.h"
#include "editreg.h"
#include "editoroptionspage.h"
#include "fontpg.h"
#include "filesup.h"
#include "splash.h"
#include "tipdlg.h"
//#include "aboutdlg.h"
#include "edfopdlg.h"
#include "FileNewDlg.h"
#include "FileOpenDlgEx.h"
#include "WorkSpace.h"
#include "CodeTemplate.h"
#include "ToolRunner.h"
#include "xmlsupport.h"
#include "PopUpDocument.h"
#include "PopUpFrameWnd.h"
#include "PopUpView.h"
#include "JavaDeclManager.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int ListToString (CString &sResult, const CList<CString, LPCTSTR> &listSource)
{
POSITION pos = listSource.GetHeadPosition ();
CString item;
while (pos)
{
item = listSource.GetNext (pos);
sResult += item + _T ('\n');
}
return listSource.GetCount ();
}
int StringToList (CList<CString, LPCTSTR> &listResult, CString sSource)
{
int pos;
CString sItem;
while ((pos = sSource.Find (_T ('\n'))) != -1)
{
sItem = sSource.Left (pos);
if (!listResult.Find (sItem))
listResult.AddTail (sItem);
sSource = sSource.Mid (pos + 1);
}
if (*(LPCTSTR) sSource)
{
if (!listResult.Find (sSource))
listResult.AddTail (sSource);
}
return listResult.GetCount ();
}
/////////////////////////////////////////////////////////////////////////////
// CVisualJavaApp
BEGIN_MESSAGE_MAP(CVisualJavaApp, CWinApp)
//{{AFX_MSG_MAP(CVisualJavaApp)
ON_COMMAND(ID_FILE_NEWPROJECT, OnFileNewproject)
ON_UPDATE_COMMAND_UI(ID_FILE_NEWPROJECT, OnUpdateFileNewproject)
//}}AFX_MSG_MAP
ON_COMMAND (ID_APP_ABOUT, OnAppAbout)
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_FILE_OPEN, /*CWinApp::*/OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
ON_REGISTERED_THREAD_MESSAGE(m_msgAddToProjView,OnAddToProjectView)
ON_REGISTERED_THREAD_MESSAGE(m_msgRemoveFromProjView,OnRemoveFromProjectView)
ON_REGISTERED_THREAD_MESSAGE(m_msgMoveBlockInView,OnMoveBlockInView)
ON_REGISTERED_THREAD_MESSAGE(m_msgAddHeaderItem,OnAddHeaderItem)
ON_REGISTERED_THREAD_MESSAGE(m_msgRemoveHeaderItem,OnRemoveHeaderItem)
ON_REGISTERED_THREAD_MESSAGE(m_msgAddNewDeclMgr,OnAddDeclMgr)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVisualJavaApp construction
CWorkSpace *CVisualJavaApp::m_pCurWorkSpace = NULL;
CString CVisualJavaApp::m_strCurrentProject;
CList<CJavaDeclManager*,CJavaDeclManager*> CVisualJavaApp::m_lGlobalDeclarationList;
CList<back_to_front_map*,back_to_front_map*> CVisualJavaApp::m_lParsingMap;
CVisualJavaApp::CVisualJavaApp(): m_dwFlags (EP_OPEN_LAST_DOCS|EP_CREATE_NEW_DOC_IF_ALONE|EP_SAVE_SETS_ON_EXIT|EP_NOTIFY_CHANGES|EP_ADVANCED_UI|EP_REMEMBER_LASTPOS)
{
m_pToolRunner = new CToolRunner;
}
CVisualJavaApp::~CVisualJavaApp()
{
delete m_pCodeTemplates;
delete m_pToolRunner;
for(POSITION nPos = CVisualJavaApp::m_lGlobalDeclarationList.GetHeadPosition(); nPos != NULL;)
{
CJavaDeclManager *pDeclMgr = CVisualJavaApp::m_lGlobalDeclarationList.GetNext(nPos);
delete pDeclMgr;
}
for(POSITION pos = m_lParsingMap.GetHeadPosition(); pos != NULL;)
delete m_lParsingMap.GetNext(pos);
}
DWORD CVisualJavaApp::GetFlags ()
{
return m_dwFlags;
}
void CVisualJavaApp::SetFlags (DWORD dwFlags)
{
if (m_dwFlags != dwFlags)
{
m_dwFlags = dwFlags;
}
}
void CVisualJavaApp::LoadSettings ()
{
CVisualJavaView::LoadSettings ();
CMemComboBox::LoadSettings ();
/*CReg reg;
if (reg.Open (HKEY_CURRENT_USER, REG_EDITPAD_IDE, KEY_READ))
{
reg.LoadString (_T ("LastFiles"), m_sLastDocs);
reg.LoadNumber (_T ("Flags"), &m_dwFlags);
CString sProjects;
reg.LoadString (_T ("RecentProjects"), sProjects);
StringToList (m_lstProjects, sProjects);
}
reg.Close ();*/
/*CReg regJJ;
CString sKey += CString("Window Settings");
if (regJJ.Open (HKEY_CURRENT_USER, REGISTRY_ROOT, KEY_READ))
{
}*/
}
void CVisualJavaApp::LoadLastDocs ()
{
/*int pos;
while ((pos = m_sLastDocs.Find (_T ('\n'))) != -1)
{
OpenDocumentFile (m_sLastDocs.Left (pos));
m_sLastDocs = m_sLastDocs.Mid (pos + 1);
}
if (*(LPCTSTR) m_sLastDocs)
{
OpenDocumentFile (m_sLastDocs);
m_sLastDocs.Empty ();
}*/
}
void CVisualJavaApp::SaveSettings ()
{
CVisualJavaView::SaveSettings ();
/*
CMemComboBox::SaveSettings ();
CReg regJJ;
CString sWindowKey = REGISTRY_ROOT;
sWindowKey += CString("Window Settings");
if (regJJ.Create (HKEY_CURRENT_USER, sWindowKey, KEY_WRITE))
{
}
/*CReg reg;
if (reg.Create (HKEY_CURRENT_USER, REG_EDITPAD_IDE, KEY_WRITE))
{
VERIFY (reg.SaveString (_T ("LastFiles"), m_sLastDocs));
VERIFY (reg.SaveNumber (_T ("Flags"), m_dwFlags));
CString sProjects;
ListToString (sProjects, m_lstProjects);
VERIFY (reg.SaveString (_T ("RecentProjects"), sProjects));
}
reg.Close ();
if (reg.Create (HKEY_CURRENT_USER, REG_EDITPAD, KEY_WRITE))
{
// VERIFY (reg.SaveString (_T ("WIspellPath"), CEditPadView::szWIspellPath));
}
reg.Close ();
struct
{
TCHAR path [_MAX_PATH];
time_t stamp;
} oOdd[REMEMBERED_TO_REMOVE];
time_t stamp;
time (&stamp);
stamp += 1000;
int i;
for (i = 0; i < REMEMBERED_TO_REMOVE; i++)
oOdd[i].stamp = stamp;
CString sKey = REG_EDITPAD;
sKey += _T ("\\Remembered");
DWORD nEntries;
LPCTSTR pszPath;
RegVal vValue;
if (reg.Open (HKEY_CURRENT_USER, sKey, KEY_READ|KEY_WRITE) && reg.HasEntries (NULL, &nEntries) && nEntries > MAX_REMEMBERED && reg.FindFirstValue (pszPath, &vValue))
{
DWORD dwLastPos[3];
int nDelta, nMaxDelta, nPos;
do
{
if (RegValGetBinary (&vValue, (LPBYTE) dwLastPos, sizeof (dwLastPos)))
{
nMaxDelta = 0;
nPos = -1;
for (i = 0; i < REMEMBERED_TO_REMOVE; i++)
{
nDelta = oOdd[i].stamp - *dwLastPos;
if (nDelta > nMaxDelta)
{
nMaxDelta = nDelta;
nPos = i;
}
}
if (nPos >= 0)
{
_tcscpy (oOdd[nPos].path, pszPath);
oOdd[nPos].stamp = *dwLastPos;
}
}
}
while (reg.FindNextValue (pszPath, &vValue));
reg.FindClose ();
for (i = 0; i < REMEMBERED_TO_REMOVE; i++)
reg.DeleteKey (oOdd[i].path);
}*/
}
void CVisualJavaApp::SaveLastDocs ()
{
POSITION pos = GetFirstDocTemplatePosition ();
ASSERT (pos);
CDocTemplate *pDocTempl = GetNextDocTemplate (pos);
pos = pDocTempl->GetFirstDocPosition ();
CString name, names;
while (pos)
{
CDocument *pDoc = pDocTempl->GetNextDoc (pos);
name = pDoc->GetPathName ();
if (!name.IsEmpty ())
{
names += name + _T ('\n');
}
}
m_sLastDocs = names;
}
void CVisualJavaApp::OnMoveBlockInView(DWORD dwDecl)
{
__CBaseDecl *pDecl = (__CBaseDecl*)dwDecl;
CJavaDeclManager* pDeclMgr = (CJavaDeclManager*)pDecl->m_pDeclMgr;
if(pDecl->getKind() == CLASS_DECL)
{
CJavaClassDecl* pClass = (CJavaClassDecl*)pDecl;
HTREEITEM hParent = (pClass->getParent())?pClass->getParent()->getTreeLoc():pDeclMgr->getSourceTreeItem();
pDecl->setTreeLoc(AddItem(pClass->getDeclName(),hParent,IS_CLASS,0,dwDecl));
MoveChildren((CJavaBlockDecl*)pClass);
}
else
if(pDecl->getKind() == INTERFACE_DECL)
{
CJavaInterfaceDecl* pInterface = (CJavaInterfaceDecl*)pDecl;
HTREEITEM hParent = (pInterface->getParent())?pInterface->getParent()->getTreeLoc():pDeclMgr->getSourceTreeItem();
pDecl->setTreeLoc(AddItem(pInterface->getDeclName(),hParent,IS_INTERFACE,0,dwDecl));
MoveChildren((CJavaBlockDecl*)pInterface);
}
else
if(pDecl->getKind() == METHOD_DECL)
{
CJavaMethodDecl* pMethod = (CJavaMethodDecl*)dwDecl;
HTREEITEM hParent = (pMethod->getParent())?pMethod->getParent()->getTreeLoc():pDeclMgr->getSourceTreeItem();
UINT mod = ACCESS(pMethod->getAccessModifier());
pMethod->setTreeLoc(AddFunc(pMethod->getParameterizedName(),hParent,mod,dwDecl));
MoveChildren((CJavaBlockDecl*)pMethod);
}
else
if(pDecl->getKind() == BLOCK_DECL)
{
CJavaBlockDecl* pBlock = (CJavaBlockDecl*)dwDecl;
HTREEITEM hParent = (pBlock->getParent())?pBlock->getParent()->getTreeLoc():pDeclMgr->getSourceTreeItem();
pBlock->setTreeLoc(AddItem("block...",hParent,IS_BLOCK,0,dwDecl));
MoveChildren(pBlock);
}
}
void CVisualJavaApp::MoveChildren(CJavaBlockDecl *pBlock)
{
DECL_LIST* pList = pBlock->GetMemberList();
for(POSITION pos = pList->GetHeadPosition();pos != NULL;)
{
__CBaseDecl* pDecl = pList->GetNext(pos);
if(ISBLOCK(pDecl->getKind()))
OnMoveBlockInView((DWORD)pDecl);
else
OnAddToProjectView((DWORD)pDecl);
}
}
void CVisualJavaApp::OnAddToProjectView(DWORD dwDecl)
{
__CBaseDecl *pDecl = (__CBaseDecl*)dwDecl;
CJavaDeclManager* pDeclMgr = (CJavaDeclManager*)pDecl->m_pDeclMgr;
if(pDecl->getKind() == CLASS_DECL)
{
CJavaClassDecl* pClass = (CJavaClassDecl*)pDecl;
HTREEITEM hParent = (pClass->getParent())?pClass->getParent()->getTreeLoc():pDeclMgr->getSourceTreeItem();
pDecl->setTreeLoc(AddItem(pClass->getDeclName(),hParent,IS_CLASS,0,dwDecl));
}
else
if(pDecl->getKind() == INTERFACE_DECL)
{
CJavaInterfaceDecl* pInterface = (CJavaInterfaceDecl*)pDecl;
HTREEITEM hParent = (pInterface->getParent())?pInterface->getParent()->getTreeLoc():pDeclMgr->getSourceTreeItem();
pDecl->setTreeLoc(AddItem(pInterface->getDeclName(),hParent,IS_INTERFACE,0,dwDecl));
}
else
if(pDecl->getKind() == METHOD_DECL)
{
CJavaMethodDecl* pMethod = (CJavaMethodDecl*)dwDecl;
HTREEITEM hParent = (pMethod->getParent())?pMethod->getParent()->getTreeLoc():pDeclMgr->getSourceTreeItem();
UINT mod = ACCESS(pMethod->getAccessModifier());
pMethod->setTreeLoc(AddFunc(pMethod->getParameterizedName(),hParent,mod,dwDecl));
}
else
if(pDecl->getKind() == BLOCK_DECL)
{
CJavaBlockDecl* pBlock = (CJavaBlockDecl*)dwDecl;
HTREEITEM hParent = (pBlock->getParent())?pBlock->getParent()->getTreeLoc():pDeclMgr->getSourceTreeItem();
pBlock->setTreeLoc(AddItem("block...",hParent,IS_BLOCK,0,dwDecl));
}
else
if(pDecl->getKind() == FIELD_DECL)
{
CJavaFieldDecl* pField = (CJavaFieldDecl*)dwDecl;
HTREEITEM hParent = (pField->getParent())?pField->getParent()->getTreeLoc():pDeclMgr->getSourceTreeItem();
UINT mod = ACCESS(pField->getAccessModifier());
int count = pField->getVarCount();
for(int i = 0; i<count; i++)
{
CString strName = pField->getVar(i);
HTREEITEM loc = AddVar(strName,hParent,mod,dwDecl);
pField->setLoc(i,loc);
}//pDeclMgr->ResumeThread();//let parser continue now,child items wouldn't be added to tree b4 parents
}
else
if(pDecl->getKind() == IMPORT_DECL)
{
CImportDecl* pImport = (CImportDecl*)dwDecl;
pImport->setTreeLoc(AddItem(pImport->getDeclName(),pDeclMgr->getImportTreeItem(),IS_IMPORT,0,dwDecl));
}//pDeclMgr->ResumeThread();//let parser continue now,child items wouldn't be added to tree b4 parents
}
void CVisualJavaApp::OnRemoveFromProjectView(DWORD dwItem,DWORD dwType)
{
RemoveItem((HTREEITEM)dwItem,(UINT)dwType);
}
#define ID_PROJECTHEADER 10
#define ID_SOURCEHEADER 11
#define ID_IMPORTHEADER 12
void CVisualJavaApp::OnAddHeaderItem(WPARAM wParam,LPARAM lParam)
{
CJavaDeclManager* pDeclMgr = (CJavaDeclManager*)wParam;
char* pszFile = (char*)lParam;
CString strFile(pszFile);
int len = strlen(pszFile);
CString strSource;
for(int I=len-1;I>=0;I--)
{
if(pszFile[I] == '.')
{
--I;
{
for(I; ((pszFile[I] !='\\')&&(I>=0)); I--)
strSource.Insert(0,pszFile[I]);
//m_strSource += ".java";
}
break;
}
}
free(pszFile);
pDeclMgr->setSourceFile(strSource);
//add root items to view
if(pDeclMgr->getParser()->totalParse())
{
HTREEITEM hProject = addProject(pDeclMgr->m_strProject/*+" classes"*/);
pDeclMgr->setProjectTreeItem(hProject);
HTREEITEM hSource = addSource(hProject,"Source: "+strSource);
pDeclMgr->setSourceTreeItem(hSource);
HTREEITEM hImports = addImports(hSource,strSource+"Imports...");
pDeclMgr->setImportTreeItem(hImports);
}//pDeclMgr->ResumeThread();
}
void CVisualJavaApp::OnRemoveHeaderItem(WPARAM wParam,LPARAM lParam)
{
CJavaDeclManager* pDeclMgr = (CJavaDeclManager*)wParam;
RemoveItem(pDeclMgr->m_hProject);
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CVisualJavaApp object
CVisualJavaApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CVisualJavaApp initialization
BOOL CVisualJavaApp::InitInstance()
{
// Initialize OLE libraries
if (!AfxOleInit())
{
// AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -