📄 editpad.cpp
字号:
sPath = pDoc->GetPathName ();
if (sPath.IsEmpty () && (!bAlone || !(m_dwFlags & EP_CREATE_NEW_DOC_IF_ALONE)))
{
m_pMainWnd->SendMessage (WM_COMMAND, ID_FILE_CLOSE);
break;
}
bAlone = false;
}
while (pos);
}
if (m_dwFlags & EP_ADVANCED_UI)
LoadCustomState ();
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow (m_dwFlags & EP_MAXIMIZE_FRAME_WND ? SW_SHOWMAXIMIZED : m_nCmdShow);
pMainFrame->UpdateWindow ();
if (bSplash)
splash.DestroyWindow();
CTipDlg dlg;
if(dlg.m_bStartup)
dlg.DoModal();
return TRUE;
}
BOOL CEditPadApp::
ExitInstance ()
{
FreeLibrary (GetModuleHandle (_T ("RICHED32.DLL")));
if (m_dwFlags & EP_SAVE_SETS_ON_EXIT)
{
SaveSettings ();
}
BOOL result = CWinApp::ExitInstance ();
return result;
}
void CEditPadApp::ParseCommandLine(CCommandLineInfo &rCmdInfo) // by Serge Weinstock
{
// notepad receive only one argument, so we have to merge all the args
m_OneArg.Empty();
for (int i = 1; i < __argc; i++)
{
if (i > 1)
m_OneArg += _T(' ');
m_OneArg += __targv[i];
}
rCmdInfo.ParseParam(m_OneArg, false, true);
}
/////////////////////////////////////////////////////////////////////////////
// Customization load/save methods
#define KEYBOARD_ENTRY _T("Keyboard")
#define MOUSE_ENTRY _T("Mouse")
#define MENU_ENTRY _T("Menus")
void CEditPadApp::LoadCustomState ()
{
if (m_dwFlags & EP_ADVANCED_UI)
{
CString strKbdEntry = REGISTRY_ROOT;
strKbdEntry += KEYBOARD_ENTRY;
m_KeyboardManager.LoadState (strKbdEntry);
CString strMenuEntry = REGISTRY_ROOT;
strMenuEntry += MENU_ENTRY;
// m_ContextMenuManager.AddMenu (_T("Document Menu"), IDR_EDITPADTYPE);
// m_ContextMenuManager.AddMenu (_T("RTF Menu"), IDR_EDITPADRICHTYPE);
// m_ContextMenuManager.AddMenu (_T("Binary Menu"), IDR_EDITPADBINTYPE);
m_ContextMenuManager.AddMenu (_T("Context Menu"), IDR_CONTEXT_MENU);
m_ContextMenuManager.AddMenu (_T("Toolbar Menu"), IDR_POPUP_TOOLBAR);
m_ContextMenuManager.LoadState (strMenuEntry);
}
}
void CEditPadApp::SaveCustomState ()
{
CWnd *pWnd = AfxGetMainWnd ();
if(pWnd->IsKindOf (RUNTIME_CLASS (CMainFrame)))
{
CString strKbdEntry = REGISTRY_ROOT;
strKbdEntry += KEYBOARD_ENTRY;
m_KeyboardManager.SaveState (strKbdEntry);
CString strMenuEntry = REGISTRY_ROOT;
strMenuEntry += MENU_ENTRY;
m_ContextMenuManager.SaveState (strMenuEntry);
}
}
BOOL CEditPadApp::ShowPopupMenu (UINT uiMenuResId, const CPoint &point, CWnd *pWnd)
{
if (m_dwFlags & EP_ADVANCED_UI)
{
return m_ContextMenuManager.ShowPopupMenu (uiMenuResId, point.x, point.y, pWnd);
}
else
{
return FALSE;
}
}
/////////////////////////////////////////////////////////////////////////////
// CEditPadApp message handlers
class CPubDocManager : public CObject
{
DECLARE_DYNAMIC(CDocManager)
public:
// Constructor
CDocManager();
//Document functions
virtual void AddDocTemplate(CDocTemplate* pTemplate) = 0;
virtual POSITION GetFirstDocTemplatePosition() const = 0;
virtual CDocTemplate* GetNextDocTemplate(POSITION& pos) const = 0;
virtual void RegisterShellFileTypes(BOOL bCompat) = 0;
// void UnregisterShellFileTypes();
virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName) = 0; // open named file
virtual BOOL SaveAllModified() = 0; // save before exit
virtual void CloseAllDocuments(BOOL bEndSession) = 0; // close documents before exiting
virtual int GetOpenDocumentCount() = 0;
// helper for standard commdlg dialogs
virtual BOOL DoPromptFileName(CString& fileName, UINT nIDSTitle,
DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate) = 0;
//Commands
// Advanced: process async DDE request
virtual BOOL OnDDECommand(LPTSTR lpszCommand) = 0;
virtual void OnFileNew() = 0;
virtual void OnFileOpen() = 0;
// Implementation
CPtrList m_templateList;
// int GetDocumentCount(); // helper to count number of total documents
// static CPtrList* pStaticList; // for static CDocTemplate objects
// static BOOL bStaticInit; // TRUE during static initialization
// static CDocManager* pStaticDocManager; // for static CDocTemplate objects
public:
// virtual ~CDocManager();
#ifdef _DEBUG
virtual void AssertValid() const = 0;
virtual void Dump(CDumpContext& dc) const = 0;
#endif
};
void CEditPadApp::OnFileNew()
{
if (m_pDocManager != NULL)
{
CDocTemplate *pBinTempl = (CDocTemplate*) ((CPubDocManager*) m_pDocManager)->m_templateList.GetTail ();
if (((CPubDocManager*) m_pDocManager)->m_templateList.GetCount () > 1)
{
((CPubDocManager*) m_pDocManager)->m_templateList.RemoveTail ();
CWinApp::OnFileNew();
((CPubDocManager*) m_pDocManager)->m_templateList.AddTail (pBinTempl);
}
else
CWinApp::OnFileNew();
}
}
void CEditPadApp::OnFileOpen()
{
ASSERT(m_pDocManager != NULL);
CEditFileOpenDlg dlgFile (TRUE, _T (""), _T (""), OFN_ALLOWMULTISELECT|OFN_FILEMUSTEXIST|OFN_EXPLORER|OFN_ENABLEHOOK, _T("Supported Documents (...)|*.lsp;*.bas;*.vb;*.vbs;*.frm;*.dsm;*.bat;*.btm;*.cmd;*.c;*.cc;*.cpp;*.cxx;*.h;*.hpp;*.hxx;*.hm;*.inl;*.rh;*.tlh;*.tli;*.xs;*.dcl;*.dcc;*.f;*.f90;*.f9p;*.fpp;*.html;*.htm;*.shtml;*.ihtml;*.ssi;*.rul;*.java;*.jav;*.pas;*.pl;*.txt;*.doc;*.diz;*.py;*.rc;*.dlg;*.rex;*.rexx;*.sgml;*.sh;*.conf;*.scm;*.sql;*.tcl;*.text;*.sty;*.cls;*.clo;*.ltx;*.fd;*.dtx|All Files (*.*)|*.*||"), AfxGetMainWnd ());
static TCHAR szFileListBuffer[8192];
CString title;
VERIFY (title.LoadString (AFX_IDS_OPENFILE));
/*CString strFilter;
CString strDefault;
if (pTemplate != NULL)
{
ASSERT_VALID(pTemplate);
_AfxAppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate, &strDefault);
}
else
{
// do for all doc template
POSITION pos = m_templateList.GetHeadPosition();
BOOL bFirst = TRUE;
while (pos != NULL)
{
CDocTemplate* pTemplate = (CDocTemplate*)m_templateList.GetNext(pos);
_AfxAppendFilterSuffix(strFilter, dlgFile.m_ofn, pTemplate,
bFirst ? &strDefault : NULL);
bFirst = FALSE;
}
}
// append the "*.*" all files filter
CString allFilter;
VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
strFilter += allFilter;
strFilter += (TCHAR)'\0'; // next string please
strFilter += _T("*.*");
strFilter += (TCHAR)'\0'; // last string
dlgFile.m_ofn.nMaxCustFilter++;
dlgFile.m_ofn.lpstrFilter = strFilter;*/
*szFileListBuffer = _T ('\0');
dlgFile.m_ofn.lpstrFile = szFileListBuffer;
dlgFile.m_ofn.nMaxFile = countof (szFileListBuffer);
dlgFile.m_ofn.lpstrTitle = title;
static TCHAR szPath[_MAX_PATH];
dlgFile.m_ofn.lpstrInitialDir = szPath;
if (dlgFile.DoModal() == IDOK)
{
POSITION pos = dlgFile.GetStartPosition ();
CEditPadDoc *pDoc;
int oldEncoding = CCrystalTextBuffer::m_nDefaultEncoding;
CCrystalTextBuffer::m_nDefaultEncoding = dlgFile.m_nEncoding;
while (pos)
{
pDoc = (CEditPadDoc*) OpenDocumentFileEx (dlgFile.GetNextPathName (pos), dlgFile.m_nFormat);
if (pDoc && dlgFile.GetReadOnlyPref())
pDoc->OnReadOnly ();
}
CCrystalTextBuffer::m_nDefaultEncoding = oldEncoding;
}
}
void CEditPadApp::OnAppAbout ()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal ();
}
void CEditPadApp::OnTipOfTheDay ()
{
CTipDlg dlg;
dlg.DoModal();
}
void CEditPadApp::OnFileSaveAll ()
{
POSITION pos = GetFirstDocTemplatePosition ();
ASSERT (pos);
CDocTemplate *pDocTempl = GetNextDocTemplate (pos);
pos = pDocTempl->GetFirstDocPosition ();
while (pos)
{
CEditPadDoc *pDoc = (CEditPadDoc*) pDocTempl->GetNextDoc (pos);
ASSERT (pDoc);
CString sDocPath = pDoc->GetPathName ();
if (pDoc->IsModified ())
pDoc->DoSave (sDocPath);
}
// SaveAllModified ();
}
void CEditPadApp::OnViewOptionsGeneral()
{
CGeneralPage pgGeneral;
CEditorOptionsPage pgEditor;
CFontPage pgFont;
CString sTitle;
sTitle.LoadString (IDS_SHEET_OPTIONS);
CPropertySheet psOptions (sTitle, AfxGetMainWnd ());
psOptions.AddPage (&pgGeneral);
psOptions.AddPage (&pgEditor);
psOptions.AddPage (&pgFont);
psOptions.DoModal ();
}
#include <..\src\afximpl.h>
CDocument *CEditPadApp::OpenDocumentFileEx(LPCTSTR lpszFileName, int nType)
{
TCHAR szPath[_MAX_PATH];
ASSERT (_tcslen (lpszFileName) < countof (szPath));
TCHAR szTemp[_MAX_PATH];
if (lpszFileName[0] == '\"')
++lpszFileName;
_tcsncpy (szTemp, lpszFileName, _MAX_PATH);
LPTSTR lpszLast = _tcsrchr (szTemp, '\"');
if (lpszLast != NULL)
*lpszLast = 0;
AfxFullPath (szPath, szTemp);
TCHAR szLinkName[_MAX_PATH];
if (AfxResolveShortcut (AfxGetMainWnd (), szPath, szLinkName, _MAX_PATH))
_tcscpy (szPath, szLinkName);
POSITION pos = GetFirstDocTemplatePosition ();
CDocTemplate *pTempl, *pBestTemplate = NULL;
CDocument *pOpenDocument = NULL;
CDocTemplate::Confidence match;
int nIndex = 0;
if (nType == 1)
nType = 0;
while (pos)
{
pTempl = GetNextDocTemplate (pos);
ASSERT_KINDOF(CDocTemplate, pTempl);
ASSERT (pOpenDocument == NULL);
match = pTempl->MatchDocType (szPath, pOpenDocument);
if (match == CDocTemplate::yesAlreadyOpen)
break;
if (nIndex++ == nType)
pBestTemplate = pTempl;
}
ASSERT (pTempl);
if (pOpenDocument != NULL)
{
POSITION pos = pOpenDocument->GetFirstViewPosition();
if (pos)
{
CView* pView = pOpenDocument->GetNextView(pos); // get first one
ASSERT_VALID(pView);
CFrameWnd* pFrame = pView->GetParentFrame();
if (pFrame != NULL)
pFrame->ActivateFrame();
else
TRACE0("Error: Can not find a frame for document to activate.\n");
CFrameWnd* pAppFrame;
if (pFrame != (pAppFrame = (CFrameWnd*)AfxGetApp()->m_pMainWnd))
{
ASSERT_KINDOF(CFrameWnd, pAppFrame);
pAppFrame->ActivateFrame();
}
}
else
{
TRACE0("Error: Can not find a view for document to activate.\n");
}
return pOpenDocument;
}
if (pBestTemplate == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_OPEN_DOC);
return NULL;
}
return pBestTemplate->OpenDocumentFile (szPath);
}
void CEditPadApp::
OnUpdateToolsSpellingSet (CCmdUI * pCmdUI)
{
pCmdUI->Enable (CCrystalEditView::LoadSpellDll (FALSE));
}
void CEditPadApp::
OnToolsSpellingSet ()
{
if (CCrystalEditView::LoadSpellDll ())
{
CCrystalEditView::spellData.hParent = AfxGetMainWnd ()->GetSafeHwnd ();
CCrystalEditView::SpellConfig (&CCrystalEditView::spellData);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -