OSDN Git Service

Plugins: Fix a crash on Window XP
[winmerge-jp/winmerge-jp.git] / Src / ConfirmFolderCopyDlg.cpp
index ba884fb..06480de 100644 (file)
@@ -1,43 +1,24 @@
-/////////////////////////////////////////////////////////////////////////////
-//    License (GPLv2+):
-//    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  ConfirmFolderCopyDlg.cpp
  *
  * @brief Implementation file for ConfirmFolderCopyDlg dialog
  */
-// ID line follows -- this is updated by SVN
-// $Id$
 
 #include "stdafx.h"
-#include "Merge.h"
 #include "ConfirmFolderCopyDlg.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
 #endif
 
 
 // ConfirmFolderCopyDlg dialog
 
-IMPLEMENT_DYNAMIC(ConfirmFolderCopyDlg, CDialog)
-ConfirmFolderCopyDlg::ConfirmFolderCopyDlg(CWnd* pParent /*=NULL*/)
-       : CDialog(ConfirmFolderCopyDlg::IDD, pParent)
+IMPLEMENT_DYNAMIC(ConfirmFolderCopyDlg, CTrDialog)
+ConfirmFolderCopyDlg::ConfirmFolderCopyDlg(CWnd* pParent /*= nullptr*/)
+       : CTrDialog(ConfirmFolderCopyDlg::IDD, pParent)
+       , m_dontAskAgain(false)
 {
 }
 
@@ -47,20 +28,22 @@ ConfirmFolderCopyDlg::~ConfirmFolderCopyDlg()
 
 void ConfirmFolderCopyDlg::DoDataExchange(CDataExchange* pDX)
 {
-       CDialog::DoDataExchange(pDX);
+       CTrDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(ConfirmFolderCopyDlg)
        DDX_Text(pDX, IDC_FLDCONFIRM_FROM_TEXT, m_fromText);
        DDX_Text(pDX, IDC_FLDCONFIRM_TO_TEXT, m_toText);
        DDX_Text(pDX, IDC_FLDCONFIRM_FROM_PATH, m_fromPath);
        DDX_Text(pDX, IDC_FLDCONFIRM_TO_PATH, m_toPath);
        DDX_Text(pDX, IDC_FLDCONFIRM_QUERY, m_question);
+       DDX_Check(pDX, IDC_FLDCONFIRM_DONTASKAGAIN, m_dontAskAgain);
        //}}AFX_DATA_MAP
 }
 
 
-BEGIN_MESSAGE_MAP(ConfirmFolderCopyDlg, CDialog)
+BEGIN_MESSAGE_MAP(ConfirmFolderCopyDlg, CTrDialog)
        ON_BN_CLICKED(IDNO, OnBnClickedNo)
        ON_BN_CLICKED(IDYES, OnBnClickedYes)
+       ON_BN_CLICKED(IDC_FLDCONFIRM_DONTASKAGAIN, OnBnClickedDontAskAgain)
 END_MESSAGE_MAP()
 
 
@@ -72,30 +55,34 @@ END_MESSAGE_MAP()
  */
 BOOL ConfirmFolderCopyDlg::OnInitDialog() 
 {
-       theApp.TranslateDialog(m_hWnd);
-       CDialog::OnInitDialog();
-
-       // Load warning icon
-       // TODO: we can have per-action icons?
-       HICON icon = AfxGetApp()->LoadStandardIcon(IDI_EXCLAMATION);
-       CStatic * pIcon = (CStatic *) GetDlgItem(IDC_FLDCONFIRM_ICON);
-       pIcon->SetIcon(icon);
-
-       // setup handler for resizing this dialog       
-       m_constraint.InitializeCurrentSize(this);
-       // configure how individual controls adjust when dialog resizes
-       m_constraint.ConstrainItem(IDC_FLDCONFIRM_FROM_PATH, 0, 1, 0, 0); // grows right
-       m_constraint.ConstrainItem(IDC_FLDCONFIRM_TO_PATH, 0, 1, 0, 0); // grows right
-       // IDC_SAVECLOSING_DISCARDALL doesn't move
-       m_constraint.ConstrainItem(IDYES, 1, 0, 0, 0); // slides right
-       m_constraint.ConstrainItem(IDNO, 1, 0, 0, 0); // slides right
-       m_constraint.DisallowHeightGrowth();
-       m_constraint.SubclassWnd(); // install subclassing
-       // persist size via registry
-       m_constraint.LoadPosition(_T("ResizeableDialogs"), _T("FolderCopyConfirmDlg"), false);
+       CTrDialog::OnInitDialog();
+
+       UINT storedDecision = AfxGetApp()->GetProfileInt(REGISTRY_SECTION_MESSAGEBOX, _T("FolderCopyConfirmDlgDontAskAgain"), IDNO);
+       if (storedDecision == IDYES)
+               EndDialog(IDYES);
+       else
+       {
+               // Load warning icon
+               // TODO: we can have per-action icons?
+               HICON icon = AfxGetApp()->LoadStandardIcon(IDI_EXCLAMATION);
+               SendDlgItemMessage(IDC_FLDCONFIRM_ICON, STM_SETICON, (WPARAM)icon, 0L);
+
+               if (!m_caption.empty())
+                       SetWindowText(m_caption.c_str());
+
+               // setup handler for resizing this dialog       
+               m_constraint.InitializeCurrentSize(this);
+               m_constraint.DisallowHeightGrowth();
+               m_constraint.SubclassWnd(); // install subclassing
+               // persist size via registry
+               m_constraint.LoadPosition(_T("ResizeableDialogs"), _T("FolderCopyConfirmDlg"), false);
+
+               String strDontAskAgain = LoadResString(IDS_MESSAGEBOX_DONT_ASK_AGAIN);
+               GetDlgItem(IDC_FLDCONFIRM_DONTASKAGAIN)->SetWindowText(strDontAskAgain.c_str());
+       }
 
        return TRUE;  // return TRUE unless you set the focus to a control
-                     // EXCEPTION: OCX Property Pages should return FALSE
+                                 // EXCEPTION: OCX Property Pages should return FALSE
 }
 
 /**
@@ -113,3 +100,17 @@ void ConfirmFolderCopyDlg::OnBnClickedYes()
 {
        EndDialog(IDYES);
 }
+
+/**
+ * @brief Handle the "Don't ask again" checkbox, writing to the same registry key used by CMessageBoxDialog. 
+ * It doesn't use its algorithm for generating a value name, but it doesn't matter, since it won't collide
+ * with a value generated by CMessageBoxDialog and will also be reset by the Reset button in the Options dialog.
+ */
+void ConfirmFolderCopyDlg::OnBnClickedDontAskAgain()
+{
+       UpdateData();
+       if (m_dontAskAgain)
+               AfxGetApp()->WriteProfileInt(REGISTRY_SECTION_MESSAGEBOX, _T("FolderCopyConfirmDlgDontAskAgain"), IDYES);
+       else
+               AfxGetApp()->WriteProfileInt(REGISTRY_SECTION_MESSAGEBOX, _T("FolderCopyConfirmDlgDontAskAgain"), IDNO);
+}