OSDN Git Service

Shell Extension for Windows 11 or later (5)
[winmerge-jp/winmerge-jp.git] / Src / DirView.h
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 /////////////////////////////////////////////////////////////////////////////
6 /**
7  *  @file DirView.h
8  *
9  *  @brief Declaration of class CDirView
10  */
11 #pragma once
12
13 /////////////////////////////////////////////////////////////////////////////
14 // CDirView view
15 #include <afxcview.h>
16 #include <memory>
17 #include <optional>
18 #include "OptionsDirColors.h"
19 #include "SortHeaderCtrl.h"
20 #include "UnicodeString.h"
21 #include "DirItemIterator.h"
22 #include "DirActions.h"
23
24 class FileActionScript;
25
26 typedef enum { eMain, eContext } eMenuType;
27
28 class CDirDoc;
29 class CDirFrame;
30
31 class PackingInfo;
32 class PathContext;
33 class DirCompProgressBar;
34 class CompareStats;
35 struct DirColInfo;
36 class CLoadSaveCodepageDlg;
37 class CShellContextMenu;
38 class CDiffContext;
39 class DirViewColItems;
40 class DirItemEnumerator;
41 struct IListCtrl;
42
43 /**
44  * @brief Position value for special items (..) in directory compare view.
45  */
46 const uintptr_t SPECIAL_ITEM_POS = (uintptr_t)(reinterpret_cast<DIFFITEM *>( - 1L));
47
48 /** Default column width in directory compare */
49 const UINT DefColumnWidth = 111;
50
51 /**
52  * @brief Directory compare results view.
53  *
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.
57  *
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.
61  */
62 class CDirView : public CListView
63 {
64         friend struct FileCmpReport;
65         friend DirItemEnumerator;
66 protected:
67         CDirView();           // protected constructor used by dynamic creation
68         DECLARE_DYNCREATE(CDirView)
69
70 // Attributes
71 public:
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();
77
78 // Operations
79 public:
80         CDirFrame * GetParentFrame();
81
82         void StartCompare(CompareStats *pCompareStats);
83         void Redisplay();
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         bool IsDiffItemSpecial(const DIFFITEM* diffpos) const { return diffpos == reinterpret_cast<DIFFITEM*>(SPECIAL_ITEM_POS); };
90         // for populating list
91         void DeleteItem(int sel, bool removeDIFFITEM = false);
92         void DeleteAllDisplayItems();
93         void SetFont(const LOGFONT & lf);
94
95         void SortColumnsAppropriately();
96
97         UINT GetSelectedCount() const;
98         int GetFirstSelectedInd();
99         void AddParentFolderItem(bool bEnable);
100         void RefreshOptions();
101
102         bool HasNextDiff();
103         bool HasPrevDiff();
104         void MoveToNextDiff();
105         void MoveToPrevDiff();
106         void OpenNextDiff();
107         void OpenPrevDiff();
108         void OpenFirstFile();
109         void OpenLastFile();
110         void OpenNextFile();
111         void OpenPrevFile();
112         bool IsFirstFile();
113         bool IsLastFile();
114
115         void SetActivePane(int pane);
116
117 // Implementation types
118 private:
119
120 // Implementation in DirActions.cpp
121 private:
122         void GetItemFileNames(int sel, String& strLeft, String& strRight) const;
123         void GetItemFileNames(int sel, PathContext * paths) const;
124         void FormatEncodingDialogDisplays(CLoadSaveCodepageDlg * dlg);
125         DirActions MakeDirActions(DirActions::method_type func) const;
126         DirActions MakeDirActions(DirActions::method_type2 func) const;
127         Counts Count(DirActions::method_type2 func) const;
128         void DoDirAction(DirActions::method_type func, const String& status_message);
129         void DoDirActionTo(SIDE_TYPE stype, DirActions::method_type func, const String& status_message);
130         void DoOpen(SIDE_TYPE stype);
131         void DoOpenWith(SIDE_TYPE stype);
132         void DoOpenWithEditor(SIDE_TYPE stype);
133         void DoOpenParentFolder(SIDE_TYPE stype);
134         void DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI, bool openableForDir = true);
135         void ConfirmAndPerformActions(FileActionScript & actions);
136         void PerformActionList(FileActionScript & actions);
137         void UpdateAfterFileScript(FileActionScript & actionList);
138         void DoFileEncodingDialog();
139
140 // End DirActions.cpp
141         void ReflectGetdispinfo(NMLVDISPINFO *);
142
143 // Implementation in DirViewColHandler.cpp
144 public:
145         void UpdateColumnNames();
146         void SetColAlignments();
147         // class CompareState is used to pass parameters to the PFNLVCOMPARE callback function.
148         class CompareState
149         {
150         private:
151                 const DirViewColItems *const pColItems;
152                 const CDiffContext *const pCtxt;
153                 const int sortCol;
154                 const bool bSortAscending;
155                 const bool bTreeMode;
156         public:
157                 CompareState(const CDiffContext *pCtxt, const DirViewColItems *pColItems, int sortCol, bool bSortAscending, bool bTreeMode);
158                 static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
159         } friend;
160         void UpdateDiffItemStatus(UINT nIdx);
161 private:
162         void InitiateSort();
163         void NameColumn(const DirColInfo *col, int subitem);
164         int AddNewItem(int i, DIFFITEM *diffpos, int iImage, int iIndent);
165 // End DirViewCols.cpp
166
167 private:
168
169 // Overrides
170         // ClassWizard generated virtual function overrides
171         //{{AFX_VIRTUAL(CDirView)
172 public:
173         virtual void OnInitialUpdate();
174         virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
175 protected:
176         virtual BOOL PreTranslateMessage(MSG* pMsg);
177         virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
178         virtual BOOL OnChildNotify(UINT, WPARAM, LPARAM, LRESULT*);
179         virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
180         //}}AFX_VIRTUAL
181
182 // Implementation
183 protected:
184         virtual ~CDirView();
185         int GetFocusedItem();
186         int GetFirstDifferentItem();
187         int GetLastDifferentItem();
188         int AddSpecialItems();
189         std::vector<String>     GetCurrentColRegKeys();
190         void OpenSpecialItems(CDirDoc *pDoc, DIFFITEM *pos1, DIFFITEM *pos2, DIFFITEM *pos3);
191
192 // Implementation data
193 protected:
194         CSortHeaderCtrl m_ctlSortHeader;
195         CImageList m_imageList;
196         CImageList m_imageState;
197         CListCtrl* m_pList;
198         std::unique_ptr<IListCtrl> m_pIList;
199         int m_nEscCloses; /**< Cached value for option for ESC closing window */
200         bool m_bExpandSubdirs;
201         CFont m_font; /**< User-selected font */
202         UINT m_nHiddenItems; /**< Count of items we have hidden */
203         bool m_bTreeMode; /**< `true` if tree mode is on*/
204         DirViewFilterSettings m_dirfilter;
205         std::unique_ptr<DirCompProgressBar> m_pCmpProgressBar;
206         clock_t m_compareStart; /**< Starting process time of the compare */
207         bool m_bUserCancelEdit; /**< `true` if the user cancels rename */
208         String m_lastCopyFolder; /**< Last Copy To -target folder. */
209
210         std::optional<int> m_firstDiffItem;
211         std::optional<int> m_lastDiffItem;
212         DIRCOLORSETTINGS m_cachedColors; /**< Cached color settings */
213         bool m_bUseColors;
214
215         std::unique_ptr<CShellContextMenu> m_pShellContextMenuLeft; /**< Shell context menu for group of left files */
216         std::unique_ptr<CShellContextMenu> m_pShellContextMenuMiddle; /**< Shell context menu for group of middle files */
217         std::unique_ptr<CShellContextMenu> m_pShellContextMenuRight; /**< Shell context menu for group of right files */
218         HMENU m_hCurrentMenu; /**< Current shell context menu (either left or right) */
219         std::unique_ptr<DirViewTreeState> m_pSavedTreeState;
220         std::unique_ptr<DirViewColItems> m_pColItems;
221         int m_nActivePane;
222
223         // Generated message map functions
224         afx_msg void OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult);
225         afx_msg void OnContextMenu(CWnd*, CPoint point);
226         //{{AFX_MSG(CDirView)
227         afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
228         afx_msg void OnDirCopy(UINT id);
229         template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
230         afx_msg void OnCtxtDirCopy();
231         afx_msg void OnUpdateDirCopy(CCmdUI* pCmdUI);
232         template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
233         afx_msg void OnUpdateCtxtDirCopy(CCmdUI* pCmdUI);
234         template<SIDE_TYPE stype>
235         afx_msg void OnCtxtDirDel();
236         template<SIDE_TYPE stype>
237         afx_msg void OnUpdateCtxtDirDel(CCmdUI* pCmdUI);
238         afx_msg void OnCtxtDirDelBoth();
239         afx_msg void OnUpdateCtxtDirDelBoth(CCmdUI* pCmdUI);
240         template<SIDE_TYPE stype>
241         afx_msg void OnCtxtDirOpen();
242         template<SIDE_TYPE stype>
243         afx_msg void OnUpdateCtxtDirOpen(CCmdUI* pCmdUI);
244         template<SIDE_TYPE stype>
245         afx_msg void OnCtxtDirOpenWith();
246         template<SIDE_TYPE stype>
247         afx_msg void OnUpdateCtxtDirOpenWith(CCmdUI* pCmdUI);
248         template<SIDE_TYPE stype>
249         afx_msg void OnCtxtDirOpenWithEditor();
250         template<SIDE_TYPE stype>
251         afx_msg void OnUpdateCtxtDirOpenWithEditor(CCmdUI* pCmdUI);
252         template<SIDE_TYPE stype>
253         afx_msg void OnCtxtDirOpenParentFolder();
254         template<SIDE_TYPE stype>
255         afx_msg void OnUpdateCtxtDirOpenParentFolder(CCmdUI* pCmdUI);
256         template<SIDE_TYPE stype>
257         afx_msg void OnCtxtDirCopyTo();
258         template<SIDE_TYPE stype>
259         afx_msg void OnUpdateCtxtDirCopyTo(CCmdUI* pCmdUI);
260         afx_msg void OnUpdateCtxtDirCopyBothTo(CCmdUI* pCmdUI);
261         afx_msg void OnUpdateCtxtDirCopyBothDiffsOnlyTo(CCmdUI* pCmdUI);
262         template<SIDE_TYPE stype>
263         afx_msg void OnUpdateCtxtDirCopy2(CCmdUI* pCmdUI);
264         afx_msg void OnUpdateCtxtDirCopyBoth2(CCmdUI* pCmdUI);
265         afx_msg void OnDestroy();
266         afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
267         afx_msg void OnClick(NMHDR* pNMHDR, LRESULT* pResult);
268         afx_msg void OnFirstdiff();
269         afx_msg void OnUpdateFirstdiff(CCmdUI* pCmdUI);
270         afx_msg void OnLastdiff();
271         afx_msg void OnUpdateLastdiff(CCmdUI* pCmdUI);
272         afx_msg void OnNextdiff();
273         afx_msg void OnUpdateNextdiff(CCmdUI* pCmdUI);
274         afx_msg void OnPrevdiff();
275         afx_msg void OnUpdatePrevdiff(CCmdUI* pCmdUI);
276         afx_msg void OnCurdiff();
277         afx_msg void OnUpdateCurdiff(CCmdUI* pCmdUI);
278         afx_msg void OnUpdateSave(CCmdUI* pCmdUI);
279         afx_msg LRESULT OnUpdateUIMessage(WPARAM wParam, LPARAM lParam);
280         afx_msg void OnRefresh();
281         afx_msg void OnUpdateRefresh(CCmdUI* pCmdUI);
282         afx_msg void OnTimer(UINT_PTR nIDEvent);
283         afx_msg void OnEditColumns();
284         template<SIDE_TYPE stype>
285         afx_msg void OnReadOnly();
286         template<SIDE_TYPE stype>
287         afx_msg void OnUpdateReadOnly(CCmdUI* pCmdUI);
288         afx_msg void OnUpdateStatusLeftRO(CCmdUI* pCmdUI);
289         afx_msg void OnUpdateStatusMiddleRO(CCmdUI* pCmdUI);
290         afx_msg void OnUpdateStatusRightRO(CCmdUI* pCmdUI);
291         afx_msg void OnCustomizeColumns();
292         afx_msg void OnOpenWithUnpacker();
293         afx_msg void OnUpdateCtxtOpenWithUnpacker(CCmdUI* pCmdUI);
294         afx_msg void OnToolsGenerateReport();
295         afx_msg LRESULT OnGenerateFileCmpReport(WPARAM wParam, LPARAM lParam);
296         afx_msg void OnToolsGeneratePatch();
297         template<int flag>
298         afx_msg void OnCtxtDirZip();
299         template<SIDE_TYPE stype>
300         afx_msg void OnCtxtDirShellContextMenu();
301         afx_msg void OnSelectAll();
302         afx_msg void OnUpdateSelectAll(CCmdUI* pCmdUI);
303         afx_msg void OnPluginSettings(UINT nID);
304         afx_msg void OnUpdatePluginMode(CCmdUI* pCmdUI);
305         template<SIDE_TYPE side>
306         afx_msg void OnCopyPathnames();
307         afx_msg void OnCopyBothPathnames();
308         afx_msg void OnCopyFilenames();
309         afx_msg void OnUpdateCopyFilenames(CCmdUI* pCmdUI);
310         template<SIDE_TYPE side>
311         afx_msg void OnCopyToClipboard();
312         afx_msg void OnCopyBothToClipboard();
313         afx_msg void OnItemRename();
314         afx_msg void OnUpdateItemRename(CCmdUI* pCmdUI);
315         afx_msg void OnHideFilenames();
316         afx_msg void OnSize(UINT nType, int cx, int cy);
317         template<SIDE_TYPE stype>
318         afx_msg void OnCtxtDirMoveTo();
319         template<SIDE_TYPE stype>
320         afx_msg void OnUpdateCtxtDirMoveTo(CCmdUI* pCmdUI);
321         afx_msg void OnUpdateHideFilenames(CCmdUI* pCmdUI);
322         afx_msg void OnDelete();
323         afx_msg void OnUpdateDelete(CCmdUI* pCmdUI);
324         afx_msg void OnMarkedRescan();
325         afx_msg void OnUpdateStatusNum(CCmdUI* pCmdUI);
326         afx_msg void OnViewShowHiddenItems();
327         afx_msg void OnUpdateViewShowHiddenItems(CCmdUI* pCmdUI);
328         afx_msg void OnViewTreeMode();
329         afx_msg void OnUpdateViewTreeMode(CCmdUI* pCmdUI);
330         afx_msg void OnViewExpandAllSubdirs();
331         afx_msg void OnUpdateViewExpandAllSubdirs(CCmdUI* pCmdUI);
332         afx_msg void OnViewCollapseAllSubdirs();
333         afx_msg void OnUpdateViewCollapseAllSubdirs(CCmdUI* pCmdUI);
334         template <int pane1, int pane2>
335         afx_msg void OnViewSwapPanes();
336         template <int pane1, int pane2>
337         afx_msg void OnUpdateViewSwapPanes(CCmdUI* pCmdUI);
338         afx_msg void OnOptionsShowDifferent();
339         afx_msg void OnOptionsShowIdentical();
340         afx_msg void OnOptionsShowUniqueLeft();
341         afx_msg void OnOptionsShowUniqueMiddle();
342         afx_msg void OnOptionsShowUniqueRight();
343         afx_msg void OnOptionsShowBinaries();
344         afx_msg void OnOptionsShowSkipped();
345         afx_msg void OnOptionsShowDifferentLeftOnly();
346         afx_msg void OnOptionsShowDifferentMiddleOnly();
347         afx_msg void OnOptionsShowDifferentRightOnly();
348         afx_msg void OnOptionsShowMissingLeftOnly();
349         afx_msg void OnOptionsShowMissingMiddleOnly();
350         afx_msg void OnOptionsShowMissingRightOnly();
351         afx_msg void OnUpdateOptionsShowdifferent(CCmdUI* pCmdUI);
352         afx_msg void OnUpdateOptionsShowidentical(CCmdUI* pCmdUI);
353         afx_msg void OnUpdateOptionsShowuniqueleft(CCmdUI* pCmdUI);
354         afx_msg void OnUpdateOptionsShowuniquemiddle(CCmdUI* pCmdUI);
355         afx_msg void OnUpdateOptionsShowuniqueright(CCmdUI* pCmdUI);
356         afx_msg void OnUpdateOptionsShowBinaries(CCmdUI* pCmdUI);
357         afx_msg void OnUpdateOptionsShowSkipped(CCmdUI* pCmdUI);
358         afx_msg void OnUpdateOptionsShowDifferentLeftOnly(CCmdUI* pCmdUI);
359         afx_msg void OnUpdateOptionsShowDifferentMiddleOnly(CCmdUI* pCmdUI);
360         afx_msg void OnUpdateOptionsShowDifferentRightOnly(CCmdUI* pCmdUI);
361         afx_msg void OnUpdateOptionsShowMissingLeftOnly(CCmdUI* pCmdUI);
362         afx_msg void OnUpdateOptionsShowMissingMiddleOnly(CCmdUI* pCmdUI);
363         afx_msg void OnUpdateOptionsShowMissingRightOnly(CCmdUI* pCmdUI);
364         afx_msg void OnMergeCompare(UINT nID);
365         template<SELECTIONTYPE seltype>
366         afx_msg void OnMergeCompare2();
367         afx_msg void OnMergeCompareNonHorizontally();
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 OnUpdateNoUnpacker(CCmdUI* pCmdUI);
373         afx_msg void OnViewCompareStatistics();
374         afx_msg void OnFileEncoding();
375         afx_msg void OnHelp();
376         afx_msg void OnEditCopy();
377         afx_msg void OnEditCut();
378         afx_msg void OnEditPaste();
379         afx_msg void OnEditUndo();
380         afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
381         afx_msg void OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult);
382         afx_msg void OnBeginLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
383         afx_msg void OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
384         afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
385         afx_msg void OnSearch();
386         afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
387         afx_msg void OnBnClickedComparisonStop();
388         afx_msg void OnBnClickedComparisonPause();
389         afx_msg void OnBnClickedComparisonContinue();
390         //}}AFX_MSG
391         DECLARE_MESSAGE_MAP()
392         bool OnHeaderBeginDrag(LPNMHEADER hdr, LRESULT* pResult);
393         bool OnHeaderEndDrag(LPNMHEADER hdr, LRESULT* pResult);
394
395 private:
396         void Open(CDirDoc *pDoc, const PathContext& paths, DWORD dwFlags[3], FileTextEncoding encoding[3], PackingInfo * infoUnpacker = nullptr);
397         void OpenSelection(CDirDoc *pDoc, SELECTIONTYPE selectionType = SELECTIONTYPE_NORMAL, PackingInfo * infoUnpacker = nullptr, bool openableForDir = true);
398         void OpenSelection(SELECTIONTYPE selectionType = SELECTIONTYPE_NORMAL, PackingInfo * infoUnpacker = nullptr, bool openableForDir = true);
399         void OpenSelectionAs(UINT id);
400         bool GetSelectedItems(int * sel1, int * sel2, int * sel3);
401         void OpenParentDirectory(CDirDoc *pDocOpen);
402         template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
403         void DoUpdateDirCopy(CCmdUI* pCmdUI, eMenuType menuType);
404         const DIFFITEM &GetDiffItem(int sel) const;
405         DIFFITEM &GetDiffItem(int sel);
406         int GetSingleSelectedItem() const;
407         void MoveFocus(int currentInd, int i, int selCount);
408
409         void FixReordering();
410         void HeaderContextMenu(CPoint point, int i);
411         void ListContextMenu(CPoint point, int i);
412         bool ListShellContextMenu(SIDE_TYPE side);
413         void ShowShellContextMenu(SIDE_TYPE side);
414         CShellContextMenu* GetCorrespondingShellContextMenu(HMENU hMenu) const;
415         void ReloadColumns();
416         bool IsLabelEdit() const;
417         void CollapseSubdir(int sel);
418         void ExpandSubdir(int sel, bool bRecursive = false);
419         void GetColors(int nRow, int nCol, COLORREF& clrBk, COLORREF& clrText) const;
420         int GetDefColumnWidth() const { return MulDiv(DefColumnWidth, CClientDC(const_cast<CDirView *>(this)).GetDeviceCaps(LOGPIXELSX), 72); };
421
422 public:
423         DirItemIterator Begin() const { return DirItemIterator(m_pIList.get()); }
424         DirItemIterator End() const { return DirItemIterator(); }
425         DirItemIterator RevBegin() const { return DirItemIterator(m_pIList.get(), -1, false, true); }
426         DirItemIterator RevEnd() const { return DirItemIterator(); }
427         DirItemIterator SelBegin() const { return DirItemIterator(m_pIList.get(), -1, true); }
428         DirItemIterator SelEnd() const { return DirItemIterator(); }
429         DirItemIterator SelRevBegin() const { return DirItemIterator(m_pIList.get(), -1, true, true); }
430         DirItemIterator SelRevEnd() const { return DirItemIterator(); }
431 };
432
433 #ifndef _DEBUG  // debug version in DirView.cpp
434 inline CDirDoc* CDirView::GetDocument()
435 { return reinterpret_cast<CDirDoc*>(m_pDocument); }
436 #endif