12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313 |
- // 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());
-
- int j = 0;
- for(; 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();
- }
|