OSDN Git Service

Delete left/right + allow copy uniques
authorChristian List <list1974@hotmail.com>
Mon, 25 Nov 2002 22:38:58 +0000 (22:38 +0000)
committerChristian List <list1974@hotmail.com>
Mon, 25 Nov 2002 22:38:58 +0000 (22:38 +0000)
Code added on behalf of Perry Rapp

Src/DirView.cpp
Src/DirView.h
Src/MainFrm.cpp
Src/MainFrm.h
Src/Merge.rc
Src/resource.h

index 6259b02..fde4c9c 100644 (file)
@@ -58,8 +58,16 @@ BEGIN_MESSAGE_MAP(CDirView, CListViewEx)
        ON_WM_LBUTTONDBLCLK()
        ON_COMMAND(ID_R2L, OnDirCopyFileToLeft)
        ON_UPDATE_COMMAND_UI(ID_R2L, OnUpdateDirCopyFileToLeft)
+       ON_COMMAND(ID_DIR_COPY_FILE_TO_LEFT, OnCtxtDirCopyFileToLeft)
+       ON_UPDATE_COMMAND_UI(ID_DIR_COPY_FILE_TO_LEFT, OnUpdateCtxtDirCopyFileToLeft)
        ON_COMMAND(ID_L2R, OnDirCopyFileToRight)
        ON_UPDATE_COMMAND_UI(ID_L2R, OnUpdateDirCopyFileToRight)
+       ON_COMMAND(ID_DIR_COPY_FILE_TO_RIGHT, OnCtxtDirCopyFileToRight)
+       ON_UPDATE_COMMAND_UI(ID_DIR_COPY_FILE_TO_RIGHT, OnUpdateCtxtDirCopyFileToRight)
+       ON_COMMAND(ID_DIR_DEL_LEFT, OnCtxtDirDelLeft)
+       ON_UPDATE_COMMAND_UI(ID_DIR_DEL_LEFT, OnUpdateCtxtDirDelLeft)
+       ON_COMMAND(ID_DIR_DEL_RIGHT, OnCtxtDirDelRight)
+       ON_UPDATE_COMMAND_UI(ID_DIR_DEL_RIGHT, OnUpdateCtxtDirDelRight)
        ON_WM_DESTROY()
        ON_WM_CHAR()
        //}}AFX_MSG_MAP
@@ -178,6 +186,7 @@ void CDirView::OnLButtonDblClk(UINT nFlags, CPoint point)
        CListViewEx::OnLButtonDblClk(nFlags, point);
 }
 
+
 void CDirView::OnContextMenu(CWnd*, CPoint point)
 {
 
@@ -203,173 +212,266 @@ void CDirView::OnContextMenu(CWnd*, CPoint point)
                // set the menu items with the proper directory names
                CString s, sl, sr;
                GetSelectedDirNames(sl, sr);
-               AfxFormatString1(s, IDS_COPY2DIR_FMT, sl);
-               pPopup->ModifyMenu(ID_DIR_COPY_FILE_TO_LEFT, MF_BYCOMMAND|MF_STRING, ID_DIR_COPY_FILE_TO_LEFT, s);
-               AfxFormatString1(s, IDS_COPY2DIR_FMT, sr);
-               pPopup->ModifyMenu(ID_DIR_COPY_FILE_TO_RIGHT, MF_BYCOMMAND|MF_STRING, ID_DIR_COPY_FILE_TO_RIGHT, s);
+
+               
+               ModifyPopup(pPopup, IDS_COPY2DIR_LEFT_FMT, ID_DIR_COPY_FILE_TO_LEFT, sl);
+               ModifyPopup(pPopup, IDS_COPY2DIR_RIGHT_FMT, ID_DIR_COPY_FILE_TO_RIGHT, sr);
+               ModifyPopup(pPopup, IDS_DEL_LEFT_FMT, ID_DIR_DEL_LEFT, sl);
+               ModifyPopup(pPopup, IDS_DEL_RIGHT_FMT, ID_DIR_DEL_RIGHT, sr);
+               // 
 
                while (pWndPopupOwner->GetStyle() & WS_CHILD)
                        pWndPopupOwner = pWndPopupOwner->GetParent();
 
+               // invoke context menu
                pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
                        pWndPopupOwner);
        }
 }
 
+// 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)
+{
+       CString s;
+       AfxFormatString1(s, nStringResource, szPath);
+       pPopup->ModifyMenu(nMenuId, MF_BYCOMMAND|MF_STRING, nMenuId, s);
+}
+
+// given index in list control, get position & DIFFITEM reference to its data
+const DIFFITEM& CDirView::GetDiffItem(int sel, POSITION & pos)
+{
+       pos = reinterpret_cast<POSITION>(m_pList->GetItemData(sel));
+       const DIFFITEM& di = GetDocument()->m_pCtxt->m_dirlist.GetAt(pos);
+       return di;
+}
+
+// User chose (main menu) Copy from right to left
 void CDirView::OnDirCopyFileToLeft() 
 {
+       DoCopyFileToLeft();
+}
+
+// User chose (context men) Copy from right to left
+void CDirView::OnCtxtDirCopyFileToLeft()
+{
+       DoCopyFileToLeft();
+}
+
+// Prompt & copy item from right to left, if legal
+void CDirView::DoCopyFileToLeft() 
+{
        int sel = m_pList->GetNextItem(-1, LVNI_SELECTED);
-       CString s, sl, sr, slFile, srFile;
+       if (sel == -1) return;
+
+       CString sl, sr, slFile, srFile;
+       if (!GetSelectedDirNames(sl, sr) || !GetSelectedFileNames(slFile, srFile))
+               return;
 
-       if (sel != -1
-               && GetSelectedDirNames(sl, sr)
-               && GetSelectedFileNames(slFile, srFile))
+       CDirDoc *pd = GetDocument();
+       CString s;
+       // find item from document
+       POSITION pos;
+       const DIFFITEM& di = GetDiffItem(sel, pos);
+       // what we do depends on comparison result for this item
+       switch(di.code)
        {
-               CDirDoc *pd = GetDocument();
-               CString s;
-               POSITION pos = reinterpret_cast<POSITION>(m_pList->GetItemData(sel));
-               DIFFITEM di = pd->m_pCtxt->m_dirlist.GetAt(pos);
-               switch(di.code)
-               {
-               case FILE_LUNIQUE:
-                       AfxFormatString1(s, IDS_CONFIRM_DELETE, slFile);
-                       if (AfxMessageBox(s, MB_YESNO|MB_ICONQUESTION)==IDYES)
+       case FILE_LUNIQUE:
+               ConfirmAndDeleteAndUpdate(slFile, pos, sel);
+               break;
+       case FILE_RUNIQUE:
+       case FILE_DIFF:
+       case FILE_BINDIFF:
+               AfxFormatString1(s, IDS_CONFIRM_COPY2DIR, sl);
+               if (AfxMessageBox(s, MB_YESNO|MB_ICONQUESTION)==IDYES)
+               {               
+                       if (mf->SyncFiles(srFile, slFile))
                        {
-                               if(DeleteFile(slFile))
-                               {
-                                       pd->m_pCtxt->m_dirlist.RemoveAt(pos);
-                                       GetListCtrl().DeleteItem(sel);
-                               }
+                               mf->UpdateCurrentFileStatus(FILE_SAME);
                        }
-                       break;
-               case FILE_RUNIQUE:
-               case FILE_DIFF:
-               case FILE_BINDIFF:
-                       AfxFormatString1(s, IDS_CONFIRM_COPY2DIR, sl);
-                       if (AfxMessageBox(s, MB_YESNO|MB_ICONQUESTION)==IDYES)
-                       {               
-                               if (mf->SyncFiles(srFile, slFile))
-                               {
-                                       mf->UpdateCurrentFileStatus(FILE_SAME);
-                               }
-                       }
-                       break;
-               case FILE_LDIRUNIQUE:
-               case FILE_RDIRUNIQUE:
-               case FILE_SAME:
-               default:
-                       //pCmdUI->Enable(FALSE);
-                       break;
                }
+               break;
+       case FILE_LDIRUNIQUE:
+       case FILE_RDIRUNIQUE:
+                       // TODO 2002-11-22: Enable uniques also, but must write code to do recursive copy
+       case FILE_SAME:
+       default:
+               // Not allowed, and should have been disabled choices anyway
+               break;
        }
 }
 
+// Update context menu Copy Right to Left item
+void CDirView::OnUpdateCtxtDirCopyFileToLeft(CCmdUI* pCmdUI) 
+{
+       DoUpdateDirCopyFileToLeft(pCmdUI);
+}
+
+// Update main menu Copy Right to Left item
 void CDirView::OnUpdateDirCopyFileToLeft(CCmdUI* pCmdUI) 
 {
+       DoUpdateDirCopyFileToLeft(pCmdUI);
+}
+
+// Should Copy to Left be enabled or disabled ? (both main menu & context menu use this)
+void CDirView::DoUpdateDirCopyFileToLeft(CCmdUI* pCmdUI) 
+{
        int sel = m_pList->GetNextItem(-1, LVNI_SELECTED);
-       if (sel != -1)
+       if (sel == -1)
        {
-               CDirDoc *pd = GetDocument();
-               POSITION pos = reinterpret_cast<POSITION>(m_pList->GetItemData(sel));
-               DIFFITEM di = pd->m_pCtxt->m_dirlist.GetAt(pos);
-               switch(di.code)
-               {
-               case FILE_LUNIQUE:
-               case FILE_RUNIQUE:
-               case FILE_DIFF:
-               case FILE_BINDIFF:
-                       pCmdUI->Enable(TRUE);
-                       break;
-               case FILE_SAME:
-               case FILE_LDIRUNIQUE:
-               case FILE_RDIRUNIQUE:
-               default:
-                       pCmdUI->Enable(FALSE);
-                       break;
-               }
+               // no item there
+               pCmdUI->Enable(FALSE);
+               return;
        }
-       else
+       // found item (normal case)
+       // find item from document
+       POSITION pos;
+       const DIFFITEM& di = GetDiffItem(sel, pos);
+       // what we do depends on comparison result for this item
+       switch(di.code)
        {
+       case FILE_LUNIQUE:
+               pCmdUI->Enable(FALSE); // no right item, so can't copy to left
+               break;
+       case FILE_RUNIQUE:
+       case FILE_DIFF:
+       case FILE_BINDIFF:
+               pCmdUI->Enable(TRUE);
+               break;
+       case FILE_SAME:
+               pCmdUI->Enable(FALSE);
+               break;
+       case FILE_LDIRUNIQUE:
+               pCmdUI->Enable(FALSE); // no right item, so can't copy to left
+               break;
+       case FILE_RDIRUNIQUE:
+       // TODO 2002-11-22: Enable unique also, but must write code to do recursive copy
+               pCmdUI->Enable(FALSE);
+               break;
+       default:
                pCmdUI->Enable(FALSE);
+               break;
        }
 }
 
+
+// Prompt & delete file, & remove its data entries
+void CDirView::ConfirmAndDeleteAndUpdate(LPCTSTR szFile, POSITION pos, int sel)
+{
+       // May want an option to suppress these message boxes
+
+       if (!mf->ConfirmAndDelete(szFile))
+               return;
+       // remove item data from document & screen
+       GetDocument()->m_pCtxt->m_dirlist.RemoveAt(pos);
+       GetListCtrl().DeleteItem(sel);
+}
+
+// User chose (main menu) Copy from left to right
 void CDirView::OnDirCopyFileToRight() 
 {
+       DoCopyFileToRight();
+}
+
+// User chose (context menu) Copy from left to right
+void CDirView::OnCtxtDirCopyFileToRight()
+{
+       DoCopyFileToRight();
+}
+
+// Prompt & copy item from left to right, if legal
+void CDirView::DoCopyFileToRight() 
+{
        int sel = m_pList->GetNextItem(-1, LVNI_SELECTED);
-       CString s, sl, sr, slFile, srFile;
+       if (sel == -1) return;
 
-       if (sel != -1
-               && GetSelectedDirNames(sl, sr)
-               && GetSelectedFileNames(slFile, srFile))
+       CString sl, sr, slFile, srFile;
+       if (!GetSelectedDirNames(sl, sr) || !GetSelectedFileNames(slFile, srFile))
+               return;
+
+       CDirDoc *pd = GetDocument();
+       CString s;
+       // find item from document
+       POSITION pos;
+       const DIFFITEM& di = GetDiffItem(sel, pos);
+       // what we do depends on comparison result for this item
+       switch(di.code)
        {
-               CDirDoc *pd = GetDocument();
-               CString s;
-               POSITION pos = reinterpret_cast<POSITION>(m_pList->GetItemData(sel));
-               DIFFITEM di = pd->m_pCtxt->m_dirlist.GetAt(pos);
-               switch(di.code)
-               {
-               case FILE_RUNIQUE:
-                       AfxFormatString1(s, IDS_CONFIRM_DELETE, srFile);
-                       if (AfxMessageBox(s, MB_YESNO|MB_ICONQUESTION)==IDYES)
+       case FILE_RUNIQUE:
+               ConfirmAndDeleteAndUpdate(srFile, pos, sel);
+               break;
+       case FILE_LUNIQUE:
+       case FILE_DIFF:
+       case FILE_BINDIFF:
+               AfxFormatString1(s, IDS_CONFIRM_COPY2DIR, sr);
+               if (AfxMessageBox(s, MB_YESNO|MB_ICONQUESTION)==IDYES)
+               {               
+                       CString left, right;
+                       if (mf->SyncFiles(slFile, srFile))
                        {
-                               if(DeleteFile(srFile))
-                               {
-                                       pd->m_pCtxt->m_dirlist.RemoveAt(pos);
-                                       GetListCtrl().DeleteItem(sel);
-                               }
-                       }
-                       break;
-               case FILE_LUNIQUE:
-               case FILE_DIFF:
-               case FILE_BINDIFF:
-                       AfxFormatString1(s, IDS_CONFIRM_COPY2DIR, sr);
-                       if (AfxMessageBox(s, MB_YESNO|MB_ICONQUESTION)==IDYES)
-                       {               
-                               CString left, right;
-                               if (mf->SyncFiles(slFile, srFile))
-                               {
-                                       mf->UpdateCurrentFileStatus(FILE_SAME);
-                               }
+                               mf->UpdateCurrentFileStatus(FILE_SAME);
                        }
-                       break;
-               case FILE_LDIRUNIQUE:
-               case FILE_RDIRUNIQUE:
-               case FILE_SAME:
-               default:
-                       //pCmdUI->Enable(FALSE);
-                       break;
                }
+               break;
+       case FILE_LDIRUNIQUE:
+       case FILE_RDIRUNIQUE:
+                       // TODO 2002-11-22: Enable uniques also, but must write code to do recursive copy
+       case FILE_SAME:
+       default:
+               // Not allowed, and should have been disabled choices anyway
+               break;
        }
 }
 
+// Update context menu Copy Right to Left item
+void CDirView::OnUpdateCtxtDirCopyFileToRight(CCmdUI* pCmdUI) 
+{
+       DoUpdateDirCopyFileToRight(pCmdUI);
+}
+
+// Update main menu Copy Left to Right item
 void CDirView::OnUpdateDirCopyFileToRight(CCmdUI* pCmdUI) 
 {
+       DoUpdateDirCopyFileToRight(pCmdUI);
+}
+
+// Should Copy to Right be enabled or disabled ? (both main menu & context menu use this)
+void CDirView::DoUpdateDirCopyFileToRight(CCmdUI* pCmdUI) 
+{
        int sel = m_pList->GetNextItem(-1, LVNI_SELECTED);
-       if (sel != -1)
+       if (sel == -1)
        {
-               CDirDoc *pd = GetDocument();
-               POSITION pos = reinterpret_cast<POSITION>(m_pList->GetItemData(sel));
-               DIFFITEM di = pd->m_pCtxt->m_dirlist.GetAt(pos);
-               switch(di.code)
-               {
-               case FILE_RUNIQUE:
-               case FILE_LUNIQUE:
-               case FILE_DIFF:
-               case FILE_BINDIFF:
-                       pCmdUI->Enable(TRUE);
-                       break;
-               case FILE_LDIRUNIQUE:
-               case FILE_RDIRUNIQUE:
-               case FILE_SAME:
-               default:
-                       pCmdUI->Enable(FALSE);
-                       break;
-               }
+               // no item there
+               pCmdUI->Enable(FALSE);
+               return;
        }
-       else
+       // found item (normal case)
+       // find item from document
+       POSITION pos;
+       const DIFFITEM& di = GetDiffItem(sel, pos);
+       switch(di.code)
        {
+       case FILE_LUNIQUE:
+               pCmdUI->Enable(TRUE);
+               break;
+       case FILE_RUNIQUE:
+               pCmdUI->Enable(FALSE); // no left item, so can't copy to right
+               break;
+       case FILE_DIFF:
+       case FILE_BINDIFF:
+               pCmdUI->Enable(TRUE);
+               break;
+       case FILE_LDIRUNIQUE:
+       // TODO 2002-11-22: Enable unique also, but must write code to do recursive copy
+               pCmdUI->Enable(FALSE);
+               break;
+       case FILE_RDIRUNIQUE:
+               pCmdUI->Enable(FALSE); // no left item, so can't copy to right
+               break;
+       case FILE_SAME:
+       default:
                pCmdUI->Enable(FALSE);
+               break;
        }
 }
 
@@ -588,3 +690,142 @@ void CDirView::OpenSelection()
        }
 
 }
+
+// User chose (context menu) delete left
+void CDirView::OnCtxtDirDelLeft()
+{
+       DoDelLeft();
+}
+
+// Prompt & delete left, if legal
+void CDirView::DoDelLeft() 
+{
+       int sel = m_pList->GetNextItem(-1, LVNI_SELECTED);
+       if (sel == -1) return;
+
+       CString sl, sr, slFile, srFile;
+       if (!GetSelectedDirNames(sl, sr) || !GetSelectedFileNames(slFile, srFile))
+               return;
+
+       // find item from document
+       POSITION pos;
+       const DIFFITEM& di = GetDiffItem(sel, pos);
+
+       ConfirmAndDeleteAndUpdate(slFile, pos, sel);
+}
+
+void CDirView::OnUpdateCtxtDirDelLeft(CCmdUI* pCmdUI)
+{
+       DoUpdateCtxtDirDelLeft(pCmdUI);
+}
+
+// Should Delete left be enabled or disabled ? (both main menu & context menu use this)
+void CDirView::DoUpdateCtxtDirDelLeft(CCmdUI* pCmdUI) 
+{
+       int sel = m_pList->GetNextItem(-1, LVNI_SELECTED);
+       if (sel == -1)
+       {
+               // no item there
+               pCmdUI->Enable(FALSE);
+               return;
+       }
+       // found item (normal case)
+       // find item from document
+       POSITION pos;
+       const DIFFITEM& di = GetDiffItem(sel, pos);
+       // what we do depends on comparison result for this item
+       switch(di.code)
+       {
+       case FILE_LUNIQUE:
+               pCmdUI->Enable(TRUE);
+               break;
+       case FILE_RUNIQUE:
+               pCmdUI->Enable(FALSE); // no left item, so can't delete left
+               break;
+       case FILE_DIFF:
+       case FILE_BINDIFF:
+               pCmdUI->Enable(TRUE);
+               break;
+       case FILE_SAME:
+               pCmdUI->Enable(FALSE);
+               break;
+       case FILE_LDIRUNIQUE:
+               pCmdUI->Enable(TRUE);
+               break;
+       case FILE_RDIRUNIQUE:
+               pCmdUI->Enable(FALSE); // no left item, so can't delete left
+               break;
+       default:
+               pCmdUI->Enable(FALSE);
+               break;
+       }
+}
+// User chose (context menu) delete right
+void CDirView::OnCtxtDirDelRight()
+{
+       DoDelRight();
+}
+
+// Prompt & delete right, if legal
+void CDirView::DoDelRight() 
+{
+       int sel = m_pList->GetNextItem(-1, LVNI_SELECTED);
+       if (sel == -1) return;
+
+       CString sl, sr, slFile, srFile;
+       if (!GetSelectedDirNames(sl, sr) || !GetSelectedFileNames(slFile, srFile))
+               return;
+
+       // find item from document
+       POSITION pos;
+       const DIFFITEM& di = GetDiffItem(sel, pos);
+
+       ConfirmAndDeleteAndUpdate(srFile, pos, sel);
+}
+
+void CDirView::OnUpdateCtxtDirDelRight(CCmdUI* pCmdUI) 
+{
+       DoUpdateCtxtDirDelRight(pCmdUI);
+}
+
+// Should Delete right be enabled or disabled ?
+void CDirView::DoUpdateCtxtDirDelRight(CCmdUI* pCmdUI) 
+{
+       int sel = m_pList->GetNextItem(-1, LVNI_SELECTED);
+       if (sel == -1)
+       {
+               // no item there
+               pCmdUI->Enable(FALSE);
+               return;
+       }
+       // found item (normal case)
+       // find item from document
+       POSITION pos;
+       const DIFFITEM& di = GetDiffItem(sel, pos);
+       // what we do depends on comparison result for this item
+       switch(di.code)
+       {
+       case FILE_LUNIQUE:
+               pCmdUI->Enable(FALSE); // no right item, so can't delete right
+               break;
+       case FILE_RUNIQUE:
+               pCmdUI->Enable(TRUE);
+               break;
+       case FILE_DIFF:
+       case FILE_BINDIFF:
+               pCmdUI->Enable(TRUE);
+               break;
+       case FILE_SAME:
+               pCmdUI->Enable(FALSE);
+               break;
+       case FILE_LDIRUNIQUE:
+               pCmdUI->Enable(FALSE); // no right item, so can't delete right
+               break;
+       case FILE_RDIRUNIQUE:
+               pCmdUI->Enable(TRUE);
+               break;
+       default:
+               pCmdUI->Enable(FALSE);
+               break;
+       }
+}
index 526976b..3dd7be8 100644 (file)
 #include "listvwex.h"
 #include "SortHeaderCtrl.h"
 
+
+struct tagDIFFITEM;
+typedef struct tagDIFFITEM DIFFITEM;
+
+
 class CDirDoc;
 
 class CDirView : public CListViewEx
@@ -87,15 +92,35 @@ protected:
        //{{AFX_MSG(CDirView)
        afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
        afx_msg void OnDirCopyFileToLeft();
+       afx_msg void OnCtxtDirCopyFileToLeft();
        afx_msg void OnUpdateDirCopyFileToLeft(CCmdUI* pCmdUI);
        afx_msg void OnDirCopyFileToRight();
+       afx_msg void OnCtxtDirCopyFileToRight();
        afx_msg void OnUpdateDirCopyFileToRight(CCmdUI* pCmdUI);
+       afx_msg void OnUpdateCtxtDirCopyFileToLeft(CCmdUI* pCmdUI);
+       afx_msg void OnUpdateCtxtDirCopyFileToRight(CCmdUI* pCmdUI);
+       afx_msg void OnCtxtDirDelLeft();
+       afx_msg void OnUpdateCtxtDirDelLeft(CCmdUI* pCmdUI);
+       afx_msg void OnCtxtDirDelRight();
+       afx_msg void OnUpdateCtxtDirDelRight(CCmdUI* pCmdUI);
        afx_msg void OnDestroy();
        afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
 private:
        void OpenSelection();
+       const DIFFITEM& CDirView::GetDiffItem(int sel, POSITION & pos);
+       void DoCopyFileToRight();
+       void DoCopyFileToLeft();
+       void DoUpdateDirCopyFileToLeft(CCmdUI* pCmdUI);
+       void DoUpdateDirCopyFileToRight(CCmdUI* pCmdUI);
+       void ModifyPopup(CMenu * pPopup, int nStringResource, int nMenuId, LPCTSTR szPath);
+       void DoDelLeft();
+       void DoDelRight();
+       void ConfirmAndDeleteAndUpdate(LPCTSTR szFile, POSITION pos, int sel);
+       void DoUpdateCtxtDirDelLeft(CCmdUI* pCmdUI);
+       void DoUpdateCtxtDirDelRight(CCmdUI* pCmdUI);
+
 };
 
 #ifndef _DEBUG  // debug version in DirView.cpp
index 0d4cd11..4bb3678 100644 (file)
@@ -812,6 +812,65 @@ BOOL CMainFrame::CreateBackup(LPCTSTR pszPath)
        return TRUE;
 }
 
+// Get user language description of error, if available
+static CString
+GetSystemErrorDesc(int nerr)
+{
+       LPVOID lpMsgBuf;
+       CString str = _T("?");
+       if (FormatMessage( 
+               FORMAT_MESSAGE_ALLOCATE_BUFFER | 
+               FORMAT_MESSAGE_FROM_SYSTEM | 
+               FORMAT_MESSAGE_IGNORE_INSERTS,
+               NULL,
+               nerr,
+               0, // Default language
+               (LPTSTR) &lpMsgBuf,
+               0,
+               NULL 
+               ))
+       {
+               str = (LPCTSTR)lpMsgBuf;
+       }
+       // Free the buffer.
+       LocalFree( lpMsgBuf );
+       return str;
+}
+
+// trim trailing line returns
+static void TrimRightLines(CString & str)
+{
+       str.Replace(_T("\n"), _T(""));
+       str.Replace(_T("\r"), _T(""));
+}
+
+// Delete file (return TRUE if deleted, else put up error & return FALSE)
+static BOOL DeleteOrError(LPCTSTR szFile)
+{
+       // TODO: 2002-11-22, need to handle deleting directories
+       if (!DeleteFile(szFile))
+       {
+               CString sError = GetSystemErrorDesc(GetLastError());
+               TrimRightLines(sError);
+               CString s;
+               AfxFormatString1(s, IDS_DELETE_FAILED, sError);
+               AfxMessageBox(s, MB_OK|MB_ICONSTOP);
+               return FALSE;
+       }
+       return TRUE;
+}
+
+// Prompt & delete file (return TRUE if deleted)
+BOOL CMainFrame::ConfirmAndDelete(LPCTSTR szFile)
+{
+       CString s;
+       AfxFormatString1(s, IDS_CONFIRM_DELETE, szFile);
+       if (AfxMessageBox(s, MB_YESNO|MB_ICONQUESTION)!=IDYES)
+               return FALSE;
+       return DeleteOrError(szFile);
+}
+
+
 BOOL CMainFrame::SyncFiles(LPCTSTR pszSrc, LPCTSTR pszDest)
 {
        CString strSavePath(pszDest);
index 48fff1d..97a2a42 100644 (file)
@@ -75,6 +75,7 @@ public:
        CString m_sPattern;
        void UpdateResources();
        void UpdateCurrentFileStatus(UINT nStatus);
+       BOOL ConfirmAndDelete(LPCTSTR szFile);
        BOOL SyncFiles(LPCTSTR pszSrc, LPCTSTR pszDest);
        BOOL CreateBackup(LPCTSTR pszPath);
        UINT m_nTabSize;
index a2e12e6..2fa74e4 100644 (file)
@@ -160,6 +160,8 @@ BEGIN
     BEGIN
         MENUITEM "Copy file to left",           ID_DIR_COPY_FILE_TO_LEFT
         MENUITEM "Copy file to right",          ID_DIR_COPY_FILE_TO_RIGHT
+        MENUITEM "Delete left",                 ID_DIR_DEL_LEFT
+        MENUITEM "Delete right",                ID_DIR_DEL_RIGHT
     END
 END
 
@@ -590,7 +592,7 @@ BEGIN
     IDS_ALLFILES            "All Files (*.*)|*.*||"
     IDS_CONFIRM_ALL_LEFT    "Are you sure you want to copy all differences to the left file?"
     IDS_CONFIRM_ALL_RIGHT   "Are you sure you want to copy all differences to the right file?"
-    IDS_COPY2DIR_FMT        "Copy file to %1"
+    IDS_COPY2DIR_LEFT_FMT   "Copy file to left: %1"
     IDS_CONFIRM_COPY2DIR    "Are you sure you want to copy the selected file to %1?"
     IDS_FONT_CHANGE         "The selected font change will not be applied to any currently visible difference windows."
     IDS_DIRECTORY_WINDOW_TITLE "Directory Comparison Results"
@@ -755,6 +757,8 @@ BEGIN
     ID_CURDIFF              "Scroll to the current difference\nCurrent Diff"
     ID_LASTDIFF             "Scroll to the last difference\nLast Diff"
     ID_DIFFNUM              "placeholder"
+    ID_DIR_DEL_LEFT         "Delete selected file on left"
+    ID_DIR_DEL_RIGHT        "Delete selected file on right"
 END
 
 STRINGTABLE DISCARDABLE 
@@ -928,6 +932,14 @@ BEGIN
     IDS_LTIME_HEADER        "Left Date"
     IDS_RTIME_HEADER        "Right Date"
     IDS_EXTENSION_HEADER    "Extension"
+    IDS_COPY2DIR_RIGHT_FMT  "Copy file to right: %1"
+    IDS_DEL_LEFT_FMT        "Delete left: %1"
+END
+
+STRINGTABLE DISCARDABLE 
+BEGIN
+    IDS_DEL_RIGHT_FMT       "Del right: %1"
+    IDS_DELETE_FAILED       "Delete failed: %1"
 END
 
 #endif    // English (U.S.) resources
index a97dd02..e1acc15 100644 (file)
@@ -24,7 +24,7 @@
 #define IDS_CONFIRM_ALL_LEFT            132
 #define IDD_PROPPAGE_LARGE              133
 #define IDS_CONFIRM_ALL_RIGHT           133
-#define IDS_COPY2DIR_FMT                134
+#define IDS_COPY2DIR_LEFT_FMT           134
 #define IDD_CLEARCASE                   134
 #define IDS_CONFIRM_COPY2DIR            135
 #define IDD_PROPPAGE_FILTER             135
 #define IDS_LTIME_HEADER                171
 #define IDS_RTIME_HEADER                172
 #define IDS_EXTENSION_HEADER            173
+#define IDS_COPY2DIR_RIGHT_FMT          174
+#define IDS_DEL_LEFT_FMT                175
+#define IDS_DEL_RIGHT_FMT               176
+#define IDS_DELETE_FAILED               177
 #define IDB_EQUAL                       213
 #define IDB_NOTEQUAL                    214
 #define IDB_RFOLDER                     215
 #define ID_CURDIFF                      32804
 #define ID_LASTDIFF                     32805
 #define ID_DIFFNUM                      32806
+#define ID_DIR_DEL_LEFT                 32807
+#define ID_DIR_DEL_RIGHT                32808
 
 // Next default values for new objects
 // 
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_3D_CONTROLS                     1
 #define _APS_NEXT_RESOURCE_VALUE        135
-#define _APS_NEXT_COMMAND_VALUE         32807
+#define _APS_NEXT_COMMAND_VALUE         32809
 #define _APS_NEXT_CONTROL_VALUE         1032
 #define _APS_NEXT_SYMED_VALUE           106
 #endif