📄 visualjavadoc.cpp
字号:
// VisualJavaDoc.cpp : implementation of the CVisualJavaDoc class
//
#include "stdafx.h"
#include "VisualJava.h"
#include "VisualJavaDoc.h"
#include "VisualJavaView.h"
#include "editcmd.h"
#include "filesup.h"
#include "mainfrm.h"
#include "editreg.h"
#include "registry.h"
#include "InsertClass.h"
#include "JavaDeclManager.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVisualJavaDoc
IMPLEMENT_DYNCREATE(CVisualJavaDoc, CDocument)
BEGIN_MESSAGE_MAP(CVisualJavaDoc, CDocument)
//{{AFX_MSG_MAP(CVisualJavaDoc)
ON_COMMAND(ID_INSERT_NEW_CLASS, OnInsertNewClass)
ON_UPDATE_COMMAND_UI(ID_INSERT_NEW_CLASS, OnUpdateInsertNewClass)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVisualJavaDoc construction/destruction
// Line allocation granularity
CString matchType(UINT nType)
{
switch(nType)
{
case CE_ACTION_UNKNOWN:
return _T("unknown");
case CE_ACTION_PASTE:
return _T("paste");
case CE_ACTION_DELSEL:
return _T("delsel");
case CE_ACTION_CUT:
return _T("cut");
case CE_ACTION_TYPING:
return _T("typing");
case CE_ACTION_BACKSPACE:
return _T("backspace");
case CE_ACTION_INDENT:
return _T("indent");
case CE_ACTION_DRAGDROP:
return _T("dragAndDrop");
case CE_ACTION_REPLACE:
return _T("replace");
case CE_ACTION_DELETE:
return _T("delete");
case CE_ACTION_AUTOINDENT:
return _T("autoIndent");
case CE_ACTION_AUTOCOMPLETE:
return _T("autoComplete");
case CE_ACTION_AUTOEXPAND:
return _T("autoExpand");
case CE_ACTION_LOWERCASE:
return _T("lowercase");
case CE_ACTION_UPPERCASE:
return _T("uppercase");
case CE_ACTION_SWAPCASE:
return _T("swapcase");
case CE_ACTION_CAPITALIZE:
return _T("capitalized");
case CE_ACTION_SENTENCIZE:
return _T("sentence");
case CE_ACTION_RECODE:
return _T("recode");
case CE_ACTION_SPELL:
return _T("spell");
}return _T("");
}
#pragma warning(disable:4355)
CVisualJavaDoc::CVisualJavaDoc():m_xTextBuffer (this)
{
}
/**
void CVisualJavaDoc::init(CJavaTextBuffer* pBuf)
{
m_pTextBuffer = pBuf;
m_pTextBuffer->getDeclMgr()->m_fnPtrAddMethod = AddFunc;
m_pTextBuffer->getDeclMgr()->m_fnPtrAddVar = AddVar;
m_pTextBuffer->getDeclMgr()->m_fnPtrRemoveItem = RemoveItem;
m_pTextBuffer->getDeclMgr()->m_fnPtrAddItem = AddItem;
m_pTextBuffer->getDeclMgr()->m_fnPtrPrintBound = PrintBound;
m_pTextBuffer->getDeclMgr()->m_fnPtrAddProject = addProject;
m_pTextBuffer->getDeclMgr()->m_fnPtrAddImport = addImports;
m_pTextBuffer->getDeclMgr()->m_fnPtrAddSource = addSource;
m_pTextBuffer->getDeclMgr()->m_fnPtrRemoveOnContainZero = removeOnContainZero;
m_pTextBuffer->getDeclMgr()->m_strProject = theApp.m_strCurrentProject;
}
**/
#pragma warning(default:4355)
CVisualJavaDoc::~CVisualJavaDoc()
{
m_xTextBuffer.FreeAll();
//delete m_pTextBuffer;
}
void CVisualJavaDoc::DeleteContents()
{
CDocument::DeleteContents();
m_xTextBuffer.FreeAll();
}
void CVisualJavaDoc::CloseUnused()
{
////////////////////////////////////////////////////////////////////
// loop through all of the documents
// and close the ones that match the criteria of:
// 1) NOT previously saved ( CDocument::GetPathName() is empty)
// and
// 2) NOT modified ( CDocument::IsModified () is zero )
// and
// 3) NOT the document we are in the process of opening (this)
////////////////////////////////////////////////////////////////////
CWinApp *pApp = AfxGetApp ();
CDocTemplate *pDocTemplate;
CDocument *pDoc;
POSITION tpos = pApp->GetFirstDocTemplatePosition (), dpos;
while(tpos)
{
pDocTemplate = pApp->GetNextDocTemplate (tpos);
if(pDocTemplate)
{
loop:
dpos = pDocTemplate->GetFirstDocPosition();
while(dpos)
{
pDoc = pDocTemplate->GetNextDoc (dpos);
if(this != pDoc && // if not self-referred
pDoc->GetPathName () == _T ("") && // and not saved
!pDoc->IsModified ()) // and not modified
{
pDoc->OnCloseDocument (); // then close it
goto loop; // and loop the doclist again
}
}
}
}
}
void CVisualJavaDoc::OnFileEvent (WPARAM wEvent, LPCTSTR pszPathName)
{
if(!(theApp.m_dwFlags & EP_NOTIFY_CHANGES))
return;
MessageBeep (MB_ICONEXCLAMATION);
CFrameWnd *pwndMain= (CFrameWnd*) theApp.GetMainWnd ();
ASSERT (pwndMain);
if(!pwndMain->IsWindowVisible ())
if(pwndMain->IsKindOf (RUNTIME_CLASS (CMainFrame)))
((CMainFrame*) pwndMain)->FlashUntilFocus ();
CView *pView = (CView*) m_viewList.GetHead ();
if(pwndMain->IsKindOf (RUNTIME_CLASS (CMainFrame)))
{
((CMainFrame*) pwndMain)->MDIActivate (pView->GetParent ());
((CMainFrame*) pwndMain)->FlashUntilFocus ();
}
if(wEvent & FE_MODIFIED)
{
bool bReload = (theApp.m_dwFlags & EP_AUTO_RELOAD) != 0;
if(!bReload)
{
CString sMsg;
sMsg.Format (IDS_FILE_CHANGED, pszPathName);
bReload = AfxMessageBox (sMsg, MB_YESNO|MB_ICONQUESTION) == IDYES;
}
if(bReload)
{
POSITION pos = GetFirstViewPosition ();
ASSERT (pos);
CVisualJavaView *pView;
do
{
pView = (CVisualJavaView*) GetNextView (pos);
pView->PushCursor();
}
while (pos);
m_xTextBuffer.FreeAll ();
m_xTextBuffer.LoadFromFile(pszPathName);
pos = GetFirstViewPosition ();
ASSERT (pos);
do
{
pView = (CVisualJavaView*) GetNextView (pos);
pView->PopCursor ();
HWND hWnd = pView->GetSafeHwnd ();
::RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE|RDW_INTERNALPAINT|RDW_ERASE|RDW_ERASENOW|RDW_UPDATENOW|RDW_NOFRAME);
}
while (pos);
}
}
else
if(wEvent & FE_DELETED)
{
if(!(theApp.m_dwFlags & EP_AUTO_RELOAD))
{
CString sMsg;
sMsg.Format(IDS_FILE_DELETED, pszPathName);
AfxMessageBox(sMsg, MB_OK|MB_ICONINFORMATION);
}
}
}
BOOL CVisualJavaDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument ())
return FALSE;
m_xTextBuffer.InitNew ();
return TRUE;
}
BOOL CVisualJavaDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if(!CDocument::OnOpenDocument(lpszPathName))
{
if(!OnNewDocument())
return FALSE;
SetPathName(lpszPathName);
CloseUnused();
return TRUE;
}CloseUnused();
if(m_xTextBuffer.LoadFromFile(lpszPathName))
{
if(theApp.m_dwFlags & EP_NOTIFY_CHANGES)
{
AddFile(lpszPathName);
StartWatching();
}
/**
if(!m_pTextBuffer->getDeclMgr()->m_bInitParse)
{
char* szpFile = NULL;
createText(szpFile,lpszPathName);
m_pTextBuffer->getDeclMgr()->PostThreadMessage(m_msgFileLoaded,(WPARAM)szpFile,0);
}**/return TRUE;
}return FALSE;
}
BOOL CVisualJavaDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
CString sOld = GetExt (GetPathName ()), sNew = GetExt (lpszPathName);
if (_tcsicmp (sOld, sNew))
{
m_xTextBuffer.RetypeViews (lpszPathName);
UpdateAllViews(NULL);
}
if(theApp.m_dwFlags & EP_NOTIFY_CHANGES)
{
StopWatching ();
RemoveFile(lpszPathName);
}
BOOL bSuccess = m_xTextBuffer.SaveToFile(lpszPathName);
if(theApp.m_dwFlags & EP_NOTIFY_CHANGES)
{
AddFile(lpszPathName);
StartWatching();
}
if(!bSuccess)
{
CString sFormat, sMsg;
sFormat.LoadString (IDS_FILE_CANNOT_BE_SAVED);
sMsg.Format(sFormat, lpszPathName);
AfxMessageBox (sMsg);
}
return bSuccess; // Note - we didn't call inherited member!
}
void CVisualJavaDoc::OnReadOnly ()
{
if (!m_xTextBuffer.GetReadOnly ())
{
m_xTextBuffer.SetReadOnly (TRUE);
AfxMessageBox (_T("Document now read-only!"));
}
else
m_xTextBuffer.SetReadOnly (FALSE);
}
void CVisualJavaDoc::OnUpdateReadOnly (CCmdUI * pCmdUI)
{
pCmdUI->SetCheck (m_xTextBuffer.GetReadOnly ());
}
void CVisualJavaDoc::OnCloseDocument()
{
CString sDoc = GetPathName();
if(!sDoc.IsEmpty () && (theApp.m_dwFlags & EP_NOTIFY_CHANGES))
{
StopWatching();
RemoveFile(sDoc);
}
CDocTemplate *pDocTemplate = GetDocTemplate();
POSITION pos = pDocTemplate->GetFirstDocPosition();
ASSERT(pos);
pDocTemplate->GetNextDoc(pos);
if(!pos)
{
CWnd *pWnd = AfxGetMainWnd();
if(pWnd->IsKindOf (RUNTIME_CLASS (CMainFrame)))
((CMainFrame*) pWnd)->ChooseStatusBar (FALSE);
}
if(theApp.m_dwFlags & EP_REMEMBER_LASTPOS && !sDoc.IsEmpty ())
{
pos = GetFirstViewPosition();
if(pos)
{
ASSERT(pos);
CVisualJavaView *pView = (CVisualJavaView*)GetNextView(pos);
CPoint ptCursor = pView->GetCursorPos ();
time_t stamp;
DWORD dwLastPos[3] = { time (&stamp), ptCursor.x, ptCursor.y };
CString sKey = REGISTRY_ROOT;
sKey += _T ("\\Remembered");
CReg reg;
if(reg.Create (HKEY_CURRENT_USER, sKey, KEY_WRITE))
{
VERIFY(reg.SaveBinary(sDoc,(LPBYTE)dwLastPos,sizeof(dwLastPos)));
}
}
}
CDocument::OnCloseDocument();
//m_strTitle.Empty();
//m_strPathName.Empty();
}
/////////////////////////////////////////////////////////////////////////////
// CVisualJavaDoc serialization
void CVisualJavaDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CVisualJavaDoc diagnostics
#ifdef _DEBUG
void CVisualJavaDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CVisualJavaDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CVisualJavaDoc commands
void CVisualJavaDoc::OnInsertNewClass()
{
CInsertClass dlg;
dlg.DoModal();
}
void CVisualJavaDoc::OnUpdateInsertNewClass(CCmdUI* pCmdUI)
{
pCmdUI->Enable();
}
CJavaTextBuffer* CVisualJavaDoc::getBuffer()
{
return &m_xTextBuffer;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -