1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997 Dean P. Grimm
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.
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.
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.
19 /////////////////////////////////////////////////////////////////////////////
23 * @brief Declaration of class CDirView
27 /////////////////////////////////////////////////////////////////////////////
31 #include "OptionsDiffColors.h"
32 #include "SortHeaderCtrl.h"
33 #include "UnicodeString.h"
34 #include "DirItemIterator.h"
35 #include "DirActions.h"
37 class FileActionScript;
39 typedef enum { eMain, eContext } eMenuType;
46 class DirCompProgressBar;
49 class CLoadSaveCodepageDlg;
50 class CShellContextMenu;
52 class DirViewColItems;
53 class DirItemEnumerator;
57 * @brief Position value for special items (..) in directory compare view.
59 const uintptr_t SPECIAL_ITEM_POS = (uintptr_t)(reinterpret_cast<DIFFITEM *>( - 1L));
61 /** Default column width in directory compare */
62 const UINT DefColumnWidth = 150;
65 * @brief Directory compare results view.
67 * Directory compare view is list-view based, so it shows one result (for
68 * folder or file, commonly called as 'item') in one line. User can select
69 * visible columns, re-order columns, sort by column etc.
71 * Actual data is stored in CDiffContext in CDirDoc. Dircompare items and
72 * CDiffContext items are linked by storing POSITION of CDiffContext item
73 * as CDirView listitem key.
75 class CDirView : public CListView
77 friend struct FileCmpReport;
78 friend DirItemEnumerator;
80 CDirView(); // protected constructor used by dynamic creation
81 DECLARE_DYNCREATE(CDirView)
85 CDirDoc* GetDocument(); // non-debug version is inline
86 // const version, for const methods to be able to call
87 const CDirDoc * GetDocument() const { return const_cast<CDirView *>(this)->GetDocument(); }
88 const CDiffContext& GetDiffContext() const;
89 CDiffContext& GetDiffContext();
93 CDirFrame * GetParentFrame();
95 void StartCompare(CompareStats *pCompareStats);
97 void RedisplayChildren(DIFFITEM *diffpos, int level, UINT &index, int &alldiffs);
98 void UpdateResources();
99 void LoadColumnHeaderItems();
100 DIFFITEM *GetItemKey(int idx) const;
101 int GetItemIndex(DIFFITEM *key);
102 // for populating list
103 void DeleteItem(int sel);
104 void DeleteAllDisplayItems();
105 void SetFont(const LOGFONT & lf);
107 void SortColumnsAppropriately();
109 UINT GetSelectedCount() const;
110 int GetFirstSelectedInd();
111 void AddParentFolderItem(bool bEnable);
112 void RefreshOptions();
116 void MoveToNextDiff();
117 void MoveToPrevDiff();
120 void SetActivePane(int pane);
122 // Implementation types
125 // Implementation in DirActions.cpp
127 void GetItemFileNames(int sel, String& strLeft, String& strRight) const;
128 void GetItemFileNames(int sel, PathContext * paths) const;
129 void FormatEncodingDialogDisplays(CLoadSaveCodepageDlg * dlg);
130 DirActions MakeDirActions(DirActions::method_type func) const;
131 DirActions MakeDirActions(DirActions::method_type2 func) const;
132 Counts Count(DirActions::method_type2 func) const;
133 void DoDirAction(DirActions::method_type func, const String& status_message);
134 void DoDirActionTo(SIDE_TYPE stype, DirActions::method_type func, const String& status_message);
135 void DoOpen(SIDE_TYPE stype);
136 void DoOpenWith(SIDE_TYPE stype);
137 void DoOpenWithEditor(SIDE_TYPE stype);
138 void DoOpenParentFolder(SIDE_TYPE stype);
139 void DoUpdateOpen(SELECTIONTYPE selectionType, CCmdUI* pCmdUI);
140 void ConfirmAndPerformActions(FileActionScript & actions);
141 void PerformActionList(FileActionScript & actions);
142 void UpdateAfterFileScript(FileActionScript & actionList);
143 void DoFileEncodingDialog();
145 // End DirActions.cpp
146 void ReflectGetdispinfo(NMLVDISPINFO *);
148 // Implementation in DirViewColHandler.cpp
150 void UpdateColumnNames();
151 void SetColAlignments();
152 // class CompareState is used to pass parameters to the PFNLVCOMPARE callback function.
156 const DirViewColItems *const pColItems;
157 const CDiffContext *const pCtxt;
159 const bool bSortAscending;
160 const bool bTreeMode;
162 CompareState(const CDiffContext *pCtxt, const DirViewColItems *pColItems, int sortCol, bool bSortAscending, bool bTreeMode);
163 static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
165 void UpdateDiffItemStatus(UINT nIdx);
168 void NameColumn(const char* idname, int subitem);
169 int AddNewItem(int i, DIFFITEM *diffpos, int iImage, int iIndent);
170 // End DirViewCols.cpp
175 // ClassWizard generated virtual function overrides
176 //{{AFX_VIRTUAL(CDirView)
178 virtual void OnInitialUpdate();
180 virtual BOOL PreTranslateMessage(MSG* pMsg);
181 virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
182 virtual BOOL OnChildNotify(UINT, WPARAM, LPARAM, LRESULT*);
183 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
189 int GetFocusedItem();
190 int GetFirstDifferentItem();
191 int GetLastDifferentItem();
192 int AddSpecialItems();
193 void GetCurrentColRegKeys(std::vector<String>& colKeys);
194 void OpenSpecialItems(DIFFITEM *pos1, DIFFITEM *pos2, DIFFITEM *pos3);
196 // Implementation data
198 CSortHeaderCtrl m_ctlSortHeader;
199 CImageList m_imageList;
200 CImageList m_imageState;
202 std::unique_ptr<IListCtrl> m_pIList;
203 bool m_bEscCloses; /**< Cached value for option for ESC closing window */
204 bool m_bExpandSubdirs;
205 CFont m_font; /**< User-selected font */
206 UINT m_nHiddenItems; /**< Count of items we have hidden */
207 bool m_bTreeMode; /**< `true` if tree mode is on*/
208 DirViewFilterSettings m_dirfilter;
209 std::unique_ptr<DirCompProgressBar> m_pCmpProgressBar;
210 clock_t m_compareStart; /**< Starting process time of the compare */
211 bool m_bUserCancelEdit; /**< `true` if the user cancels rename */
212 String m_lastCopyFolder; /**< Last Copy To -target folder. */
216 bool m_bNeedSearchFirstDiffItem;
217 bool m_bNeedSearchLastDiffItem;
218 COLORSETTINGS m_cachedColors; /**< Cached color settings */
220 std::unique_ptr<CShellContextMenu> m_pShellContextMenuLeft; /**< Shell context menu for group of left files */
221 std::unique_ptr<CShellContextMenu> m_pShellContextMenuMiddle; /**< Shell context menu for group of middle files */
222 std::unique_ptr<CShellContextMenu> m_pShellContextMenuRight; /**< Shell context menu for group of right files */
223 HMENU m_hCurrentMenu; /**< Current shell context menu (either left or right) */
224 std::unique_ptr<DirViewTreeState> m_pSavedTreeState;
225 std::unique_ptr<DirViewColItems> m_pColItems;
228 // Generated message map functions
229 afx_msg void OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult);
230 afx_msg void OnContextMenu(CWnd*, CPoint point);
231 //{{AFX_MSG(CDirView)
232 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
233 afx_msg void OnDirCopy(UINT id);
234 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
235 afx_msg void OnCtxtDirCopy();
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 OnCtxtDirOpenParentFolder();
259 template<SIDE_TYPE stype>
260 afx_msg void OnUpdateCtxtDirOpenParentFolder(CCmdUI* pCmdUI);
261 template<SIDE_TYPE stype>
262 afx_msg void OnCtxtDirCopyTo();
263 template<SIDE_TYPE stype>
264 afx_msg void OnUpdateCtxtDirCopyTo(CCmdUI* pCmdUI);
265 afx_msg void OnUpdateCtxtDirCopyBothTo(CCmdUI* pCmdUI);
266 afx_msg void OnUpdateCtxtDirCopyBothDiffsOnlyTo(CCmdUI* pCmdUI);
267 afx_msg void OnDestroy();
268 afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
269 afx_msg void OnClick(NMHDR* pNMHDR, LRESULT* pResult);
270 afx_msg void OnFirstdiff();
271 afx_msg void OnUpdateFirstdiff(CCmdUI* pCmdUI);
272 afx_msg void OnLastdiff();
273 afx_msg void OnUpdateLastdiff(CCmdUI* pCmdUI);
274 afx_msg void OnNextdiff();
275 afx_msg void OnUpdateNextdiff(CCmdUI* pCmdUI);
276 afx_msg void OnPrevdiff();
277 afx_msg void OnUpdatePrevdiff(CCmdUI* pCmdUI);
278 afx_msg void OnCurdiff();
279 afx_msg void OnUpdateCurdiff(CCmdUI* pCmdUI);
280 afx_msg void OnUpdateSave(CCmdUI* pCmdUI);
281 afx_msg LRESULT OnUpdateUIMessage(WPARAM wParam, LPARAM lParam);
282 afx_msg void OnRefresh();
283 afx_msg void OnUpdateRefresh(CCmdUI* pCmdUI);
284 afx_msg void OnTimer(UINT_PTR nIDEvent);
285 afx_msg void OnEditColumns();
286 template<SIDE_TYPE stype>
287 afx_msg void OnReadOnly();
288 template<SIDE_TYPE stype>
289 afx_msg void OnUpdateReadOnly(CCmdUI* pCmdUI);
290 afx_msg void OnUpdateStatusLeftRO(CCmdUI* pCmdUI);
291 afx_msg void OnUpdateStatusMiddleRO(CCmdUI* pCmdUI);
292 afx_msg void OnUpdateStatusRightRO(CCmdUI* pCmdUI);
293 afx_msg void OnCustomizeColumns();
294 afx_msg void OnCtxtOpenWithUnpacker();
295 afx_msg void OnUpdateCtxtOpenWithUnpacker(CCmdUI* pCmdUI);
296 afx_msg void OnToolsGenerateReport();
297 afx_msg void OnToolsGeneratePatch();
299 afx_msg void OnCtxtDirZip();
300 template<SIDE_TYPE stype>
301 afx_msg void OnCtxtDirShellContextMenu();
302 afx_msg void OnUpdateCtxtDir(CCmdUI* pCmdUI);
303 afx_msg void OnSelectAll();
304 afx_msg void OnUpdateSelectAll(CCmdUI* pCmdUI);
305 afx_msg void OnPluginPredifferMode(UINT nID);
306 afx_msg void OnUpdatePluginPredifferMode(CCmdUI* pCmdUI);
307 template<SIDE_TYPE side>
308 afx_msg void OnCopyPathnames();
309 afx_msg void OnCopyBothPathnames();
310 afx_msg void OnCopyFilenames();
311 afx_msg void OnUpdateCopyFilenames(CCmdUI* pCmdUI);
312 template<SIDE_TYPE side>
313 afx_msg void OnCopyToClipboard();
314 afx_msg void OnCopyBothToClipboard();
315 afx_msg void OnItemRename();
316 afx_msg void OnUpdateItemRename(CCmdUI* pCmdUI);
317 afx_msg void OnHideFilenames();
318 afx_msg void OnSize(UINT nType, int cx, int cy);
319 template<SIDE_TYPE stype>
320 afx_msg void OnCtxtDirMoveTo();
321 template<SIDE_TYPE stype>
322 afx_msg void OnUpdateCtxtDirMoveTo(CCmdUI* pCmdUI);
323 afx_msg void OnUpdateHideFilenames(CCmdUI* pCmdUI);
324 afx_msg void OnDelete();
325 afx_msg void OnUpdateDelete(CCmdUI* pCmdUI);
326 afx_msg void OnMarkedRescan();
327 afx_msg void OnUpdateStatusNum(CCmdUI* pCmdUI);
328 afx_msg void OnViewShowHiddenItems();
329 afx_msg void OnUpdateViewShowHiddenItems(CCmdUI* pCmdUI);
330 afx_msg void OnViewTreeMode();
331 afx_msg void OnUpdateViewTreeMode(CCmdUI* pCmdUI);
332 afx_msg void OnViewExpandAllSubdirs();
333 afx_msg void OnUpdateViewExpandAllSubdirs(CCmdUI* pCmdUI);
334 afx_msg void OnViewCollapseAllSubdirs();
335 afx_msg void OnUpdateViewCollapseAllSubdirs(CCmdUI* pCmdUI);
336 afx_msg void OnViewSwapPanes();
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 OnUpdateOptionsShowdifferent(CCmdUI* pCmdUI);
348 afx_msg void OnUpdateOptionsShowidentical(CCmdUI* pCmdUI);
349 afx_msg void OnUpdateOptionsShowuniqueleft(CCmdUI* pCmdUI);
350 afx_msg void OnUpdateOptionsShowuniquemiddle(CCmdUI* pCmdUI);
351 afx_msg void OnUpdateOptionsShowuniqueright(CCmdUI* pCmdUI);
352 afx_msg void OnUpdateOptionsShowBinaries(CCmdUI* pCmdUI);
353 afx_msg void OnUpdateOptionsShowSkipped(CCmdUI* pCmdUI);
354 afx_msg void OnUpdateOptionsShowDifferentLeftOnly(CCmdUI* pCmdUI);
355 afx_msg void OnUpdateOptionsShowDifferentMiddleOnly(CCmdUI* pCmdUI);
356 afx_msg void OnUpdateOptionsShowDifferentRightOnly(CCmdUI* pCmdUI);
357 afx_msg void OnMergeCompare();
358 template<SELECTIONTYPE seltype>
359 afx_msg void OnMergeCompare2();
360 afx_msg void OnMergeCompareXML();
361 afx_msg void OnMergeCompareAs(UINT nID);
362 afx_msg void OnUpdateMergeCompare(CCmdUI *pCmdUI);
363 template<SELECTIONTYPE seltype>
364 afx_msg void OnUpdateMergeCompare2(CCmdUI *pCmdUI);
365 afx_msg void OnViewCompareStatistics();
366 afx_msg void OnFileEncoding();
367 afx_msg void OnHelp();
368 afx_msg void OnEditCopy();
369 afx_msg void OnEditCut();
370 afx_msg void OnEditPaste();
371 afx_msg void OnEditUndo();
372 afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
373 afx_msg void OnItemChanged(NMHDR* pNMHDR, LRESULT* pResult);
374 afx_msg void OnBeginLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
375 afx_msg void OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult);
376 afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);
377 afx_msg void OnSearch();
378 afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);
379 afx_msg void OnBnClickedComparisonStop();
380 afx_msg void OnBnClickedComparisonPause();
381 afx_msg void OnBnClickedComparisonContinue();
383 DECLARE_MESSAGE_MAP()
384 bool OnHeaderBeginDrag(LPNMHEADER hdr, LRESULT* pResult);
385 bool OnHeaderEndDrag(LPNMHEADER hdr, LRESULT* pResult);
388 void OpenSelection(SELECTIONTYPE selectionType = SELECTIONTYPE_NORMAL, PackingInfo * infoUnpacker = nullptr);
389 void OpenSelectionAs(UINT id);
390 bool GetSelectedItems(int * sel1, int * sel2, int * sel3);
391 void OpenParentDirectory();
392 template<SIDE_TYPE srctype, SIDE_TYPE dsttype>
393 void DoUpdateDirCopy(CCmdUI* pCmdUI, eMenuType menuType);
394 const DIFFITEM &GetDiffItem(int sel) const;
395 DIFFITEM &GetDiffItem(int sel);
396 int GetSingleSelectedItem() const;
397 void MoveFocus(int currentInd, int i, int selCount);
399 void FixReordering();
400 void HeaderContextMenu(CPoint point, int i);
401 void ListContextMenu(CPoint point, int i);
402 bool ListShellContextMenu(SIDE_TYPE side);
403 void ShowShellContextMenu(SIDE_TYPE side);
404 CShellContextMenu* GetCorrespondingShellContextMenu(HMENU hMenu) const;
405 void ReloadColumns();
406 bool IsLabelEdit() const;
407 void CollapseSubdir(int sel);
408 void ExpandSubdir(int sel, bool bRecursive = false);
409 void GetColors(int nRow, int nCol, COLORREF& clrBk, COLORREF& clrText) const;
411 DirItemIterator Begin() const { return DirItemIterator(m_pIList.get()); }
412 DirItemIterator End() const { return DirItemIterator(); }
413 DirItemIterator RevBegin() const { return DirItemIterator(m_pIList.get(), -1, false, true); }
414 DirItemIterator RevEnd() const { return DirItemIterator(); }
415 DirItemIterator SelBegin() const { return DirItemIterator(m_pIList.get(), -1, true); }
416 DirItemIterator SelEnd() const { return DirItemIterator(); }
417 DirItemIterator SelRevBegin() const { return DirItemIterator(m_pIList.get(), -1, true, true); }
418 DirItemIterator SelRevEnd() const { return DirItemIterator(); }
421 #ifndef _DEBUG // debug version in DirView.cpp
422 inline CDirDoc* CDirView::GetDocument()
423 { return reinterpret_cast<CDirDoc*>(m_pDocument); }