1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997 Dean P. Grimm
4 // SPDX-License-Identifier: GPL-2.0-or-later
5 /////////////////////////////////////////////////////////////////////////////
9 * @brief Declaration of class CDirView
13 /////////////////////////////////////////////////////////////////////////////
18 #include "OptionsDirColors.h"
19 #include "SortHeaderCtrl.h"
20 #include "UnicodeString.h"
21 #include "DirItemIterator.h"
22 #include "DirActions.h"
24 class FileActionScript;
26 typedef enum { eMain, eContext } eMenuType;
33 class DirCompProgressBar;
36 class CLoadSaveCodepageDlg;
37 class CShellContextMenu;
39 class DirViewColItems;
40 class DirItemEnumerator;
44 * @brief Position value for special items (..) in directory compare view.
46 const uintptr_t SPECIAL_ITEM_POS = (uintptr_t)(reinterpret_cast<DIFFITEM *>( - 1L));
48 /** Default column width in directory compare */
49 const UINT DefColumnWidth = 111;
52 * @brief Directory compare results view.
54 * Directory compare view is list-view based, so it shows one result (for
55 * folder or file, commonly called as 'item') in one line. User can select
56 * visible columns, re-order columns, sort by column etc.
58 * Actual data is stored in CDiffContext in CDirDoc. Dircompare items and
59 * CDiffContext items are linked by storing POSITION of CDiffContext item
60 * as CDirView listitem key.
62 class CDirView : public CListView
64 friend struct FileCmpReport;
65 friend DirItemEnumerator;
67 CDirView(); // protected constructor used by dynamic creation
68 DECLARE_DYNCREATE(CDirView)
72 CDirDoc* GetDocument(); // non-debug version is inline
73 // const version, for const methods to be able to call
74 const CDirDoc * GetDocument() const { return const_cast<CDirView *>(this)->GetDocument(); }
75 const CDiffContext& GetDiffContext() const;
76 CDiffContext& GetDiffContext();
80 CDirFrame * GetParentFrame();
82 void StartCompare(CompareStats *pCompareStats);
84 void RedisplayChildren(DIFFITEM *diffpos, int level, UINT &index, int &alldiffs);
85 void UpdateResources();
86 void LoadColumnHeaderItems();
87 DIFFITEM *GetItemKey(int idx) const;
88 int GetItemIndex(DIFFITEM *key);
89 // for populating list
90 void DeleteItem(int sel, bool removeDIFFITEM = false);
91 void DeleteAllDisplayItems();
92 void SetFont(const LOGFONT & lf);
94 void SortColumnsAppropriately();
96 UINT GetSelectedCount() const;
97 int GetFirstSelectedInd();
98 void AddParentFolderItem(bool bEnable);
99 void RefreshOptions();
103 void MoveToNextDiff();
104 void MoveToPrevDiff();
107 void OpenFirstFile();
114 void SetActivePane(int pane);
116 // Implementation types
119 // Implementation in DirActions.cpp
121 void GetItemFileNames(int sel, String& strLeft, String& strRight) const;
122 void GetItemFileNames(int sel, PathContext * paths) const;
123 void FormatEncodingDialogDisplays(CLoadSaveCodepageDlg * dlg);
124 DirActions MakeDirActions(DirActions::method_type func) const;
125 DirActions MakeDirActions(DirActions::method_type2 func) const;
126 Counts Count(DirActions::method_type2 func) const;
127 void DoDirAction(DirActions::method_type func, const String& status_message);
128 void DoDirActionTo(SIDE_TYPE stype, DirActions::method_type func, const String& status_message);
129 void DoOpen(SIDE_TYPE stype);
130 void DoOpenWith(SIDE_TYPE stype);
131 void DoOpenWithEditor(SIDE_TYPE stype);
132 void DoOpenParentFolder(SIDE_TYPE stype);
133 void DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI, bool openableForDir = true);
134 void ConfirmAndPerformActions(FileActionScript & actions);
135 void PerformActionList(FileActionScript & actions);
136 void UpdateAfterFileScript(FileActionScript & actionList);
137 void DoFileEncodingDialog();
139 // End DirActions.cpp
140 void ReflectGetdispinfo(NMLVDISPINFO *);
142 // Implementation in DirViewColHandler.cpp
144 void UpdateColumnNames();
145 void SetColAlignments();
146 // class CompareState is used to pass parameters to the PFNLVCOMPARE callback function.
150 const DirViewColItems *const pColItems;
151 const CDiffContext *const pCtxt;
153 const bool bSortAscending;
154 const bool bTreeMode;
156 CompareState(const CDiffContext *pCtxt, const DirViewColItems *pColItems, int sortCol, bool bSortAscending, bool bTreeMode);
157 static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
159 void UpdateDiffItemStatus(UINT nIdx);
162 void NameColumn(const DirColInfo *col, int subitem);
163 int AddNewItem(int i, DIFFITEM *diffpos, int iImage, int iIndent);
164 // End DirViewCols.cpp
169 // ClassWizard generated virtual function overrides
170 //{{AFX_VIRTUAL(CDirView)
172 virtual void OnInitialUpdate();
173 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
175 virtual BOOL PreTranslateMessage(MSG* pMsg);
176 virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
177 virtual BOOL OnChildNotify(UINT, WPARAM, LPARAM, LRESULT*);
178 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
184 int GetFocusedItem();
185 int GetFirstDifferentItem();
186 int GetLastDifferentItem();
187 int AddSpecialItems();
188 std::vector<String> GetCurrentColRegKeys();
189 void OpenSpecialItems(DIFFITEM *pos1, DIFFITEM *pos2, DIFFITEM *pos3);
191 // Implementation data
193 CSortHeaderCtrl m_ctlSortHeader;
194 CImageList m_imageList;
195 CImageList m_imageState;
197 std::unique_ptr<IListCtrl> m_pIList;
198 int m_nEscCloses; /**< Cached value for option for ESC closing window */
199 bool m_bExpandSubdirs;
200 CFont m_font; /**< User-selected font */
201 UINT m_nHiddenItems; /**< Count of items we have hidden */
202 bool m_bTreeMode; /**< `true` if tree mode is on*/
203 DirViewFilterSettings m_dirfilter;
204 std::unique_ptr<DirCompProgressBar> m_pCmpProgressBar;
205 clock_t m_compareStart; /**< Starting process time of the compare */
206 bool m_bUserCancelEdit; /**< `true` if the user cancels rename */
207 String m_lastCopyFolder; /**< Last Copy To -target folder. */
209 std::optional<int> m_firstDiffItem;
210 std::optional<int> m_lastDiffItem;
211 DIRCOLORSETTINGS m_cachedColors; /**< Cached color settings */
214 std::unique_ptr<CShellContextMenu> m_pShellContextMenuLeft; /**< Shell context menu for group of left files */
215 std::unique_ptr<CShellContextMenu> m_pShellContextMenuMiddle; /**< Shell context menu for group of middle files */
216 std::unique_ptr<CShellContextMenu> m_pShellContextMenuRight; /**< Shell context menu for group of right files */
217 HMENU m_hCurrentMenu; /**< Current shell context menu (either left or right) */
218 std::unique_ptr<DirViewTreeState> m_pSavedTreeState;
219 std::unique_ptr<DirViewColItems> m_pColItems;
222 // Generated message map functions
223 afx_msg void OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult);
224 afx_msg void OnContextMenu(CWnd*, CPoint point);
225 //{{AFX_MSG(CDirView)
226 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
227 afx_msg void OnDirCopy(UINT id);
228 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
229 afx_msg void OnCtxtDirCopy();
230 afx_msg void OnUpdateDirCopy(CCmdUI* pCmdUI);
231 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
232 afx_msg void OnUpdateCtxtDirCopy(CCmdUI* pCmdUI);
233 template<SIDE_TYPE stype>
234 afx_msg void OnCtxtDirDel();
235 template<SIDE_TYPE stype>
236 afx_msg void OnUpdateCtxtDirDel(CCmdUI* pCmdUI);
237 afx_msg void OnCtxtDirDelBoth();
238 afx_msg void OnUpdateCtxtDirDelBoth(CCmdUI* pCmdUI);
239 template<SIDE_TYPE stype>
240 afx_msg void OnCtxtDirOpen();
241 template<SIDE_TYPE stype>
242 afx_msg void OnUpdateCtxtDirOpen(CCmdUI* pCmdUI);
243 template<SIDE_TYPE stype>
244 afx_msg void OnCtxtDirOpenWith();
245 template<SIDE_TYPE stype>
246 afx_msg void OnUpdateCtxtDirOpenWith(CCmdUI* pCmdUI);
247 template<SIDE_TYPE stype>
248 afx_msg void OnCtxtDirOpenWithEditor();
249 template<SIDE_TYPE stype>
250 afx_msg void OnUpdateCtxtDirOpenWithEditor(CCmdUI* pCmdUI);
251 template<SIDE_TYPE stype>
252 afx_msg void OnCtxtDirOpenParentFolder();
253 template<SIDE_TYPE stype>
254 afx_msg void OnUpdateCtxtDirOpenParentFolder(CCmdUI* pCmdUI);
255 template<SIDE_TYPE stype>
256 afx_msg void OnCtxtDirCopyTo();
257 template<SIDE_TYPE stype>
258 afx_msg void OnUpdateCtxtDirCopyTo(CCmdUI* pCmdUI);
259 afx_msg void OnUpdateCtxtDirCopyBothTo(CCmdUI* pCmdUI);
260 afx_msg void OnUpdateCtxtDirCopyBothDiffsOnlyTo(CCmdUI* pCmdUI);
261 template<SIDE_TYPE stype>
262 afx_msg void OnUpdateCtxtDirCopy2(CCmdUI* pCmdUI);
263 afx_msg void OnUpdateCtxtDirCopyBoth2(CCmdUI* pCmdUI);
264 afx_msg void OnDestroy();
265 afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
266 afx_msg void OnClick(NMHDR* pNMHDR, LRESULT* pResult);
267 afx_msg void OnFirstdiff();
268 afx_msg void OnUpdateFirstdiff(CCmdUI* pCmdUI);
269 afx_msg void OnLastdiff();
270 afx_msg void OnUpdateLastdiff(CCmdUI* pCmdUI);
271 afx_msg void OnNextdiff();
272 afx_msg void OnUpdateNextdiff(CCmdUI* pCmdUI);
273 afx_msg void OnPrevdiff();
274 afx_msg void OnUpdatePrevdiff(CCmdUI* pCmdUI);
275 afx_msg void OnCurdiff();
276 afx_msg void OnUpdateCurdiff(CCmdUI* pCmdUI);
277 afx_msg void OnUpdateSave(CCmdUI* pCmdUI);
278 afx_msg LRESULT OnUpdateUIMessage(WPARAM wParam, LPARAM lParam);
279 afx_msg void OnRefresh();
280 afx_msg void OnUpdateRefresh(CCmdUI* pCmdUI);
281 afx_msg void OnTimer(UINT_PTR nIDEvent);
282 afx_msg void OnEditColumns();
283 template<SIDE_TYPE stype>
284 afx_msg void OnReadOnly();
285 template<SIDE_TYPE stype>
286 afx_msg void OnUpdateReadOnly(CCmdUI* pCmdUI);
287 afx_msg void OnUpdateStatusLeftRO(CCmdUI* pCmdUI);
288 afx_msg void OnUpdateStatusMiddleRO(CCmdUI* pCmdUI);
289 afx_msg void OnUpdateStatusRightRO(CCmdUI* pCmdUI);
290 afx_msg void OnCustomizeColumns();
291 afx_msg void OnCtxtOpenWithUnpacker();
292 afx_msg void OnUpdateCtxtOpenWithUnpacker(CCmdUI* pCmdUI);
293 afx_msg void OnToolsGenerateReport();
294 afx_msg LRESULT OnGenerateFileCmpReport(WPARAM wParam, LPARAM lParam);
295 afx_msg void OnToolsGeneratePatch();
297 afx_msg void OnCtxtDirZip();
298 template<SIDE_TYPE stype>
299 afx_msg void OnCtxtDirShellContextMenu();
300 afx_msg void OnSelectAll();
301 afx_msg void OnUpdateSelectAll(CCmdUI* pCmdUI);
302 afx_msg void OnPluginPredifferMode(UINT nID);
303 afx_msg void OnUpdatePluginPredifferMode(CCmdUI* pCmdUI);
304 template<SIDE_TYPE side>
305 afx_msg void OnCopyPathnames();
306 afx_msg void OnCopyBothPathnames();
307 afx_msg void OnCopyFilenames();
308 afx_msg void OnUpdateCopyFilenames(CCmdUI* pCmdUI);
309 template<SIDE_TYPE side>
310 afx_msg void OnCopyToClipboard();
311 afx_msg void OnCopyBothToClipboard();
312 afx_msg void OnItemRename();
313 afx_msg void OnUpdateItemRename(CCmdUI* pCmdUI);
314 afx_msg void OnHideFilenames();
315 afx_msg void OnSize(UINT nType, int cx, int cy);
316 template<SIDE_TYPE stype>
317 afx_msg void OnCtxtDirMoveTo();
318 template<SIDE_TYPE stype>
319 afx_msg void OnUpdateCtxtDirMoveTo(CCmdUI* pCmdUI);
320 afx_msg void OnUpdateHideFilenames(CCmdUI* pCmdUI);
321 afx_msg void OnDelete();
322 afx_msg void OnUpdateDelete(CCmdUI* pCmdUI);
323 afx_msg void OnMarkedRescan();
324 afx_msg void OnUpdateStatusNum(CCmdUI* pCmdUI);
325 afx_msg void OnViewShowHiddenItems();
326 afx_msg void OnUpdateViewShowHiddenItems(CCmdUI* pCmdUI);
327 afx_msg void OnViewTreeMode();
328 afx_msg void OnUpdateViewTreeMode(CCmdUI* pCmdUI);
329 afx_msg void OnViewExpandAllSubdirs();
330 afx_msg void OnUpdateViewExpandAllSubdirs(CCmdUI* pCmdUI);
331 afx_msg void OnViewCollapseAllSubdirs();
332 afx_msg void OnUpdateViewCollapseAllSubdirs(CCmdUI* pCmdUI);
333 template <int pane1, int pane2>
334 afx_msg void OnViewSwapPanes();
335 template <int pane1, int pane2>
336 afx_msg void OnUpdateViewSwapPanes(CCmdUI* pCmdUI);
337 afx_msg void OnOptionsShowDifferent();
338 afx_msg void OnOptionsShowIdentical();
339 afx_msg void OnOptionsShowUniqueLeft();
340 afx_msg void OnOptionsShowUniqueMiddle();
341 afx_msg void OnOptionsShowUniqueRight();
342 afx_msg void OnOptionsShowBinaries();
343 afx_msg void OnOptionsShowSkipped();
344 afx_msg void OnOptionsShowDifferentLeftOnly();
345 afx_msg void OnOptionsShowDifferentMiddleOnly();
346 afx_msg void OnOptionsShowDifferentRightOnly();
347 afx_msg void OnOptionsShowMissingLeftOnly();
348 afx_msg void OnOptionsShowMissingMiddleOnly();
349 afx_msg void OnOptionsShowMissingRightOnly();
350 afx_msg void OnUpdateOptionsShowdifferent(CCmdUI* pCmdUI);
351 afx_msg void OnUpdateOptionsShowidentical(CCmdUI* pCmdUI);
352 afx_msg void OnUpdateOptionsShowuniqueleft(CCmdUI* pCmdUI);
353 afx_msg void OnUpdateOptionsShowuniquemiddle(CCmdUI* pCmdUI);
354 afx_msg void OnUpdateOptionsShowuniqueright(CCmdUI* pCmdUI);
355 afx_msg void OnUpdateOptionsShowBinaries(CCmdUI* pCmdUI);
356 afx_msg void OnUpdateOptionsShowSkipped(CCmdUI* pCmdUI);
357 afx_msg void OnUpdateOptionsShowDifferentLeftOnly(CCmdUI* pCmdUI);
358 afx_msg void OnUpdateOptionsShowDifferentMiddleOnly(CCmdUI* pCmdUI);
359 afx_msg void OnUpdateOptionsShowDifferentRightOnly(CCmdUI* pCmdUI);
360 afx_msg void OnUpdateOptionsShowMissingLeftOnly(CCmdUI* pCmdUI);
361 afx_msg void OnUpdateOptionsShowMissingMiddleOnly(CCmdUI* pCmdUI);
362 afx_msg void OnUpdateOptionsShowMissingRightOnly(CCmdUI* pCmdUI);
363 afx_msg void OnMergeCompare();
364 template<SELECTIONTYPE seltype>
365 afx_msg void OnMergeCompare2();
366 afx_msg void OnMergeCompareNonHorizontally();
367 afx_msg void OnMergeCompareXML();
368 afx_msg void OnMergeCompareAs(UINT nID);
369 afx_msg void OnUpdateMergeCompare(CCmdUI *pCmdUI);
370 template<SELECTIONTYPE seltype>
371 afx_msg void OnUpdateMergeCompare2(CCmdUI *pCmdUI);
372 afx_msg void OnViewCompareStatistics();
373 afx_msg void OnFileEncoding();
374 afx_msg void OnHelp();
375 afx_msg void OnEditCopy();
376 afx_msg void OnEditCut();
377 afx_msg void OnEditPaste();
378 afx_msg void OnEditUndo();
379 afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
380 afx_msg void OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult);
381 afx_msg void OnBeginLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
382 afx_msg void OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
383 afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
384 afx_msg void OnSearch();
385 afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
386 afx_msg void OnBnClickedComparisonStop();
387 afx_msg void OnBnClickedComparisonPause();
388 afx_msg void OnBnClickedComparisonContinue();
390 DECLARE_MESSAGE_MAP()
391 bool OnHeaderBeginDrag(LPNMHEADER hdr, LRESULT* pResult);
392 bool OnHeaderEndDrag(LPNMHEADER hdr, LRESULT* pResult);
395 void Open(const PathContext& paths, DWORD dwFlags[3], FileTextEncoding encoding[3], PackingInfo * infoUnpacker = nullptr);
396 void OpenSelection(SELECTIONTYPE selectionType = SELECTIONTYPE_NORMAL, PackingInfo * infoUnpacker = nullptr, bool openableForDir = true);
397 void OpenSelectionAs(UINT id);
398 bool GetSelectedItems(int * sel1, int * sel2, int * sel3);
399 void OpenParentDirectory();
400 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
401 void DoUpdateDirCopy(CCmdUI* pCmdUI, eMenuType menuType);
402 const DIFFITEM &GetDiffItem(int sel) const;
403 DIFFITEM &GetDiffItem(int sel);
404 int GetSingleSelectedItem() const;
405 void MoveFocus(int currentInd, int i, int selCount);
407 void FixReordering();
408 void HeaderContextMenu(CPoint point, int i);
409 void ListContextMenu(CPoint point, int i);
410 bool ListShellContextMenu(SIDE_TYPE side);
411 void ShowShellContextMenu(SIDE_TYPE side);
412 CShellContextMenu* GetCorrespondingShellContextMenu(HMENU hMenu) const;
413 void ReloadColumns();
414 bool IsLabelEdit() const;
415 void CollapseSubdir(int sel);
416 void ExpandSubdir(int sel, bool bRecursive = false);
417 void GetColors(int nRow, int nCol, COLORREF& clrBk, COLORREF& clrText) const;
418 int GetDefColumnWidth() const { return MulDiv(DefColumnWidth, CClientDC(const_cast<CDirView *>(this)).GetDeviceCaps(LOGPIXELSX), 72); };
421 DirItemIterator Begin() const { return DirItemIterator(m_pIList.get()); }
422 DirItemIterator End() const { return DirItemIterator(); }
423 DirItemIterator RevBegin() const { return DirItemIterator(m_pIList.get(), -1, false, true); }
424 DirItemIterator RevEnd() const { return DirItemIterator(); }
425 DirItemIterator SelBegin() const { return DirItemIterator(m_pIList.get(), -1, true); }
426 DirItemIterator SelEnd() const { return DirItemIterator(); }
427 DirItemIterator SelRevBegin() const { return DirItemIterator(m_pIList.get(), -1, true, true); }
428 DirItemIterator SelRevEnd() const { return DirItemIterator(); }
431 #ifndef _DEBUG // debug version in DirView.cpp
432 inline CDirDoc* CDirView::GetDocument()
433 { return reinterpret_cast<CDirDoc*>(m_pDocument); }