1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997-2000 Thingamahoochie Software
5 // SPDX-License-Identifier: GPL-2.0-or-later
6 /////////////////////////////////////////////////////////////////////////////
10 * @brief Implementation file for PropGeneral propertyheet
15 #include "PropGeneral.h"
17 #include "OptionsDef.h"
18 #include "OptionsMgr.h"
19 #include "OptionsPanel.h"
20 #include "LanguageSelect.h"
27 * @brief Constructor initialising members.
29 PropGeneral::PropGeneral(COptionsMgr *optionsMgr)
30 : OptionsPanel(optionsMgr, PropGeneral::IDD)
32 , m_bScrollToFirstInlineDiff(false)
33 , m_nSingleInstance(0)
34 , m_bVerifyPaths(false)
35 , m_nCloseWindowWithEsc(1)
36 , m_bAskMultiWindowClose(false)
37 , m_nAutoCompleteSource(0)
38 , m_bPreserveFiletime(false)
39 , m_bShowSelectFolderOnStartup(false)
40 , m_bCloseWithOK(true)
44 PropGeneral::~PropGeneral()
48 BOOL PropGeneral::OnInitDialog()
50 OptionsPanel::OnInitDialog();
52 CComboBox *pWnd = (CComboBox*)GetDlgItem(IDC_AUTO_COMPLETE_SOURCE);
53 ASSERT(pWnd != nullptr);
55 pWnd->AddString(_("Disabled").c_str());
56 pWnd->AddString(_("From file system").c_str());
57 pWnd->AddString(_("From Most Recently Used list").c_str());
59 pWnd->SetCurSel(m_nAutoCompleteSource);
61 pWnd = (CComboBox*)GetDlgItem(IDC_ESC_CLOSES_WINDOW);
62 ASSERT(pWnd != nullptr);
64 pWnd->AddString(_("Disabled").c_str());
65 pWnd->AddString(_("MDI child window or main window").c_str());
66 pWnd->AddString(_("MDI child window only").c_str());
67 pWnd->AddString(_("Close main window if there is only one MDI child window").c_str());
69 pWnd->SetCurSel(m_nCloseWindowWithEsc);
71 pWnd = (CComboBox*)GetDlgItem(IDC_SINGLE_INSTANCE);
72 ASSERT(pWnd != nullptr);
74 pWnd->AddString(_("Disabled").c_str());
75 pWnd->AddString(_("Allow only one instance to run").c_str());
76 pWnd->AddString(_("Allow only one instance to run and wait for the instance to terminate").c_str());
78 pWnd->SetCurSel(m_nSingleInstance);
80 m_ctlLangList.SetDroppedWidth(600);
81 m_ctlLangList.EnableWindow(FALSE);
82 m_asyncLanguagesLoader = Concurrent::CreateTask([hwnd = m_hWnd] {
83 std::vector<std::pair<LANGID, String>> langs = theApp.m_pLangDlg->GetAvailableLanguages();
84 ::PostMessage(hwnd, WM_APP, 0, 0);
87 return TRUE; // return TRUE unless you set the focus to a control
90 void PropGeneral::DoDataExchange(CDataExchange* pDX)
92 CPropertyPage::DoDataExchange(pDX);
93 //{{AFX_DATA_MAP(PropGeneral)
94 DDX_Check(pDX, IDC_SCROLL_CHECK, m_bScroll);
95 DDX_Check(pDX, IDC_SCROLL_TO_FIRST_INLINE_DIFF_CHECK, m_bScrollToFirstInlineDiff);
96 DDX_CBIndex(pDX, IDC_SINGLE_INSTANCE, m_nSingleInstance);
97 DDX_Check(pDX, IDC_VERIFY_OPEN_PATHS, m_bVerifyPaths);
98 DDX_CBIndex(pDX, IDC_ESC_CLOSES_WINDOW, m_nCloseWindowWithEsc);
99 DDX_Check(pDX, IDC_ASK_MULTIWINDOW_CLOSE, m_bAskMultiWindowClose);
100 DDX_CBIndex(pDX, IDC_AUTO_COMPLETE_SOURCE, m_nAutoCompleteSource);
101 DDX_Check(pDX, IDC_PRESERVE_FILETIME, m_bPreserveFiletime);
102 DDX_Check(pDX, IDC_STARTUP_FOLDER_SELECT, m_bShowSelectFolderOnStartup);
103 DDX_Check(pDX, IDC_CLOSE_WITH_OK, m_bCloseWithOK);
104 DDX_Control(pDX, IDC_LANGUAGE_LIST, m_ctlLangList);
109 BEGIN_MESSAGE_MAP(PropGeneral, OptionsPanel)
110 //{{AFX_MSG_MAP(PropGeneral)
111 ON_MESSAGE(WM_APP, OnLoadLanguages)
116 * @brief Reads options values from storage to UI.
118 void PropGeneral::ReadOptions()
120 m_bScroll = GetOptionsMgr()->GetBool(OPT_SCROLL_TO_FIRST);
121 m_bScrollToFirstInlineDiff = GetOptionsMgr()->GetBool(OPT_SCROLL_TO_FIRST_INLINE_DIFF);
122 m_nSingleInstance = GetOptionsMgr()->GetInt(OPT_SINGLE_INSTANCE);
123 m_bVerifyPaths = GetOptionsMgr()->GetBool(OPT_VERIFY_OPEN_PATHS);
124 m_nCloseWindowWithEsc = GetOptionsMgr()->GetInt(OPT_CLOSE_WITH_ESC);
125 m_bAskMultiWindowClose = GetOptionsMgr()->GetBool(OPT_ASK_MULTIWINDOW_CLOSE);
126 m_nAutoCompleteSource = GetOptionsMgr()->GetInt(OPT_AUTO_COMPLETE_SOURCE);
127 m_bPreserveFiletime = GetOptionsMgr()->GetBool(OPT_PRESERVE_FILETIMES);
128 m_bShowSelectFolderOnStartup = GetOptionsMgr()->GetBool(OPT_SHOW_SELECT_FILES_AT_STARTUP);
129 m_bCloseWithOK = GetOptionsMgr()->GetBool(OPT_CLOSE_WITH_OK);
133 * @brief Writes options values from UI to storage.
135 void PropGeneral::WriteOptions()
137 GetOptionsMgr()->SaveOption(OPT_SCROLL_TO_FIRST, m_bScroll);
138 GetOptionsMgr()->SaveOption(OPT_SCROLL_TO_FIRST_INLINE_DIFF, m_bScrollToFirstInlineDiff);
139 GetOptionsMgr()->SaveOption(OPT_SINGLE_INSTANCE, m_nSingleInstance);
140 GetOptionsMgr()->SaveOption(OPT_VERIFY_OPEN_PATHS, m_bVerifyPaths);
141 GetOptionsMgr()->SaveOption(OPT_CLOSE_WITH_ESC, m_nCloseWindowWithEsc);
142 GetOptionsMgr()->SaveOption(OPT_ASK_MULTIWINDOW_CLOSE, m_bAskMultiWindowClose);
143 GetOptionsMgr()->SaveOption(OPT_AUTO_COMPLETE_SOURCE, m_nAutoCompleteSource);
144 GetOptionsMgr()->SaveOption(OPT_PRESERVE_FILETIMES, m_bPreserveFiletime);
145 GetOptionsMgr()->SaveOption(OPT_SHOW_SELECT_FILES_AT_STARTUP, m_bShowSelectFolderOnStartup);
146 GetOptionsMgr()->SaveOption(OPT_CLOSE_WITH_OK, m_bCloseWithOK);
147 int index = m_ctlLangList.GetCurSel();
150 WORD lang = (WORD)m_ctlLangList.GetItemData(index);
151 GetOptionsMgr()->SaveOption(OPT_SELECTED_LANGUAGE, (int)lang);
155 LRESULT PropGeneral::OnLoadLanguages(WPARAM, LPARAM)
157 for (auto&& i : m_asyncLanguagesLoader.Get())
159 m_ctlLangList.AddString(i.second.c_str());
160 m_ctlLangList.SetItemData(m_ctlLangList.GetCount() - 1, i.first);
161 if (i.first == theApp.m_pLangDlg->GetLangId())
162 m_ctlLangList.SetCurSel(m_ctlLangList.GetCount() - 1);
164 m_ctlLangList.EnableWindow(TRUE);