OSDN Git Service

Add Expand Different Subfolders menu item (#1964)
[winmerge-jp/winmerge-jp.git] / Src / DirSelectFilesDlg.cpp
1 /**
2  * @file  DirSelectFilesDlg.cpp
3  *
4  * @brief Implementation of the DirSelectFilesDlg dialog.
5  */
6
7 #include "stdafx.h"
8 #include "DirSelectFilesDlg.h"
9 #include "TrDialogs.h"
10
11 #ifdef _DEBUG
12 #define new DEBUG_NEW
13 #endif
14
15 class DirSelectFilesDlg::Impl : public CTrDialog
16 {
17 // Construction
18 public:
19         explicit Impl(DirSelectFilesDlg *p, CWnd* pParent = nullptr);   // standard constructor
20
21 // Dialog Data
22         //{{AFX_DATA(DirSelectFilesDlg)
23         enum { IDD = IDD_SELECT_FILES_OR_FOLDERS };
24         //}}AFX_DATA
25
26 // Overrides
27         // ClassWizard generated virtual function overrides
28         //{{AFX_VIRTUAL(DirSelectFilesDlg)
29         protected:
30         virtual BOOL OnInitDialog() override;
31         virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
32         //}}AFX_VIRTUAL
33
34 // Implementation
35 protected:
36
37         // Generated message map functions
38         //{{AFX_MSG(DirSelectFilesDlg)
39                 // NOTE: the ClassWizard will add member functions here
40         afx_msg void OnBnClicked(UINT id);
41         afx_msg void OnBnClickedResetButton();
42         //}}AFX_MSG
43         DECLARE_MESSAGE_MAP()
44
45 private:
46         void UpdateButtonCaptions();
47         DirSelectFilesDlg *m_p;
48 };
49
50 /////////////////////////////////////////////////////////////////////////////
51 // DirSelectFilesDlg dialog
52
53 /**
54  * @brief Constructor.
55  */
56 DirSelectFilesDlg::Impl::Impl(DirSelectFilesDlg *p, CWnd* pParent /*= nullptr*/)
57         : CTrDialog(DirSelectFilesDlg::Impl::IDD, pParent), m_p(p)
58 {
59 }
60
61 void DirSelectFilesDlg::Impl::DoDataExchange(CDataExchange* pDX)
62 {
63         CTrDialog::DoDataExchange(pDX);
64         //{{AFX_DATA_MAP(DirSelectFilesDlg)
65         //}}AFX_DATA_MAP
66 }
67
68 BEGIN_MESSAGE_MAP(DirSelectFilesDlg::Impl, CTrDialog)
69         //{{AFX_MSG_MAP(DirSelectFilesDlg::Impl)
70                 // NOTE: the ClassWizard will add message map macros here
71         ON_CONTROL_RANGE(BN_CLICKED, IDC_LEFT1, IDC_LEFT1 + 3 * 3, OnBnClicked)
72         ON_BN_CLICKED(IDC_RESET, OnBnClickedResetButton)
73         //}}AFX_MSG_MAP
74 END_MESSAGE_MAP()
75
76 /////////////////////////////////////////////////////////////////////////////
77 // DirSelectFilesDlg message handlers
78
79 BOOL DirSelectFilesDlg::Impl::OnInitDialog()
80 {
81         CenterWindow();
82         LangTranslateDialog(m_hWnd);
83         CDialog::OnInitDialog();
84         for (int i = 0; i < 3; ++i)
85         {
86                 if (m_p->m_pdi[i])
87                         SetDlgItemText(IDC_FIRST + i, m_p->m_pdi[i]->diffFileInfo[0].GetFile());
88                 for (int j = 0; j < 3; ++j)
89                         GetDlgItem(IDC_LEFT1 + i * 3 + j)->ShowWindow(m_p->m_pdi[i] && m_p->m_pdi[i]->diffcode.exists(j));
90         }
91         return true;
92 }
93
94 void DirSelectFilesDlg::Impl::OnBnClicked(UINT id)
95 {
96         std::vector<int>& selectedButtons = m_p->m_selectedButtons;
97         String text;
98         GetDlgItemText(id, text);
99         if (!text.empty())
100                 selectedButtons.erase(std::find(selectedButtons.begin(), selectedButtons.end(), static_cast<int>(id - IDC_LEFT1)));
101         else
102                 selectedButtons.push_back(id - IDC_LEFT1);
103         if (selectedButtons.size() > 3)
104                 selectedButtons.erase(selectedButtons.begin());
105         UpdateButtonCaptions();
106 }
107
108 void DirSelectFilesDlg::Impl::OnBnClickedResetButton()
109 {
110         m_p->m_selectedButtons.clear();
111         UpdateButtonCaptions();
112 }
113
114 void DirSelectFilesDlg::Impl::UpdateButtonCaptions()
115 {
116         for (int i = 0; i < 9; ++i)
117         {
118                 SetDlgItemText(IDC_LEFT1 + i, _T(""));
119         }
120         int c = 1;
121         for (int i: m_p->m_selectedButtons)
122         {
123                 SetDlgItemText(IDC_LEFT1 + i, strutils::to_str(c));
124                 ++c;
125         }
126 }
127
128 DirSelectFilesDlg::DirSelectFilesDlg() : m_pimpl(new DirSelectFilesDlg::Impl(this)) {}
129 DirSelectFilesDlg::~DirSelectFilesDlg() = default;
130 int DirSelectFilesDlg::DoModal() { return static_cast<int>(m_pimpl->DoModal()); }
131