OSDN Git Service

Fix an issue where the folder column is not updated for child items after renaming...
authorJun Tajima <56220423+tjmprm77@users.noreply.github.com>
Mon, 18 Jul 2022 13:21:40 +0000 (22:21 +0900)
committerGitHub <noreply@github.com>
Mon, 18 Jul 2022 13:21:40 +0000 (22:21 +0900)
- Add a process to update the path of child items after renaming a directory.
- This commit also fixes an issue where file comparisons of child items after renaming a directory would result in empty files comparison instead of the intended files comparison.

Src/DirActions.cpp
Src/DirActions.h
Src/DirView.cpp

index 72e5725..190c019 100644 (file)
@@ -1100,6 +1100,26 @@ void UpdateStatusFromDisk(CDiffContext& ctxt, DIFFITEM& di, int index)
        }
 }
 
+/**
+ * @brief Update the paths of the diff items recursively.
+ * @param[in] nDirs Number of directories to compare.
+ * @param[in,out] di\81@Item to update the path.
+ */
+void UpdatePaths(int nDirs, DIFFITEM& di)
+{
+       assert(nDirs == 2 || nDirs == 3);
+
+       if (di.HasChildren())
+       {
+               for (DIFFITEM* pdic = di.GetFirstChild(); pdic; pdic = pdic->GetFwdSiblingLink())
+               {
+                       for (int i = 0; i < nDirs; i++)
+                               pdic->diffFileInfo[i].path = paths::ConcatPath(di.diffFileInfo[i].path, di.diffFileInfo[i].filename);
+                       UpdatePaths(nDirs, *pdic);
+               }
+       }
+}
+
 void SetDiffCounts(DIFFITEM& di, unsigned diffs, unsigned ignored)
 {
        di.nidiffs = ignored; // see StoreDiffResult() in DirScan.cpp
index 5ea4cbd..e2c13dc 100644 (file)
@@ -168,6 +168,7 @@ void SetDiffCompare(DIFFITEM& di, unsigned diffcode);
 void CopyDiffSideAndProperties(DIFFITEM& di, int src, int dst);
 void UnsetDiffSide(DIFFITEM& di, int index);
 void UpdateStatusFromDisk(CDiffContext& ctxt, DIFFITEM& di, int index);
+void UpdatePaths(int nDirs, DIFFITEM& di);
 void SetDiffCounts(DIFFITEM& di, unsigned diffs, unsigned ignored);
 void SetItemViewFlag(DIFFITEM& di, unsigned flag, unsigned mask);
 void SetItemViewFlag(CDiffContext& ctxt, unsigned flag, unsigned mask);
index 0db7849..06a36e7 100644 (file)
@@ -3473,26 +3473,37 @@ afx_msg void CDirView::OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult)
                                unsigned sideFlags = (di.diffcode.diffcode & DIFFCODE::SIDEFLAGS);
                                *pResult = DoItemRename(it, GetDiffContext(), String(sText));
                                // Rescan the item if side flags change due to renaming.
-                               if (*pResult && ((di.diffcode.diffcode & DIFFCODE::SIDEFLAGS) != sideFlags))
+                               if (*pResult)
                                {
-                                       // Delete the item with the same file name as after renaming.
-                                       if (di.HasParent())
+                                       if ((di.diffcode.diffcode & DIFFCODE::SIDEFLAGS) != sideFlags)
                                        {
-                                               for (DIFFITEM* pItem = di.GetParentLink()->GetFirstChild(); pItem != nullptr; pItem = pItem->GetFwdSiblingLink())
+                                               // Delete the item with the same file name as after renaming.
+                                               if (di.HasParent())
                                                {
-                                                       if ((pItem != &di) && (pItem->diffcode.isDirectory() == di.diffcode.isDirectory()) && (collstr(pItem->diffFileInfo[0].filename, di.diffFileInfo[0].filename, false) == 0))
+                                                       for (DIFFITEM* pItem = di.GetParentLink()->GetFirstChild(); pItem != nullptr; pItem = pItem->GetFwdSiblingLink())
                                                        {
-                                                               pItem->DelinkFromSiblings();
-                                                               delete pItem;
-                                                               break;
+                                                               if ((pItem != &di) && (pItem->diffcode.isDirectory() == di.diffcode.isDirectory()) && (collstr(pItem->diffFileInfo[0].filename, di.diffFileInfo[0].filename, false) == 0))
+                                                               {
+                                                                       pItem->DelinkFromSiblings();
+                                                                       delete pItem;
+                                                                       break;
+                                                               }
                                                        }
                                                }
+                                               // Rescan the item.
+                                               MarkForRescan(di);
+                                               m_pSavedTreeState.reset(SaveTreeState(GetDiffContext()));
+                                               GetDocument()->SetMarkedRescan();
+                                               GetDocument()->Rescan();
+                                       }
+                                       else {
+                                               int nDirs = GetDiffContext().GetCompareDirs();
+                                               assert(nDirs == 2 || nDirs == 3);
+                                               UpdatePaths(nDirs, di);
+
+                                               int nIdx = reinterpret_cast<NMLVDISPINFO*>(pNMHDR)->item.iItem;
+                                               UpdateDiffItemStatus(nIdx);
                                        }
-                                       // Rescan the item.
-                                       MarkForRescan(di);
-                                       m_pSavedTreeState.reset(SaveTreeState(GetDiffContext()));
-                                       GetDocument()->SetMarkedRescan();
-                                       GetDocument()->Rescan();
                                }
                        } catch (ContentsChangedException& e) {
                                AfxMessageBox(e.m_msg.c_str(), MB_ICONWARNING);