📄 cedtdoc.cpp
字号:
EmptyUndoBuffer();
EmptyRedoBuffer();
m_bRecordingUndo = TRUE;
m_nRecordingCount = 0;
m_nEncodingType = ENCODING_TYPE_ASCII; m_nFileFormat = FILE_FORMAT_DOS;
if( CCedtApp::m_bOpenTemplate ) m_clsAnalyzedText.FileLoad(CCedtApp::m_szOpenTemplatePathName, m_nEncodingType, m_nFileFormat);
else m_clsAnalyzedText.AddTail("");
ZeroMemory( & m_clsFileStatus, sizeof(m_clsFileStatus) );
m_dwFileAttribute = FILE_ATTRIBUTE_NORMAL;
m_szLangSpecFile = ""; m_clsLangSpec.ResetContents();
m_szKeywordsFile = ""; m_clsKeywords.ResetContents();
m_bAutomaticSyntaxType = TRUE;
if( CCedtApp::m_bOpenTemplate && DetectSyntaxType(CCedtApp::m_szOpenTemplatePathName, m_clsAnalyzedText.GetHead()) ) LoadSyntaxInformation();
AnalyzeText();
CCedtApp::m_szOpenTemplatePathName = "";
CCedtApp::m_bOpenTemplate = FALSE;
// ReinitializeAllViews();
// FormatScreenText();
// UpdateAllViews(NULL);
return TRUE;
}
BOOL CCedtDoc::OnReloadDocument(LPCTSTR lpszPathName, INT nEncodingType)
{
if( ! strlen(lpszPathName) ) return FALSE;
// m_nFtpAccount = m_nCurrentFtpAccount;
// m_szRemotePathName = m_szCurrentRemotePathName;
// This code segment imitate CDocument::OnOpenDocument(lpszPathName)
if( IsModified() ) TRACE0("Warning: OnReloadDocument replaces an unsaved document.\n");
CFileException fe;
CFile * pFile = GetFile(lpszPathName, CFile::modeRead | CFile::shareDenyNone, &fe);
if( pFile == NULL ) {
ReportSaveLoadException(lpszPathName, &fe, FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
return FALSE;
}
ReleaseFile(pFile, FALSE);
DeleteContents();
SetModifiedFlag(FALSE);
// End of code segment CDocument::OnOpenDocument(lpszPathName)
m_bDocumentSaved = FALSE;
m_nSavedUndoCount = 0;
EmptyUndoBuffer();
EmptyRedoBuffer();
m_bRecordingUndo = TRUE;
m_nRecordingCount = 0;
DetectEncodingTypeAndFileFormat(lpszPathName, m_nEncodingType, m_nFileFormat);
if( nEncodingType != ENCODING_TYPE_UNKNOWN ) m_nEncodingType = nEncodingType;
m_clsAnalyzedText.FileLoad(lpszPathName, m_nEncodingType, m_nFileFormat);
CFile::GetStatus(lpszPathName, m_clsFileStatus);
m_dwFileAttribute = GetFileAttributes(lpszPathName);
// m_szLangSpecFileName = ""; m_clsLangSpec.Reset();
// m_szKeywordsFileName = ""; m_clsKeywords.Reset();
// m_bAutomaticSyntaxType = TRUE;
// if( DetectSyntaxType(lpszPathName, m_clsAnalyzedText.GetHead()) ) LoadSyntaxInformation();
AnalyzeText();
ReinitializeAllViews();
// FormatScreenText();
UpdateAllViews(NULL);
return TRUE;
}
BOOL CCedtDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
m_nFtpAccount = m_nCurrentFtpAccount;
m_szRemotePathName = m_szCurrentRemotePathName;
// make backup file
if( m_nMakeBackupFile == 2 && ! IsRemoteFile() && VerifyFilePath(lpszPathName) ) {
if( ! BackupDocument(lpszPathName) ) AfxMessageBox( IDS_ERR_FILE_BACKUP_FAILED );
}
// This code segment replaces CDocument::OnOpenDocument(lpszPathName)
if( IsModified() ) TRACE0("Warning: OnOpenDocument replaces an unsaved document.\n");
CFileException fe;
CFile * pFile = GetFile(lpszPathName, CFile::modeRead | CFile::shareDenyNone, &fe);
if( pFile == NULL ) {
ReportSaveLoadException(lpszPathName, &fe, FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
return FALSE;
}
ReleaseFile(pFile, FALSE);
DeleteContents();
SetModifiedFlag(FALSE);
// End of code segment CDocument::OnOpenDocument(lpszPathName)
m_bDocumentSaved = FALSE;
m_nSavedUndoCount = 0;
EmptyUndoBuffer();
EmptyRedoBuffer();
m_bRecordingUndo = TRUE;
m_nRecordingCount = 0;
DetectEncodingTypeAndFileFormat(lpszPathName, m_nEncodingType, m_nFileFormat);
m_clsAnalyzedText.FileLoad(lpszPathName, m_nEncodingType, m_nFileFormat);
CFile::GetStatus(lpszPathName, m_clsFileStatus);
m_dwFileAttribute = GetFileAttributes(lpszPathName);
m_szLangSpecFile = ""; m_clsLangSpec.ResetContents();
m_szKeywordsFile = ""; m_clsKeywords.ResetContents();
m_bAutomaticSyntaxType = TRUE;
if( DetectSyntaxType(lpszPathName, m_clsAnalyzedText.GetHead()) ) LoadSyntaxInformation();
AnalyzeText();
// ReinitializeAllViews();
// FormatScreenText();
// UpdateAllViews(NULL);
return TRUE;
}
BOOL CCedtDoc::OnSaveDocument(LPCTSTR lpszPathName)
{
// retrieve old path name
CString szOldPathName = GetPathName();
if( szOldPathName.IsEmpty() ) szOldPathName = GetTitle();
// check if file can be written
DWORD dwAttrib = 0x00000000;
if( VerifyFilePath(lpszPathName) ) dwAttrib = GetFileAttributes(lpszPathName);
if( dwAttrib == 0xFFFFFFFF ) { // GetFileAttributes() error
INT nReturn = AfxMessageBox( IDS_ERR_FILE_ATTR_CHECK, MB_YESNO );
if( nReturn != IDYES ) return FALSE;
} else if( (dwAttrib & FILE_ATTRIBUTE_DIRECTORY) || (dwAttrib & FILE_ATTRIBUTE_READONLY) ) {
CString szMessage; szMessage.Format( IDS_ERR_FILE_SAVE_DENIED1, lpszPathName );
AfxMessageBox( szMessage, MB_OK | MB_ICONSTOP ); return FALSE;
} else if( (dwAttrib & FILE_ATTRIBUTE_HIDDEN) || (dwAttrib & FILE_ATTRIBUTE_SYSTEM) ) {
CString szMessage; szMessage.Format( IDS_ERR_FILE_SAVE_DENIED2, lpszPathName );
AfxMessageBox( szMessage, MB_OK | MB_ICONSTOP ); return FALSE;
}
m_nFtpAccount = m_nCurrentFtpAccount;
m_szRemotePathName = m_szCurrentRemotePathName;
// make backup file
if( m_nMakeBackupFile == 1 && ! IsRemoteFile() && VerifyFilePath(lpszPathName) ) {
if( ! BackupDocument(lpszPathName) ) AfxMessageBox( IDS_ERR_FILE_BACKUP_FAILED );
}
// check if it need to remove trailing spaces
if( m_bRemoveTrailingSpacesBeforeSaving ) {
CCedtView * pView = (CCedtView *)GetFirstView();
pView->SendMessage(WM_COMMAND, ID_EDIT_REMOVE_TRAILING_SPACES, 0L);
}
// check if it need to convert tabs to spaces
if( m_bConvertTabsToSpacesBeforeSaving ) {
CCedtView * pView = (CCedtView *)GetFirstView();
pView->SendMessage(WM_COMMAND, ID_EDIT_CONVERT_TABS_TO_SPACES, 0L);
}
// This code segment replaces CDocument::OnSaveDocument(lpszPathName)
CFileException fe;
CFile * pFile = GetFile(lpszPathName, CFile::modeReadWrite | CFile::modeCreate | CFile::shareExclusive, &fe);
if( pFile == NULL ) {
ReportSaveLoadException(lpszPathName, &fe, TRUE, AFX_IDP_INVALID_FILENAME);
return FALSE;
}
ReleaseFile(pFile, FALSE);
SetModifiedFlag(FALSE); // back to unmodified
// End of code segment CDocument::OnSaveDocument(lpszPathName)
m_bDocumentSaved = TRUE;
m_nSavedUndoCount = GetUndoBufferCount();
// EmptyUndoBuffer(); - do not empty undo buffer
// EmptyRedoBuffer(); - do not empty redo buffer
m_bRecordingUndo = TRUE;
m_nRecordingCount = 0;
if( m_bSaveFilesInUnixFormat ) m_nFileFormat = FILE_FORMAT_UNIX;
if( IsRemoteFile() && m_bSaveRemoteFilesInUnixFormat ) m_nFileFormat = FILE_FORMAT_UNIX;
m_clsAnalyzedText.FileSave(lpszPathName, m_nEncodingType, m_nFileFormat);
CFile::GetStatus(lpszPathName, m_clsFileStatus);
m_dwFileAttribute = GetFileAttributes(lpszPathName);
CString szOldExtension = GetFileExtension(szOldPathName);
CString szNewExtension = GetFileExtension(lpszPathName);
if( m_bAutomaticSyntaxType && szNewExtension != szOldExtension ) {
m_szLangSpecFile = ""; m_clsLangSpec.ResetContents();
m_szKeywordsFile = ""; m_clsKeywords.ResetContents();
m_bAutomaticSyntaxType = TRUE;
if( DetectSyntaxType(lpszPathName, m_clsAnalyzedText.GetHead()) ) LoadSyntaxInformation();
AnalyzeText();
// ReinitializeAllViews();
FormatScreenText();
UpdateAllViews(NULL);
} else {
// ReinitializeAllViews();
// FormatScreenText();
UpdateAllViews(NULL);
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -