⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cedtviewhndredit.cpp

📁 Crimson编辑器的英文版,完成从韩文版变成英文版的移植,并且附带可执行文件和注册表文件,无需原先的安装包,是改写编辑器的最理想选择.
💻 CPP
📖 第 1 页 / 共 2 页
字号:

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

void CCedtView::OnEditSelectWord() 
{
	EventSelectWord(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_EDIT_SELECT_WORD);

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

void CCedtView::OnEditSelectBlock() 
{
	EventSelectBlock(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_EDIT_SELECT_BLOCK);

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

/////////////////////////////////////////////////////////////////////////////
// CHANGE CASE
void CCedtView::OnEditUpperCase() 
{
	BeginActionRecording(TRUE);

	EventUpperCase(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_EDIT_UPPER_CASE);

	EndActionRecording();
	EmptyRedoBuffer(); CheckIfAllActionsCanBeUndone();

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

void CCedtView::OnEditLowerCase() 
{
	BeginActionRecording(TRUE);

	EventLowerCase(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_EDIT_LOWER_CASE);

	EndActionRecording();
	EmptyRedoBuffer(); CheckIfAllActionsCanBeUndone();

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

void CCedtView::OnEditCapitalize() 
{
	BeginActionRecording(TRUE);

	EventCapitalize(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_EDIT_CAPITALIZE);

	EndActionRecording();
	EmptyRedoBuffer(); CheckIfAllActionsCanBeUndone();

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

void CCedtView::OnEditInvertCase() 
{
	BeginActionRecording(TRUE);

	EventInvertCase(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_EDIT_INVERT_CASE);

	EndActionRecording();
	EmptyRedoBuffer(); CheckIfAllActionsCanBeUndone();

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

/////////////////////////////////////////////////////////////////////////////
// DOCUMENT EDIT
void CCedtView::OnEditConvertTabsToSpaces() 
{
	BeginActionRecording(TRUE);

	EventConvertTabsToSpaces(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_EDIT_CONVERT_TABS_TO_SPACES);

	EndActionRecording();
	EmptyRedoBuffer(); CheckIfAllActionsCanBeUndone();

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

void CCedtView::OnEditConvertSpacesToTabs() 
{
	BeginActionRecording(TRUE);

	EventConvertSpacesToTabs(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_EDIT_CONVERT_SPACES_TO_TABS);

	EndActionRecording();
	EmptyRedoBuffer(); CheckIfAllActionsCanBeUndone();

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

void CCedtView::OnEditLeadingSpacesToTabs() 
{
	BeginActionRecording(TRUE);

	EventLeadingSpacesToTabs(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_EDIT_LEADING_SPACES_TO_TABS);

	EndActionRecording();
	EmptyRedoBuffer(); CheckIfAllActionsCanBeUndone();

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

void CCedtView::OnEditRemoveTrailingSpaces() 
{
	BeginActionRecording(TRUE);

	EventRemoveTrailingSpaces(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_EDIT_REMOVE_TRAILING_SPACES);

	EndActionRecording();
	EmptyRedoBuffer(); CheckIfAllActionsCanBeUndone();

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

/////////////////////////////////////////////////////////////////////////////
// UNDO & REDO
void CCedtView::OnEditUndo() 
{
	if( IsMacroRecording() ) { 
		CString szMessage; szMessage.Format(IDS_ERR_ILLEGAL_MACRO_DEF, "Undo");
		AfxMessageBox(szMessage); CancelMacroRecording(); return;
	} else if( ! GetUndoBufferCount() ) return;

	BeginActionRecording(FALSE);

	EventUndoLastAction(FALSE);

	EndActionRecording();
	CheckIfAllActionsAreUndone();

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

void CCedtView::OnEditRedo() 
{
	if( IsMacroRecording() ) { 
		CString szMessage; szMessage.Format(IDS_ERR_ILLEGAL_MACRO_DEF, "Redo");
		AfxMessageBox(szMessage); CancelMacroRecording(); return;
	} else if( ! GetRedoBufferCount() ) return;

	BeginActionRecording(TRUE);

	EventRedoLastUndo(FALSE);

	EndActionRecording();
	CheckIfAllActionsAreUndone();

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

/////////////////////////////////////////////////////////////////////////////
// SEARCH & REPLACE
void CCedtView::OnSearchFind() 
{
	// static dialog box to remember last settings...
	static CFindDialog dlg;

	dlg.m_szFindString = GetCurrentWord();
	if( m_bSelected && ! GetSelectedLineCount() ) dlg.m_szFindString = GetSelectedString();

	if( dlg.DoModal() != IDOK ) return;

	CString szFindString = dlg.m_szFindString;
	UINT nOptions = COMPOSE_SEARCH_OPTION(dlg.m_bWholeWord, dlg.m_bMatchCase, dlg.m_bRegularExpression);

	CRegExp clsTestRegExp; // compile regular expression for test
	if( HAS_REG_EXP(nOptions) && ! clsTestRegExp.RegComp(szFindString) ) { 
		CString szMessage; szMessage.Format(IDS_ERR_REG_COMP_FAILED, szFindString);
		AfxMessageBox(szMessage); return; // test failed
	}

	EventFindString(szFindString, nOptions, FALSE);
	if( IsMacroRecording() ) MacroRecordFind(szFindString, nOptions);

	if( dlg.m_nDirection == 1 /* forward */ ) {
		PostMessage(WM_COMMAND, ID_SEARCH_NEXT_OCCURRENCE, 0L);
	} else {
		PostMessage(WM_COMMAND, ID_SEARCH_PREV_OCCURRENCE, 0L);
	}
}

void CCedtView::OnSearchReplace() 
{
	// static dialog box to remember last settings...
	static CReplaceDialog dlg;

//	dlg.m_szFindString = GetCurrentWord();
	if( m_bSelected && ! GetSelectedLineCount() ) dlg.m_szFindString = GetSelectedString();

	if( ! m_bColumnMode && m_bSelected && GetSelectedLineCount() ) dlg.m_nRange = 0;
	else dlg.m_nRange = 1;

	if( dlg.DoModal() != IDOK ) return;

	CString szFindString = dlg.m_szFindString;
	CString szReplaceString = dlg.m_szReplaceString;
	UINT nOptions = COMPOSE_SEARCH_OPTION(dlg.m_bWholeWord, dlg.m_bMatchCase, dlg.m_bRegularExpression);

	CRegExp clsTestRegExp; // compile regular expression for test
	if( HAS_REG_EXP(nOptions) && ! clsTestRegExp.RegComp(szFindString) ) { 
		CString szMessage; szMessage.Format(IDS_ERR_REG_COMP_FAILED, szFindString);
		AfxMessageBox(szMessage); return; // test failed
	}

	EventReplaceString(szFindString, szReplaceString, nOptions, FALSE);
	if( IsMacroRecording() ) MacroRecordReplace(szFindString, szReplaceString, nOptions);

	if( dlg.m_bReplaceAll ) {
		switch( dlg.m_nRange ) {
		case 0: // replace all in selection
			PostMessage(WM_COMMAND, ID_SEARCH_REPALL_IN_SELECTION, 0L);
			break;
		case 1: // replace all in file
			PostMessage(WM_COMMAND, ID_SEARCH_REPALL_IN_FILE, 0L);
			break;
		case 2: // replace all in open files
			PostMessage(WM_COMMAND, ID_SEARCH_REPALL_IN_OPEN_FILES, 0L);
			break;
		}
	} else  PostMessage(WM_COMMAND, ID_SEARCH_NEXT_OCCURRENCE, 0L);
}

void CCedtView::OnSearchNextWord() 
{
	EventFindCurrentString(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_NEXT_WORD);

	PostMessage(WM_COMMAND, ID_SEARCH_NEXT_OCCURRENCE, 0L);
}

void CCedtView::OnSearchPrevWord() 
{
	EventFindCurrentString(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_PREV_WORD);

	PostMessage(WM_COMMAND, ID_SEARCH_PREV_OCCURRENCE, 0L);
}

void CCedtView::OnSearchFindNext() 
{
	EventFindSelectedString(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_FIND_NEXT);

	PostMessage(WM_COMMAND, ID_SEARCH_NEXT_OCCURRENCE, 0L);
}

void CCedtView::OnSearchFindPrev() 
{
	EventFindSelectedString(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_FIND_PREV);

	PostMessage(WM_COMMAND, ID_SEARCH_PREV_OCCURRENCE, 0L);
}

void CCedtView::OnSearchNextOccurrence() 
{
	BOOL bFound = EventSearchNextOccurrence(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_NEXT_OCCURRENCE);

	if( bFound && m_bReplaceSearch ) PostMessage(WM_COMMAND, ID_SEARCH_ASK_REPLACE, 0L);

	if( bFound ) {
		if( ! IsCaretVisible() ) SetScrollPosToMakeCaretCenter();
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else {
		CString szMessage; szMessage.Format(IDS_MSG_SEARCH_NOT_FOUND, m_szFindString);
		AfxMessageBox( szMessage );
	}
}

void CCedtView::OnSearchPrevOccurrence() 
{
	BOOL bFound = EventSearchPrevOccurrence(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_PREV_OCCURRENCE);

	if( bFound && m_bReplaceSearch ) PostMessage(WM_COMMAND, ID_SEARCH_ASK_REPLACE, 0L);

	if( bFound ) {
		if( ! IsCaretVisible() ) SetScrollPosToMakeCaretCenter();
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else {
		CString szMessage; szMessage.Format(IDS_MSG_SEARCH_NOT_FOUND, m_szFindString);
		AfxMessageBox( szMessage );
	}
}

void CCedtView::OnSearchAskReplace() 
{
	if( ! m_bSelected || GetSelectedLineCount() ) return;
	CAskReplaceDialog dlg;

	INT nBegX, nBegY, nEndX, nEndY; GetSelectedPosition( nBegX, nBegY, nEndX, nEndY );
	CPoint point( nBegX-m_nScrollPosX+GetLeftMargin(), nBegY-m_nScrollPosY+GetCharHeight()+1 ); 
	ClientToScreen( & point ); dlg.SetInitialPos( point );

	if( dlg.DoModal() == IDOK ) PostMessage(WM_COMMAND, ID_SEARCH_REPLACE_THIS, 0L);
	if( dlg.m_bReplaceAll     ) PostMessage(WM_COMMAND, ID_SEARCH_REPALL_IN_FILE, 0L);
	if( dlg.m_bSearchNext     ) PostMessage(WM_COMMAND, ID_SEARCH_NEXT_OCCURRENCE, 0L);
	if( dlg.m_bSearchPrev     ) PostMessage(WM_COMMAND, ID_SEARCH_PREV_OCCURRENCE, 0L);
}

void CCedtView::OnSearchReplaceThisOccurrence() 
{
	BeginActionRecording(TRUE);

	INT nReplaced = EventReplaceThisOccurrence(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_REPLACE_THIS);

	EndActionRecording();
	EmptyRedoBuffer(); CheckIfAllActionsCanBeUndone();

	SetScrollPosToMakeCaretVisible();
	Invalidate(); UpdateWindow(); UpdateAllViews();
}

void CCedtView::OnSearchReplaceAllInSelection() 
{
	BeginActionRecording(TRUE);

	INT nReplaced = EventReplaceAllInSelection(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_REPALL_IN_SELECTION);

	EndActionRecording();
	EmptyRedoBuffer(); CheckIfAllActionsCanBeUndone();

	if( nReplaced ) {
		SetScrollPosToMakeCaretVisible();
		Invalidate(); UpdateWindow(); UpdateAllViews();

		CString szMessage; szMessage.Format(IDS_MSG_REPLACE_RESULT, nReplaced);
		AfxMessageBox( szMessage );
	} else {
		CString szMessage; szMessage.Format(IDS_MSG_SEARCH_NOT_FOUND, m_szFindString);
		AfxMessageBox( szMessage );
	}
}

void CCedtView::OnSearchReplaceAllInFile() 
{
	BeginActionRecording(TRUE);

	INT nReplaced = EventReplaceAllInFile(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_REPALL_IN_FILE);

	EndActionRecording();
	EmptyRedoBuffer(); CheckIfAllActionsCanBeUndone();

	if( nReplaced ) {
		SetScrollPosToMakeCaretVisible();
		Invalidate(); UpdateWindow(); UpdateAllViews();

		CString szMessage; szMessage.Format(IDS_MSG_REPLACE_RESULT, nReplaced);
		AfxMessageBox( szMessage );
	} else {
		CString szMessage; szMessage.Format(IDS_MSG_SEARCH_NOT_FOUND, m_szFindString);
		AfxMessageBox( szMessage );
	}
}

void CCedtView::OnSearchReplaceAllInFileOutputWindow() 
{
	CMainFrame * pFrame = (CMainFrame *)AfxGetMainWnd(); ASSERT( pFrame );
	CCedtDoc * pDoc = (CCedtDoc *)GetDocument(); ASSERT( pDoc );

	BeginActionRecording(TRUE);

	INT nReplaced = EventReplaceAllInFile(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_REPALL_IN_FILE);

	EndActionRecording();
	EmptyRedoBuffer(); CheckIfAllActionsCanBeUndone();

	if( nReplaced ) {
		SetScrollPosToMakeCaretVisible();
		Invalidate(); UpdateWindow(); UpdateAllViews();

		CString szMessage; szMessage.Format(IDS_OUT_REPLACE_RESULT, pDoc->GetTitle(), nReplaced);
		pFrame->AddStringToOutputWindow( szMessage );
	} else {
		CString szMessage; szMessage.Format(IDS_OUT_REPLACE_NOT_FOUND, pDoc->GetTitle(), m_szFindString);
		pFrame->AddStringToOutputWindow( szMessage );
	}
}

void CCedtView::OnSearchReplaceAllInOpenFiles() 
{
	if( IsMacroRecording() ) { 
		CString szMessage; szMessage.Format(IDS_ERR_ILLEGAL_MACRO_DEF, "Replace All In Open Files");
		AfxMessageBox(szMessage); CancelMacroRecording(); return;
	}

	CMainFrame * pFrame = (CMainFrame *)AfxGetMainWnd();
	if( ! pFrame->CanUseOutputWindow() ) {
		AfxMessageBox(IDS_ERR_OUTPUT_WINDOW_OCCUPIED, MB_OK | MB_ICONSTOP); return;
	}

	if( ! pFrame->IsOutputWindowVisible() ) pFrame->ShowOutputWindow(TRUE);

	pFrame->SetOutputWindowOccupied(TRUE);
	pFrame->EnableOutputWindowInput(FALSE);

	pFrame->ClearOutputWindowContents();

	CString szMessage; szMessage.LoadString(IDS_OUT_REPLACE_TITLE);
	pFrame->AddStringToOutputWindow( szMessage );

	CCedtApp * pApp = (CCedtApp *)AfxGetApp();
	POSITION posDoc = pApp->GetFirstDocPosition();
	while( posDoc ) {
		CCedtDoc * pDoc = (CCedtDoc *)pApp->GetNextDoc( posDoc );
		CCedtView * pView = (CCedtView *)pDoc->GetFirstView();

		pView->SendMessage(WM_COMMAND, ID_SEARCH_REPALL_IN_FILE_OUTPUT, 0L);
	}

	pFrame->SetOutputWindowOccupied(FALSE);
	pFrame->EnableOutputWindowInput(FALSE);
}

void CCedtView::OnSearchGoTo() 
{
	CGoToDialog dlg;

	dlg.m_szRange.Format(IDS_CTRL_GO_TO_DIALOG, 1, GetLastIdxY() + 1);
	dlg.m_nLineNumber = GetIdxYFromPosY( m_nCaretPosY ) + 1;

	if( dlg.DoModal() == IDOK ) OnSearchGoTo( dlg.m_nLineNumber );
}

void CCedtView::OnSearchGoTo(INT nLineNumber)
{
	BOOL bRedraw = EventGoToLine(nLineNumber, FALSE);
	if( IsMacroRecording() ) MacroRecordGoTo(nLineNumber);

	if( ! IsCaretVisible() ) { 
		SetScrollPosToMakeCaretCenter(); 
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else if( bRedraw ) {
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else UpdateCaretPosition();
}

void CCedtView::OnSearchToggleBookmark() 
{
	BOOL bRedraw = EventToggleBookmark(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_TOGGLE_BOOKMARK);

	SetScrollPosToMakeCaretVisible();
	if( bRedraw ) {
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else UpdateCaretPosition();
}

void CCedtView::OnSearchNextBookmark() 
{
	BOOL bRedraw = EventNextBookmark(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_NEXT_BOOKMARK);

	if( ! IsCaretVisible() ) { 
		SetScrollPosToMakeCaretCenter(); 
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else if( bRedraw ) {
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else UpdateCaretPosition();
}

void CCedtView::OnSearchPrevBookmark() 
{
	BOOL bRedraw = EventPrevBookmark(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_PREV_BOOKMARK);

	if( ! IsCaretVisible() ) {
		SetScrollPosToMakeCaretCenter();
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else if( bRedraw ) {
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else UpdateCaretPosition();
}

void CCedtView::OnSearchPrevEdit() 
{
	if( ! GetUndoBufferCount() ) return;

	BOOL bRedraw = EventPrevEditingPosition(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_PREV_EDIT);

	if( ! IsCaretVisible() ) {
		SetScrollPosToMakeCaretCenter();
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else if( bRedraw ) {
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else UpdateCaretPosition();
}

void CCedtView::OnSearchPairsBegin() 
{
	BOOL bRedraw = EventPairsBeginPosition(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_PAIRS_BEGIN);

	if( ! IsCaretVisible() ) {
		SetScrollPosToMakeCaretCenter();
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else if( bRedraw ) {
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else UpdateCaretPosition();
}

void CCedtView::OnSearchPairsEnd() 
{
	BOOL bRedraw = EventPairsEndPosition(FALSE);
	if( IsMacroRecording() ) MacroRecordCommand(ID_SEARCH_PAIRS_END);

	if( ! IsCaretVisible() ) {
		SetScrollPosToMakeCaretCenter();
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else if( bRedraw ) {
		Invalidate(); UpdateWindow(); UpdateAllViews();
	} else UpdateCaretPosition();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -