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;
41 /////////////////////////////////////////////////////////////////////////////
43 // See Merge.cpp for the implementation of this class
46 enum { IDLE_TIMER = 9754 };
49 * @brief WinMerge application class
51 class CMergeApp : public CWinApp
54 bool m_bNeedIdleTimer;
55 CMultiDocTemplate* m_pOpenTemplate;
56 CMultiDocTemplate* m_pDiffTemplate;
57 CMultiDocTemplate* m_pHexMergeTemplate;
58 CMultiDocTemplate* m_pDirTemplate;
59 std::unique_ptr<CLanguageSelect> m_pLangDlg;
60 std::unique_ptr<FileFilterHelper> m_pGlobalFileFilter;
61 std::unique_ptr<SyntaxColors> m_pSyntaxColors; /**< Syntax color container */
62 std::unique_ptr<CCrystalTextMarkers> m_pMarkers; /**< Marker container */
63 String m_strSaveAsPath; /**< "3rd path" where output saved if given */
64 bool m_bEscShutdown; /**< If commandline switch -e given ESC closes appliction */
65 SyntaxColors * GetMainSyntaxColors() { return m_pSyntaxColors.get(); }
66 CCrystalTextMarkers * GetMainMarkers() const { return m_pMarkers.get(); }
67 MergeCmdLineInfo::ExitNoDiff m_bExitIfNoDiff; /**< Exit if files are identical? */
68 std::unique_ptr<LineFiltersList> m_pLineFilters; /**< List of linefilters */
69 std::unique_ptr<SubstitutionFiltersList> m_pSubstitutionFiltersList;
71 WORD GetLangId() const;
72 void SetIndicators(CStatusBar &, const UINT *, int) const;
73 void TranslateMenu(HMENU) const;
74 void TranslateDialog(HWND) const;
75 String LoadString(UINT) const;
76 bool TranslateString(const std::string&, String&) const;
77 std::wstring LoadDialogCaption(LPCTSTR) const;
83 void AddToRecentProjectsMRU(LPCTSTR sPathName);
84 void SetNeedIdleTimer();
85 void SetLastCompareResult(int nResult) { m_nLastCompareResult = nResult; }
87 COptionsMgr * GetMergeOptionsMgr() { return static_cast<COptionsMgr *> (m_pOptions.get()); }
88 FileFilterHelper * GetGlobalFileFilter() { return m_pGlobalFileFilter.get(); }
89 void ShowHelp(LPCTSTR helpLocation = nullptr);
90 static void OpenFileToExternalEditor(const String& file, int nLineNumber = 1);
91 static bool CreateBackup(bool bFolder, const String& pszPath);
92 static int HandleReadonlySave(String& strSavePath, bool bMultiFile, bool &bApplyToAll);
93 static String GetPackingErrorMessage(int pane, int paneCount, const String& path, const String& pluginName);
94 bool GetMergingMode() const;
95 void SetMergingMode(bool bMergingMode);
96 static void SetupTempPath();
97 bool IsReallyIdle() const;
99 virtual UINT GetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault) override;
100 virtual BOOL WriteProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nValue) override;
101 virtual CString GetProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL) override;
102 virtual BOOL WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszValue) override;
103 virtual HINSTANCE LoadAppLangResourceDLL() override { return nullptr; }; // Disable loading lang resource dll
109 // ClassWizard generated virtual function overrides
110 //{{AFX_VIRTUAL(CMergeApp)
112 virtual BOOL InitInstance();
113 virtual int ExitInstance();
114 virtual int DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt);
115 virtual BOOL OnIdle(LONG lCount);
118 void InitializeFileFilters();
119 bool ParseArgsAndDoOpen(MergeCmdLineInfo& cmdInfo, CMainFrame* pMainFrame);
120 void UpdateDefaultCodepage(int cpDefaultMode, int cpCustomCodepage);
121 void UpdateCodepageModule();
122 void ApplyCommandLineConfigOptions(MergeCmdLineInfo & cmdInfo);
126 bool LoadProjectFile(const String& sProject, ProjectFile &project);
127 bool SaveProjectFile(const String& sProject, const ProjectFile &project);
128 bool LoadAndOpenProjectFile(const String& sFilepath, const String& sReportFile = _T(""));
129 bool IsProjectFile(const String& filepath) const;
133 * @name Active operations counter.
134 * These functions implement counter for active operations. We need to
135 * track active operations during whose user cannot exit the application.
136 * E.g. copying files in folder compare is such an operation.
139 * Increment the active operation counter.
141 void AddOperation() { InterlockedIncrement(&m_nActiveOperations); }
143 * Decrement the active operation counter.
145 void RemoveOperation()
147 ASSERT(m_nActiveOperations > 0);
148 InterlockedDecrement( &m_nActiveOperations);
151 * Get the active operations count.
153 LONG GetActiveOperations() const { return m_nActiveOperations; }
156 //{{AFX_MSG(CMergeApp)
157 afx_msg BOOL OnOpenRecentFile(UINT nID);
158 afx_msg void OnAppAbout();
159 afx_msg void OnHelp();
160 afx_msg void OnMergingMode();
161 afx_msg void OnUpdateMergingMode(CCmdUI* pCmdUI);
162 afx_msg void OnUpdateMergingStatus(CCmdUI* pCmdUI);
164 DECLARE_MESSAGE_MAP()
166 std::unique_ptr<COptionsMgr> m_pOptions;
167 CAssureScriptsForThread * m_mainThreadScripts;
168 int m_nLastCompareResult;
169 bool m_bNonInteractive;
170 LONG m_nActiveOperations; /**< Active operations count. */
171 bool m_bMergingMode; /**< Merging or Edit mode */
173 ATL::CImage m_imageForInitializingGdiplus;
176 extern CMergeApp theApp;
179 * @brief Set flag so that application will broadcast notification at next
180 * idle time (via WM_TIMER id=IDLE_TIMER)
182 inline void CMergeApp::SetNeedIdleTimer()
184 m_bNeedIdleTimer = true;
187 COptionsMgr* CreateOptionManager();