OSDN Git Service

Improve plugin system (#797) (6)
[winmerge-jp/winmerge-jp.git] / Src / DirDoc.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  DirDoc.h
8  *
9  * @brief Declaration file for CDirDoc
10  *
11  */
12 #pragma once
13
14 #include <memory>
15 #include "DiffThread.h"
16 #include "PluginManager.h"
17 #include "FileFilterHelper.h"
18 #include "DirCmpReport.h"
19
20 class CDirView;
21 struct IMergeDoc;
22 typedef CTypedPtrList<CPtrList, IMergeDoc *> MergeDocPtrList;
23 class DirDocFilterGlobal;
24 class DirDocFilterByExtension;
25 class CTempPathContext;
26 struct FileActionItem;
27 struct FileLocation;
28
29 /////////////////////////////////////////////////////////////////////////////
30 // CDirDoc document
31
32 /**
33  * @brief Class for folder compare data.
34  * This class is "document" class for folder compare. It has compare context,
35  * which in turn has a list of differences and other compare result data.
36  * This class also has compare statistics which are updated during compare.
37  * GUI calls this class to operate with results.
38  */
39 class CDirDoc : public CDocument
40 {
41 protected:
42         CDirDoc();           // protected constructor used by dynamic creation
43         DECLARE_DYNCREATE(CDirDoc)
44
45 // Attributes
46 public:
47         CTempPathContext *m_pTempPathContext;
48         int m_nDirs;
49         static int m_nDirsTemp;
50
51 // Operations
52 public:
53         bool CloseMergeDocs();
54         CDirView * GetMainView() const;
55
56 // Overrides
57         // ClassWizard generated virtual function overrides
58         //{{AFX_VIRTUAL(CDirDoc)
59         public:
60         virtual void Serialize(CArchive& ar);   // overridden for document i/o
61         virtual void SetTitle(LPCTSTR lpszTitle);
62         protected:
63         virtual BOOL OnNewDocument();
64         virtual BOOL SaveModified();
65         //}}AFX_VIRTUAL
66
67 // Implementation
68 public:
69         void InitCompare(const PathContext & paths, bool bRecursive, CTempPathContext *);
70         void DiffThreadCallback(int& state);
71         void Rescan();
72         bool GetReadOnly(int nIndex) const;
73         const bool *GetReadOnly(void) const;
74         void SetReadOnly(int nIndex, bool bReadOnly);
75         String GetReportFile() const { return m_sReportFile; }
76         void SetReportFile(const String& sReportFile) { m_sReportFile = sReportFile; }
77         bool GetGeneratingReport() const { return m_bGeneratingReport; }
78         void SetGeneratingReport(bool bGeneratingReport) { m_bGeneratingReport = bGeneratingReport; }
79         void SetReport(DirCmpReport* pReport) { m_pReport.reset(pReport);  }
80         bool HasDirView() const { return m_pDirView != nullptr; }
81         void RefreshOptions();
82         void CompareReady();
83         void UpdateChangedItem(const PathContext & paths,
84                 UINT nDiffs, UINT nTrivialDiffs, bool bIdentical);
85         void UpdateResources();
86         void InitStatusStrings();
87         void ReloadItemStatus(DIFFITEM *diffPos, int idx);
88         void Redisplay();
89         virtual ~CDirDoc();
90         void SetDirView( CDirView *newView ); // TODO Perry
91         void AddMergeDoc(IMergeDoc * pMergeDoc);
92         void MergeDocClosing(IMergeDoc * pMergeDoc);
93         CDiffThread m_diffThread;
94         void UpdateHeaderPath(int nIndex);
95         void AbortCurrentScan();
96         void PauseCurrentScan();
97         void ContinueCurrentScan();
98         bool IsCurrentScanAbortable() const;
99         void SetDescriptions(const String strDesc[]);
100         void ApplyDisplayRoot(int nIndex, String &);
101
102         bool HasDiffs() const { return m_pCtxt != nullptr; }
103         const CDiffContext & GetDiffContext() const { return *m_pCtxt; }
104         CDiffContext& GetDiffContext() { return *m_pCtxt.get(); }
105         void SetMarkedRescan() {m_bMarkedRescan = true; }
106         const CompareStats * GetCompareStats() const { return m_pCompareStats.get(); };
107         bool IsArchiveFolders() const;
108         PluginManager& GetPluginManager() { return m_pluginman; };
109         void Swap(int idx1, int idx2);
110         bool MoveableToNextDiff();
111         bool MoveableToPrevDiff();
112         void MoveToNextDiff(IMergeDoc *pMergeDoc);
113         void MoveToPrevDiff(IMergeDoc *pMergeDoc);
114         void MoveToFirstFile(IMergeDoc* pMergeDoc);
115         void MoveToLastFile(IMergeDoc* pMergeDoc);
116         void MoveToNextFile(IMergeDoc* pMergeDoc);
117         void MoveToPrevFile(IMergeDoc* pMergeDoc);
118         bool IsFirstFile();
119         bool IsLastFile();
120
121         bool CompareFilesIfFilesAreLarge(int nFiles, const FileLocation ifileloc[]);
122
123 protected:
124         void InitDiffContext(CDiffContext *pCtxt);
125         void LoadLineFilterList(CDiffContext *pCtxt);
126         void LoadSubstitutionFiltersList(CDiffContext* pCtxt);
127
128         // Generated message map functions
129         //{{AFX_MSG(CDirDoc)
130                 // NOTE - the ClassWizard will add and remove member functions here.
131         //}}AFX_MSG
132         DECLARE_MESSAGE_MAP()
133
134         // Implementation data
135 private:
136         std::unique_ptr<CDiffContext> m_pCtxt; /**< Pointer to diff-data */
137         CDirView *m_pDirView; /**< Pointer to GUI */
138         std::unique_ptr<CompareStats> m_pCompareStats; /**< Compare statistics */
139         MergeDocPtrList m_MergeDocs; /**< List of file compares opened from this compare */
140         bool m_bRO[3]; /**< Is left/middle/right side read-only */
141         String m_strDesc[3]; /**< Left/middle/right side desription text */
142         String m_sReportFile;
143         PluginManager m_pluginman;
144         FileFilterHelper m_imgfileFilter;
145         bool m_bMarkedRescan; /**< If `true` next rescan scans only marked items */
146         bool m_bGeneratingReport;
147         std::unique_ptr<DirCmpReport> m_pReport;
148 };
149
150 /**
151  * @brief Set left/middle/right side readonly-status
152  * @param nIndex Select side to set 
153  * @param bReadOnly New status of selected side
154  */
155 inline void CDirDoc::SetReadOnly(int nIndex, bool bReadOnly)
156 {
157         m_bRO[nIndex] = bReadOnly;
158 }
159
160 /**
161  * @brief Return left/middle/right side readonly-status
162  * @param nIndex Select side to ask
163  */
164 inline bool CDirDoc::GetReadOnly(int nIndex) const
165 {
166         return m_bRO[nIndex];
167 }
168
169 inline const bool *CDirDoc::GetReadOnly(void) const
170 {
171         return m_bRO;
172 }
173