📄 cedtvieweditadv.cpp
字号:
#include "stdafx.h"
#include "cedtHeader.h"
void CCedtView::ActionDeleteLineSelection()
{
INT nBegX, nBegY, nEndX, nEndY; GetSelectedIndex(nBegX, nBegY, nEndX, nEndY);
if( nBegY != nEndY ) DeleteLineSelection(nBegX, nBegY, nEndX, nEndY);
else DeleteString(nBegX, nBegY, nEndX-nBegX);
SetCaretPosY( GetPosYFromIdxY( nBegX, nBegY ) );
CFormatedString & rLine = GetLineFromPosY( m_nCaretPosY );
SetCaretPosX( GetPosXFromIdxX( rLine, nBegX ) );
}
void CCedtView::ActionDeleteColumnSelection()
{
INT nBegX, nBegY, nEndX, nEndY; GetSelectedPosition(nBegX, nBegY, nEndX, nEndY);
DeleteColumnSelection(nBegX, nBegY, nEndX, nEndY);
SetCaretPosY( nBegY ); m_nAnchorPosY = nEndY;
SetCaretPosX( nBegX ); m_nAnchorPosX = nBegX;
}
void CCedtView::ActionDeleteColumnChar()
{
INT nLineHeight = GetLineHeight();
INT nBegX, nBegY, nEndX, nEndY; GetSelectedPosition(nBegX, nBegY, nEndX, nEndY);
for(INT nPosY = nBegY; nPosY <= nEndY; nPosY += nLineHeight ) {
CFormatedString & rLine = GetLineFromPosY( nPosY );
INT nIdxY = GetIdxYFromPosY( nPosY ), nLstX = GetLastPosX( rLine );
if( nBegX < nLstX ) {
INT nIdxX = GetIdxXFromPosX( rLine, nBegX, TRUE );
FORMATEDWORDINFO & rWord = GetWordFromIdxX( rLine, nIdxX );
if( rWord.m_cType == WT_DBCHAR ) {
DeleteString(nIdxX, nIdxY, 2);
InsertChar(nIdxX, nIdxY, ' ');
} else DeleteChar(nIdxX, nIdxY);
}
}
SetCaretPosY( nBegY ); m_nAnchorPosY = nEndY;
SetCaretPosX( nBegX ); m_nAnchorPosX = nBegX;
}
void CCedtView::ActionDeleteColumnPrevChar()
{
INT nLineHeight = GetLineHeight(), nAveCharWidth = GetAveCharWidth();
INT nBegX, nBegY, nEndX, nEndY; GetSelectedPosition(nBegX, nBegY, nEndX, nEndY);
if( nBegX <= 0 ) return;
else nBegX = nEndX = nBegX - nAveCharWidth;
for(INT nPosY = nBegY; nPosY <= nEndY; nPosY += nLineHeight ) {
CFormatedString & rLine = GetLineFromPosY( nPosY );
INT nIdxY = GetIdxYFromPosY( nPosY ), nLstX = GetLastPosX( rLine );
if( nBegX < nLstX ) {
INT nIdxX = GetIdxXFromPosX( rLine, nBegX, TRUE );
FORMATEDWORDINFO & rWord = GetWordFromIdxX( rLine, nIdxX );
if( rWord.m_cType == WT_DBCHAR ) {
DeleteString(nIdxX, nIdxY, 2);
InsertChar(nIdxX, nIdxY, ' ');
} else DeleteChar(nIdxX, nIdxY);
}
}
SetCaretPosY( nBegY ); m_nAnchorPosY = nEndY;
SetCaretPosX( nBegX ); m_nAnchorPosX = nBegX;
}
void CCedtView::ActionDeleteColumnToEndOfLine()
{
INT nLineHeight = GetLineHeight();
INT nBegX, nBegY, nEndX, nEndY; GetSelectedPosition(nBegX, nBegY, nEndX, nEndY);
for(INT nPosY = nBegY; nPosY <= nEndY; nPosY += nLineHeight ) {
CFormatedString & rLine = GetLineFromPosY( nPosY );
INT nIdxY = GetIdxYFromPosY( nPosY ), nLstX = GetLastPosX( rLine );
if( nBegX < nLstX ) {
INT nIdxX = GetIdxXFromPosX( rLine, nBegX, TRUE );
FORMATEDWORDINFO & rWord = GetWordFromIdxX( rLine, nIdxX );
INT nLdxX = GetIdxXFromPosX( rLine, nLstX, TRUE );
if( rWord.m_cType == WT_DBCHAR && rWord.m_nPosition < nBegX ) {
DeleteString(nIdxX, nIdxY, nLdxX - nIdxX);
InsertChar(nIdxX, nIdxY, ' ');
} else DeleteString(nIdxX, nIdxY, nLdxX - nIdxX);
}
}
SetCaretPosY( nBegY ); m_nAnchorPosY = nEndY;
SetCaretPosX( nBegX ); m_nAnchorPosX = nBegX;
}
void CCedtView::ActionDeleteColumnToBeginOfLine()
{
INT nLineHeight = GetLineHeight();
INT nBegX, nBegY, nEndX, nEndY; GetSelectedPosition(nBegX, nBegY, nEndX, nEndY);
if( nBegX <= 0 ) return;
for(INT nPosY = nBegY; nPosY <= nEndY; nPosY += nLineHeight ) {
CFormatedString & rLine = GetLineFromPosY( nPosY );
INT nIdxY = GetIdxYFromPosY( nPosY ), nLstX = GetLastPosX( rLine );
if( nBegX < nLstX ) {
INT nIdxX = GetIdxXFromPosX( rLine, nBegX, TRUE );
FORMATEDWORDINFO & rWord = GetWordFromIdxX( rLine, nIdxX );
if( rWord.m_cType == WT_DBCHAR && rWord.m_nPosition < nBegX ) {
DeleteString(0, nIdxY, nIdxX + 2);
InsertChar(0, nIdxY, ' ');
} else DeleteString(0, nIdxY, nIdxX);
} else {
INT nIdxX = GetIdxXFromPosX( rLine, nLstX, TRUE );
DeleteString(0, nIdxY, nIdxX);
}
}
nBegX = nEndX = 0;
SetCaretPosY( nBegY ); m_nAnchorPosY = nEndY;
SetCaretPosX( nBegX ); m_nAnchorPosX = nBegX;
}
void CCedtView::ActionCopyLineSelection(CMemText & rBlock)
{
rBlock.RemoveAll(); INT nBegX, nBegY, nEndX, nEndY;
GetSelectedIndex(nBegX, nBegY, nEndX, nEndY);
if( nBegY != nEndY ) CopyToLineSelection(rBlock, nBegX, nBegY, nEndX, nEndY);
else { rBlock.AddTail(""); CopyToString(rBlock.GetTail(), nBegX, nBegY, nEndX-nBegX); }
}
void CCedtView::ActionCopyColumnSelection(CMemText & rBlock)
{
rBlock.RemoveAll(); INT nBegX, nBegY, nEndX, nEndY;
GetSelectedPosition(nBegX, nBegY, nEndX, nEndY);
CopyToColumnSelection(rBlock, nBegX, nBegY, nEndX, nEndY);
}
void CCedtView::ActionCopyLine(CMemText & rBlock)
{
rBlock.RemoveAll(); INT nIdxY = GetIdxYFromPosY( m_nCaretPosY );
rBlock.AddTail( GetLineFromIdxY( nIdxY ) );
rBlock.AddTail( "" );
}
void CCedtView::ActionCopyFilePath(CMemText & rBlock)
{
rBlock.RemoveAll(); CCedtDoc * pDoc = (CCedtDoc *)GetDocument();
CString szPathName = pDoc->GetTitle();
rBlock.AddTail(szPathName);
}
void CCedtView::ActionPasteLineSelection(CMemText & rBlock)
{
INT nBegX, nBegY; PositionToIndex( m_nCaretPosX, m_nCaretPosY, nBegX, nBegY );
INT nEndX = nBegX, nEndY = nBegY;
if( rBlock.GetCount() == 1 ) {
LPCTSTR lpszString = rBlock.GetTail();
InsertString(nBegX, nBegY, lpszString);
nEndX = nBegX + strlen(lpszString);
} else if( rBlock.GetCount() > 1 ) InsertLineSelection(nBegX, nBegY, nEndX, nEndY, rBlock);
SetCaretPosY( GetPosYFromIdxY( nEndX, nEndY ) );
CFormatedString & rLine = GetLineFromPosY( m_nCaretPosY );
SetCaretPosX( GetPosXFromIdxX( rLine, nEndX ) );
}
void CCedtView::ActionPasteColumnSelection(CMemText & rBlock)
{
INT nBegX = m_nCaretPosX, nBegY = m_nCaretPosY;
INT nEndX = nBegX, nEndY = nBegY;
InsertColumnSelection(nBegX, nBegY, nEndX, nEndY, rBlock);
SetCaretPosY( nBegY ); m_nAnchorPosY = nBegY;
SetCaretPosX( nEndX ); m_nAnchorPosX = nEndX;
}
void CCedtView::ActionChangeLineSelection(CMemText & rBlock)
{
INT nBegX, nBegY, nEndX, nEndY;
GetSelectedIndex(nBegX, nBegY, nEndX, nEndY);
if( nBegY != nEndY ) DeleteLineSelection(nBegX, nBegY, nEndX, nEndY);
else DeleteString(nBegX, nBegY, nEndX-nBegX);
if( nBegY != nEndY ) InsertLineSelection(nBegX, nBegY, nEndX, nEndY, rBlock);
else InsertString(nBegX, nBegY, rBlock.GetTail());
}
void CCedtView::ActionChangeColumnSelection(CMemText & rBlock)
{
INT nBegX, nBegY, nEndX, nEndY;
GetSelectedPosition(nBegX, nBegY, nEndX, nEndY);
DeleteColumnSelection(nBegX, nBegY, nEndX, nEndY);
InsertColumnSelection(nBegX, nBegY, nEndX, nEndY, rBlock);
}
void CCedtView::ActionIndentLineSelection()
{
INT nBegX, nBegY, nEndX, nEndY;
GetSelectedIndex(nBegX, nBegY, nEndX, nEndY);
ArrangeLineSelection(nBegX, nBegY, nEndX, nEndY);
IndentLineSelection(nBegX, nBegY, nEndX, nEndY);
SetCaretPosY( GetPosYFromIdxY( nBegX, nBegY ) );
CFormatedString & rLne2 = GetLineFromPosY( m_nCaretPosY );
SetCaretPosX( GetPosXFromIdxX( rLne2, nBegX ) );
m_nAnchorPosY = GetPosYFromIdxY( nEndX, nEndY );
CFormatedString & rLne3 = GetLineFromPosY( m_nAnchorPosY );
m_nAnchorPosX = GetPosXFromIdxX( rLne3, nEndX );
}
void CCedtView::ActionUnindentLineSelection()
{
INT nBegX, nBegY, nEndX, nEndY;
GetSelectedIndex(nBegX, nBegY, nEndX, nEndY);
ArrangeLineSelection(nBegX, nBegY, nEndX, nEndY);
UnindentLineSelection(nBegX, nBegY, nEndX, nEndY);
SetCaretPosY( GetPosYFromIdxY( nBegX, nBegY ) );
CFormatedString & rLne2 = GetLineFromPosY( m_nCaretPosY );
SetCaretPosX( GetPosXFromIdxX( rLne2, nBegX ) );
m_nAnchorPosY = GetPosYFromIdxY( nEndX, nEndY );
CFormatedString & rLne3 = GetLineFromPosY( m_nAnchorPosY );
m_nAnchorPosX = GetPosXFromIdxX( rLne3, nEndX );
}
void CCedtView::ActionMakeCommentLineSelection()
{
INT nBegX, nBegY, nEndX, nEndY;
GetSelectedIndex(nBegX, nBegY, nEndX, nEndY);
ArrangeLineSelection(nBegX, nBegY, nEndX, nEndY);
MakeCommentLineSelection(nBegX, nBegY, nEndX, nEndY);
SetCaretPosY( GetPosYFromIdxY( nBegX, nBegY ) );
CFormatedString & rLne2 = GetLineFromPosY( m_nCaretPosY );
SetCaretPosX( GetPosXFromIdxX( rLne2, nBegX ) );
m_nAnchorPosY = GetPosYFromIdxY( nEndX, nEndY );
CFormatedString & rLne3 = GetLineFromPosY( m_nAnchorPosY );
m_nAnchorPosX = GetPosXFromIdxX( rLne3, nEndX );
}
void CCedtView::ActionReleaseCommentLineSelection()
{
INT nBegX, nBegY, nEndX, nEndY;
GetSelectedIndex(nBegX, nBegY, nEndX, nEndY);
ArrangeLineSelection(nBegX, nBegY, nEndX, nEndY);
ReleaseCommentLineSelection(nBegX, nBegY, nEndX, nEndY);
SetCaretPosY( GetPosYFromIdxY( nBegX, nBegY ) );
CFormatedString & rLne2 = GetLineFromPosY( m_nCaretPosY );
SetCaretPosX( GetPosXFromIdxX( rLne2, nBegX ) );
m_nAnchorPosY = GetPosYFromIdxY( nEndX, nEndY );
CFormatedString & rLne3 = GetLineFromPosY( m_nAnchorPosY );
m_nAnchorPosX = GetPosXFromIdxX( rLne3, nEndX );
}
void CCedtView::ActionConvertTabsToSpaces()
{
INT nIdxX, nIdxY; PositionToIndex( m_nCaretPosX, m_nCaretPosY, nIdxX, nIdxY );
INT nAncX, nAncY; PositionToIndex( m_nAnchorPosX, m_nAnchorPosY, nAncX, nAncY );
ConvertTabsToSpacesDocument();
IndexToPosition( nIdxX, nIdxY, m_nCaretPosX, m_nCaretPosY );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -