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(false)
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());
68 pWnd->SetCurSel(m_nCloseWindowWithEsc);
70 m_ctlLangList.SetDroppedWidth(600);
71 m_ctlLangList.EnableWindow(FALSE);
72 m_asyncLanguagesLoader = Concurrent::CreateTask([hwnd = m_hWnd] {
73 std::vector<std::pair<LANGID, String>> langs = theApp.m_pLangDlg->GetAvailableLanguages();
74 ::PostMessage(hwnd, WM_APP, 0, 0);
77 return TRUE; // return TRUE unless you set the focus to a control
80 void PropGeneral::DoDataExchange(CDataExchange* pDX)
82 CPropertyPage::DoDataExchange(pDX);
83 //{{AFX_DATA_MAP(PropGeneral)
84 DDX_Check(pDX, IDC_SCROLL_CHECK, m_bScroll);
85 DDX_Check(pDX, IDC_SCROLL_TO_FIRST_INLINE_DIFF_CHECK, m_bScrollToFirstInlineDiff);
86 DDX_Check(pDX, IDC_SINGLE_INSTANCE, m_nSingleInstance);
87 DDX_Check(pDX, IDC_VERIFY_OPEN_PATHS, m_bVerifyPaths);
88 DDX_CBIndex(pDX, IDC_ESC_CLOSES_WINDOW, m_nCloseWindowWithEsc);
89 DDX_Check(pDX, IDC_ASK_MULTIWINDOW_CLOSE, m_bAskMultiWindowClose);
90 DDX_CBIndex(pDX, IDC_AUTO_COMPLETE_SOURCE, m_nAutoCompleteSource);
91 DDX_Check(pDX, IDC_PRESERVE_FILETIME, m_bPreserveFiletime);
92 DDX_Check(pDX, IDC_STARTUP_FOLDER_SELECT, m_bShowSelectFolderOnStartup);
93 DDX_Check(pDX, IDC_CLOSE_WITH_OK, m_bCloseWithOK);
94 DDX_Control(pDX, IDC_LANGUAGE_LIST, m_ctlLangList);
99 BEGIN_MESSAGE_MAP(PropGeneral, OptionsPanel)
100 //{{AFX_MSG_MAP(PropGeneral)
101 ON_BN_CLICKED(IDC_RESET_ALL_MESSAGE_BOXES, OnResetAllMessageBoxes)
102 ON_MESSAGE(WM_APP, OnLoadLanguages)
107 * @brief Reads options values from storage to UI.
109 void PropGeneral::ReadOptions()
111 m_bScroll = GetOptionsMgr()->GetBool(OPT_SCROLL_TO_FIRST);
112 m_bScrollToFirstInlineDiff = GetOptionsMgr()->GetBool(OPT_SCROLL_TO_FIRST_INLINE_DIFF);
113 m_nSingleInstance = GetOptionsMgr()->GetInt(OPT_SINGLE_INSTANCE);
114 m_bVerifyPaths = GetOptionsMgr()->GetBool(OPT_VERIFY_OPEN_PATHS);
115 m_nCloseWindowWithEsc = GetOptionsMgr()->GetInt(OPT_CLOSE_WITH_ESC);
116 m_bAskMultiWindowClose = GetOptionsMgr()->GetBool(OPT_ASK_MULTIWINDOW_CLOSE);
117 m_nAutoCompleteSource = GetOptionsMgr()->GetInt(OPT_AUTO_COMPLETE_SOURCE);
118 m_bPreserveFiletime = GetOptionsMgr()->GetBool(OPT_PRESERVE_FILETIMES);
119 m_bShowSelectFolderOnStartup = GetOptionsMgr()->GetBool(OPT_SHOW_SELECT_FILES_AT_STARTUP);
120 m_bCloseWithOK = GetOptionsMgr()->GetBool(OPT_CLOSE_WITH_OK);
124 * @brief Writes options values from UI to storage.
126 void PropGeneral::WriteOptions()
128 GetOptionsMgr()->SaveOption(OPT_SCROLL_TO_FIRST, m_bScroll);
129 GetOptionsMgr()->SaveOption(OPT_SCROLL_TO_FIRST_INLINE_DIFF, m_bScrollToFirstInlineDiff);
130 GetOptionsMgr()->SaveOption(OPT_SINGLE_INSTANCE, m_nSingleInstance);
131 GetOptionsMgr()->SaveOption(OPT_VERIFY_OPEN_PATHS, m_bVerifyPaths);
132 GetOptionsMgr()->SaveOption(OPT_CLOSE_WITH_ESC, m_nCloseWindowWithEsc);
133 GetOptionsMgr()->SaveOption(OPT_ASK_MULTIWINDOW_CLOSE, m_bAskMultiWindowClose);
134 GetOptionsMgr()->SaveOption(OPT_AUTO_COMPLETE_SOURCE, m_nAutoCompleteSource);
135 GetOptionsMgr()->SaveOption(OPT_PRESERVE_FILETIMES, m_bPreserveFiletime);
136 GetOptionsMgr()->SaveOption(OPT_SHOW_SELECT_FILES_AT_STARTUP, m_bShowSelectFolderOnStartup);
137 GetOptionsMgr()->SaveOption(OPT_CLOSE_WITH_OK, m_bCloseWithOK);
138 int index = m_ctlLangList.GetCurSel();
141 WORD lang = (WORD)m_ctlLangList.GetItemData(index);
142 GetOptionsMgr()->SaveOption(OPT_SELECTED_LANGUAGE, (int)lang);
147 * @brief Called when user wants to see all messageboxes again.
149 void PropGeneral::OnResetAllMessageBoxes()
151 CMessageBoxDialog::ResetMessageBoxes();
152 // The "don't show again" checkbox of the Confirm Copy dialog uses the same registry key
153 // as CMessageBoxDialog does, so its state will also be reset
154 AfxMessageBox(_("All message boxes are now displayed again.").c_str(), MB_ICONINFORMATION);
157 LRESULT PropGeneral::OnLoadLanguages(WPARAM, LPARAM)
159 for (auto&& i : m_asyncLanguagesLoader.Get())
161 m_ctlLangList.AddString(i.second.c_str());
162 m_ctlLangList.SetItemData(m_ctlLangList.GetCount() - 1, i.first);
163 if (i.first == theApp.m_pLangDlg->GetLangId())
164 m_ctlLangList.SetCurSel(m_ctlLangList.GetCount() - 1);
166 m_ctlLangList.EnableWindow(TRUE);