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 /////////////////////////////////////////////////////////////////////////////
9 * @brief main header file for the MERGE application
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
21 #error include 'stdafx.h' before including this file for PCH
25 #include "MergeCmdLineInfo.h"
26 #include "resource.h" // main symbols
29 class FileFilterHelper;
30 class CAssureScriptsForThread;
32 class CLanguageSelect;
33 class MergeCmdLineInfo;
36 class LineFiltersList;
37 class SubstitutionFiltersList;
39 class CCrystalTextMarkers;
42 /////////////////////////////////////////////////////////////////////////////
44 // See Merge.cpp for the implementation of this class
47 enum { IDLE_TIMER = 9754 };
50 * @brief WinMerge application class
52 class CMergeApp : public CWinApp
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;
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;
84 void AddToRecentProjectsMRU(LPCTSTR sPathName);
85 void SetNeedIdleTimer();
86 void SetLastCompareResult(int nResult) { m_nLastCompareResult = nResult; }
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;
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
110 // ClassWizard generated virtual function overrides
111 //{{AFX_VIRTUAL(CMergeApp)
113 virtual BOOL InitInstance();
114 virtual int ExitInstance();
115 virtual int DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt);
116 virtual BOOL OnIdle(LONG lCount);
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);
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;
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.
140 * Increment the active operation counter.
142 void AddOperation() { InterlockedIncrement(&m_nActiveOperations); }
144 * Decrement the active operation counter.
146 void RemoveOperation()
148 ASSERT(m_nActiveOperations > 0);
149 InterlockedDecrement( &m_nActiveOperations);
152 * Get the active operations count.
154 LONG GetActiveOperations() const { return m_nActiveOperations; }
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);
165 DECLARE_MESSAGE_MAP()
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 */
174 ATL::CImage m_imageForInitializingGdiplus;
177 extern CMergeApp theApp;
180 * @brief Set flag so that application will broadcast notification at next
181 * idle time (via WM_TIMER id=IDLE_TIMER)
183 inline void CMergeApp::SetNeedIdleTimer()
185 m_bNeedIdleTimer = true;
188 COptionsMgr* CreateOptionManager();