OSDN Git Service

856ca802732b7c0669236c8baa0290bd461eac6c
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / FormatPatchDlg.cpp
1 // FormatPatch.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "FormatPatchDlg.h"\r
7 #include "git.h"\r
8 #include "BrowseFolder.h"\r
9 #include "LogDlg.h"\r
10 #include "BrowseRefsDlg.h"\r
11 // CFormatPatchDlg dialog\r
12 \r
13 IMPLEMENT_DYNAMIC(CFormatPatchDlg, CResizableStandAloneDialog)\r
14 \r
15 CFormatPatchDlg::CFormatPatchDlg(CWnd* pParent /*=NULL*/)\r
16         : CResizableStandAloneDialog(CFormatPatchDlg::IDD, pParent),\r
17         m_regSendMail(_T("Software\\TortoiseGit\\TortoiseProc\\FormatPatch\\SendMail"),0)\r
18 {\r
19         m_Num=1;\r
20         this->m_bSendMail = m_regSendMail;\r
21         this->m_Radio = IDC_RADIO_SINCE;\r
22 }\r
23 \r
24 CFormatPatchDlg::~CFormatPatchDlg()\r
25 {\r
26 }\r
27 \r
28 void CFormatPatchDlg::DoDataExchange(CDataExchange* pDX)\r
29 {\r
30         CDialog::DoDataExchange(pDX);\r
31         DDX_Control(pDX, IDC_COMBOBOXEX_DIR,    m_cDir);\r
32         DDX_Control(pDX, IDC_COMBOBOXEX_SINCE,  m_cSince);\r
33         DDX_Control(pDX, IDC_COMBOBOXEX_FROM,   m_cFrom);\r
34         DDX_Control(pDX, IDC_COMBOBOXEX_TO,             m_cTo);\r
35         DDX_Control(pDX, IDC_EDIT_NUM,                  m_cNum);\r
36 \r
37         DDX_Text(pDX,IDC_EDIT_NUM,m_Num);\r
38 \r
39         DDX_Text(pDX, IDC_COMBOBOXEX_DIR,       m_Dir);\r
40         DDX_Text(pDX, IDC_COMBOBOXEX_SINCE,     m_Since);\r
41         DDX_Text(pDX, IDC_COMBOBOXEX_FROM,      m_From);\r
42         DDX_Text(pDX, IDC_COMBOBOXEX_TO,        m_To);\r
43         \r
44         DDX_Check(pDX, IDC_CHECK_SENDMAIL, m_bSendMail);\r
45 }\r
46 \r
47 \r
48 BEGIN_MESSAGE_MAP(CFormatPatchDlg, CResizableStandAloneDialog)\r
49         ON_BN_CLICKED(IDC_BUTTON_DIR, &CFormatPatchDlg::OnBnClickedButtonDir)\r
50         ON_BN_CLICKED(IDC_BUTTON_FROM, &CFormatPatchDlg::OnBnClickedButtonFrom)\r
51         ON_BN_CLICKED(IDC_BUTTON_TO, &CFormatPatchDlg::OnBnClickedButtonTo)\r
52         ON_BN_CLICKED(IDOK, &CFormatPatchDlg::OnBnClickedOk)\r
53         ON_BN_CLICKED(IDC_RADIO_SINCE, &CFormatPatchDlg::OnBnClickedRadio)\r
54         ON_BN_CLICKED(IDC_RADIO_NUM, &CFormatPatchDlg::OnBnClickedRadio)\r
55         ON_BN_CLICKED(IDC_RADIO_RANGE, &CFormatPatchDlg::OnBnClickedRadio)\r
56         ON_BN_CLICKED(IDC_BUTTON_REF, &CFormatPatchDlg::OnBnClickedButtonRef)\r
57 END_MESSAGE_MAP()\r
58 \r
59 BOOL CFormatPatchDlg::OnInitDialog()\r
60 {\r
61         CResizableStandAloneDialog::OnInitDialog();\r
62         \r
63         AddAnchor(IDC_GROUP_DIR, TOP_LEFT, TOP_RIGHT);\r
64         AddAnchor(IDC_COMBOBOXEX_DIR,TOP_LEFT, TOP_RIGHT);\r
65         AddAnchor(IDC_BUTTON_DIR, TOP_RIGHT);\r
66 \r
67         AddAnchor(IDC_GROUP_VERSION, TOP_LEFT, TOP_RIGHT);\r
68         AddAnchor(IDC_COMBOBOXEX_SINCE, TOP_LEFT, TOP_RIGHT);\r
69         AddAnchor(IDC_EDIT_NUM, TOP_LEFT, TOP_RIGHT);\r
70         AddAnchor(IDC_SPIN_NUM, TOP_RIGHT);\r
71 \r
72         AddAnchor(IDC_COMBOBOXEX_FROM, TOP_LEFT, TOP_RIGHT);\r
73         AddAnchor(IDC_COMBOBOXEX_TO, TOP_LEFT, TOP_RIGHT);\r
74 \r
75         AddAnchor(IDC_BUTTON_FROM,  TOP_RIGHT);\r
76         AddAnchor(IDC_BUTTON_TO,        TOP_RIGHT);\r
77         AddAnchor(IDC_CHECK_SENDMAIL,BOTTOM_LEFT);\r
78         AddAnchor(IDOK,BOTTOM_RIGHT);\r
79         AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
80         AddAnchor(IDHELP, BOTTOM_RIGHT);\r
81 \r
82         this->AddOthersToAnchor();\r
83 \r
84         m_cDir.SetPathHistory(TRUE);\r
85         m_cDir.LoadHistory(_T("Software\\TortoiseGit\\History\\FormatPatchURLS"), _T("path"));\r
86         m_cDir.SetCurSel(0);\r
87 \r
88         STRING_VECTOR list;\r
89         g_Git.GetBranchList(list,NULL,CGit::BRANCH_ALL);\r
90         m_cSince.SetMaxHistoryItems(list.size());\r
91         m_cSince.AddString(list);\r
92 \r
93         if(!m_Since.IsEmpty())\r
94                 m_cSince.SetWindowText(m_Since);\r
95 \r
96         m_cFrom.LoadHistory(_T("Software\\TortoiseGit\\History\\FormatPatchFromURLS"), _T("ver"));\r
97         m_cFrom.SetCurSel(0);\r
98 \r
99         if(!m_From.IsEmpty())\r
100                 m_cFrom.SetWindowText(m_From);\r
101 \r
102         m_cTo.LoadHistory(_T("Software\\TortoiseGit\\History\\FormatPatchToURLS"), _T("ver"));\r
103         m_cTo.SetCurSel(0);\r
104 \r
105         if(!m_To.IsEmpty())\r
106                 m_cTo.SetWindowText(m_To);\r
107 \r
108         this->CheckRadioButton(IDC_RADIO_SINCE,IDC_RADIO_RANGE,this->m_Radio);\r
109         \r
110         OnBnClickedRadio();\r
111 \r
112         EnableSaveRestore(_T("FormatPatchDlg"));\r
113         return TRUE;\r
114 }\r
115 // CFormatPatchDlg message handlers\r
116 \r
117 void CFormatPatchDlg::OnBnClickedButtonDir()\r
118 {\r
119         // TODO: Add your control notification handler code here\r
120         CBrowseFolder browseFolder;\r
121         browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;\r
122         CString strCloneDirectory;\r
123         this->UpdateData(TRUE);\r
124         strCloneDirectory=m_Dir;\r
125         if (browseFolder.Show(GetSafeHwnd(), strCloneDirectory) == CBrowseFolder::OK) \r
126         {\r
127                 m_Dir=strCloneDirectory;\r
128                 this->UpdateData(FALSE);\r
129         }\r
130 }\r
131 \r
132 void CFormatPatchDlg::OnBnClickedButtonFrom()\r
133 {\r
134         CLogDlg dlg;\r
135         // tell the dialog to use mode for selecting revisions\r
136         dlg.SetSelect(true);\r
137         // only one revision must be selected however\r
138         dlg.SingleSelection(true);\r
139         if ( dlg.DoModal() == IDOK )\r
140         {\r
141                 // get selected hash if any\r
142                 CString selectedHash = dlg.GetSelectedHash();\r
143                 // load into window, do this even if empty so that it is clear that nothing has been selected\r
144                 m_cFrom.AddString(selectedHash);\r
145                 CheckRadioButton(IDC_RADIO_SINCE, IDC_RADIO_RANGE, IDC_RADIO_RANGE);\r
146                 OnBnClickedRadio();\r
147         }\r
148 }\r
149 \r
150 void CFormatPatchDlg::OnBnClickedButtonTo()\r
151 {\r
152         CLogDlg dlg;\r
153         // tell the dialog to use mode for selecting revisions\r
154         dlg.SetSelect(true);\r
155         // only one revision must be selected however\r
156         dlg.SingleSelection(true);\r
157         if ( dlg.DoModal() == IDOK )\r
158         {\r
159                 // get selected hash if any\r
160                 CString selectedHash = dlg.GetSelectedHash();\r
161                 // load into window, do this even if empty so that it is clear that nothing has been selected\r
162                 m_cTo.AddString(selectedHash);\r
163                 CheckRadioButton(IDC_RADIO_SINCE, IDC_RADIO_RANGE, IDC_RADIO_RANGE);\r
164                 OnBnClickedRadio();\r
165         }\r
166 }\r
167 \r
168 void CFormatPatchDlg::OnBnClickedOk()\r
169 {\r
170         // TODO: Add your control notification handler code here\r
171 \r
172         m_cDir.SaveHistory();\r
173         m_cFrom.SaveHistory();\r
174         m_cTo.SaveHistory();\r
175         this->UpdateData(TRUE);\r
176         this->m_Radio=GetCheckedRadioButton(IDC_RADIO_SINCE,IDC_RADIO_RANGE);\r
177 \r
178         m_regSendMail=this->m_bSendMail;\r
179         OnOK();\r
180 }\r
181 \r
182 void CFormatPatchDlg::OnBnClickedRadio()\r
183 {\r
184         // TODO: Add your control notification handler code here\r
185         int radio=this->GetCheckedRadioButton(IDC_RADIO_SINCE,IDC_RADIO_RANGE);\r
186         m_cSince.EnableWindow(FALSE);\r
187         m_cNum.EnableWindow(FALSE);\r
188         m_cFrom.EnableWindow(FALSE);\r
189         m_cTo.EnableWindow(FALSE);\r
190         switch(radio)\r
191         {\r
192         case IDC_RADIO_SINCE:\r
193                 m_cSince.EnableWindow(TRUE);\r
194                 break;\r
195         case IDC_RADIO_NUM:\r
196                 m_cNum.EnableWindow(TRUE);\r
197                 break;\r
198         case IDC_RADIO_RANGE:\r
199                 m_cFrom.EnableWindow(TRUE);\r
200                 m_cTo.EnableWindow(TRUE);\r
201         }\r
202 }\r
203 \r
204 void CFormatPatchDlg::OnBnClickedButtonRef()\r
205 {\r
206         if(CBrowseRefsDlg::PickRefForCombo(&m_cSince, gPickRef_NoTag))\r
207         {\r
208                 CheckRadioButton(IDC_RADIO_SINCE, IDC_RADIO_RANGE, IDC_RADIO_SINCE);\r
209                 OnBnClickedRadio();\r
210         }\r
211 }\r