OSDN Git Service

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