📄 visualjavadoc.cpp
字号:
CFrameWnd* CVisualJavaDoc::GetDocFrame()
{
POSITION pos = GetFirstViewPosition();
if(pos)
{
CView* pView = GetNextView(pos); // get first one
ASSERT_VALID(pView);
CFrameWnd* pFrame = pView->GetParentFrame();
return pFrame;
}
return NULL;
}
void CVisualJavaDoc::AttachBuffer()
{
POSITION pos = GetFirstViewPosition();
for(pos; pos != NULL;)
{
CVisualJavaView* pView = (CVisualJavaView*)GetNextView(pos);
ASSERT_VALID(pView);
//pView->AttachToBuffer(m_pTextBuffer);
pView->SetTextBuffer(&m_xTextBuffer);
pView->SetTextType("java");
}
}
//*******************************textbuffer**************************************//
CJavaTextBuffer::CJavaTextBuffer (CVisualJavaDoc * pDoc)
{
m_pOwnerDoc = pDoc;
/*
m_bDelDeclMgr = bTotalParse;//weither we want the declaration manager deleted
//when this textbuffer is destroyed
m_pOwnerDoc = pDoc;
if(bTotalParse)//don't spawn a new thread if this is not a java file for editing
{
m_pDeclManager = (CDeclManager*)AfxBeginThread(RUNTIME_CLASS(CJavaDeclManager),
THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
m_pDeclManager->m_bAutoDelete = FALSE;
getDeclMgr()->m_bIsThread = TRUE;
getDeclMgr()->m_nMainThreadID = ::GetCurrentThreadId();
DWORD result = m_pDeclManager->ResumeThread();
getDeclMgr()->PostThreadMessage(m_msgMainThreadID,(WPARAM)m_nMainAppThreadID,0);
getDeclMgr()->PostThreadMessage(m_msgInit,(WPARAM)this,(LPARAM)bTotalParse);
}
else
{
m_pDeclManager = (CDeclManager*)new CJavaDeclManager;
getDeclMgr()->OnInitSingleThreaded(this,false);
//make types declared in this document available for code autocompletion
/**CVisualJavaApp::addDeclMgr((CJavaDeclManager*)m_pDeclManager);**
}*/
}
CJavaTextBuffer::~CJavaTextBuffer()
{/*
m_pDeclManager->m_bValidDoc = FALSE;
if(m_bDelDeclMgr)
{
/**
CVisualJavaApp::removeDeclMgr((CJavaDeclManager*)m_pDeclManager);
**
//terminate thread,if it is active
delete m_pDeclManager;
}**/
}
BOOL CJavaTextBuffer::GetLine( int nLineIndex, CString &strLine )
{
int nLineLength = GetLineLength( nLineIndex );
if(nLineLength <= 0)
return FALSE;
_tcsncpy ( strLine.GetBuffer( nLineLength ), GetLineChars( nLineIndex ), nLineLength );
strLine.ReleaseBuffer( nLineLength );
return TRUE;
}
BOOL CJavaTextBuffer::InsertTextExt(CCrystalTextView * pSource, int nLine, int nPos,
LPCTSTR pszText, int &nEndLine, int &nEndChar,
int nAction /*= CE_ACTION_UNKNOWN*/)
{
if(!CCrystalTextBuffer::InsertTextExt(pSource,nLine,nPos,pszText,
nEndLine,nEndChar,nAction))
return FALSE;
__CEditContext *pEditContext = new __CEditContext(nPos,nLine,
nEndChar,nEndLine,NULL);
if(createText(pEditContext->m_pszText,pszText))
OnInsertEdit(pEditContext);
else delete pEditContext;
return TRUE;
}
BOOL CJavaTextBuffer::DeleteTextExt(CCrystalTextView * pSource, int nStartLine,
int nStartPos, int nEndLine, int nEndPos,
int nAction /*= CE_ACTION_UNKNOWN*/)
{
if(!CCrystalTextBuffer::DeleteTextExt(pSource,nStartLine,nStartPos,
nEndLine,nEndPos,nAction))
return FALSE;
__CEditContext *pEditContext = new __CEditContext(nStartPos,nStartLine,
nEndPos,nEndLine,NULL);
OnDeleteEdit(pEditContext);
return TRUE;
}
BOOL CJavaTextBuffer::InternalInsertTextExt(CCrystalTextView * pSource, int nLine,
int nPos, LPCTSTR pszText, int &nEndLine, int &nEndChar)
{
if(!CCrystalTextBuffer::InternalInsertTextExt(pSource,nLine,nPos,pszText,nEndLine,nEndChar))
return FALSE;
__CEditContext *pEditContext = new __CEditContext(nPos,nLine,
nEndChar,nEndLine,NULL);
if(createText(pEditContext->m_pszText,pszText))
{
OnInsertEdit(pEditContext);
}
else delete pEditContext;
return TRUE;
}
BOOL CJavaTextBuffer::InternalDeleteTextExt(CCrystalTextView * pSource, int nStartLine,
int nStartPos, int nEndLine, int nEndPos)
{
if(!CCrystalTextBuffer::InternalDeleteTextExt(pSource,nStartLine,nStartPos,nEndLine,nEndPos))
return FALSE;
__CEditContext *pEditContext = new __CEditContext(nStartPos,nStartLine,
nEndPos,nEndLine,NULL);
OnDeleteEdit(pEditContext);
return TRUE;
}
void CJavaTextBuffer::OnInsertEdit(__CEditContext* pContext)
{
CVisualJavaApp::SendEditMsg(m_pOwnerDoc->GetPathName(),m_msgInsertEdit,pContext);
//delete pEditContext;
//m_pDeclManager->PostThreadMessage(m_msgInsertEdit,(WPARAM)pEditContext,0);
}
void CJavaTextBuffer::OnDeleteEdit(__CEditContext* pContext)
{
CVisualJavaApp::SendEditMsg(m_pOwnerDoc->GetPathName(),m_msgDeleteEdit,pContext);
//delete pEditContext;
//m_pDeclManager->PostThreadMessage(m_msgDeleteEdit,(WPARAM)pEditContext,0);
}
void CJavaTextBuffer::SetModified (BOOL bModified /*= TRUE*/)
{
CCrystalTextBuffer::SetModified (bModified);
m_pOwnerDoc->SetModifiedFlag (bModified);
if(bModified)
{
CString sTitle;
CWnd *pWnd = AfxGetMainWnd ();
pWnd->GetWindowText (sTitle);
BOOL bMaxi;
CWnd *pWnd2 = ((CMDIFrameWnd*) pWnd)->MDIGetActive (&bMaxi);
if(sTitle.Left (2) != _T("* "))
{
sTitle = _T ("* ") + (bMaxi ? sTitle.Left (7) : sTitle);
pWnd->SetWindowText (sTitle);
}
if(!bMaxi)
{
pWnd2->GetWindowText (sTitle);
if (sTitle.Right (2) != _T(" *"))
{
sTitle += _T (" *");
pWnd2->SetWindowText (sTitle);
}
}
}
else
{
CString sTitle;
CWnd *pWnd = AfxGetMainWnd ();
pWnd->GetWindowText (sTitle);
BOOL bMaxi;
CWnd *pWnd2 = ((CMDIFrameWnd*) pWnd)->MDIGetActive (&bMaxi);
if(sTitle.Left (2) == _T("* "))
{
sTitle = bMaxi ? sTitle.Mid (2, 7) : sTitle.Mid (2);
pWnd->SetWindowText (sTitle);
}
if(!bMaxi)
{
pWnd2->GetWindowText (sTitle);
if (sTitle.Right (2) == _T(" *"))
{
sTitle = sTitle.Left (sTitle.GetLength () - 2);
pWnd2->SetWindowText (sTitle);
}
}
}
};
void CJavaTextBuffer::FillUndoRedoListBox(CListBox* pListBox,UINT nAction)
{
if(nAction == 0)//undo
{
int nCount = m_aUndoBuf.GetSize();
for(int I=0; I<nCount;I++)
pListBox->AddString(matchType(m_aUndoBuf[I].m_nAction));
}
else //redo
{
int nCount = m_nUndoPosition - m_aUndoBuf.GetSize();
for(int I=0; I<nCount;I++)
pListBox->AddString(matchType(m_aUndoBuf[I].m_nAction));
}
}
BOOL CJavaTextBuffer::InsertParserText(int nLine, int nPos, LPCTSTR pszText,
int &nEndLine, int &nEndChar)
{
ASSERT (m_bInit); // Text buffer not yet initialized.
// You must call InitNew() or LoadFromFile() first!
ASSERT (nLine >= 0 && nLine < m_aLines.GetSize ());
ASSERT (nPos >= 0 && nPos <= m_aLines[nLine]->m_nLength);
if (m_bReadOnly)
return FALSE;
CInsertContext context;
context.m_ptStart.x = nPos;
context.m_ptStart.y = nLine;
int nRestCount = m_aLines[nLine]->m_nLength - nPos;
LPTSTR pszRestChars = NULL;
if(nRestCount > 0)
{
pszRestChars = new TCHAR[nRestCount];
memcpy (pszRestChars, m_aLines[nLine]->m_pcLine + nPos, nRestCount * sizeof (TCHAR));
m_aLines[nLine]->m_nLength = nPos;
}
int nCurrentLine = nLine;
BOOL bNewLines = FALSE;
int nTextPos;
for(;;)
{
nTextPos = 0;
while (pszText[nTextPos] != 0 && pszText[nTextPos] != _T ('\r'))
nTextPos++;
if (nCurrentLine == nLine)
{
AppendLine (nLine, pszText, nTextPos);
}
else
{
InsertLine (pszText, nTextPos, nCurrentLine);
bNewLines = TRUE;
}
if (pszText[nTextPos] == 0)
{
nEndLine = nCurrentLine;
nEndChar = m_aLines[nCurrentLine]->m_nLength;
AppendLine (nCurrentLine, pszRestChars, nRestCount);
break;
}
nCurrentLine++;
nTextPos++;
if (pszText[nTextPos] == _T ('\n'))
{
nTextPos++;
}
else
{
ASSERT (FALSE); // Invalid line-end format passed
}
pszText += nTextPos;
}
if (pszRestChars != NULL)
delete pszRestChars;
context.m_ptEnd.x = nEndChar;
context.m_ptEnd.y = nEndLine;
//**if (bNewLines)
//** UpdateViews (pSource, &context, UPDATE_HORZRANGE | UPDATE_VERTRANGE, nLine);
//**else
//** UpdateViews (pSource, &context, UPDATE_SINGLELINE | UPDATE_HORZRANGE, nLine);
//**
//**if(!m_bModified)
//** SetModified (TRUE);
//BEGIN SW
// remember current cursor position as last editing position
m_ptLastChange = context.m_ptEnd;
//END SW
return TRUE;
}
BOOL CJavaTextBuffer::DeleteParserText(int nStartLine, int nStartChar,
int nEndLine, int nEndChar)
{
ASSERT (m_bInit); // Text buffer not yet initialized.
// You must call InitNew() or LoadFromFile() first!
ASSERT (nStartLine >= 0 && nStartLine < m_aLines.GetSize ());
ASSERT (nStartChar >= 0 && nStartChar <= m_aLines[nStartLine]->m_nLength);
ASSERT (nEndLine >= 0 && nEndLine < m_aLines.GetSize ());
ASSERT (nEndChar >= 0 && nEndChar <= m_aLines[nEndLine]->m_nLength);
ASSERT (nStartLine < nEndLine || nStartLine == nEndLine && nStartChar < nEndChar);
if(m_bReadOnly)
return FALSE;
CDeleteContext context;
context.m_ptStart.y = nStartLine;
context.m_ptStart.x = nStartChar;
context.m_ptEnd.y = nEndLine;
context.m_ptEnd.x = nEndChar;
if(nStartLine == nEndLine)
{
SLineInfo * li = m_aLines[nStartLine];
if(nEndChar < li->m_nLength)
{
memcpy (li->m_pcLine + nStartChar, li->m_pcLine + nEndChar,
sizeof (TCHAR) * (li->m_nLength - nEndChar));
}
li->m_nLength -= (nEndChar - nStartChar);
//** UpdateViews (pSource, &context, UPDATE_SINGLELINE | UPDATE_HORZRANGE, nStartLine);
}
else
{
int nRestCount = m_aLines[nEndLine]->m_nLength - nEndChar;
LPTSTR pszRestChars = NULL;
if(nRestCount > 0)
{
pszRestChars = new TCHAR[nRestCount];
memcpy (pszRestChars, m_aLines[nEndLine]->m_pcLine + nEndChar, nRestCount * sizeof (TCHAR));
}
int nDelCount = nEndLine - nStartLine;
for(int L = nStartLine + 1; L <= nEndLine; L++)
{
delete m_aLines[L]->m_pcLine;
delete m_aLines[L];
}
m_aLines.RemoveAt(nStartLine + 1, nDelCount);
// nEndLine is no more valid
m_aLines[nStartLine]->m_nLength = nStartChar;
if(nRestCount > 0)
{
AppendLine (nStartLine, pszRestChars, nRestCount);
delete pszRestChars;
}
//**UpdateViews (pSource, &context, UPDATE_HORZRANGE | UPDATE_VERTRANGE, nStartLine);
}
//**if (!m_bModified)
//** SetModified (TRUE);
//BEGIN SW
// remember current cursor position as last editing position
m_ptLastChange = context.m_ptStart;
//END SW
return TRUE;
}
void CVisualJavaDoc::SetDocTemplate(CDocTemplate *pDocTemplate){
m_pDocTemplate = pDocTemplate;
}
__CEditContext::__CEditContext()
{
m_nStartChar = 0;
m_nStartLine = 0;
m_nEndChar = 0;
m_nEndLine = 0;m_pszText = NULL;
}
__CEditContext::__CEditContext(int startchar,int startline,
int endchar,int endline,char* pchar)
{
m_szpText = pchar;
m_nStartChar = startchar;
m_nStartLine = startline;
m_nEndChar = endchar;
m_nEndLine = endline;
}
__CEditContext::~__CEditContext()
{
// delete m_pszText;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -