1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997-2000 Thingamahoochie Software
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /////////////////////////////////////////////////////////////////////////////
24 * @brief Implementation file for PropGeneral propertyheet
29 #include "PropGeneral.h"
31 #include "OptionsDef.h"
32 #include "OptionsMgr.h"
33 #include "OptionsPanel.h"
34 #include "LanguageSelect.h"
41 * @brief Constructor initialising members.
43 PropGeneral::PropGeneral(COptionsMgr *optionsMgr)
44 : OptionsPanel(optionsMgr, PropGeneral::IDD)
46 , m_bSingleInstance(false)
47 , m_bVerifyPaths(false)
48 , m_bCloseWindowWithEsc(false) // default is false !
49 , m_bAskMultiWindowClose(false)
50 , m_nAutoCompleteSource(0)
51 , m_bPreserveFiletime(false)
52 , m_bShowSelectFolderOnStartup(false)
53 , m_bCloseWithOK(true)
54 , m_pLoadLanguagesThread(nullptr)
58 PropGeneral::~PropGeneral()
62 BOOL PropGeneral::OnInitDialog()
64 OptionsPanel::OnInitDialog();
66 CComboBox *pWnd = (CComboBox*)GetDlgItem(IDC_AUTO_COMPLETE_SOURCE);
67 ASSERT(pWnd != nullptr);
69 pWnd->AddString(_("Disabled").c_str());
70 pWnd->AddString(_("From file system").c_str());
71 pWnd->AddString(_("From MRU list").c_str());
73 pWnd->SetCurSel(m_nAutoCompleteSource);
75 m_ctlLangList.SetDroppedWidth(600);
76 m_ctlLangList.EnableWindow(FALSE);
77 m_pLoadLanguagesThread = AfxBeginThread(LoadLanguagesThreadProc, this, 0, 0, CREATE_SUSPENDED);
78 m_pLoadLanguagesThread->m_bAutoDelete = FALSE;
79 m_pLoadLanguagesThread->ResumeThread();
81 return TRUE; // return TRUE unless you set the focus to a control
84 void PropGeneral::OnDestroy()
86 if (m_pLoadLanguagesThread!=nullptr)
88 WaitForSingleObject(m_pLoadLanguagesThread->m_hThread, INFINITE);
89 delete m_pLoadLanguagesThread;
91 OptionsPanel::OnDestroy();
94 void PropGeneral::DoDataExchange(CDataExchange* pDX)
96 CPropertyPage::DoDataExchange(pDX);
97 //{{AFX_DATA_MAP(PropGeneral)
98 DDX_Check(pDX, IDC_SCROLL_CHECK, m_bScroll);
99 DDX_Check(pDX, IDC_SINGLE_INSTANCE, m_bSingleInstance);
100 DDX_Check(pDX, IDC_VERIFY_OPEN_PATHS, m_bVerifyPaths);
101 DDX_Check(pDX, IDC_ESC_CLOSES_WINDOW, m_bCloseWindowWithEsc);
102 DDX_Check(pDX, IDC_ASK_MULTIWINDOW_CLOSE, m_bAskMultiWindowClose);
103 DDX_CBIndex(pDX, IDC_AUTO_COMPLETE_SOURCE, m_nAutoCompleteSource);
104 DDX_Check(pDX, IDC_PRESERVE_FILETIME, m_bPreserveFiletime);
105 DDX_Check(pDX, IDC_STARTUP_FOLDER_SELECT, m_bShowSelectFolderOnStartup);
106 DDX_Check(pDX, IDC_CLOSE_WITH_OK, m_bCloseWithOK);
107 DDX_Control(pDX, IDC_LANGUAGE_LIST, m_ctlLangList);
112 BEGIN_MESSAGE_MAP(PropGeneral, CPropertyPage)
113 //{{AFX_MSG_MAP(PropGeneral)
114 ON_BN_CLICKED(IDC_RESET_ALL_MESSAGE_BOXES, OnResetAllMessageBoxes)
115 ON_MESSAGE(WM_APP, OnLoadLanguages)
121 * @brief Reads options values from storage to UI.
123 void PropGeneral::ReadOptions()
125 m_bScroll = GetOptionsMgr()->GetBool(OPT_SCROLL_TO_FIRST);
126 m_bSingleInstance = GetOptionsMgr()->GetBool(OPT_SINGLE_INSTANCE);
127 m_bVerifyPaths = GetOptionsMgr()->GetBool(OPT_VERIFY_OPEN_PATHS);
128 m_bCloseWindowWithEsc = GetOptionsMgr()->GetBool(OPT_CLOSE_WITH_ESC);
129 m_bAskMultiWindowClose = GetOptionsMgr()->GetBool(OPT_ASK_MULTIWINDOW_CLOSE);
130 m_nAutoCompleteSource = GetOptionsMgr()->GetInt(OPT_AUTO_COMPLETE_SOURCE);
131 m_bPreserveFiletime = GetOptionsMgr()->GetBool(OPT_PRESERVE_FILETIMES);
132 m_bShowSelectFolderOnStartup = GetOptionsMgr()->GetBool(OPT_SHOW_SELECT_FILES_AT_STARTUP);
133 m_bCloseWithOK = GetOptionsMgr()->GetBool(OPT_CLOSE_WITH_OK);
137 * @brief Writes options values from UI to storage.
139 void PropGeneral::WriteOptions()
141 GetOptionsMgr()->SaveOption(OPT_SCROLL_TO_FIRST, m_bScroll);
142 GetOptionsMgr()->SaveOption(OPT_SINGLE_INSTANCE, m_bSingleInstance);
143 GetOptionsMgr()->SaveOption(OPT_VERIFY_OPEN_PATHS, m_bVerifyPaths);
144 GetOptionsMgr()->SaveOption(OPT_CLOSE_WITH_ESC, m_bCloseWindowWithEsc);
145 GetOptionsMgr()->SaveOption(OPT_ASK_MULTIWINDOW_CLOSE, m_bAskMultiWindowClose);
146 GetOptionsMgr()->SaveOption(OPT_AUTO_COMPLETE_SOURCE, m_nAutoCompleteSource);
147 GetOptionsMgr()->SaveOption(OPT_PRESERVE_FILETIMES, m_bPreserveFiletime);
148 GetOptionsMgr()->SaveOption(OPT_SHOW_SELECT_FILES_AT_STARTUP, m_bShowSelectFolderOnStartup);
149 GetOptionsMgr()->SaveOption(OPT_CLOSE_WITH_OK, m_bCloseWithOK);
150 int index = m_ctlLangList.GetCurSel();
153 WORD lang = (WORD)m_ctlLangList.GetItemData(index);
154 GetOptionsMgr()->SaveOption(OPT_SELECTED_LANGUAGE, (int)lang);
159 * @brief Called when user wants to see all messageboxes again.
161 void PropGeneral::OnResetAllMessageBoxes()
163 CMessageBoxDialog::ResetMessageBoxes();
164 AfxMessageBox(_("All message boxes are now displayed again.").c_str(), MB_ICONINFORMATION);
167 UINT PropGeneral::LoadLanguagesThreadProc(void *pParam)
169 PropGeneral *pPropGeneral = reinterpret_cast<PropGeneral *>(pParam);
170 pPropGeneral->m_langs = theApp.m_pLangDlg->GetAvailableLanguages();
171 pPropGeneral->PostMessage(WM_APP);
175 LRESULT PropGeneral::OnLoadLanguages(WPARAM, LPARAM)
177 for (auto&& i : m_langs)
179 m_ctlLangList.AddString(i.second.c_str());
180 m_ctlLangList.SetItemData(m_ctlLangList.GetCount() - 1, i.first);
181 if (i.first == theApp.m_pLangDlg->GetLangId())
182 m_ctlLangList.SetCurSel(m_ctlLangList.GetCount() - 1);
184 m_ctlLangList.EnableWindow(TRUE);