OSDN Git Service

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