OSDN Git Service

Improve plugin system (#797)
[winmerge-jp/winmerge-jp.git] / Src / Merge.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  Merge.h
8  *
9  * @brief main header file for the MERGE application
10  *
11  */
12 #pragma once
13
14 #define WMU_CHILDFRAMEADDED                                             (WM_APP + 10)
15 #define WMU_CHILDFRAMEREMOVED                                   (WM_APP + 11)
16 #define WMU_CHILDFRAMEACTIVATE                                  (WM_APP + 12)
17 #define WMU_CHILDFRAMEACTIVATED                                 (WM_APP + 13)
18 #define IDT_UPDATEMAINMENU 1
19
20 #ifndef __AFXWIN_H__
21         #error include 'stdafx.h' before including this file for PCH
22 #endif
23
24 #include <memory>
25 #include "MergeCmdLineInfo.h"
26 #include "resource.h"       // main symbols
27
28 struct FileFilter;
29 class FileFilterHelper;
30 class CAssureScriptsForThread;
31 class CMainFrame;
32 class CLanguageSelect;
33 class MergeCmdLineInfo;
34 class ProjectFile;
35 class COptionsMgr;
36 class LineFiltersList;
37 class SubstitutionFiltersList;
38 class SyntaxColors;
39 class CCrystalTextMarkers;
40 class PackingInfo;
41
42 /////////////////////////////////////////////////////////////////////////////
43 // CMergeApp:
44 // See Merge.cpp for the implementation of this class
45 //
46
47 enum { IDLE_TIMER = 9754 };
48
49 /**
50  * @brief WinMerge application class
51  */
52 class CMergeApp : public CWinApp
53 {
54 public:
55         bool m_bNeedIdleTimer;
56         CMultiDocTemplate* m_pOpenTemplate;
57         CMultiDocTemplate* m_pDiffTemplate;
58         CMultiDocTemplate* m_pHexMergeTemplate;
59         CMultiDocTemplate* m_pDirTemplate;
60         std::unique_ptr<CLanguageSelect> m_pLangDlg;
61         std::unique_ptr<FileFilterHelper> m_pGlobalFileFilter;
62         std::unique_ptr<SyntaxColors> m_pSyntaxColors; /**< Syntax color container */
63         std::unique_ptr<CCrystalTextMarkers> m_pMarkers; /**< Marker container */
64         String m_strSaveAsPath; /**< "3rd path" where output saved if given */
65         bool m_bEscShutdown; /**< If commandline switch -e given ESC closes appliction */
66         SyntaxColors * GetMainSyntaxColors() { return m_pSyntaxColors.get(); }
67         CCrystalTextMarkers * GetMainMarkers() const { return m_pMarkers.get(); }
68         MergeCmdLineInfo::ExitNoDiff m_bExitIfNoDiff; /**< Exit if files are identical? */
69         std::unique_ptr<LineFiltersList> m_pLineFilters; /**< List of linefilters */
70         std::unique_ptr<SubstitutionFiltersList> m_pSubstitutionFiltersList;
71
72         WORD GetLangId() const;
73         void SetIndicators(CStatusBar &, const UINT *, int) const;
74         void TranslateMenu(HMENU) const;
75         void TranslateDialog(HWND) const;
76         String LoadString(UINT) const;
77         bool TranslateString(const std::string&, String&) const;
78         std::wstring LoadDialogCaption(LPCTSTR) const;
79
80         CMergeApp();
81         ~CMergeApp();
82
83 public:
84         void AddToRecentProjectsMRU(LPCTSTR sPathName);
85         void SetNeedIdleTimer();
86         void SetLastCompareResult(int nResult) { m_nLastCompareResult = nResult; }
87
88         COptionsMgr * GetMergeOptionsMgr() { return static_cast<COptionsMgr *> (m_pOptions.get()); }
89         FileFilterHelper * GetGlobalFileFilter() { return m_pGlobalFileFilter.get(); }
90         void ShowHelp(LPCTSTR helpLocation = nullptr);
91         static void OpenFileToExternalEditor(const String& file, int nLineNumber = 1);
92         static bool CreateBackup(bool bFolder, const String& pszPath);
93         static int HandleReadonlySave(String& strSavePath, bool bMultiFile, bool &bApplyToAll);
94         static String GetPackingErrorMessage(int pane, int paneCount, const String& path, const PackingInfo& plugin);
95         bool GetMergingMode() const;
96         void SetMergingMode(bool bMergingMode);
97         static void SetupTempPath();
98         bool IsReallyIdle() const;
99
100         virtual UINT GetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault) override;
101         virtual BOOL WriteProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nValue) override;
102         virtual CString GetProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL) override;
103         virtual BOOL WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszValue) override;
104         virtual HINSTANCE LoadAppLangResourceDLL() override { return nullptr; }; // Disable loading lang resource dll
105
106 // Implementation
107 protected:
108
109 // Overrides
110         // ClassWizard generated virtual function overrides
111         //{{AFX_VIRTUAL(CMergeApp)
112         public:
113         virtual BOOL InitInstance();
114         virtual int ExitInstance();
115         virtual int DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt);
116         virtual BOOL OnIdle(LONG lCount);
117         //}}AFX_VIRTUAL
118
119         void InitializeFileFilters();
120         bool ParseArgsAndDoOpen(MergeCmdLineInfo& cmdInfo, CMainFrame* pMainFrame);
121         void UpdateDefaultCodepage(int cpDefaultMode, int cpCustomCodepage);
122         void UpdateCodepageModule();
123         void ApplyCommandLineConfigOptions(MergeCmdLineInfo & cmdInfo);
124
125         // End MergeArgs.cpp
126
127         bool LoadProjectFile(const String& sProject, ProjectFile &project);
128         bool SaveProjectFile(const String& sProject, const ProjectFile &project);
129         bool LoadAndOpenProjectFile(const String& sFilepath, const String& sReportFile = _T(""));
130         bool IsProjectFile(const String& filepath) const;
131
132         //@{
133         /**
134          * @name Active operations counter.
135          * These functions implement counter for active operations. We need to
136          * track active operations during whose user cannot exit the application.
137          * E.g. copying files in folder compare is such an operation.
138          */
139         /**
140          * Increment the active operation counter.
141          */
142         void AddOperation() { InterlockedIncrement(&m_nActiveOperations); }
143         /**
144          * Decrement the active operation counter.
145          */
146         void RemoveOperation()
147         {
148                 ASSERT(m_nActiveOperations > 0);
149                 InterlockedDecrement( &m_nActiveOperations);
150         }
151         /**
152          * Get the active operations count.
153          */
154         LONG GetActiveOperations() const { return m_nActiveOperations; }
155         //@}
156
157         //{{AFX_MSG(CMergeApp)
158         afx_msg BOOL OnOpenRecentFile(UINT nID);
159         afx_msg void OnAppAbout();
160         afx_msg void OnHelp();
161         afx_msg void OnMergingMode();
162         afx_msg void OnUpdateMergingMode(CCmdUI* pCmdUI);
163         afx_msg void OnUpdateMergingStatus(CCmdUI* pCmdUI);
164         //}}AFX_MSG
165         DECLARE_MESSAGE_MAP()
166 private:
167         std::unique_ptr<COptionsMgr> m_pOptions;
168         CAssureScriptsForThread * m_mainThreadScripts;
169         int m_nLastCompareResult;
170         bool m_bNonInteractive;
171         LONG m_nActiveOperations; /**< Active operations count. */
172         bool m_bMergingMode; /**< Merging or Edit mode */
173         CFont m_fontGUI;
174         ATL::CImage m_imageForInitializingGdiplus;
175 };
176
177 extern CMergeApp theApp;
178
179 /**
180  * @brief Set flag so that application will broadcast notification at next
181  * idle time (via WM_TIMER id=IDLE_TIMER)
182  */
183 inline void CMergeApp::SetNeedIdleTimer()
184 {
185         m_bNeedIdleTimer = true;
186 }
187
188 COptionsMgr* CreateOptionManager();