OSDN Git Service

Plugins: Fix a crash on Window XP
[winmerge-jp/winmerge-jp.git] / Src / PropGeneral.cpp
index c1e55ef..06b815a 100644 (file)
@@ -2,21 +2,7 @@
 //    WinMerge:  an interactive diff/merge utility
 //    Copyright (C) 1997-2000  Thingamahoochie Software
 //    Author: Dean Grimm
-//
-//    This program is free software; you can redistribute it and/or modify
-//    it under the terms of the GNU General Public License as published by
-//    the Free Software Foundation; either version 2 of the License, or
-//    (at your option) any later version.
-//
-//    This program is distributed in the hope that it will be useful,
-//    but WITHOUT ANY WARRANTY; without even the implied warranty of
-//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//    GNU General Public License for more details.
-//
-//    You should have received a copy of the GNU General Public License
-//    along with this program; if not, write to the Free Software
-//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
+//    SPDX-License-Identifier: GPL-2.0-or-later
 /////////////////////////////////////////////////////////////////////////////
 /** 
  * @file  PropGeneral.h
 #include "OptionsMgr.h"
 #include "OptionsPanel.h"
 #include "LanguageSelect.h"
-#include "DDXHelper.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
 #endif
 
 /** 
  * @brief Constructor initialising members.
  */
 PropGeneral::PropGeneral(COptionsMgr *optionsMgr) 
-: OptionsPanel(optionsMgr, PropGeneral::IDD)
-, m_bScroll(false)
-, m_bSingleInstance(false)
-, m_bVerifyPaths(false)
-, m_bCloseWindowWithEsc(TRUE)
-, m_bAskMultiWindowClose(false)
-, m_nAutoCompleteSource(0)
-, m_bPreserveFiletime(false)
-, m_bShowSelectFolderOnStartup(false)
-, m_bCloseWithOK(true)
+       : OptionsPanel(optionsMgr, PropGeneral::IDD)
+       , m_bScroll(false)
+       , m_bScrollToFirstInlineDiff(false)
+       , m_nSingleInstance(0)
+       , m_bVerifyPaths(false)
+       , m_nCloseWindowWithEsc(1)
+       , m_bAskMultiWindowClose(false)
+       , m_nAutoCompleteSource(0)
+       , m_bPreserveFiletime(false)
+       , m_bShowSelectFolderOnStartup(false)
+       , m_bCloseWithOK(true)
 {
 }
 
@@ -63,28 +47,42 @@ PropGeneral::~PropGeneral()
 
 BOOL PropGeneral::OnInitDialog()
 {
-       theApp.TranslateDialog(m_hWnd);
-       CPropertyPage::OnInitDialog();
+       OptionsPanel::OnInitDialog();
 
        CComboBox *pWnd = (CComboBox*)GetDlgItem(IDC_AUTO_COMPLETE_SOURCE);
-       ASSERT(NULL != pWnd);
+       ASSERT(pWnd != nullptr);
 
        pWnd->AddString(_("Disabled").c_str());
        pWnd->AddString(_("From file system").c_str());
-       pWnd->AddString(_("From MRU list").c_str());
+       pWnd->AddString(_("From Most Recently Used list").c_str());
 
        pWnd->SetCurSel(m_nAutoCompleteSource);
 
-       m_ctlLangList.SetDroppedWidth(600);
+       pWnd = (CComboBox*)GetDlgItem(IDC_ESC_CLOSES_WINDOW);
+       ASSERT(pWnd != nullptr);
 
-       for (auto&& i : theApp.m_pLangDlg->GetAvailableLanguages())
-       {
-               m_ctlLangList.AddString(i.second.c_str());
-               m_ctlLangList.SetItemData(m_ctlLangList.GetCount() - 1, i.first);
-               if (i.first == theApp.m_pLangDlg->GetLangId())
-                       m_ctlLangList.SetCurSel(m_ctlLangList.GetCount() - 1);
-       }
+       pWnd->AddString(_("Disabled").c_str());
+       pWnd->AddString(_("MDI child window or main window").c_str());
+       pWnd->AddString(_("MDI child window only").c_str());
+
+       pWnd->SetCurSel(m_nCloseWindowWithEsc);
+
+       pWnd = (CComboBox*)GetDlgItem(IDC_SINGLE_INSTANCE);
+       ASSERT(pWnd != nullptr);
+
+       pWnd->AddString(_("Disabled").c_str());
+       pWnd->AddString(_("Allow only one instance to run").c_str());
+       pWnd->AddString(_("Allow only one instance to run and wait for the instance to terminate").c_str());
 
+       pWnd->SetCurSel(m_nSingleInstance);
+
+       m_ctlLangList.SetDroppedWidth(600);
+       m_ctlLangList.EnableWindow(FALSE);
+       m_asyncLanguagesLoader = Concurrent::CreateTask([hwnd = m_hWnd] {
+                       std::vector<std::pair<LANGID, String>> langs = theApp.m_pLangDlg->GetAvailableLanguages();
+                       ::PostMessage(hwnd, WM_APP, 0, 0);
+                       return langs;
+               });
        return TRUE;  // return TRUE  unless you set the focus to a control
 }
 
@@ -93,9 +91,10 @@ void PropGeneral::DoDataExchange(CDataExchange* pDX)
        CPropertyPage::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(PropGeneral)
        DDX_Check(pDX, IDC_SCROLL_CHECK, m_bScroll);
-       DDX_Check(pDX, IDC_SINGLE_INSTANCE, m_bSingleInstance);
+       DDX_Check(pDX, IDC_SCROLL_TO_FIRST_INLINE_DIFF_CHECK, m_bScrollToFirstInlineDiff);
+       DDX_CBIndex(pDX, IDC_SINGLE_INSTANCE, m_nSingleInstance);
        DDX_Check(pDX, IDC_VERIFY_OPEN_PATHS, m_bVerifyPaths);
-       DDX_Check(pDX, IDC_ESC_CLOSES_WINDOW, m_bCloseWindowWithEsc);
+       DDX_CBIndex(pDX, IDC_ESC_CLOSES_WINDOW, m_nCloseWindowWithEsc);
        DDX_Check(pDX, IDC_ASK_MULTIWINDOW_CLOSE, m_bAskMultiWindowClose);
        DDX_CBIndex(pDX, IDC_AUTO_COMPLETE_SOURCE, m_nAutoCompleteSource);
        DDX_Check(pDX, IDC_PRESERVE_FILETIME, m_bPreserveFiletime);
@@ -106,9 +105,10 @@ void PropGeneral::DoDataExchange(CDataExchange* pDX)
 }
 
 
-BEGIN_MESSAGE_MAP(PropGeneral, CPropertyPage)
+BEGIN_MESSAGE_MAP(PropGeneral, OptionsPanel)
        //{{AFX_MSG_MAP(PropGeneral)
        ON_BN_CLICKED(IDC_RESET_ALL_MESSAGE_BOXES, OnResetAllMessageBoxes)
+       ON_MESSAGE(WM_APP, OnLoadLanguages)
        //}}AFX_MSG_MAP
 END_MESSAGE_MAP()
 
@@ -118,9 +118,10 @@ END_MESSAGE_MAP()
 void PropGeneral::ReadOptions()
 {
        m_bScroll = GetOptionsMgr()->GetBool(OPT_SCROLL_TO_FIRST);
-       m_bSingleInstance = GetOptionsMgr()->GetBool(OPT_SINGLE_INSTANCE);
+       m_bScrollToFirstInlineDiff = GetOptionsMgr()->GetBool(OPT_SCROLL_TO_FIRST_INLINE_DIFF);
+       m_nSingleInstance = GetOptionsMgr()->GetInt(OPT_SINGLE_INSTANCE);
        m_bVerifyPaths = GetOptionsMgr()->GetBool(OPT_VERIFY_OPEN_PATHS);
-       m_bCloseWindowWithEsc = GetOptionsMgr()->GetBool(OPT_CLOSE_WITH_ESC);
+       m_nCloseWindowWithEsc = GetOptionsMgr()->GetInt(OPT_CLOSE_WITH_ESC);
        m_bAskMultiWindowClose = GetOptionsMgr()->GetBool(OPT_ASK_MULTIWINDOW_CLOSE);
        m_nAutoCompleteSource = GetOptionsMgr()->GetInt(OPT_AUTO_COMPLETE_SOURCE);
        m_bPreserveFiletime = GetOptionsMgr()->GetBool(OPT_PRESERVE_FILETIMES);
@@ -134,9 +135,10 @@ void PropGeneral::ReadOptions()
 void PropGeneral::WriteOptions()
 {
        GetOptionsMgr()->SaveOption(OPT_SCROLL_TO_FIRST, m_bScroll);
-       GetOptionsMgr()->SaveOption(OPT_SINGLE_INSTANCE, m_bSingleInstance);
+       GetOptionsMgr()->SaveOption(OPT_SCROLL_TO_FIRST_INLINE_DIFF, m_bScrollToFirstInlineDiff);
+       GetOptionsMgr()->SaveOption(OPT_SINGLE_INSTANCE, m_nSingleInstance);
        GetOptionsMgr()->SaveOption(OPT_VERIFY_OPEN_PATHS, m_bVerifyPaths);
-       GetOptionsMgr()->SaveOption(OPT_CLOSE_WITH_ESC, m_bCloseWindowWithEsc);
+       GetOptionsMgr()->SaveOption(OPT_CLOSE_WITH_ESC, m_nCloseWindowWithEsc);
        GetOptionsMgr()->SaveOption(OPT_ASK_MULTIWINDOW_CLOSE, m_bAskMultiWindowClose);
        GetOptionsMgr()->SaveOption(OPT_AUTO_COMPLETE_SOURCE, m_nAutoCompleteSource);
        GetOptionsMgr()->SaveOption(OPT_PRESERVE_FILETIMES, m_bPreserveFiletime);
@@ -156,5 +158,20 @@ void PropGeneral::WriteOptions()
 void PropGeneral::OnResetAllMessageBoxes()
 {
        CMessageBoxDialog::ResetMessageBoxes();
-       LangMessageBox(IDS_MESSAGE_BOX_ARE_RESET, MB_ICONINFORMATION);
+       // The "don't show again" checkbox of the Confirm Copy dialog uses the same registry key
+       // as CMessageBoxDialog does, so its state will also be reset
+       AfxMessageBox(_("All message boxes are now displayed again.").c_str(), MB_ICONINFORMATION);
+}
+
+LRESULT PropGeneral::OnLoadLanguages(WPARAM, LPARAM)
+{
+       for (auto&& i : m_asyncLanguagesLoader.Get())
+       {
+               m_ctlLangList.AddString(i.second.c_str());
+               m_ctlLangList.SetItemData(m_ctlLangList.GetCount() - 1, i.first);
+               if (i.first == theApp.m_pLangDlg->GetLangId())
+                       m_ctlLangList.SetCurSel(m_ctlLangList.GetCount() - 1);
+       }
+       m_ctlLangList.EnableWindow(TRUE);
+       return 0;
 }