From: boca4711 <boc...@us...> - 2005-10-16 11:58:49
|
Update of /cvsroot/anyedit/AnyEditv2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16522 Modified Files: AnyEditDoc.cpp AnyEditDoc.h Log Message: - Add save last positions - Removed error message "Check for write permission in Temp directory. Class view disabled!" - File reload is possible on non modified files too Index: AnyEditDoc.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEditDoc.h,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** AnyEditDoc.h 12 Oct 2005 18:55:57 -0000 1.28 --- AnyEditDoc.h 16 Oct 2005 11:58:41 -0000 1.29 *************** *** 106,113 **** --- 106,118 ---- // Implementation public: + void LockCheckLastAccessTime(bool bLock); + bool IsOnOpenFile(void); + void SetLastChangePosition(long nPos, long nOffset); + long GetLastChangePosition(long nPos); bool IsFileReadOnly(void); void ReloadFile(void); CAnyEditView* GetFirstEditView() const; void SetDocScintilla(CScintillaEx * m_pscin); + void SetLastAccessTime(); #ifdef _DEBUG *************** *** 117,120 **** --- 122,127 ---- protected: + bool m_bOnOpenFile; + long m_arLastPositions[3]; // the three last textpositions bool m_bLockCheckLastAccessTime; bool m_bFileReadOnly; *************** *** 122,126 **** // Helpers - void SetLastAccessTime(); void RemoveTempCopy(BOOL bForgetName = FALSE); void CleanProjectFile(); --- 129,132 ---- Index: AnyEditDoc.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/AnyEditDoc.cpp,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** AnyEditDoc.cpp 14 Apr 2005 12:01:42 -0000 1.53 --- AnyEditDoc.cpp 16 Oct 2005 11:58:41 -0000 1.54 *************** *** 96,99 **** --- 96,102 ---- m_bLockCheckLastAccessTime = false; m_bSelectCopy = false; + for (int i = 0; i < 3; i++) + m_arLastPositions[i] = INVALID_POSITION; + m_bOnOpenFile = false; } *************** *** 281,286 **** --- 284,295 ---- // Use Scintilla to open the file. CAnyEditView* pFirstView = GetFirstEditView(); + m_bOnOpenFile = true; if (!pFirstView->GetScintillaControl()->OpenFile(lpszPathName)) + { + m_bOnOpenFile = false; return FALSE; + } + + m_bOnOpenFile = false; SetPathName(lpszPathName); *************** *** 588,592 **** if(!fp.Open((LPCTSTR)m_sTempCopyPath, CFile::modeCreate | CFile::modeWrite, &e)) { ! AfxMessageBox("Check for Write permissions in Temp directory! Class view disabled !"); return bResult; } --- 597,602 ---- if(!fp.Open((LPCTSTR)m_sTempCopyPath, CFile::modeCreate | CFile::modeWrite, &e)) { ! // AfxMessageBox("Check for Write permissions in Temp directory! Class view disabled !"); ! // try later again return bResult; } *************** *** 916,920 **** --- 926,932 ---- int nCurrentLine = pFirstView->GetScintillaControl()->GetCurLineNumber(); pFirstView->GetScintillaControl()->SetFocus(); + m_bOnOpenFile = true; pFirstView->GetScintillaControl()->OpenFile(GetPathName()); + m_bOnOpenFile = false; if (nCurrentLine < pFirstView->GetScintillaControl()->GetLineCount()) pFirstView->GetScintillaControl()->GotoLineEnsureVisible(nCurrentLine); *************** *** 1054,1057 **** void CAnyEditDoc::OnUpdateFileReload(CCmdUI* pCmdUI) { ! pCmdUI->Enable(! GetPathName().IsEmpty() && IsModified()); } --- 1066,1158 ---- void CAnyEditDoc::OnUpdateFileReload(CCmdUI* pCmdUI) { ! // pCmdUI->Enable(! GetPathName().IsEmpty() && IsModified()); ! pCmdUI->Enable(! GetPathName().IsEmpty() ); ! } ! ! /// Get last position of change. ! long CAnyEditDoc::GetLastChangePosition(long nPos) ! { ! CScintillaEx* pScintilla = GetFirstEditView()->GetScintillaControl(); ! int nCurrentLine = pScintilla->LineFromPosition(nPos); ! ! // check if current position is on same line ! int nIndex = -1; ! for (int i = 0; i < 3; i++) ! { ! if (m_arLastPositions[i] != INVALID_POSITION && pScintilla->LineFromPosition(m_arLastPositions[i]) == nCurrentLine) ! { ! nIndex = i; ! break; ! } ! } ! long nLastPosition; ! if (nIndex == 0 || nIndex == 1) ! nLastPosition = m_arLastPositions[nIndex + 1]; ! else ! nLastPosition = m_arLastPositions[0]; ! ! // last position of change ! return nLastPosition; ! } ! ! /// Set last position of change, remove oldest entry and adjust other positions with offset if needed. ! void CAnyEditDoc::SetLastChangePosition(long nPos, long nOffset) ! { ! CScintillaEx* pScintilla = GetFirstEditView()->GetScintillaControl(); ! int nCurrentLine; ! long nNewPos = nPos + nOffset; ! ! nCurrentLine = pScintilla->LineFromPosition(nNewPos); ! // check if current position is on same line ! int nIndex = -1; ! for (int i = 0; i < 3; i++) ! { ! // ignore invalid positions ! if (m_arLastPositions[i] == INVALID_POSITION) ! break; ! if (pScintilla->LineFromPosition(m_arLastPositions[i]) == nCurrentLine) ! { ! nIndex = i; ! break; ! } ! if (i == 0 && pScintilla->LineFromPosition(m_arLastPositions[i]) == pScintilla->LineFromPosition(nPos)) ! { ! // check if last change was on same position e.g. pasting some lines ! nIndex = i; ! break; ! } ! } ! ! if (nIndex == 0) ! { ! m_arLastPositions[0] = nNewPos; ! } ! else if (nIndex == 1) ! { ! m_arLastPositions[1] = m_arLastPositions[0]; ! m_arLastPositions[0] = nNewPos; ! } ! else // (nIndex == 2 || nIndex == -1) ! { ! m_arLastPositions[2] = m_arLastPositions[1]; ! m_arLastPositions[1] = m_arLastPositions[0]; ! m_arLastPositions[0] = nNewPos; ! } ! ! // adjust positions with offset ! if (m_arLastPositions[2] > nPos) ! m_arLastPositions[2] += nOffset; ! if (m_arLastPositions[1] > nPos) ! m_arLastPositions[1] += nOffset; ! } ! ! /// If file is opened IsOnOpenFile returns true otherwise false ! bool CAnyEditDoc::IsOnOpenFile() ! { ! return m_bOnOpenFile; ! } ! ! void CAnyEditDoc::LockCheckLastAccessTime(bool bLock) ! { ! m_bLockCheckLastAccessTime = bLock; } |