OSDN Git Service

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