//
#include "stdafx.h"
+#include "DirActions.h"
#include "Merge.h"
#include "UnicodeString.h"
#include "DirView.h"
#include "FileOrFolderSelect.h"
#include "ConfirmFolderCopyDlg.h"
#include "SourceControl.h"
+#include "DirItemIterator.h"
+#include "IListCtrlImpl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
* @brief Format warning message about invalid folder compare contents.
* @param [in] failedPath Path that failed (didn't exist).
*/
-void CDirView::WarnContentsChanged(const String & failedPath)
+static void WarnContentsChanged(const String & failedPath)
{
String msg = string_format_string1(
_("Operation aborted!\n\nFolder contents at disks has changed, path\n%1\nwas not found.\n\nPlease refresh the compare."),
AfxMessageBox(msg.c_str(), MB_ICONWARNING);
}
-/// Prompt & copy item from right to left, if legal
-void CDirView::DoCopyRightToLeft()
+struct ContentsChangedException
{
- WaitStatusCursor waitstatus(_("Copying files..."));
+ ContentsChangedException(const String& failpath) : m_failpath(failpath) {}
+ String m_failpath;
+};
- // First we build a list of desired actions
- FileActionScript actionScript;
- int sel = -1;
- while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+struct CopyRightToLeftFunctor
+{
+ CopyRightToLeftFunctor(const CDiffContext *pctxt, FileActionScript& actionScript) : m_pctxt(pctxt), m_actionScript(actionScript) {}
+
+ void operator()(const std::pair<int, const DIFFITEM *> it)
{
- const DIFFITEM& di = GetDiffItem(sel);
+ const DIFFITEM& di = *it.second;
if (di.diffcode.diffcode != 0 && IsItemCopyableToLeft(di))
{
FileActionItem act;
- GetItemFileNames(sel, act.dest, act.src);
+ ::GetItemFileNames(m_pctxt, di, act.dest, act.src);
// We must check that paths still exists
String failpath;
- bool succeed = CheckPathsExist(act.src, act.dest, ALLOW_ALL,
- ALLOW_DONT_CARE, failpath);
- if (succeed == false)
- {
- WarnContentsChanged(failpath);
- return;
- }
+ if (!CheckPathsExist(act.src, act.dest, ALLOW_ALL,
+ ALLOW_DONT_CARE, failpath))
+ throw ContentsChangedException(failpath);
- act.context = sel;
+ act.context = it.first;
act.dirflag = di.diffcode.isDirectory();
act.atype = FileAction::ACT_COPY;
act.UIResult = FileActionItem::UI_SYNC;
act.UIOrigin = FileActionItem::UI_RIGHT;
act.UIDestination = FileActionItem::UI_LEFT;
- actionScript.AddActionItem(act);
+ m_actionScript.AddActionItem(act);
}
}
- // Now we prompt, and execute actions
- ConfirmAndPerformActions(actionScript);
-}
+ const CDiffContext *m_pctxt;
+ FileActionScript& m_actionScript;
+};
-/// Prompt & copy item from left to right, if legal
-void CDirView::DoCopyLeftToRight()
+struct CopyLeftToRightFunctor
{
- WaitStatusCursor waitstatus(_("Copying files..."));
+ CopyLeftToRightFunctor(const CDiffContext *pctxt, FileActionScript& actionScript) : m_pctxt(pctxt), m_actionScript(actionScript) {}
- // First we build a list of desired actions
- FileActionScript actionScript;
- int sel = -1;
- while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+ void operator()(const std::pair<int, const DIFFITEM *> it)
{
- const DIFFITEM& di = GetDiffItem(sel);
+ const DIFFITEM& di = *it.second;
if (di.diffcode.diffcode != 0 && IsItemCopyableToRight(di))
{
FileActionItem act;
- GetItemFileNames(sel, act.src, act.dest);
+ ::GetItemFileNames(m_pctxt, di, act.src, act.dest);
// We must first check that paths still exists
String failpath;
- bool succeed = CheckPathsExist(act.src, act.dest, ALLOW_ALL,
- ALLOW_DONT_CARE, failpath);
- if (succeed == false)
- {
- WarnContentsChanged(failpath);
- return;
- }
+ if (CheckPathsExist(act.src, act.dest, ALLOW_ALL,
+ ALLOW_DONT_CARE, failpath))
+ throw ContentsChangedException(failpath);
- act.context = sel;
+ act.context = it.first;
act.dirflag = di.diffcode.isDirectory();
act.atype = FileAction::ACT_COPY;
act.UIResult = FileActionItem::UI_SYNC;
act.UIOrigin = FileActionItem::UI_LEFT;
act.UIDestination = FileActionItem::UI_RIGHT;
- actionScript.AddActionItem(act);
+ m_actionScript.AddActionItem(act);
}
}
- // Now we prompt, and execute actions
- ConfirmAndPerformActions(actionScript);
-}
+ const CDiffContext *m_pctxt;
+ FileActionScript& m_actionScript;
+};
-/// Prompt & delete left, if legal
-void CDirView::DoDelLeft()
+
+struct DelLeftFunctor
{
- WaitStatusCursor waitstatus(_("Deleting files..."));
+ DelLeftFunctor(const CDiffContext *pctxt, FileActionScript& actionScript) : m_pctxt(pctxt), m_actionScript(actionScript) {}
- // First we build a list of desired actions
- FileActionScript actionScript;
- int sel=-1;
- while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+ void operator()(const std::pair<int, const DIFFITEM *> it)
{
- const DIFFITEM& di = GetDiffItem(sel);
+ const DIFFITEM& di = *it.second;
if (di.diffcode.diffcode != 0 && IsItemDeletableOnLeft(di))
{
String dmy;
FileActionItem act;
- GetItemFileNames(sel, act.src, dmy);
+ GetItemFileNames(m_pctxt, di, act.src, dmy);
// We must check that path still exists
String failpath;
- bool succeed = CheckPathsExist(act.src, dmy, ALLOW_ALL,
- ALLOW_DONT_CARE, failpath);
- if (succeed == false)
- {
- WarnContentsChanged(failpath);
- return;
- }
+ if (CheckPathsExist(act.src, dmy, ALLOW_ALL,
+ ALLOW_DONT_CARE, failpath))
+ throw ContentsChangedException(failpath);
- act.context = sel;
+ act.context = it.first;
act.dirflag = di.diffcode.isDirectory();
act.atype = FileAction::ACT_DEL;
act.UIResult = FileActionItem::UI_DEL_LEFT;
- actionScript.AddActionItem(act);
+ m_actionScript.AddActionItem(act);
}
}
- // Now we prompt, and execute actions
- ConfirmAndPerformActions(actionScript);
-}
-/// Prompt & delete right, if legal
-void CDirView::DoDelRight()
+ const CDiffContext *m_pctxt;
+ FileActionScript& m_actionScript;
+};
+
+
+struct DelRightFunctor
{
- WaitStatusCursor waitstatus(_("Deleting files..."));
+ DelRightFunctor(const CDiffContext *pctxt, FileActionScript& actionScript) : m_pctxt(pctxt), m_actionScript(actionScript) {}
- // First we build a list of desired actions
- FileActionScript actionScript;
- int sel = -1;
- while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+ void operator()(const std::pair<int, const DIFFITEM *> it)
{
- const DIFFITEM& di = GetDiffItem(sel);
-
+ const DIFFITEM& di = *it.second;
if (di.diffcode.diffcode != 0 && IsItemDeletableOnRight(di))
{
FileActionItem act;
String dmy;
- GetItemFileNames(sel, dmy, act.src);
+ GetItemFileNames(m_pctxt, di, dmy, act.src);
// We must first check that path still exists
String failpath;
- bool succeed = CheckPathsExist(act.src, dmy, ALLOW_ALL,
- ALLOW_DONT_CARE, failpath);
- if (succeed == false)
- {
- WarnContentsChanged(failpath);
- return;
- }
+ if (CheckPathsExist(act.src, dmy, ALLOW_ALL,
+ ALLOW_DONT_CARE, failpath))
+ throw ContentsChangedException(failpath);
- act.context = sel;
+ act.context = it.first;
act.dirflag = di.diffcode.isDirectory();
act.atype = FileAction::ACT_DEL;
act.UIResult = FileActionItem::UI_DEL_RIGHT;
- actionScript.AddActionItem(act);
+ m_actionScript.AddActionItem(act);
}
}
- // Now we prompt, and execute actions
- ConfirmAndPerformActions(actionScript);
-}
+ const CDiffContext *m_pctxt;
+ FileActionScript& m_actionScript;
+};
-/**
- * @brief Prompt & delete both, if legal.
- */
-void CDirView::DoDelBoth()
+struct DelBothFunctor
{
- WaitStatusCursor waitstatus(_("Deleting files..."));
+ DelBothFunctor(const CDiffContext *pctxt, FileActionScript& actionScript) : m_pctxt(pctxt), m_actionScript(actionScript) {}
- // First we build a list of desired actions
- FileActionScript actionScript;
- int sel = -1;
- while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+ void operator()(const std::pair<int, const DIFFITEM *> it)
{
- const DIFFITEM& di = GetDiffItem(sel);
+ const DIFFITEM& di = *it.second;
if (di.diffcode.diffcode != 0 && IsItemDeletableOnBoth(di))
{
FileActionItem act;
- GetItemFileNames(sel, act.dest, act.src);
+ ::GetItemFileNames(m_pctxt, di, act.dest, act.src);
// We must first check that paths still exists
String failpath;
- bool succeed = CheckPathsExist(act.src, act.dest, ALLOW_ALL,
- ALLOW_ALL, failpath);
- if (succeed == false)
- {
- WarnContentsChanged(failpath);
- return;
- }
+ if (CheckPathsExist(act.src, act.dest, ALLOW_ALL,
+ ALLOW_ALL, failpath))
+ throw ContentsChangedException(failpath);
- act.context = sel;
+ act.context = it.first;
act.dirflag = di.diffcode.isDirectory();
act.atype = FileAction::ACT_DEL;
act.UIResult = FileActionItem::UI_DEL_BOTH;
- actionScript.AddActionItem(act);
+ m_actionScript.AddActionItem(act);
}
}
- // Now we prompt, and execute actions
- ConfirmAndPerformActions(actionScript);
-}
-/**
- * @brief Delete left, right or both items.
- * @note Usually we don't need to check for read-only in this level of code.
- * Usually we can disable handling read-only items/sides by disabling GUI
- * element. But in this case the GUI element effects to both sides and can
- * be selected when another side is read-only.
- */
-void CDirView::DoDelAll()
+ const CDiffContext *m_pctxt;
+ FileActionScript& m_actionScript;
+};
+
+struct DelAllFunctor
{
- WaitStatusCursor waitstatus(_("Deleting files..."));
+ DelAllFunctor(const CDiffContext *pctxt, bool leftRO, bool rightRO, FileActionScript& actionScript) :
+ m_pctxt(pctxt), m_leftRO(leftRO), m_rightRO(rightRO), m_actionScript(actionScript) {}
- // First we build a list of desired actions
- FileActionScript actionScript;
- int sel = -1;
- String slFile, srFile;
- while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+ void operator()(const std::pair<int, const DIFFITEM *> it)
{
- const DIFFITEM& di = GetDiffItem(sel);
-
+ const DIFFITEM& di = *it.second;
if (di.diffcode.diffcode != 0)
{
- GetItemFileNames(sel, slFile, srFile);
+ String slFile, srFile;
+ GetItemFileNames(m_pctxt, di, slFile, srFile);
int leftFlags = ALLOW_DONT_CARE;
int rightFlags = ALLOW_DONT_CARE;
- bool leftRO = GetDocument()->GetReadOnly(true);
- bool rightRO = GetDocument()->GetReadOnly(false);
FileActionItem act;
- if (IsItemDeletableOnBoth(di) && !leftRO && !rightRO)
+ if (IsItemDeletableOnBoth(di) && !m_leftRO && !m_rightRO)
{
leftFlags = ALLOW_ALL;
rightFlags = ALLOW_ALL;
act.dest = slFile;
act.UIResult = FileActionItem::UI_DEL_BOTH;
}
- else if (IsItemDeletableOnLeft(di) && !leftRO)
+ else if (IsItemDeletableOnLeft(di) && !m_leftRO)
{
leftFlags = ALLOW_ALL;
act.src = slFile;
act.UIResult = FileActionItem::UI_DEL_LEFT;
}
- else if (IsItemDeletableOnRight(di) && !rightRO)
+ else if (IsItemDeletableOnRight(di) && !m_rightRO)
{
rightFlags = ALLOW_ALL;
act.src = srFile;
{
// We must first check that paths still exists
String failpath;
- bool succeed = CheckPathsExist(slFile, srFile, leftFlags,
- rightFlags, failpath);
- if (succeed == false)
- {
- WarnContentsChanged(failpath);
- return;
- }
+ if (CheckPathsExist(slFile, srFile, leftFlags,
+ rightFlags, failpath))
+ throw ContentsChangedException(failpath);
act.dirflag = di.diffcode.isDirectory();
- act.context = sel;
+ act.context = it.first;
act.atype = FileAction::ACT_DEL;
- actionScript.AddActionItem(act);
+ m_actionScript.AddActionItem(act);
}
}
}
- // Now we prompt, and execute actions
- ConfirmAndPerformActions(actionScript);
-}
+ bool m_leftRO, m_rightRO;
+ const CDiffContext *m_pctxt;
+ FileActionScript& m_actionScript;
+};
-/**
- * @brief Copy selected left-side files to user-specified directory
- *
- * When copying files from recursive compare file subdirectory is also
- * read so directory structure is preserved.
- */
-void CDirView::DoCopyLeftTo()
+struct CopyLeftToFunctor
{
- String destPath;
- String startPath(m_lastCopyFolder);
-
- if (!SelectFolder(destPath, startPath.c_str(), _("Left side - select destination folder:")))
- return;
-
- m_lastCopyFolder = destPath;
- WaitStatusCursor waitstatus(_("Copying files..."));
+ CopyLeftToFunctor(const CDiffContext *pctxt, const String& destPath, FileActionScript& actionScript) :
+ m_pctxt(pctxt), m_destPath(destPath), m_actionScript(actionScript) {}
- FileActionScript actionScript;
- int sel = -1;
- String slFile, srFile;
- while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+ void operator()(const std::pair<int, const DIFFITEM *> it)
{
- const DIFFITEM& di = GetDiffItem(sel);
+ const DIFFITEM& di = *it.second;
if (di.diffcode.diffcode != 0 && IsItemCopyableToOnLeft(di))
{
- GetItemFileNames(sel, slFile, srFile);
+ String slFile, srFile;
+ GetItemFileNames(m_pctxt, di, slFile, srFile);
// We must check that path still exists
String failpath;
- bool succeed = CheckPathsExist(slFile, srFile, ALLOW_ALL,
- ALLOW_DONT_CARE, failpath);
- if (succeed == false)
- {
- WarnContentsChanged(failpath);
- return;
- }
+ if (CheckPathsExist(slFile, srFile, ALLOW_ALL,
+ ALLOW_DONT_CARE, failpath))
+ throw ContentsChangedException(failpath);
FileActionItem act;
- String sFullDest = paths_AddTrailingSlash(destPath);
+ String sFullDest = paths_AddTrailingSlash(m_destPath);
- actionScript.m_destBase = sFullDest;
+ m_actionScript.m_destBase = sFullDest;
sFullDest += di.diffFileInfo[0].filename;
act.dest = sFullDest;
act.src = slFile;
act.dirflag = di.diffcode.isDirectory();
- act.context = sel;
+ act.context = it.first;
act.atype = FileAction::ACT_COPY;
act.UIResult = FileActionItem::UI_DONT_CARE;
act.UIOrigin = FileActionItem::UI_LEFT;
- actionScript.AddActionItem(act);
+ m_actionScript.AddActionItem(act);
}
}
- // Now we prompt, and execute actions
- ConfirmAndPerformActions(actionScript);
-}
-
-/**
- * @brief Copy selected righ-side files to user-specified directory
- *
- * When copying files from recursive compare file subdirectory is also
- * read so directory structure is preserved.
- */
-void CDirView::DoCopyRightTo()
-{
- String destPath;
- String startPath(m_lastCopyFolder);
- if (!SelectFolder(destPath, startPath.c_str(), _("Right side - select destination folder:")))
- return;
+ const CDiffContext *m_pctxt;
+ String m_destPath;
+ FileActionScript& m_actionScript;
+};
- m_lastCopyFolder = destPath;
- WaitStatusCursor waitstatus(_("Copying files..."));
+struct CopyRightToFunctor
+{
+ CopyRightToFunctor(const CDiffContext *pctxt, const String& destPath, FileActionScript& actionScript) :
+ m_pctxt(pctxt), m_destPath(destPath), m_actionScript(actionScript) {}
- FileActionScript actionScript;
- int sel = -1;
- String slFile, srFile;
- while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+ void operator()(const std::pair<int, const DIFFITEM *> it)
{
- const DIFFITEM& di = GetDiffItem(sel);
+ const DIFFITEM& di = *it.second;
if (di.diffcode.diffcode != 0 && IsItemCopyableToOnRight(di))
{
- GetItemFileNames(sel, slFile, srFile);
+ String slFile, srFile;
+
+ ::GetItemFileNames(m_pctxt, di, slFile, srFile);
// We must check that path still exists
String failpath;
- bool succeed = CheckPathsExist(srFile, slFile, ALLOW_ALL,
- ALLOW_DONT_CARE, failpath);
- if (succeed == false)
- {
- WarnContentsChanged(failpath);
- return;
- }
+ if (CheckPathsExist(srFile, slFile, ALLOW_ALL,
+ ALLOW_DONT_CARE, failpath))
+ throw ContentsChangedException(failpath);
FileActionItem act;
- String sFullDest = paths_AddTrailingSlash(destPath);
+ String sFullDest = paths_AddTrailingSlash(m_destPath);
- actionScript.m_destBase = sFullDest;
+ m_actionScript.m_destBase = sFullDest;
sFullDest += di.diffFileInfo[1].filename;
act.dest = sFullDest;
act.src = srFile;
act.dirflag = di.diffcode.isDirectory();
- act.context = sel;
+ act.context = it.first;
act.atype = FileAction::ACT_COPY;
act.UIResult = FileActionItem::UI_DONT_CARE;
act.UIOrigin = FileActionItem::UI_RIGHT;
- actionScript.AddActionItem(act);
+ m_actionScript.AddActionItem(act);
}
}
- // Now we prompt, and execute actions
- ConfirmAndPerformActions(actionScript);
-}
-
-/**
- * @brief Move selected left-side files to user-specified directory
- *
- * When moving files from recursive compare file subdirectory is also
- * read so directory structure is preserved.
- */
-void CDirView::DoMoveLeftTo()
-{
- String destPath;
- String startPath(m_lastCopyFolder);
- if (!SelectFolder(destPath, startPath.c_str(), _("Left side - select destination folder:")))
- return;
+ const CDiffContext *m_pctxt;
+ String m_destPath;
+ FileActionScript& m_actionScript;
+};
- m_lastCopyFolder = destPath;
- WaitStatusCursor waitstatus(_("Moving files..."));
+struct MoveLeftToFunctor
+{
+ MoveLeftToFunctor(const CDiffContext *pctxt, const String& destPath, FileActionScript& actionScript) :
+ m_pctxt(pctxt), m_destPath(destPath), m_actionScript(actionScript) {}
- FileActionScript actionScript;
- int sel = -1;
- String slFile, srFile;
- while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+ void operator()(const std::pair<int, const DIFFITEM *> it)
{
- const DIFFITEM& di = GetDiffItem(sel);
+ const DIFFITEM& di = *it.second;
if (di.diffcode.diffcode != 0 && IsItemCopyableToOnLeft(di) && IsItemDeletableOnLeft(di))
{
- GetItemFileNames(sel, slFile, srFile);
+ String slFile, srFile;
+ ::GetItemFileNames(m_pctxt, di, slFile, srFile);
// We must check that path still exists
String failpath;
- bool succeed = CheckPathsExist(slFile, srFile, ALLOW_ALL,
- ALLOW_DONT_CARE, failpath);
- if (succeed == false)
- {
- WarnContentsChanged(failpath);
- return;
- }
+ if (CheckPathsExist(slFile, srFile, ALLOW_ALL,
+ ALLOW_DONT_CARE, failpath))
+ throw ContentsChangedException(failpath);
FileActionItem act;
- String sFullDest = paths_AddTrailingSlash(destPath);
- actionScript.m_destBase = sFullDest;
+ String sFullDest = paths_AddTrailingSlash(m_destPath);
+ m_actionScript.m_destBase = sFullDest;
sFullDest += di.diffFileInfo[0].filename;
act.dest = sFullDest;
act.src = slFile;
act.dirflag = di.diffcode.isDirectory();
- act.context = sel;
+ act.context = it.first;
act.atype = FileAction::ACT_MOVE;
act.UIOrigin = FileActionItem::UI_LEFT;
act.UIResult = FileActionItem::UI_DEL_LEFT;
- actionScript.AddActionItem(act);
+ m_actionScript.AddActionItem(act);
}
}
- // Now we prompt, and execute actions
- ConfirmAndPerformActions(actionScript);
-}
-/**
- * @brief Move selected right-side files to user-specified directory
- *
- * When moving files from recursive compare file subdirectory is also
- * read so directory structure is preserved.
- */
-void CDirView::DoMoveRightTo()
-{
- String destPath;
- String startPath(m_lastCopyFolder);
+ const CDiffContext *m_pctxt;
+ String m_destPath;
+ FileActionScript& m_actionScript;
+};
- if (!SelectFolder(destPath, startPath.c_str(), _("Right side - select destination folder:")))
- return;
-
- m_lastCopyFolder = destPath;
- WaitStatusCursor waitstatus(_("Moving files..."));
+struct MoveRightToFunctor
+{
+ MoveRightToFunctor(const CDiffContext *pctxt, const String& destPath, FileActionScript& actionScript) :
+ m_pctxt(pctxt), m_destPath(destPath), m_actionScript(actionScript) {}
- FileActionScript actionScript;
- int sel = -1;
- String slFile, srFile;
- while ((sel = m_pList->GetNextItem(sel, LVNI_SELECTED)) != -1)
+ void operator()(const std::pair<int, const DIFFITEM *> it)
{
- const DIFFITEM& di = GetDiffItem(sel);
+ const DIFFITEM& di = *it.second;
if (di.diffcode.diffcode != 0 && IsItemCopyableToOnRight(di) && IsItemDeletableOnRight(di))
{
- GetItemFileNames(sel, slFile, srFile);
+ String slFile, srFile;
+ ::GetItemFileNames(m_pctxt, di, slFile, srFile);
// We must check that path still exists
String failpath;
- bool succeed = CheckPathsExist(srFile, slFile, ALLOW_ALL,
- ALLOW_DONT_CARE, failpath);
- if (succeed == false)
- {
- WarnContentsChanged(failpath);
- return;
- }
+ if (CheckPathsExist(srFile, slFile, ALLOW_ALL,
+ ALLOW_DONT_CARE, failpath))
+ throw ContentsChangedException(failpath);
FileActionItem act;
- String sFullDest = paths_AddTrailingSlash(destPath);
- actionScript.m_destBase = sFullDest;
+ String sFullDest = paths_AddTrailingSlash(m_destPath);
+ m_actionScript.m_destBase = sFullDest;
sFullDest += di.diffFileInfo[1].filename;
act.dest = sFullDest;
act.src = srFile;
act.dirflag = di.diffcode.isDirectory();
- act.context = sel;
+ act.context = it.first;
act.atype = FileAction::ACT_MOVE;
act.UIOrigin = FileActionItem::UI_RIGHT;
act.UIResult = FileActionItem::UI_DEL_RIGHT;
- actionScript.AddActionItem(act);
+ m_actionScript.AddActionItem(act);
}
}
- // Now we prompt, and execute actions
- ConfirmAndPerformActions(actionScript);
+
+ const CDiffContext *m_pctxt;
+ String m_destPath;
+ FileActionScript& m_actionScript;
+};
+
+template<class Functor>
+void CDirView::DoDirAction(const String& status_message)
+{
+ WaitStatusCursor waitstatus(status_message);
+
+ try {
+ // First we build a list of desired actions
+ FileActionScript actionScript;
+ std::for_each(SelectedDirItemIterator(&IListCtrlImpl(m_pList->m_hWnd)), SelectedDirItemIterator(),
+ Functor(&GetDocument()->GetDiffContext(), actionScript));
+ // Now we prompt, and execute actions
+ ConfirmAndPerformActions(actionScript);
+ } catch (ContentsChangedException& e) {
+ WarnContentsChanged(e.m_failpath);
+ }
+}
+
+template<class Functor>
+void CDirView::DoDirActionTo(const String& status_message, const String& selectfolder_title)
+{
+ String destPath;
+ String startPath(m_lastCopyFolder);
+
+ if (!SelectFolder(destPath, startPath.c_str(), selectfolder_title))
+ return;
+
+ m_lastCopyFolder = destPath;
+ WaitStatusCursor waitstatus(status_message);
+
+ try {
+ // First we build a list of desired actions
+ FileActionScript actionScript;
+ std::for_each(SelectedDirItemIterator(&IListCtrlImpl(m_pList->m_hWnd)), SelectedDirItemIterator(),
+ Functor(&GetDocument()->GetDiffContext(), destPath, actionScript));
+ // Now we prompt, and execute actions
+ ConfirmAndPerformActions(actionScript);
+ } catch (ContentsChangedException& e) {
+ WarnContentsChanged(e.m_failpath);
+ }
+}
+
+/// Prompt & copy item from right to left, if legal
+void CDirView::DoCopyRightToLeft()
+{
+ DoDirAction<CopyRightToLeftFunctor>(_("Copying files..."));
+}
+
+/// Prompt & copy item from left to right, if legal
+void CDirView::DoCopyLeftToRight()
+{
+ DoDirAction<CopyRightToLeftFunctor>(_("Copying files..."));
+}
+
+/// Prompt & delete left, if legal
+void CDirView::DoDelLeft()
+{
+ DoDirAction<CopyLeftToRightFunctor>(_("Deleting files..."));
+}
+
+/// Prompt & delete right, if legal
+void CDirView::DoDelRight()
+{
+ DoDirAction<DelRightFunctor>(_("Deleting files..."));
+}
+
+/**
+ * @brief Prompt & delete both, if legal.
+ */
+void CDirView::DoDelBoth()
+{
+ DoDirAction<DelBothFunctor>(_("Deleting files..."));
+}
+
+/**
+ * @brief Delete left, right or both items.
+ * @note Usually we don't need to check for read-only in this level of code.
+ * Usually we can disable handling read-only items/sides by disabling GUI
+ * element. But in this case the GUI element effects to both sides and can
+ * be selected when another side is read-only.
+ */
+void CDirView::DoDelAll()
+{
+ WaitStatusCursor waitstatus(_("Deleting files..."));
+
+ try {
+ // First we build a list of desired actions
+ FileActionScript actionScript;
+ std::for_each(SelectedDirItemIterator(&IListCtrlImpl(m_pList->m_hWnd)), SelectedDirItemIterator(),
+ DelAllFunctor(&GetDocument()->GetDiffContext(), GetDocument()->GetReadOnly(0), GetDocument()->GetReadOnly(1), actionScript));
+ // Now we prompt, and execute actions
+ ConfirmAndPerformActions(actionScript);
+ } catch (ContentsChangedException& e) {
+ WarnContentsChanged(e.m_failpath);
+ }
+}
+
+/**
+ * @brief Copy selected left-side files to user-specified directory
+ *
+ * When copying files from recursive compare file subdirectory is also
+ * read so directory structure is preserved.
+ */
+void CDirView::DoCopyLeftTo()
+{
+ DoDirActionTo<CopyLeftToFunctor>(_("Copying files..."), _("Left side - select destination folder:"));
+}
+
+/**
+ * @brief Copy selected righ-side files to user-specified directory
+ *
+ * When copying files from recursive compare file subdirectory is also
+ * read so directory structure is preserved.
+ */
+void CDirView::DoCopyRightTo()
+{
+ DoDirActionTo<CopyRightToFunctor>(_("Copying files..."), _("Right side - select destination folder:"));
+}
+
+/**
+ * @brief Move selected left-side files to user-specified directory
+ *
+ * When moving files from recursive compare file subdirectory is also
+ * read so directory structure is preserved.
+ */
+void CDirView::DoMoveLeftTo()
+{
+ DoDirActionTo<MoveLeftToFunctor>(_("Moving files..."), _("Left side - select destination folder:"));
+}
+
+/**
+ * @brief Move selected right-side files to user-specified directory
+ *
+ * When moving files from recursive compare file subdirectory is also
+ * read so directory structure is preserved.
+ */
+void CDirView::DoMoveRightTo()
+{
+ DoDirActionTo<MoveRightToFunctor>(_("Moving files..."), _("Right side - select destination folder:"));
}
// Confirm with user, then perform the action list
}
/// is it possible to copy item to left ?
-bool CDirView::IsItemCopyableToLeft(const DIFFITEM & di) const
+bool IsItemCopyableToLeft(const DIFFITEM & di)
{
// don't let them mess with error items
if (di.diffcode.isResultError()) return false;
return true;
}
/// is it possible to copy item to right ?
-bool CDirView::IsItemCopyableToRight(const DIFFITEM & di) const
+bool IsItemCopyableToRight(const DIFFITEM & di)
{
// don't let them mess with error items
if (di.diffcode.isResultError()) return false;
return true;
}
/// is it possible to delete left item ?
-bool CDirView::IsItemDeletableOnLeft(const DIFFITEM & di) const
+bool IsItemDeletableOnLeft(const DIFFITEM & di)
{
// don't let them mess with error items
if (di.diffcode.isResultError()) return false;
return true;
}
/// is it possible to delete right item ?
-bool CDirView::IsItemDeletableOnRight(const DIFFITEM & di) const
+bool IsItemDeletableOnRight(const DIFFITEM & di)
{
// don't let them mess with error items
if (di.diffcode.isResultError()) return false;
return true;
}
/// is it possible to delete both items ?
-bool CDirView::IsItemDeletableOnBoth(const DIFFITEM & di) const
+bool IsItemDeletableOnBoth(const DIFFITEM & di)
{
// don't let them mess with error items
if (di.diffcode.isResultError()) return false;
* @param [in] di DIFFITEM for item to check.
* @return true if the item can be opened, false otherwise.
*/
-bool CDirView::IsItemOpenable(const DIFFITEM & di) const
+bool IsItemOpenable(const CDiffContext *pctx, const DIFFITEM & di, bool treemode)
{
- if (m_bTreeMode && GetDocument()->GetRecursive())
+ if (treemode && pctx->m_bRecursive)
{
if (di.diffcode.isDirectory() ||
(!di.diffcode.isExistsFirst() || !di.diffcode.isExistsSecond())) /* FIXME: 3-pane */
return false;
}
/// is it possible to compare these three items?
-bool CDirView::AreItemsOpenable(const DIFFITEM & di1, const DIFFITEM & di2, const DIFFITEM & di3) const
+bool AreItemsOpenable(const CDiffContext *pctxt, const DIFFITEM & di1, const DIFFITEM & di2, const DIFFITEM & di3)
{
- String sLeftBasePath = GetDocument()->GetBasePath(0);
- String sMiddleBasePath = GetDocument()->GetBasePath(1);
- String sRightBasePath = GetDocument()->GetBasePath(2);
+ String sLeftBasePath = pctxt->GetPath(0);
+ String sMiddleBasePath = pctxt->GetPath(1);
+ String sRightBasePath = pctxt->GetPath(2);
String sLeftPath1 = paths_ConcatPath(di1.getFilepath(0, sLeftBasePath), di1.diffFileInfo[0].filename);
String sLeftPath2 = paths_ConcatPath(di2.getFilepath(0, sLeftBasePath), di2.diffFileInfo[0].filename);
String sLeftPath3 = paths_ConcatPath(di3.getFilepath(0, sLeftBasePath), di3.diffFileInfo[0].filename);
return false;
}
/// is it possible to open left item ?
-bool CDirView::IsItemOpenableOnLeft(const DIFFITEM & di) const
+bool IsItemOpenableOnLeft(const DIFFITEM & di)
{
// impossible if only on right
if (di.diffcode.isSideSecondOnly()) return false;
return true;
}
/// is it possible to open right item ?
-bool CDirView::IsItemOpenableOnRight(const DIFFITEM & di) const
+bool IsItemOpenableOnRight(const DIFFITEM & di)
{
// impossible if only on left
if (di.diffcode.isSideFirstOnly()) return false;
return true;
}
/// is it possible to open left ... item ?
-bool CDirView::IsItemOpenableOnLeftWith(const DIFFITEM & di) const
+bool IsItemOpenableOnLeftWith(const DIFFITEM & di)
{
return (!di.diffcode.isDirectory() && IsItemOpenableOnLeft(di));
}
/// is it possible to open with ... right item ?
-bool CDirView::IsItemOpenableOnRightWith(const DIFFITEM & di) const
+bool IsItemOpenableOnRightWith(const DIFFITEM & di)
{
return (!di.diffcode.isDirectory() && IsItemOpenableOnRight(di));
}
/// is it possible to copy to... left item?
-bool CDirView::IsItemCopyableToOnLeft(const DIFFITEM & di) const
+bool IsItemCopyableToOnLeft(const DIFFITEM & di)
{
// impossible if only on right
if (di.diffcode.isSideSecondOnly()) return false;
return true;
}
/// is it possible to copy to... right item?
-bool CDirView::IsItemCopyableToOnRight(const DIFFITEM & di) const
+bool IsItemCopyableToOnRight(const DIFFITEM & di)
{
// impossible if only on left
if (di.diffcode.isSideFirstOnly()) return false;
* @brief Get the file names on both sides for specified item.
* @note Return empty strings if item is special item.
*/
+void GetItemFileNames(const CDiffContext* pctx, const DIFFITEM & di, String& strLeft, String& strRight)
+{
+ const String leftrelpath = paths_ConcatPath(di.diffFileInfo[0].path, di.diffFileInfo[0].filename);
+ const String rightrelpath = paths_ConcatPath(di.diffFileInfo[1].path, di.diffFileInfo[1].filename);
+ const String & leftpath = pctx->GetPath(0);
+ const String & rightpath = pctx->GetPath(1);
+ strLeft = paths_ConcatPath(leftpath, leftrelpath);
+ strRight = paths_ConcatPath(rightpath, rightrelpath);
+}
+
+/**
+ * @brief Get the file names on both sides for specified item.
+ * @note Return empty strings if item is special item.
+ */
void CDirView::GetItemFileNames(int sel, String& strLeft, String& strRight) const
{
UINT_PTR diffpos = GetItemKey(sel);
}
else
{
- const DIFFITEM & di = GetDocument()->GetDiffByKey(diffpos);
- const String leftrelpath = paths_ConcatPath(di.diffFileInfo[0].path, di.diffFileInfo[0].filename);
- const String rightrelpath = paths_ConcatPath(di.diffFileInfo[1].path, di.diffFileInfo[1].filename);
- const String & leftpath = GetDocument()->GetBasePath(0);
- const String & rightpath = GetDocument()->GetBasePath(1);
- strLeft = paths_ConcatPath(leftpath, leftrelpath);
- strRight = paths_ConcatPath(rightpath, rightrelpath);
+ ::GetItemFileNames(&GetDocument()->GetDiffContext(), GetDocument()->GetDiffByKey(diffpos), strLeft, strRight);
+ }
+}
+
+void GetItemFileNames(const CDiffContext *pctxt, const DIFFITEM & di, PathContext * paths)
+{
+ for (int nIndex = 0; nIndex < pctxt->GetCompareDirs(); nIndex++)
+ {
+ const String relpath = paths_ConcatPath(di.diffFileInfo[nIndex].path, di.diffFileInfo[nIndex].filename);
+ const String & path = pctxt->GetPath(nIndex);
+ paths->SetPath(nIndex, paths_ConcatPath(path, relpath));
}
}
}
else
{
- const DIFFITEM & di = GetDocument()->GetDiffByKey(diffpos);
- for (int nIndex = 0; nIndex < GetDocument()->m_nDirs; nIndex++)
- {
- const String relpath = paths_ConcatPath(di.diffFileInfo[nIndex].path, di.diffFileInfo[nIndex].filename);
- const String & path = GetDocument()->GetBasePath(nIndex);
- paths->SetPath(nIndex, paths_ConcatPath(path, relpath));
- }
+ ::GetItemFileNames(&GetDocument()->GetDiffContext(), GetDocument()->GetDiffByKey(diffpos), paths);
}
}
if (!di.diffcode.isDirectory() && !di.diffcode.isSideFirstOnly() &&
!di.diffcode.isSideSecondOnly())
{
- GetItemFileNames(sel, slFile, srFile);
+ ::GetItemFileNames(&GetDocument()->GetDiffContext(), di, slFile, srFile);
String filteredFilenames = slFile + _T("|") + srFile;
GetDocument()->SetPluginPrediffSetting(filteredFilenames, newsetting);
}
int nSelItem = m_pList->GetNextItem(-1, LVNI_SELECTED);
ASSERT(-1 != nSelItem);
- GetItemFileNames(nSelItem, &paths);
// We must check that paths still exists
String failpath;
DIFFITEM &di = GetDiffItemRef(nSelItem);
+ ::GetItemFileNames(&GetDocument()->GetDiffContext(), di, &paths);
bool succeed = CheckPathsExist(paths.GetLeft(), paths.GetRight(),
di.diffcode.isExistsFirst() ? ALLOW_FILE | ALLOW_FOLDER : ALLOW_DONT_CARE,
di.diffcode.isExistsSecond() ? ALLOW_FILE | ALLOW_FOLDER : ALLOW_DONT_CARE,