OSDN Git Service

PATCH: [ 784302 ] Implement Read-only for files and dirs - Only background changes...
authorKimmo Varis <kimmov@gmail.com>
Wed, 27 Aug 2003 12:20:36 +0000 (12:20 +0000)
committerKimmo Varis <kimmov@gmail.com>
Wed, 27 Aug 2003 12:20:36 +0000 (12:20 +0000)
Src/DirDoc.cpp
Src/DirDoc.h
Src/DirView.cpp
Src/MainFrm.cpp
Src/MainFrm.h
Src/MergeDoc.cpp
Src/MergeDoc.h
Src/MergeEditView.cpp
Src/MergeEditView.h
Src/readme.txt

index ab7fc1d..3ada9cb 100644 (file)
@@ -321,7 +321,7 @@ static LPCTSTR GetItemPathIfShowable(const DIFFITEM & di, int llen, int rlen)
 
 void CDirDoc::Redisplay()
 {
-m_pDirView->ToDoDeleteThisValidateColumnOrdering();
+       m_pDirView->ToDoDeleteThisValidateColumnOrdering();
 
        if (m_pCtxt == NULL)
                return;
@@ -348,7 +348,7 @@ m_pDirView->ToDoDeleteThisValidateColumnOrdering();
                        cnt++;
                }
        }
-m_pDirView->ToDoDeleteThisValidateColumnOrdering();
+       m_pDirView->ToDoDeleteThisValidateColumnOrdering();
 }
 
 CDirView * CDirDoc::GetMainView()
@@ -583,3 +583,28 @@ void CDirDoc::UpdateChangedItem(LPCTSTR pathLeft, LPCTSTR pathRight, bool unifie
        // Update view
        UpdateScreenItemStatus(ind, current);
 }
+
+/**
+ * @brief Set left/right side readonly-status
+ * @param bLeft Select side to set (TRUE = left)
+ * @param bReadOnly New status of selected side
+ */
+void CDirDoc::SetReadOnly(BOOL bLeft, BOOL bReadOnly)
+{
+       if (bLeft)
+               m_bROLeft = bReadOnly;
+       else
+               m_bRORight = bReadOnly;
+}
+
+/**
+ * @brief Return left/right side readonly-status
+ * @param bLeft Select side to ask (TRUE = left)
+ */
+BOOL CDirDoc::GetReadOnly(BOOL bLeft) const
+{
+       if (bLeft)
+               return m_bROLeft;
+       else
+               return m_bRORight;
+}
index ef2de27..28dc3cf 100644 (file)
@@ -40,12 +40,18 @@ class CMergeDoc;
 typedef CTypedPtrList<CPtrList, CMergeDoc *> MergeDocPtrList;
 class DirDocFilter;
 
+/**
+ * @brief User-defined Windows-messages
+ */
 const UINT MSG_UI_UPDATE = WM_USER;
 const UINT MSG_STAT_UPDATE = WM_USER + 1;
 
 /////////////////////////////////////////////////////////////////////////////
 // CDirDoc document
 
+/**
+ * @brief Documentclass for directory compare
+ */
 class CDirDoc : public CDocument
 {
 protected:
@@ -72,6 +78,8 @@ public:
 
 // Implementation
 public:
+       BOOL GetReadOnly(BOOL bLeft) const;
+       void SetReadOnly(BOOL bLeft, BOOL bReadOnly);
        void UpdateChangedItem(LPCTSTR pathLeft, LPCTSTR pathRight, bool unified);
        POSITION FindItemFromPaths(LPCTSTR pathLeft, LPCTSTR pathRight);
        void SetDiffContext(CDiffContext *pCtxt);
@@ -107,9 +115,11 @@ private:
        CDirView *m_pDirView;
        MergeDocPtrList m_MergeDocs;
        BOOL m_bReuseMergeDocs; // policy to reuse existing merge docs
+       BOOL m_bROLeft;
+       BOOL m_bRORight;
 };
 
-// callback for file/directory filtering during diff
+/// callback for file/directory filtering during diff
 // actually we just forward these calls to the app, to CMergeApp::includeFile & includeDir
 class DirDocFilter : public IDiffFilter
 {
index 7049bc3..34c47cd 100644 (file)
@@ -230,13 +230,13 @@ void CDirView::OnLButtonDblClk(UINT nFlags, CPoint point)
 void CDirView::ReloadColumns()
 {
        LoadColumnHeaderItems();
-ToDoDeleteThisValidateColumnOrdering();
+       ToDoDeleteThisValidateColumnOrdering();
 
-ToDoDeleteThisValidateColumnOrdering();
+       ToDoDeleteThisValidateColumnOrdering();
        UpdateColumnNames();
-ToDoDeleteThisValidateColumnOrdering();
+       ToDoDeleteThisValidateColumnOrdering();
        SetColumnWidths();
-ToDoDeleteThisValidateColumnOrdering();
+       ToDoDeleteThisValidateColumnOrdering();
 }
 
 /**
@@ -353,7 +353,7 @@ ToDoDeleteThisValidateColumnOrdering();
        
 }      
 
-// Make a string out of a number
+/// Make a string out of a number
 // TODO: Ought to introduce commas every three digits, except this is locale-specific
 // How to do this with locale sensitivity ?
 CString NumToStr(int n)
@@ -363,7 +363,7 @@ CString NumToStr(int n)
        return s;
 }
 
-// Change menu item by using string resource
+/// Change menu item by using string resource
 // (Question: Why don't we just remove it from the menu resource entirely & do an Add here ?)
 void CDirView::ModifyPopup(CMenu * pPopup, int nStringResource, int nMenuId, LPCTSTR szPath)
 {
@@ -388,77 +388,88 @@ void CDirView::OnDirCopyFileToRight()
        DoCopyFileToRight();
 }
 
-// User chose (context men) Copy from right to left
+/// User chose (context men) Copy from right to left
 void CDirView::OnCtxtDirCopyFileToLeft()
 {
        DoCopyFileToLeft();
 }
-// User chose (context menu) Copy from left to right
+/// User chose (context menu) Copy from left to right
 void CDirView::OnCtxtDirCopyFileToRight()
 {
        DoCopyFileToRight();
 }
 
-// Update context menu Copy Right to Left item
+/// Update context menu Copy Right to Left item
 void CDirView::OnUpdateCtxtDirCopyFileToLeft(CCmdUI* pCmdUI) 
 {
        DoUpdateDirCopyFileToLeft(pCmdUI, eContext);
 }
-// Update context menu Copy Left to Right item
+/// Update context menu Copy Left to Right item
 void CDirView::OnUpdateCtxtDirCopyFileToRight(CCmdUI* pCmdUI) 
 {
        DoUpdateDirCopyFileToRight(pCmdUI, eContext);
 }
 
-// Update main menu Copy Right to Left item
+/// Update main menu Copy Right to Left item
 void CDirView::OnUpdateDirCopyFileToLeft(CCmdUI* pCmdUI) 
 {
        DoUpdateDirCopyFileToLeft(pCmdUI, eMain);
 }
-// Update main menu Copy Left to Right item
+/// Update main menu Copy Left to Right item
 void CDirView::OnUpdateDirCopyFileToRight(CCmdUI* pCmdUI) 
 {
        DoUpdateDirCopyFileToRight(pCmdUI, eMain);
 }
 
-// Should Copy to Left be enabled or disabled ? (both main menu & context menu use this)
+/// Should Copy to Left be enabled or disabled ? (both main menu & context menu use this)
 void CDirView::DoUpdateDirCopyFileToLeft(CCmdUI* pCmdUI, eMenuType menuType)
 {
-       int sel=-1;
-       int legalcount=0, selcount=0;
-       while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
-       {
-               const DIFFITEM& di = GetDiffItem(sel);
-               if (IsItemCopyableToLeft(di.code))
-                       ++legalcount;
-               ++selcount;
-       }
-       pCmdUI->Enable(legalcount>0);
-       if (menuType==eContext)
+       if (GetDocument()->GetReadOnly(TRUE))
+               pCmdUI->Enable(FALSE);
+       else
        {
-               CString s;
-               AfxFormatString2(s, IDS_COPY_TO_LEFT, NumToStr(legalcount), NumToStr(selcount));
-               pCmdUI->SetText(s);
+               int sel=-1;
+               int legalcount=0, selcount=0;
+               while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+               {
+                       const DIFFITEM& di = GetDiffItem(sel);
+                       if (IsItemCopyableToLeft(di.code))
+                               ++legalcount;
+                       ++selcount;
+               }
+               pCmdUI->Enable(legalcount>0);
+               if (menuType==eContext)
+               {
+                       CString s;
+                       AfxFormatString2(s, IDS_COPY_TO_LEFT, NumToStr(legalcount), NumToStr(selcount));
+                       pCmdUI->SetText(s);
+               }
        }
 }
-// Should Copy to Right be enabled or disabled ? (both main menu & context menu use this)
+
+/// Should Copy to Right be enabled or disabled ? (both main menu & context menu use this)
 void CDirView::DoUpdateDirCopyFileToRight(CCmdUI* pCmdUI, eMenuType menuType)
 {
-       int sel=-1;
-       int legalcount=0, selcount=0;
-       while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
-       {
-               const DIFFITEM& di = GetDiffItem(sel);
-               if (IsItemCopyableToRight(di.code))
-                       ++legalcount;
-               ++selcount;
-       }
-       pCmdUI->Enable(legalcount>0);
-       if (menuType==eContext)
+       if (GetDocument()->GetReadOnly(FALSE))
+               pCmdUI->Enable(FALSE);
+       else
        {
-               CString s;
-               AfxFormatString2(s, IDS_COPY_TO_RIGHT, NumToStr(legalcount), NumToStr(selcount));
-               pCmdUI->SetText(s);
+               int sel=-1;
+               int legalcount=0, selcount=0;
+               while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+               {
+                       const DIFFITEM& di = GetDiffItem(sel);
+                       if (IsItemCopyableToRight(di.code))
+                               ++legalcount;
+                       ++selcount;
+               }
+               pCmdUI->Enable(legalcount>0);
+               if (menuType==eContext)
+               {
+                       CString s;
+                       AfxFormatString2(s, IDS_COPY_TO_RIGHT, NumToStr(legalcount), NumToStr(selcount));
+                       pCmdUI->SetText(s);
+               }
        }
 }
 
@@ -532,7 +543,9 @@ void CDirView::OpenSelection()
                        {
                                CString left, right;
                                GetItemFileNames(sel, left, right);
-                               mf->ShowMergeDoc(GetDocument(), left, right);
+                               mf->ShowMergeDoc(GetDocument(), left, right,
+                                       GetDocument()->GetReadOnly(TRUE),
+                                       GetDocument()->GetReadOnly(FALSE));
                        }
                        break;
                case FILE_LDIRUNIQUE:
@@ -562,91 +575,108 @@ void CDirView::OpenSelection()
        }
 }
 
-// User chose (context menu) delete left
+/// User chose (context menu) delete left
 void CDirView::OnCtxtDirDelLeft()
 {
        DoDelLeft();
 }
-// User chose (context menu) delete right
+
+/// User chose (context menu) delete right
 void CDirView::OnCtxtDirDelRight()
 {
        DoDelRight();
 }
-// User chose (context menu) delete both
+
+/// User chose (context menu) delete both
 void CDirView::OnCtxtDirDelBoth()
 {
        DoDelBoth();
 }
 
-
-// Enable/disable Delete Left menu choice on context menu
+/// Enable/disable Delete Left menu choice on context menu
 void CDirView::OnUpdateCtxtDirDelLeft(CCmdUI* pCmdUI)
 {
        DoUpdateCtxtDirDelLeft(pCmdUI);
 }
 
-// Enable/disable Delete Right menu choice on context menu
+/// Enable/disable Delete Right menu choice on context menu
 void CDirView::OnUpdateCtxtDirDelRight(CCmdUI* pCmdUI) 
 {
        DoUpdateCtxtDirDelRight(pCmdUI);
 }
-// Enable/disable Delete Both menu choice on context menu
+/// Enable/disable Delete Both menu choice on context menu
 void CDirView::OnUpdateCtxtDirDelBoth(CCmdUI* pCmdUI) 
 {
        DoUpdateCtxtDirDelBoth(pCmdUI);
 }
 
-// Should Delete left be enabled or disabled ?
+/// Should Delete left be enabled or disabled ?
 void CDirView::DoUpdateCtxtDirDelLeft(CCmdUI* pCmdUI)
 {
-       int sel=-1;
-       int count=0, total=0;
-       while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+       if (GetDocument()->GetReadOnly(TRUE))
+               pCmdUI->Enable(FALSE);
+       else
        {
-               const DIFFITEM& di = GetDiffItem(sel);
-               if (IsItemDeletableOnLeft(di.code))
-                       ++count;
-               ++total;
+               int sel=-1;
+               int count=0, total=0;
+               while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+               {
+                       const DIFFITEM& di = GetDiffItem(sel);
+                       if (IsItemDeletableOnLeft(di.code))
+                               ++count;
+                       ++total;
+               }
+               pCmdUI->Enable(count>0);
+               CString s;
+               AfxFormatString2(s, IDS_DEL_LEFT_FMT, NumToStr(count), NumToStr(total));
+               pCmdUI->SetText(s);
        }
-       pCmdUI->Enable(count>0);
-       CString s;
-       AfxFormatString2(s, IDS_DEL_LEFT_FMT, NumToStr(count), NumToStr(total));
-       pCmdUI->SetText(s);
 }
-// Should Delete right be enabled or disabled ?
+
+/// Should Delete right be enabled or disabled ?
 void CDirView::DoUpdateCtxtDirDelRight(CCmdUI* pCmdUI) 
 {
-       int sel=-1;
-       int count=0, total=0;
-       while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+       if (GetDocument()->GetReadOnly(FALSE))
+               pCmdUI->Enable(FALSE);
+       else
        {
-               const DIFFITEM& di = GetDiffItem(sel);
-               if (IsItemDeletableOnRight(di.code))
-                       ++count;
-               ++total;
+               int sel=-1;
+               int count=0, total=0;
+               while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+               {
+                       const DIFFITEM& di = GetDiffItem(sel);
+                       if (IsItemDeletableOnRight(di.code))
+                               ++count;
+                       ++total;
+               }
+               pCmdUI->Enable(count>0);
+               CString s;
+               AfxFormatString2(s, IDS_DEL_RIGHT_FMT, NumToStr(count), NumToStr(total));
+               pCmdUI->SetText(s);
        }
-       pCmdUI->Enable(count>0);
-       CString s;
-       AfxFormatString2(s, IDS_DEL_RIGHT_FMT, NumToStr(count), NumToStr(total));
-       pCmdUI->SetText(s);
 }
 
-// Should Delete both be enabled or disabled ?
+/// Should Delete both be enabled or disabled ?
 void CDirView::DoUpdateCtxtDirDelBoth(CCmdUI* pCmdUI) 
 {
-       int sel=-1;
-       int count=0, total=0;
-       while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+       if (GetDocument()->GetReadOnly(TRUE) || GetDocument()->GetReadOnly(FALSE))
+               pCmdUI->Enable(FALSE);
+       else
        {
-               const DIFFITEM& di = GetDiffItem(sel);
-               if (IsItemDeletableOnBoth(di.code))
-                       ++count;
-               ++total;
+               int sel=-1;
+               int count=0, total=0;
+               while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+               {
+                       const DIFFITEM& di = GetDiffItem(sel);
+                       if (IsItemDeletableOnBoth(di.code))
+                               ++count;
+                       ++total;
+               }
+               pCmdUI->Enable(count>0);
+               CString s;
+               AfxFormatString2(s, IDS_DEL_BOTH_FMT, NumToStr(count), NumToStr(total));
+               pCmdUI->SetText(s);
        }
-       pCmdUI->Enable(count>0);
-       CString s;
-       AfxFormatString2(s, IDS_DEL_BOTH_FMT, NumToStr(count), NumToStr(total));
-       pCmdUI->SetText(s);
 }
 
 POSITION CDirView::GetItemKey(int idx) const
index 6fe86a3..b6bb810 100644 (file)
@@ -301,7 +301,7 @@ void CMainFrame::OnFileOpen()
 }
 
 /// Creates new MergeDoc instance and shows documents
-void CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight)
+void CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight, BOOL bROLeft, BOOL bRORight)
 {
        BOOL docNull;
        BOOL bOpenSuccess = FALSE;
@@ -311,7 +311,8 @@ void CMainFrame::ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight
        ASSERT(pMergeDoc);              // must ASSERT to get an answer to the question below ;-)
        if (!pMergeDoc) return; // when does this happen ?
 
-       bOpenSuccess = pMergeDoc->OpenDocs(szLeft, szRight);
+       bOpenSuccess = pMergeDoc->OpenDocs(szLeft, szRight,
+                       bROLeft, bRORight);
 
        if (bOpenSuccess)
        {
@@ -940,6 +941,8 @@ BOOL CMainFrame::DoFileOpen(LPCTSTR pszLeft /*=NULL*/, LPCTSTR pszRight /*=NULL*
                        CDiffContext *pCtxt = new CDiffContext(strLeft, strRight);
                        if (pCtxt != NULL)
                        {
+                               pDirDoc->SetReadOnly(TRUE, FALSE);
+                               pDirDoc->SetReadOnly(FALSE, FALSE);
                                pDirDoc->SetDiffContext(pCtxt);
                                pCtxt->SetRegExp(strExt);
                                pDirDoc->Rescan();
@@ -948,7 +951,6 @@ BOOL CMainFrame::DoFileOpen(LPCTSTR pszLeft /*=NULL*/, LPCTSTR pszRight /*=NULL*
                                        CDirView * pDirView = pDirDoc->GetMainView();
                                        pDirView->GotoFirstDiff();
                                }
-
                        }
                }
        }
index 09b706f..50443ae 100644 (file)
 //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 //
 /////////////////////////////////////////////////////////////////////////////
-// MainFrm.h : interface of the CMainFrame class
-//
-/////////////////////////////////////////////////////////////////////////////
-//
+/** 
+ * @file  MainFrm.h
+ *
+ * @brief Declaration file for CMainFrame
+ *
+ */
+// RCS ID line follows -- this is updated by CVS
 // $Id$
 
 #if !defined(AFX_MAINFRM_H__BBCD4F8C_34E4_11D1_BAA6_00A024706EDC__INCLUDED_)
@@ -37,7 +40,8 @@
 enum
 {
        FFILEOPEN_NONE          = 0x0000,
-       FFILEOPEN_NOMRU         = 0x0001
+       FFILEOPEN_NOMRU         = 0x0001,
+       FFILEOPEN_READONLY      = 0x0002,
 };
 
 class CDiffView;
@@ -51,6 +55,9 @@ typedef CTypedPtrList<CPtrList, CDirView *> DirViewList;
 typedef CTypedPtrList<CPtrList, CMergeDoc *> MergeDocList;
 typedef CTypedPtrList<CPtrList, CDirDoc *> DirDocList;
 
+/**
+ * @brief Frame class containing save-routines etc
+ */
 class CMainFrame : public CMDIFrameWnd
 {
        DECLARE_DYNAMIC(CMainFrame)
@@ -81,7 +88,7 @@ public:
        void UpdateCurrentFileStatus(CDirDoc * pDirDoc, UINT nStatus, int idx);
        BOOL DoFileOpen(LPCTSTR pszLeft = NULL, LPCTSTR pszRight = NULL,
                DWORD dwLeftFlags = 0, DWORD dwRightFlags = 0, BOOL bRecurse = FALSE);
-       void ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight);
+       void ShowMergeDoc(CDirDoc * pDirDoc, LPCTSTR szLeft, LPCTSTR szRight, BOOL bROLeft = FALSE, BOOL bRORight = FALSE);
        void UpdateResources();
        HMENU NewDefaultMenu();
        BOOL CreateBackup(LPCTSTR pszPath);
index 8ae841e..dcd5924 100644 (file)
@@ -1295,13 +1295,13 @@ void CMergeDoc::OnFileSave()
        BOOL bLModified = FALSE;
        BOOL bRModified = FALSE;
 
-       if (m_ltBuf.IsModified())
+       if (m_ltBuf.IsModified() && !m_ltBuf.GetReadOnly())
        {
                bLModified = TRUE;
                DoSave(m_strLeftFile, bLSaveSuccess, TRUE );
        }
 
-       if (m_rtBuf.IsModified())
+       if (m_rtBuf.IsModified() && !m_rtBuf.GetReadOnly())
        {
                bRModified = TRUE;
                DoSave(m_strRightFile, bRSaveSuccess, FALSE);
@@ -1470,11 +1470,8 @@ void CMergeDoc::PrimeTextBuffers()
                }
        }
 
-       m_ltBuf.SetReadOnly(FALSE);
        m_ltBuf.FinishLoading();
-       m_rtBuf.SetReadOnly(FALSE);
        m_rtBuf.FinishLoading();
-
 }
 
 BOOL CMergeDoc::SaveHelper()
@@ -1802,6 +1799,8 @@ int CMergeDoc::LoadFile(CString sFileName, BOOL bLeft)
 *
 * @param sLeftFile File to open to left side
 * @param sRightFile File to open to right side
+* @param bROLeft Is left file read-only
+* @param bRORight Is right file read-only
 *
 * @return Tells if files were loaded and scanned succesfully
 *
@@ -1810,7 +1809,8 @@ int CMergeDoc::LoadFile(CString sFileName, BOOL bLeft)
 * @sa CMainFrame::ShowMergeDoc()
 *
 */
-BOOL CMergeDoc::OpenDocs(CString sLeftFile, CString sRightFile)
+BOOL CMergeDoc::OpenDocs(CString sLeftFile, CString sRightFile,
+               BOOL bROLeft, BOOL bRORight)
 {
        int nRescanResult = RESCAN_OK;
        CChildFrame *pf = GetParentFrame();
@@ -1836,6 +1836,10 @@ BOOL CMergeDoc::OpenDocs(CString sLeftFile, CString sRightFile)
                return FALSE;
        }
        
+       // Set read-only statuses
+       m_ltBuf.SetReadOnly(bROLeft);
+       m_rtBuf.SetReadOnly(bRORight);
+
        nRescanResult = Rescan();
 
        // Open different and identical files
index af66930..6b4e3c9 100644 (file)
@@ -77,6 +77,9 @@ public:
 class CChildFrame;
 class CDirDoc;
 
+/**
+ * @brief Document class for merging two files
+ */
 class CMergeDoc : public CDocument
 {
 // Attributes
@@ -179,7 +182,8 @@ public:
        UINT m_nDiffs;
        CString m_strLeftFile, m_strRightFile;
 
-       BOOL OpenDocs(CString sLeftFile, CString sRightFile);
+       BOOL OpenDocs(CString sLeftFile, CString sRightFile,
+               BOOL bROLeft = FALSE, BOOL bRORight = FALSE);
        int LoadFile(CString sFileName, BOOL bLeft);
        void RescanIfNeeded(float timeOutInSecond);
        int Rescan(BOOL bForced = FALSE);
index bcd76f5..34def0c 100644 (file)
@@ -1,5 +1,30 @@
-// MergeEditView.cpp : implementation file
+/////////////////////////////////////////////////////////////////////////////
+//    WinMerge:  an interactive diff/merge utility
+//    Copyright (C) 1997-2000  Thingamahoochie Software
+//    Author: Dean Grimm
+//
+//    This program is free software; you can redistribute it and/or modify
+//    it under the terms of the GNU General Public License as published by
+//    the Free Software Foundation; either version 2 of the License, or
+//    (at your option) any later version.
+//
+//    This program is distributed in the hope that it will be useful,
+//    but WITHOUT ANY WARRANTY; without even the implied warranty of
+//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//    GNU General Public License for more details.
 //
+//    You should have received a copy of the GNU General Public License
+//    along with this program; if not, write to the Free Software
+//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+/////////////////////////////////////////////////////////////////////////////
+/** 
+ * @file  MergeEditView.cpp
+ *
+ * @brief Implementation of the CMergeEditView class
+ */
+// RCS ID line follows -- this is updated by CVS
+// $Id$
 
 #include "stdafx.h"
 #include "merge.h"
@@ -387,11 +412,15 @@ void CMergeEditView::OnUpdateEditCopy(CCmdUI* pCmdUI)
 
 void CMergeEditView::OnEditCut()
 {
+       if (IsReadOnly(m_bIsLeft))
+               return;
+
        CPoint ptSelStart, ptSelEnd;
        CMergeDoc * pDoc = GetDocument();
        GetSelection(ptSelStart, ptSelEnd);
 
-       if ( ptSelStart == ptSelEnd )
+       // Nothing selected
+       if (ptSelStart == ptSelEnd)
                return;
 
        CString text;
@@ -423,22 +452,34 @@ void CMergeEditView::OnEditCut()
 
 void CMergeEditView::OnUpdateEditCut(CCmdUI* pCmdUI)
 {
-       CCrystalEditViewEx::OnUpdateEditCut(pCmdUI);
+       if (!IsReadOnly(m_bIsLeft))
+               CCrystalEditViewEx::OnUpdateEditCut(pCmdUI);
+       else
+               pCmdUI->Enable(FALSE);
 }
 
 void CMergeEditView::OnEditPaste()
 {
+       if (IsReadOnly(m_bIsLeft))
+               return;
+
        CCrystalEditViewEx::Paste();
        m_pTextBuffer->SetModified(TRUE);
 }
 
 void CMergeEditView::OnUpdateEditPaste(CCmdUI* pCmdUI)
 {
-       CCrystalEditViewEx::OnUpdateEditPaste(pCmdUI);
+       if (!IsReadOnly(m_bIsLeft))
+               CCrystalEditViewEx::OnUpdateEditPaste(pCmdUI);
+       else
+               pCmdUI->Enable(FALSE);
 }
 
 void CMergeEditView::OnEditUndo()
 {
+       if (IsReadOnly(m_bIsLeft))
+               return;
+
        CMergeDoc* pDoc = GetDocument();
        CMergeEditView *tgt = *(pDoc->curUndo-1);
        if(tgt==this)
@@ -578,6 +619,7 @@ void CMergeEditView::SelectNone()
        UpdateCaret();
 }
 
+/// Check if line is inside currently selected diff
 BOOL CMergeEditView::IsLineInCurrentDiff(int nLine)
 {
        CMergeDoc *pd = GetDocument();
@@ -625,28 +667,40 @@ void CMergeEditView::UpdateLineLengths()
 
 void CMergeEditView::OnL2r()
 {
+       if (IsReadOnly(FALSE))
+               return;
        WaitStatusCursor waitstatus(LoadResString(IDS_STATUS_COPYL2R));
        GetDocument()->ListCopy(true);
 }
 
 void CMergeEditView::OnUpdateL2r(CCmdUI* pCmdUI)
 {
-       pCmdUI->Enable(GetDocument()->GetCurrentDiff()!=-1);
+       if (!IsReadOnly(FALSE))
+               pCmdUI->Enable(GetDocument()->GetCurrentDiff()!=-1);
+       else
+               pCmdUI->Enable(FALSE);
 }
 
 void CMergeEditView::OnR2l()
 {
+       if (IsReadOnly(TRUE))
+               return;
        WaitStatusCursor waitstatus(LoadResString(IDS_STATUS_COPYR2L));
        GetDocument()->ListCopy(false);
 }
 
 void CMergeEditView::OnUpdateR2l(CCmdUI* pCmdUI)
 {
-       pCmdUI->Enable(GetDocument()->GetCurrentDiff()!=-1);
+       if (!IsReadOnly(TRUE))
+               pCmdUI->Enable(GetDocument()->GetCurrentDiff()!=-1);
+       else
+               pCmdUI->Enable(FALSE);
 }
 
 void CMergeEditView::OnAllLeft()
 {
+       if (IsReadOnly(TRUE))
+               return;
        WaitStatusCursor waitstatus(LoadResString(IDS_STATUS_COPYALL2L));
 
        GetDocument()->CopyAllList(false);
@@ -654,11 +708,17 @@ void CMergeEditView::OnAllLeft()
 
 void CMergeEditView::OnUpdateAllLeft(CCmdUI* pCmdUI)
 {
-       pCmdUI->Enable(GetDocument()->m_nDiffs!=0);
+       if (!IsReadOnly(TRUE))
+               pCmdUI->Enable(GetDocument()->m_nDiffs!=0);
+       else
+               pCmdUI->Enable(FALSE);
 }
 
 void CMergeEditView::OnAllRight()
 {
+       if (IsReadOnly(FALSE))
+               return;
+
        WaitStatusCursor waitstatus(LoadResString(IDS_STATUS_COPYALL2R));
 
        GetDocument()->CopyAllList(true);
@@ -666,11 +726,17 @@ void CMergeEditView::OnAllRight()
 
 void CMergeEditView::OnUpdateAllRight(CCmdUI* pCmdUI)
 {
-       pCmdUI->Enable(GetDocument()->m_nDiffs!=0);
+       if (!IsReadOnly(FALSE))
+               pCmdUI->Enable(GetDocument()->m_nDiffs!=0);
+       else
+               pCmdUI->Enable(FALSE);
 }
 
 void CMergeEditView::OnEditOperation(int nAction, LPCTSTR pszText)
 {
+       if (IsReadOnly(m_bIsLeft))
+               return;
+
        CMergeDoc* pDoc = GetDocument();
 
        // simple hook for multiplex undo operations
@@ -709,6 +775,9 @@ void CMergeEditView::OnEditOperation(int nAction, LPCTSTR pszText)
 
 void CMergeEditView::OnEditRedo()
 {
+       if (IsReadOnly(m_bIsLeft))
+               return;
+
        CMergeDoc* pDoc = GetDocument();
        CMergeEditView *tgt = *(pDoc->curUndo);
        if(tgt==this)
@@ -734,7 +803,6 @@ void CMergeEditView::OnUpdateEditRedo(CCmdUI* pCmdUI)
 void CMergeEditView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
 {
        CCrystalEditViewEx::OnUpdate(pSender, lHint, pHint);
-       // ShowDiff(FALSE, FALSE);
 }
 
 void CMergeEditView::ShowDiff(BOOL bScroll, BOOL bSelectText)
@@ -804,6 +872,18 @@ void CMergeEditView::OnTimer(UINT nIDEvent)
        CCrystalEditViewEx::OnTimer(nIDEvent);
 }
 
+BOOL CMergeEditView::IsReadOnly(BOOL bLeft)
+{
+       CCrystalTextBuffer *pBuf = NULL;
+
+       if (bLeft)
+               pBuf = &GetDocument()->m_ltBuf;
+       else
+               pBuf = &GetDocument()->m_rtBuf;
+
+       return pBuf->GetReadOnly();
+}
+
 void CMergeEditView::OnRefresh()
 {
        CMergeDoc *pd = GetDocument();
index 5c5baaa..18c6154 100644 (file)
@@ -1,13 +1,42 @@
+/////////////////////////////////////////////////////////////////////////////
+//    WinMerge:  an interactive diff/merge utility
+//    Copyright (C) 1997  Dean P. Grimm
+//
+//    This program is free software; you can redistribute it and/or modify
+//    it under the terms of the GNU General Public License as published by
+//    the Free Software Foundation; either version 2 of the License, or
+//    (at your option) any later version.
+//
+//    This program is distributed in the hope that it will be useful,
+//    but WITHOUT ANY WARRANTY; without even the implied warranty of
+//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//    GNU General Public License for more details.
+//
+//    You should have received a copy of the GNU General Public License
+//    along with this program; if not, write to the Free Software
+//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+/////////////////////////////////////////////////////////////////////////////
+/** 
+ * @file  MergeEditView.h
+ *
+ * @brief Declaration file for CMergeEditView
+ *
+ */
+// RCS ID line follows -- this is updated by CVS
+// $Id$
+
 #if !defined(AFX_MERGEEDITVIEW_H__0CE31CFD_4BEE_4378_ADB4_B7C9F50A9F53__INCLUDED_)
 #define AFX_MERGEEDITVIEW_H__0CE31CFD_4BEE_4378_ADB4_B7C9F50A9F53__INCLUDED_
 
 #if _MSC_VER > 1000
 #pragma once
 #endif // _MSC_VER > 1000
-// MergeEditView.h : header file
-//
 
-#define CONTEXT_LINES   5
+/** 
+ * @brief Non-diff lines shown above diff when scrolling to it
+ */
+static const UINT CONTEXT_LINES   = 5;
 
 
 #define FLAG_RESCAN_WAITS_FOR_IDLE   1
@@ -81,6 +110,7 @@ private:
 // Operations
 public:
        BOOL EnableRescan(BOOL bEnable);
+       BOOL IsReadOnly(BOOL bLeft);
        void ShowDiff(BOOL bScroll, BOOL bSelectText);
        virtual void OnEditOperation(int nAction, LPCTSTR pszText);
        void UpdateLineLengths();
index 89e66c0..997543f 100644 (file)
@@ -1,3 +1,9 @@
+2003-08-27 Kimmo
+ PATCH: [ 784302 ] Implement Read-only for files and dirs
+  Only background changes, no UI changes
+  WinMerge: DirDoc.h DirDoc.cpp DirView.cpp MainFrm.h MainFrm.cpp
+   MergeDoc.h MergeDoc.cpp MergeEditView.h MergeEditView.cpp
+
 2003-08-27 Perry
  Add new colhdrs from patch#781529 to Brazilian.
  Reorder ChineseSimplified string tables to match English, and add missing entries.