Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Jan 21, 2025
1 parent 4e26a0e commit fc26d29
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Src/DirActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ struct DirActions
const int dstidx = SideToIndex(m_ctxt, dst);
if (di.diffcode.diffcode != 0 && !m_RO[dstidx] && IsItemCopyable(di, srcidx, copyOnlyDiffItems))
{
if (copyOnlyDiffItems && it.second->HasChildren())
if (it.second->HasChildren())
{
for (DIFFITEM* pdic = di.GetFirstChild(); pdic; pdic = pdic->GetFwdSiblingLink())
CopyItem(pscript, { it.first, pdic }, copyOnlyDiffItems, src, dst);
Expand Down
2 changes: 2 additions & 0 deletions Src/DirView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ void CDirView::DoDirAction(DirActions::method_type func, const String& status_me
FileActionScript *rsltScript;
rsltScript = std::accumulate(begin, end, &actionScript, MakeDirActions(func));
ASSERT(rsltScript == &actionScript);
actionScript.RemoveDuplicates();
// Now we prompt, and execute actions
ConfirmAndPerformActions(actionScript);
} catch (ContentsChangedException& e) {
Expand Down Expand Up @@ -988,6 +989,7 @@ void CDirView::DoDirActionTo(SIDE_TYPE stype, DirActions::method_type func, cons
FileActionScript *rsltScript;
rsltScript = std::accumulate(begin, end, &actionScript, MakeDirActions(func));
ASSERT(rsltScript == &actionScript);
actionScript.RemoveDuplicates();
// Now we prompt, and execute actions
ConfirmAndPerformActions(actionScript);
} catch (ContentsChangedException& e) {
Expand Down
1 change: 1 addition & 0 deletions Src/DirView.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class CDirView : public CListView
void DoOpenWithEditor(SIDE_TYPE stype);
void DoOpenParentFolder(SIDE_TYPE stype);
void DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI, bool openableForDir = true);
void RemoveDuplicatedActions(FileActionScript & actions);
void ConfirmAndPerformActions(FileActionScript & actions);
void PerformActionList(FileActionScript & actions);
void UpdateAfterFileScript(FileActionScript & actionList);
Expand Down
18 changes: 18 additions & 0 deletions Src/FileActionScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ FileActionItem FileActionScript::RemoveTailActionItem()
return item;
}

/**
* @brief Removes duplicate entries from a vector of FileActionItem objects.
*/
void FileActionScript::RemoveDuplicates()
{
auto compare = [](const FileActionItem& a, const FileActionItem& b) {
return std::tie(a.src, a.dest, a.atype) < std::tie(b.src, b.dest, b.atype);
};

auto equal = [](const FileActionItem& a, const FileActionItem& b) {
return std::tie(a.src, a.dest, a.atype) == std::tie(b.src, b.dest, b.atype);
};

std::sort(m_actions.begin(), m_actions.end(), compare);

m_actions.erase(std::unique(m_actions.begin(), m_actions.end(), equal), m_actions.end());
}

/**
* @brief Create ShellFileOperations operation lists from our scripts.
*
Expand Down
1 change: 1 addition & 0 deletions Src/FileActionScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class FileActionScript
void AddActionItem(FileActionItem & item) { m_actions.push_back(item); }

FileActionItem RemoveTailActionItem();
void RemoveDuplicates();

/**
* Get first action item in the list.
Expand Down

0 comments on commit fc26d29

Please sign in to comment.