123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311 |
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "icrEdit.h"
- #include "MainFrm.h"
- #include "IcrEditView.h"
- #include "resource.h"
- #include "..\include\kernel.h"
- #include "Const.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- DWORD CALLBACK EditStreamCallbackWriteToFile(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb);
- DWORD CALLBACK EditStreamCallbackOut(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb);
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_CBN_SELCHANGE(IDC_COMBOX, OnSelchangeComboFind)
- ON_COMMAND(ID_EDITPASTE, OnEditPaste)
- ON_COMMAND(ID_EDITCUT, OnEditcut)
- ON_UPDATE_COMMAND_UI(ID_EDITCUT, OnUpdateEditcut)
- ON_COMMAND(ID_EDITCOPY, OnEditcopy)
- ON_UPDATE_COMMAND_UI(ID_EDITCOPY, OnUpdateEditcopy)
- ON_UPDATE_COMMAND_UI(ID_EDITPASTE, OnUpdateEditpaste)
- ON_COMMAND(ID_EDITUNDO, OnEditundo)
- ON_UPDATE_COMMAND_UI(ID_EDITUNDO, OnUpdateEditundo)
- ON_COMMAND(ID_EDITREDO, OnEditredo)
- ON_UPDATE_COMMAND_UI(ID_EDITREDO, OnUpdateEditredo)
- ON_COMMAND(ID_EDITSELECTALL, OnEditselectall)
- ON_COMMAND(ID_EDITREPEAT, OnEditrepeat)
- ON_COMMAND(ID_EDITREPEATNEXT, OnEditrepeatnext)
- ON_UPDATE_COMMAND_UI(ID_EDITREPEAT, OnUpdateEditrepeat)
- ON_UPDATE_COMMAND_UI(ID_EDITREPEATNEXT, OnUpdateEditrepeatnext)
- ON_COMMAND(ID_VIEW_FONT, OnViewFont)
- ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
- ON_COMMAND(ID_EDIT_TRIMTRAILLINGSPACE, OnEditTrimtraillingspace)
- ON_COMMAND(ID_EDIT_TRIMTRAILLINGTAB, OnEditTrimtraillingtab)
- ON_COMMAND(ID_EDIT_TABTOSPACE, OnEditTabtospace)
- ON_COMMAND(ID_EDIT_SPACETOTAB, OnEditSpacetotab)
- ON_COMMAND(ID_EDIT_LEADINGSPACETOTAB, OnEditLeadingspacetotab)
- ON_COMMAND(ID_EDIT_MOVERIGHT, OnEditMoveright)
- ON_COMMAND(ID_EDIT_UNCOMMENT, OnEditUncomment)
- ON_COMMAND(ID_EDIT_MOVELEFT, OnEditMoveleft)
- ON_COMMAND(ID_EDIT_COMMENT, OnEditComment)
- ON_COMMAND(ID_EDIT_LCASE, OnEditLcase)
- ON_COMMAND(ID_EDIT_UCASE, OnEditUcase)
- ON_COMMAND(ID_EDIT_INVERT, OnEditInvert)
- ON_COMMAND(ID_EDIT_CAPITALIZE, OnEditCapitalize)
- ON_COMMAND(ID_EDIT_SENTANCECASE, OnEditSentancecase)
- ON_UPDATE_COMMAND_UI(ID_EDIT_LCASE, OnUpdateEditLcase)
- ON_UPDATE_COMMAND_UI(ID_EDIT_INVERT, OnUpdateEditInvert)
- ON_UPDATE_COMMAND_UI(ID_EDIT_SENTANCECASE, OnUpdateEditSentancecase)
- ON_UPDATE_COMMAND_UI(ID_EDIT_UCASE, OnUpdateEditUcase)
- ON_COMMAND(ID_FILE_NEW, OnFileNew)
- ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
- ON_COMMAND(ID_FILESAVE, OnFilesave)
- ON_UPDATE_COMMAND_UI(ID_EDIT_CAPITALIZE, OnUpdateEditCapitalize)
- ON_WM_CLOSE()
- ON_COMMAND(ID_FILE_SAVE_AS_, OnFileSaveAs)
- //}}AFX_MSG_MAP
- ON_WM_GETMINMAXINFO()
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- m_strFileName = "";
- }
- CMainFrame::~CMainFrame()
- {
- if( pVariantsManager )
- {
- delete pVariantsManager;
- pVariantsManager = NULL;
- }
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
- | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
- !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
- {
- TRACE0("Failed to create toolbar\n");
- return -1; // fail to create
- }
- // TODO: Delete these three lines if you don't want the toolbar to
- // be dockable
- m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
- EnableDocking(CBRS_ALIGN_ANY);
- DockControlBar(&m_wndToolBar);
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status bar\n");
- return -1; // fail to create
- }
- m_wndStatusBar.SetPaneInfo(1, ID_INDICATOR_CAPS, CBRS_BOTTOM,100);
- m_bAutoMenuEnable = FALSE;
- if(-1 == LoadToolbarCombo())
- return FALSE;
- CreateSystem();
- CHAR strDirectory[MAX_PATH_LENGTH + 1]; // 软件所在路径
- CHAR strAppName[MAX_PATH_LENGTH + 1] = {0}; // 软件名称
- CHAR strFile[MAX_FILE_LENGTH + 1] = "";
- CHAR strValue[MAX_VALUE_LENGTH + 1] = "";
- int iPosFile = 0;
- int iLenghtFile = 0;
- ////////////////////////////////////////////////////////////////////////////
- //获取应用名
- GetModuleFileName(AfxGetApp()->m_hInstance, strDirectory, MAX_PATH_LENGTH);
- iLenghtFile = strlen(strDirectory);
- for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
- {
- if (strDirectory[iPosFile] == '\\')
- {
- memset(strAppName, 0, sizeof(strAppName));
- memcpy(strAppName, strDirectory + iPosFile + 1, iLenghtFile - iPosFile - 1);
- break;
- }
- }
-
- //获取系统路径
- //#ifdef _DEBUG
- // GetCurrentDirectory(MAX_PATH_LENGTH, strDirectory);
- //#else
- GetModuleFileName(AfxGetApp()->m_hInstance, strDirectory, MAX_PATH_LENGTH);
- iLenghtFile = strlen(strDirectory);
- for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
- {
- if (strDirectory[iPosFile] == '\\')
- {
- strDirectory[iPosFile] = '\0';
- break;
- }
- }
- //#endif
- if( pVariantsManager != NULL )
- {
- pVariantsManager->Load(strDirectory);//pVariantsManager->GetVarInfo();//
- }
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- int CMainFrame::LoadToolbarCombo()
- {
- return 0;
- }
- void CMainFrame::OnEditPaste()
- {
- char * buffer;
- if(!OpenClipboard())
- return;
- buffer = (char*)::GetClipboardData(CF_TEXT);
- CloseClipboard();
- CString str = buffer;
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- CWnd *pWnd = GetFocus();
- if(pWnd->m_hWnd!=edit.m_hWnd)
- {
- pWnd->SendMessage(WM_PASTE, 0, 0);
- return;
- }
-
- CHARRANGE cr;
- edit.GetSel(cr);
- icrEditView->SetParseCookieZeroFromGivenLine(edit.LineFromChar(cr.cpMin)); //粘贴时需重置解析缓冲区
- edit.ReplaceSel(str, TRUE);
- if(cr.cpMax != cr.cpMin)
- {
- icrEditView->ReCalcCursorPostion();
- }
- }
- void CMainFrame::OnEditcut()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &SynCtrl = icrEditView->GetRichEditCtrl();
- CWnd *pWnd = GetFocus();
- if(pWnd->m_hWnd != SynCtrl.m_hWnd)
- {
- pWnd->SendMessage(WM_CUT, 0, 0);
- return;
- }
-
- CHARRANGE cr;
- SynCtrl.GetSel( cr );
- icrEditView->GetRichEditCtrl().Cut();
- if(cr.cpMax != cr.cpMin)
- {
- icrEditView->ReCalcCursorPostion();
- }
- else
- {
- SCROLLINFO si;
- si.cbSize = sizeof(si);
- icrEditView->GetScrollInfo(SB_HORZ, &si);
- icrEditView->m_nHorzMaxOld = si.nMax;
- }
- }
- void CMainFrame::OnUpdateEditcut(CCmdUI* pCmdUI)
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl& editctrl = icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- editctrl.GetSel(cr);
- pCmdUI->Enable(cr.cpMin!=cr.cpMax);
- }
- void CMainFrame::OnEditcopy()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- CWnd *pWnd = GetFocus();
- if(pWnd->m_hWnd != edit.m_hWnd)
- {
- pWnd->SendMessage(WM_COPY, 0, 0);
- }
- else
- {
- edit.Copy();
- }
- }
- void CMainFrame::OnUpdateEditcopy(CCmdUI* pCmdUI)
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl& editctrl = icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- editctrl.GetSel(cr);
- pCmdUI->Enable(cr.cpMin!=cr.cpMax);
- }
- void CMainFrame::OnUpdateEditpaste(CCmdUI* pCmdUI)
- {
- OpenClipboard();
- if(::GetClipboardData(CF_TEXT)==FALSE)
- pCmdUI->Enable(FALSE);
- else
- pCmdUI->Enable(TRUE);
- CloseClipboard();
- }
- void CMainFrame::OnEditundo()
- {
- GetFocus()->SendMessage(EM_UNDO, 0, 0);
- }
- void CMainFrame::OnUpdateEditundo(CCmdUI* pCmdUI)
- {
- CWnd *pWnd = GetFocus();
- if(!pWnd)
- return;
- BOOL bCanUndo = pWnd->SendMessage(EM_CANUNDO, 0, 0);
- pCmdUI->Enable(bCanUndo);
- }
- void CMainFrame::OnEditredo()
- {
- GetFocus()->SendMessage(EM_REDO, 0, 0);
- }
- void CMainFrame::OnUpdateEditredo(CCmdUI* pCmdUI)
- {
- CWnd *pWnd = GetFocus();
- if(!pWnd)
- return;
- BOOL bCanRedo = pWnd->SendMessage(EM_CANREDO, 0, 0);
- pCmdUI->Enable(bCanRedo);
- }
- void CMainFrame::OnEditselectall()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
- CWnd *pWnd = GetFocus();
- if(pWnd->m_hWnd != editctrl.m_hWnd)
- {
- CString str;
- pWnd->GetWindowText(str);
- CHARRANGE ichCharRange;
- ichCharRange.cpMax = str.GetLength();
- ichCharRange.cpMin = 0;
- pWnd->SendMessage(EM_EXSETSEL, 0, (LPARAM)&ichCharRange);
- return;
- }
- editctrl.SetSel(0, -1);
- editctrl.SetFocus();
- editctrl.PostMessage( WM_PAINT, 0, 0 );
- }
- void CMainFrame::OnEditrepeat()
- {
- CWinApp *app = AfxGetApp();
- CMainFrame *mainfrm = (CMainFrame *)AfxGetMainWnd();
- CIcrEditView *icrEditView=(CIcrEditView *)GetActiveView();
- CString strEdit;
- BOOL bWholeWord = app->GetProfileInt(_T("CFind"), _T("WholeWord"), 0);
- BOOL bCase = app->GetProfileInt(_T("CFind"), _T("Case"), 0);
-
- if(strEdit.IsEmpty())
- return;
- int dwFlags = 0;
- if(bCase)
- dwFlags|=FR_MATCHCASE;
- if(bWholeWord)
- dwFlags|=FR_WHOLEWORD;
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- edit.GetSel(cr);
- FINDTEXTEX *ft = new FINDTEXTEX[1];
- ft->chrg.cpMin = cr.cpMin-1;
- ft->chrg.cpMax = -1;// search through end of the text
-
- TCHAR *t = new TCHAR[strEdit.GetLength()+1];
- strcpy(t, strEdit);
- ft->lpstrText = t;
-
- icrEditView->ShowWindow(SW_HIDE);
- int nPos = edit.SendMessage(EM_FINDTEXTEX, dwFlags, (LPARAM)ft);
- if(nPos!=-1) {
- edit.SetSel(ft->chrgText.cpMin, ft->chrgText.cpMax);
- icrEditView->SetFocus();
- SetFocus();
- icrEditView->ShowWindow(SW_SHOW);
- }
- else {
- icrEditView->ShowWindow(SW_SHOW);
- CString strShow;
- strShow.Format(_T("Cannot find the string: \"%s\", search again from the end?"), strEdit);
- if(MessageBox(strShow,_T("Find"), MB_ICONINFORMATION|MB_YESNO)==IDYES)
- {
- icrEditView->ShowWindow(SW_HIDE);
- edit.SetSel(0, -1);
- icrEditView->ShowWindow(SW_SHOW);
- CHARRANGE cr;
- edit.GetSel(cr);
- edit.SetSel(cr.cpMax, cr.cpMax);
-
- OnEditrepeat();
- if(t)
- delete t;
- if(ft)
- delete ft;
- return;
- }
- }
- if(t)
- delete t;
- if(ft)
- delete ft;
- }
- void CMainFrame::OnEditrepeatnext()
- {
- CWinApp *app = AfxGetApp();
- CMainFrame *mainfrm = (CMainFrame *)AfxGetMainWnd();
- CIcrEditView *icrEditView=(CIcrEditView *)GetActiveView();
- CString strEdit;
- BOOL bWholeWord = app->GetProfileInt(_T("CFind"), _T("WholeWord"), 0);
- BOOL bCase = app->GetProfileInt(_T("CFind"), _T("Case"), 0);
-
- if(strEdit.IsEmpty())
- return;
- int dwFlags = 0;
- if(bCase)
- dwFlags|=FR_MATCHCASE;
- if(bWholeWord)
- dwFlags|=FR_WHOLEWORD;
- dwFlags|=FR_DOWN;;
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- edit.GetSel(cr);
- FINDTEXTEX *ft = new FINDTEXTEX[1];
- ft->chrg.cpMin = cr.cpMin+1;
- ft->chrg.cpMax = -1;// search through end of the text
-
- TCHAR *t = new TCHAR[strEdit.GetLength()+1];
- strcpy(t, strEdit);
- ft->lpstrText = t;
-
- icrEditView->ShowWindow(SW_HIDE);
- int nPos = edit.SendMessage(EM_FINDTEXTEX, dwFlags, (LPARAM)ft);
-
- if(nPos!=-1) {
-
- edit.SetSel(ft->chrgText.cpMin, ft->chrgText.cpMax);
- icrEditView->SetFocus();
- SetFocus();
- icrEditView->ShowWindow(SW_SHOW);
- }
- else {
- icrEditView->ShowWindow(SW_SHOW);
- CString strShow;
- strShow.Format(_T("Cannot find the string: \"%s\", search again from the beginning?"), strEdit);
- if(MessageBox(strShow, _T("Find"), MB_ICONINFORMATION|MB_YESNO)==IDYES)
- {
- edit.SetSel(0, 0);
- OnEditrepeatnext();
- if(t)
- delete t;
- if(ft)
- delete ft;
- return;
- }
- }
- if(t)
- delete t;
- if(ft)
- delete ft;
- }
- void CMainFrame::OnUpdateEditrepeat(CCmdUI* pCmdUI)
- {
- }
- void CMainFrame::OnUpdateEditrepeatnext(CCmdUI* pCmdUI)
- {
- }
- void CMainFrame::OnViewFont()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- BOOL bModify = edit.GetModify();
- edit.ShowWindow(SW_HIDE);
-
- CString strText;
- EDITSTREAM stream;
- stream.dwCookie = (DWORD)&strText;
- stream.pfnCallback = EditStreamCallbackOut;
- edit.StreamOut(SF_TEXT, stream);
-
- CHARFORMAT cr;
-
- if(strText.IsEmpty())
- {
- strText = _T(" ");
- edit.SetSel(0, 1);
- cr = icrEditView->GetCharFormatSelection();
- edit.SetSel(0, 0);
- }
- else
- {
- CHARRANGE range;
- edit.GetSel(range);
- int ntemp;
- if(range.cpMax < range.cpMin)
- {
- ntemp = range.cpMax;
- range.cpMax = range.cpMin;
- range.cpMin = ntemp;
- }
- if(range.cpMax == range.cpMin)
- {
- if(range.cpMin == 0)
- {
- edit.SetSel(0, 1);
- }
- else
- {
- edit.SetSel(range.cpMin-1, range.cpMin);
- }
-
- cr = icrEditView->GetCharFormatSelection();
- edit.SetSel(range.cpMin, range.cpMin);
- }
- else
- {
- cr = icrEditView->GetCharFormatSelection();
- }
- }
- edit.ShowWindow(SW_SHOW);
-
- CFontDialog dlg(cr, CF_BOTH|CF_NOOEMFONTS);
-
- if (dlg.DoModal() == IDOK)
- {
- CHARFORMAT cr;
- dlg.GetCharFormat(cr);
- LockWindowUpdate();
-
- icrEditView->SetWindowText(_T(""));
-
- icrEditView->SetSynEditViewFont(*dlg.m_cf.lpLogFont);
- icrEditView->SetWindowText(strText);
-
- edit.SetModify(bModify);
- UnlockWindowUpdate();
- }
- }
- void CMainFrame::SaveTheContext()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &richctrl=icrEditView->GetRichEditCtrl();
-
- if(0 == m_strFileName.GetLength())
- return;
- CFile cFile(m_strFileName, CFile::modeCreate|CFile::modeWrite);
- EDITSTREAM es;
- es.dwCookie = (DWORD) &cFile;
- es.pfnCallback = EditStreamCallbackWriteToFile;
- richctrl.StreamOut(SF_TEXT, es);
- richctrl.SetModify(FALSE);
- }
- void CMainFrame::OnFileOpen()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- if(edit.GetModify())
- {
- if(MessageBox("文件已经修改,需要保存吗??", "", MB_YESNO|MB_ICONQUESTION)==IDNO)
- ;
- else //保存
- {
- OnFilesave();
- }
- }
-
- CFileDialog fd (TRUE, _T(""), NULL, OFN_HIDEREADONLY|OFN_EXPLORER, "*.srp|*.srp||");
- if(IDCANCEL == fd.DoModal())
- {
- return;
- }
-
- m_strFileName = fd.GetPathName();
- icrEditView->LoadFile(m_strFileName);
- }
- void CMainFrame::OnEditTrimtraillingspace()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CWaitCursor wc;
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- int nfirstline = edit.GetFirstVisibleLine();
- CHARRANGE cr;
- edit.GetSel(cr);
- int nline = edit.LineFromChar(cr.cpMin);
- CString strtext;
- EDITSTREAM stream;
- stream.dwCookie = (DWORD)&strtext;
- stream.pfnCallback = EditStreamCallbackOut;
- edit.StreamOut(SF_TEXT, stream);
- CString strnewtext = _T(""), strline;
- int npos = strtext.Find('\n');
- while(npos!=-1) {
- strline = strtext.Left(npos-1);
- strline.TrimRight(0x20);
- strline += '\n';
- strtext = strtext.Right(strtext.GetLength()-npos-1);
- strnewtext += strline;
- npos = strtext.Find('\n');
- }
- icrEditView->LoadText(strnewtext);
- icrEditView->GotoLine(nfirstline+1);
- int nlineindex = edit.LineIndex(nline);
- edit.SetSel(nlineindex, nlineindex);
- icrEditView->ShowCursorPosition();
- icrEditView->SetFocus();
- SaveTheContext();
- }
- void CMainFrame::OnEditTrimtraillingtab()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CWaitCursor wc;
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- int nfirstline = edit.GetFirstVisibleLine();
- CHARRANGE cr;
- edit.GetSel(cr);
- int nline = edit.LineFromChar(cr.cpMin);
- CString strtext;
- EDITSTREAM stream;
- stream.dwCookie = (DWORD)&strtext;
- stream.pfnCallback = EditStreamCallbackOut;
- edit.StreamOut(SF_TEXT, stream);
- CString strnewtext = _T(""), strline;
- int npos = strtext.Find('\n');
- while(npos!=-1) {
- strline = strtext.Left(npos-1);
- strline.TrimRight(0x9);
- strline += '\n';
- strtext = strtext.Right(strtext.GetLength()-npos-1);
- strnewtext += strline;
- npos = strtext.Find('\n');
- }
- icrEditView->LoadText(strnewtext);
- icrEditView->GotoLine(nfirstline+1);
- int nlineindex = edit.LineIndex(nline);
- edit.SetSel(nlineindex, nlineindex);
- icrEditView->ShowCursorPosition();
- icrEditView->SetFocus();
- SaveTheContext();
- }
- void CMainFrame::OnEditTabtospace()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CWaitCursor wc;
- TCHAR chr = 0x9;
- CString strtab = chr;
- int ntabsize = icrEditView->GetTabSize();
- CString strspace((char)0x20, ntabsize);
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- int nfirstline = edit.GetFirstVisibleLine();
- CHARRANGE cr;
- edit.GetSel(cr);
- int nline = edit.LineFromChar(cr.cpMin);
- CString strtext;
- EDITSTREAM stream;
- stream.dwCookie = (DWORD)&strtext;
- stream.pfnCallback = EditStreamCallbackOut;
- edit.StreamOut(SF_TEXT, stream);
- strtext.Replace(strtab, strspace);
- icrEditView->LoadText(strtext);
- icrEditView->GotoLine(nfirstline+1);
- int nlineindex = edit.LineIndex(nline);
- edit.SetSel(nlineindex, nlineindex);
- icrEditView->ShowCursorPosition();
- icrEditView->SetFocus();
- SaveTheContext();
- }
- void CMainFrame::OnEditSpacetotab()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CWaitCursor wc;
- TCHAR chr = 0x9;
- CString strtab = chr;
- int ntabsize = icrEditView->GetTabSize();
- CString strspace((char)0x20, ntabsize);
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- int nfirstline = edit.GetFirstVisibleLine();
- CHARRANGE cr;
- edit.GetSel(cr);
- int nline = edit.LineFromChar(cr.cpMin);
- CString strtext;
- EDITSTREAM stream;
- stream.dwCookie = (DWORD)&strtext;
- stream.pfnCallback = EditStreamCallbackOut;
- edit.StreamOut(SF_TEXT, stream);
- strtext.Replace(strspace, strtab);
- icrEditView->LoadText(strtext);
- icrEditView->GotoLine(nfirstline+1);
- int nlineindex = edit.LineIndex(nline);
- edit.SetSel(nlineindex, nlineindex);
- icrEditView->ShowCursorPosition();
- icrEditView->SetFocus();
- SaveTheContext();
- }
- void CMainFrame::OnEditLeadingspacetotab()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CWaitCursor wc;
- int ntabsize = icrEditView->GetTabSize();
- CString strspace((char)0x20, ntabsize);
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- int nfirstline = edit.GetFirstVisibleLine();
- CHARRANGE cr;
- edit.GetSel(cr);
- int nline = edit.LineFromChar(cr.cpMin);
- CString strtext;
- EDITSTREAM stream;
- stream.dwCookie = (DWORD)&strtext;
- stream.pfnCallback = EditStreamCallbackOut;
- edit.StreamOut(SF_TEXT, stream);
- CString strnewtext = _T(""), strline;
- int npos = strtext.Find('\n');
- while(npos!=-1) {
- int i=0;
- strline = strtext.Left(npos);
- while(strline[i]==0x20 || strline[i]==0x9)
- i++;
- CString strtmp = strline.Left(i);
- strtmp.Replace( strspace, _T("\t"));
- strline = strtmp + strline.Right(strline.GetLength()-i);
- strline += '\n';
- strtext = strtext.Right(strtext.GetLength()-npos-1);
- strnewtext += strline;
- npos = strtext.Find('\n');
- }
- icrEditView->LoadText(strnewtext);
- icrEditView->GotoLine(nfirstline+1);
- int nlineindex = edit.LineIndex(nline);
- edit.SetSel(nlineindex, nlineindex);
- icrEditView->ShowCursorPosition();
- icrEditView->SetFocus();
- SaveTheContext();
- }
- void CMainFrame::OnEditMoveright()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &SynCtrl = icrEditView->GetRichEditCtrl();
- icrEditView->ShowWindow(SW_HIDE);
- int nfirstline, nendline;
- icrEditView->GetSelLine(nfirstline, nendline);
-
- CString strtext=_T(""), strline;
- BOOL bpriorlinerealreturn;
- int linenumber = nendline - nfirstline + 1;
- for(int i=0; i<linenumber; i++) {
- if(nfirstline+i-1<0)//判断前一行行末是否是硬回车
- bpriorlinerealreturn = TRUE;
- else
- bpriorlinerealreturn = icrEditView->GetLineString(nfirstline+i-1, strline);
- icrEditView->GetLineString(nfirstline+i, strline);
- if(bpriorlinerealreturn || nfirstline==nendline) { //如果上一行是真的换行
- int nselstart = SynCtrl.LineIndex(nfirstline+i);
- SynCtrl.SetSel(nselstart, nselstart);
- int noldlinecount = SynCtrl.GetLineCount();
- SynCtrl.ReplaceSel(_T("\t"), TRUE); //替换后可能引总行数增加
- int nnewlinecount = SynCtrl.GetLineCount();
- linenumber+=nnewlinecount-noldlinecount;
- }
- }
- int nselstart = SynCtrl.LineIndex(nfirstline);
- int nselend = SynCtrl.LineIndex(nfirstline+linenumber);
- SynCtrl.SetSel(nselstart, nselend);
- icrEditView->ShowWindow(SW_SHOW);
- }
- void CMainFrame::OnEditMoveleft()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &SynCtrl = icrEditView->GetRichEditCtrl();
- icrEditView->ShowWindow(SW_HIDE);
- int nfirstline, nendline;
- icrEditView->GetSelLine(nfirstline, nendline);
-
- CString strtext=_T(""), strline;
-
- BOOL bpriorlinerealreturn;
- int linenumber = nendline - nfirstline + 1;
-
- for(int i=0; i<linenumber; i++) {
- if(nfirstline+i-1<0)//判断前一行行末是否是硬回车
- bpriorlinerealreturn = TRUE;
- else
- bpriorlinerealreturn = icrEditView->GetLineString(nfirstline+i-1, strline);
- icrEditView->GetLineString(nfirstline+i, strline);
- if(bpriorlinerealreturn || nfirstline==nendline) { //如果上一行是真的换行
- int nselstart = SynCtrl.LineIndex(nfirstline+i);
- SynCtrl.SetSel(nselstart, nselstart);
- if(strline.Left(1)==_T("\t")) {
- SynCtrl.SetSel(nselstart, nselstart+1);
- SynCtrl.ReplaceSel(_T(""), TRUE); //替换后可能引总行数减少
- }
- else {
- if(strline!=_T(" ")) { //之所以有此判断是因为如果是空行icrEditView->GetLineString会返回一个空格
- int ncount = (strline.GetLength()>icrEditView->GetTabSize()? strline.GetLength():icrEditView->GetTabSize());
- for(int j=0; j<ncount; j++) {
- if(strline[j]!=0x20)
- break;
- }
- SynCtrl.SetSel(nselstart, nselstart+j);
- SynCtrl.ReplaceSel(_T(""), TRUE); //替换后可能引总行数减少
- }
- }
- int noldlinecount = SynCtrl.GetLineCount();
- int nnewlinecount = SynCtrl.GetLineCount();
- linenumber+=nnewlinecount-noldlinecount;
- }
- }
- int nselstart = SynCtrl.LineIndex(nfirstline);
- int nselend = SynCtrl.LineIndex(nfirstline+linenumber);
- SynCtrl.SetSel(nselstart, nselend);
- icrEditView->ShowWindow(SW_SHOW);
- }
- void CMainFrame::OnEditUncomment()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &SynCtrl = icrEditView->GetRichEditCtrl();
- int nfirstline, nendline;
- icrEditView->GetSelLine(nfirstline, nendline);
-
- //取当前语言对应的单行注释字符串
- CString strsinglecomment=icrEditView->GetSingleCommentString(icrEditView->GetLanguage());
- if(strsinglecomment.IsEmpty()) //若为空串表示当前没有进行语法关键字显示
- return;
- CString strtext=_T(""), strline;
-
- icrEditView->ShowWindow(SW_HIDE);
- BOOL bpriorlinerealreturn;
- int linenumber = nendline - nfirstline + 1;
-
- for(int i=0; i<linenumber; i++) {
- if(nfirstline+i-1<0)//判断前一行行末是否是硬回车
- bpriorlinerealreturn = TRUE;
- else
- bpriorlinerealreturn = icrEditView->GetLineString(nfirstline+i-1, strline);
- icrEditView->GetLineString(nfirstline+i, strline);
- if(bpriorlinerealreturn || nfirstline==nendline) { //如果上一行是真的换行
- int nselstart = SynCtrl.LineIndex(nfirstline+i);
- SynCtrl.SetSel(nselstart, nselstart);
- if(strline!=_T(" ")) {
- if(strline.Left(strsinglecomment.GetLength())==strsinglecomment)
- SynCtrl.SetSel(nselstart, nselstart+strsinglecomment.GetLength());
- else {
- CString strtmp = strline;
- if(strtmp.GetLength()!=0) {
- while(strtmp.GetAt(0)==0x20 || strtmp.GetAt(0)=='\t') {
- strtmp.TrimLeft(0x20);
- strtmp.TrimLeft('\t');
- if(strtmp.GetLength()==0)
- break;
- }
- if(strtmp.GetLength()>=strsinglecomment.GetLength() ) {
- if(strtmp.Left(strsinglecomment.GetLength())==strsinglecomment) {
- int npos = strline.Find(strsinglecomment);
- SynCtrl.SetSel( nselstart+npos, nselstart+npos+strsinglecomment.GetLength());
- }
- }
- }
- }
- }
-
- int noldlinecount=SynCtrl.GetLineCount();
- SynCtrl.ReplaceSel(_T(""), TRUE); //此行可能引起总的行数减少
- int nnewlinecount=SynCtrl.GetLineCount();
- linenumber+=nnewlinecount-noldlinecount;
- }
- }
- int nselstart = SynCtrl.LineIndex(nfirstline);
- int nselend = SynCtrl.LineIndex(nfirstline+linenumber);
- SynCtrl.SetSel(nselstart, nselend);
- icrEditView->ShowWindow(SW_SHOW);
- }
- void CMainFrame::OnEditComment()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &SynCtrl = icrEditView->GetRichEditCtrl();
- int nfirstline, nendline;
- icrEditView->GetSelLine(nfirstline, nendline);
-
- //取当前语言对应的单行注释字符串
- CString strsinglecomment=icrEditView->GetSingleCommentString(icrEditView->GetLanguage());
- if(strsinglecomment.IsEmpty()) //若为空串表示当前没有进行语法关键字显示
- return;
- icrEditView->ShowWindow(SW_HIDE);
- CString strtext=_T(""), strline;
- BOOL bpriorlinerealreturn;
- int linenumber = nendline - nfirstline + 1;
- for(int i=0; i<linenumber; i++) {
- if(nfirstline+i-1<0)//判断前一行行末是否是硬回车
- bpriorlinerealreturn = TRUE;
- else
- bpriorlinerealreturn = icrEditView->GetLineString(nfirstline+i-1, strline);
- icrEditView->GetLineString(nfirstline+i, strline);
- if(bpriorlinerealreturn || nfirstline==nendline) { //如果上一行是真的换行
- int nselstart = SynCtrl.LineIndex(nfirstline+i);
- SynCtrl.SetSel(nselstart, nselstart);
- int noldlinecount = SynCtrl.GetLineCount();
- SynCtrl.ReplaceSel(strsinglecomment, TRUE);
- int nnewlinecount = SynCtrl.GetLineCount();
- linenumber+=nnewlinecount-noldlinecount;
- }
- }
- int nselstart = SynCtrl.LineIndex(nfirstline);
- int nselend = SynCtrl.LineIndex(nfirstline+linenumber);
- SynCtrl.SetSel(nselstart, nselend);
- icrEditView->ShowWindow(SW_SHOW);
- }
- void CMainFrame::OnEditLcase()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- edit.GetSel(cr);
- CString strsel;
- EDITSTREAM stream;
- stream.dwCookie = (DWORD)&strsel;
- stream.pfnCallback = EditStreamCallbackOut;
- edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
-
- strsel.MakeLower();
- edit.ReplaceSel(strsel, TRUE);
- edit.SetSel(cr);
- }
- void CMainFrame::OnEditUcase()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- edit.GetSel(cr);
- CString strsel;
- EDITSTREAM stream;
- stream.dwCookie = (DWORD)&strsel;
- stream.pfnCallback = EditStreamCallbackOut;
- edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
-
- strsel.MakeUpper();
- edit.ReplaceSel(strsel, TRUE);
- edit.SetSel(cr);
- }
- void CMainFrame::OnEditInvert()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- edit.GetSel(cr);
- CString strsel;
- EDITSTREAM stream;
- stream.dwCookie = (DWORD)&strsel;
- stream.pfnCallback = EditStreamCallbackOut;
- edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
-
- for(int i=0; i<strsel.GetLength(); i++) {
- TCHAR ch = strsel[i];
- if( ch >='A' && ch <='Z' )
- strsel.SetAt(i, ch + 'a' - 'A');
- else if( ch >='a' && ch <='z' )
- strsel.SetAt(i, ch + 'A' - 'a');
- }
- edit.ReplaceSel(strsel, TRUE);
- edit.SetSel(cr);
- }
- void CMainFrame::OnEditCapitalize()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- edit.GetSel(cr);
- CString strsel;
- EDITSTREAM stream;
- stream.dwCookie = (DWORD)&strsel;
- stream.pfnCallback = EditStreamCallbackOut;
- edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
- strsel.MakeLower();
-
- BOOL bIsChar = FALSE, bInString=FALSE;
- for(int i=0; i<strsel.GetLength(); i++) {
- TCHAR ch = strsel[i];
- if( ch >='a' && ch <='z' && !bIsChar) {
- strsel.SetAt(i, ch + 'A' - 'a');
- }
- if( (ch >='a' && ch <='z') || (ch >='A' && ch <='Z') )
- bIsChar = TRUE;
- else
- bIsChar = FALSE;
- }
- edit.ReplaceSel(strsel, TRUE);
- edit.SetSel(cr);
- }
- void CMainFrame::OnEditSentancecase()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- edit.GetSel(cr);
- CString strsel;
- EDITSTREAM stream;
- stream.dwCookie = (DWORD)&strsel;
- stream.pfnCallback = EditStreamCallbackOut;
- edit.StreamOut(SF_TEXT|SFF_SELECTION, stream);
-
- BOOL bDo = TRUE;
- for(int i=0; i<strsel.GetLength(); i++) {
- TCHAR ch = strsel[i];
- if(ch == 0xa)
- bDo = TRUE;
- if( ((ch >='a' && ch <='z') || (ch >='A' && ch <='Z')) && bDo) {
- if( ch >='A' && ch <='Z' )
- strsel.SetAt(i, ch + 'a' - 'A');
- else
- strsel.SetAt(i, ch + 'A' - 'a');
- bDo = FALSE;
- }
- }
- edit.ReplaceSel(strsel, TRUE);
- edit.SetSel(cr);
- }
- CString CMainFrame::GetFileContext(CString strfile)
- {
- CString str=_T("");;
- CFileException fe;
- CFile file;
- file.Open(strfile, CFile::modeRead, &fe);
- if(fe.m_cause != CFileException::none) {
- fe.ReportError();
- return _T("");
- }
- DWORD dwSize=(DWORD)file.GetLength();
- if(dwSize==0)
- return _T("");
- try {
- LPSTR lpszContext=new TCHAR[1];
- file.Read(lpszContext, 1);
- if(*lpszContext==-1) {
- if(lpszContext!=NULL)
- delete lpszContext;
- LPWSTR lpsztext= new WCHAR[1];
- file.Read(lpsztext, 1);
- if(lpsztext!=NULL)
- delete lpsztext;
- lpsztext= new WCHAR[dwSize-1];
- DWORD dwRead=file.Read(lpsztext, dwSize-2);
- lpsztext[dwRead/2]=0;
- str=lpsztext;
- if(lpsztext!=NULL)
- delete lpsztext;
- }
- else {
- if(lpszContext!=NULL)
- delete lpszContext;
- lpszContext=new TCHAR[dwSize+2];
- file.Seek(0, CFile::begin);
- DWORD dwRead=file.Read(lpszContext, dwSize);
- file.Close();
- lpszContext[dwRead]='\0';
- str=lpszContext;
- if(lpszContext!=NULL)
- delete lpszContext;
- }
- }
- catch(...){}
-
- return str;
- }
- void CMainFrame::OnSelchangeComboFind()
- {
- }
- void CMainFrame::OnUpdateEditLcase(CCmdUI* pCmdUI)
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- editctrl.GetSel(cr);
- pCmdUI->Enable(cr.cpMin!=cr.cpMax);
- }
- void CMainFrame::OnUpdateEditInvert(CCmdUI* pCmdUI)
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- editctrl.GetSel(cr);
- pCmdUI->Enable(cr.cpMin!=cr.cpMax);
- }
- void CMainFrame::OnUpdateEditSentancecase(CCmdUI* pCmdUI)
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- editctrl.GetSel(cr);
- pCmdUI->Enable(cr.cpMin!=cr.cpMax);
- }
- void CMainFrame::OnUpdateEditUcase(CCmdUI* pCmdUI)
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- editctrl.GetSel(cr);
- pCmdUI->Enable(cr.cpMin!=cr.cpMax);
- }
- void CMainFrame::OnFileNew()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- if(!m_strFileName.IsEmpty())
- {
- if(edit.GetModify())
- {
- if(MessageBox("文件已经修改,需要保存吗?", "", MB_YESNO|MB_ICONQUESTION)==IDYES)
- {
- SaveTheContext();
- }
- }
- }
-
- edit.SetWindowText("");
- m_strFileName = "";
- icrEditView->SetSynEditViewFont(icrEditView->GetSynEditViewFont());
- }
- void CMainFrame::OnFileSaveAs()
- {
- if(m_strFileName.IsEmpty())
- {
- CFileDialog fd ( FALSE, _T(""), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.srp|*.srp||"));
- if(fd.DoModal()==IDCANCEL)
- return;
- m_strFileName = fd.GetPathName();
- }
- else
- {
- CString strFileName = m_strFileName;
- int nPos= strFileName.ReverseFind('\\');
- strFileName = strFileName.Right(strFileName.GetLength()-nPos-1);
- CFileDialog fd ( FALSE, "", NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.srp|*.srp||"));
- wsprintf(fd.m_ofn.lpstrFile, strFileName);
- if(fd.DoModal()==IDCANCEL)
- return;
- m_strFileName = fd.GetPathName();
- }
- SaveTheContext();
- }
- void CMainFrame::OnFilesave()
- {
- if(m_strFileName.IsEmpty())
- {
- CFileDialog fd ( FALSE, _T(""), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.srp|*.srp||"));
- if(fd.DoModal()==IDCANCEL)
- return;
- m_strFileName = fd.GetPathName();
- }
- SaveTheContext();
- }
- void CMainFrame::OnUpdateEditCapitalize(CCmdUI* pCmdUI)
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &editctrl=icrEditView->GetRichEditCtrl();
- CHARRANGE cr;
- editctrl.GetSel(cr);
- pCmdUI->Enable(cr.cpMin!=cr.cpMax);
-
- }
- void CMainFrame::OnClose()
- {
- CIcrEditView *icrEditView = (CIcrEditView *)GetActiveView();
- CRichEditCtrl &edit = icrEditView->GetRichEditCtrl();
- if(edit.GetModify())
- {
- int nRet = MessageBox("文件已经修改,需要保存吗?", "", MB_YESNOCANCEL|MB_ICONQUESTION);
- if(nRet==IDYES)
- {
- if(!m_strFileName.IsEmpty())
- {
- SaveTheContext();
- }
- else
- {
- CFileDialog fd ( FALSE, _T(""), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, _T("*.*|*.*||"));
- if(fd.DoModal()==IDCANCEL)
- return;
- m_strFileName = fd.GetPathName();
- SaveTheContext();
- }
- }
- else if(nRet==IDCANCEL)
- {
- return;
- }
- }
-
- CFrameWnd::OnClose();
- }
|