1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // FormatPatch.cpp : implementation file
23 #include "TortoiseProc.h"
24 #include "FormatPatchDlg.h"
26 #include "BrowseFolder.h"
28 #include "BrowseRefsDlg.h"
31 // CFormatPatchDlg dialog
33 IMPLEMENT_DYNAMIC(CFormatPatchDlg
, CHorizontalResizableStandAloneDialog
)
35 CFormatPatchDlg::CFormatPatchDlg(CWnd
* pParent
/*=NULL*/)
36 : CHorizontalResizableStandAloneDialog(CFormatPatchDlg::IDD
, pParent
),
37 m_regSendMail(_T("Software\\TortoiseGit\\TortoiseProc\\FormatPatch\\SendMail"),0)
40 this->m_bSendMail
= m_regSendMail
;
41 this->m_Radio
= IDC_RADIO_SINCE
;
44 CFormatPatchDlg::~CFormatPatchDlg()
48 void CFormatPatchDlg::DoDataExchange(CDataExchange
* pDX
)
50 CDialog::DoDataExchange(pDX
);
51 DDX_Control(pDX
, IDC_COMBOBOXEX_DIR
, m_cDir
);
52 DDX_Control(pDX
, IDC_COMBOBOXEX_SINCE
, m_cSince
);
53 DDX_Control(pDX
, IDC_COMBOBOXEX_FROM
, m_cFrom
);
54 DDX_Control(pDX
, IDC_COMBOBOXEX_TO
, m_cTo
);
55 DDX_Control(pDX
, IDC_EDIT_NUM
, m_cNum
);
56 DDX_Control(pDX
, IDC_SPIN_NUM
, m_spinNum
);
58 DDX_Text(pDX
,IDC_EDIT_NUM
,m_Num
);
60 DDX_Text(pDX
, IDC_COMBOBOXEX_DIR
, m_Dir
);
61 DDX_Text(pDX
, IDC_COMBOBOXEX_SINCE
, m_Since
);
62 DDX_Text(pDX
, IDC_COMBOBOXEX_FROM
, m_From
);
63 DDX_Text(pDX
, IDC_COMBOBOXEX_TO
, m_To
);
65 DDX_Check(pDX
, IDC_CHECK_SENDMAIL
, m_bSendMail
);
69 BEGIN_MESSAGE_MAP(CFormatPatchDlg
, CHorizontalResizableStandAloneDialog
)
70 ON_BN_CLICKED(IDC_BUTTON_DIR
, &CFormatPatchDlg::OnBnClickedButtonDir
)
71 ON_BN_CLICKED(IDC_BUTTON_FROM
, &CFormatPatchDlg::OnBnClickedButtonFrom
)
72 ON_BN_CLICKED(IDC_BUTTON_TO
, &CFormatPatchDlg::OnBnClickedButtonTo
)
73 ON_BN_CLICKED(IDOK
, &CFormatPatchDlg::OnBnClickedOk
)
74 ON_BN_CLICKED(IDC_RADIO_SINCE
, &CFormatPatchDlg::OnBnClickedRadio
)
75 ON_BN_CLICKED(IDC_RADIO_NUM
, &CFormatPatchDlg::OnBnClickedRadio
)
76 ON_BN_CLICKED(IDC_RADIO_RANGE
, &CFormatPatchDlg::OnBnClickedRadio
)
77 ON_BN_CLICKED(IDC_BUTTON_REF
, &CFormatPatchDlg::OnBnClickedButtonRef
)
80 BOOL
CFormatPatchDlg::OnInitDialog()
82 CHorizontalResizableStandAloneDialog::OnInitDialog();
83 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
85 AddAnchor(IDC_GROUP_DIR
, TOP_LEFT
, TOP_RIGHT
);
86 AddAnchor(IDC_COMBOBOXEX_DIR
,TOP_LEFT
, TOP_RIGHT
);
87 AddAnchor(IDC_BUTTON_DIR
, TOP_RIGHT
);
89 AddAnchor(IDC_GROUP_VERSION
, TOP_LEFT
, TOP_RIGHT
);
90 AddAnchor(IDC_COMBOBOXEX_SINCE
, TOP_LEFT
, TOP_RIGHT
);
91 AddAnchor(IDC_EDIT_NUM
, TOP_LEFT
, TOP_RIGHT
);
92 AddAnchor(IDC_SPIN_NUM
, TOP_RIGHT
);
94 AddAnchor(IDC_COMBOBOXEX_FROM
, TOP_LEFT
, TOP_RIGHT
);
95 AddAnchor(IDC_COMBOBOXEX_TO
, TOP_LEFT
, TOP_RIGHT
);
97 AddAnchor(IDC_BUTTON_FROM
, TOP_RIGHT
);
98 AddAnchor(IDC_BUTTON_TO
, TOP_RIGHT
);
99 AddAnchor(IDC_CHECK_SENDMAIL
,BOTTOM_LEFT
);
100 AddAnchor(IDOK
,BOTTOM_RIGHT
);
101 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
102 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
103 AddAnchor(IDC_BUTTON_REF
,TOP_RIGHT
);
105 this->AddOthersToAnchor();
107 CString sWindowTitle
;
108 GetWindowText(sWindowTitle
);
109 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
111 m_cDir
.SetPathHistory(TRUE
);
112 m_cDir
.LoadHistory(_T("Software\\TortoiseGit\\History\\FormatPatchURLS"), _T("path"));
113 m_cDir
.AddString(g_Git
.m_CurrentDir
);
116 g_Git
.GetBranchList(list
,NULL
,CGit::BRANCH_ALL_F
);
117 m_cSince
.SetMaxHistoryItems(list
.size());
118 m_cSince
.AddString(list
);
120 if(!m_Since
.IsEmpty())
121 m_cSince
.SetWindowText(m_Since
);
123 m_cFrom
.LoadHistory(_T("Software\\TortoiseGit\\History\\FormatPatchFromURLS"), _T("ver"));
124 m_cFrom
.SetCurSel(0);
126 if(!m_From
.IsEmpty())
127 m_cFrom
.SetWindowText(m_From
);
129 m_cTo
.LoadHistory(_T("Software\\TortoiseGit\\History\\FormatPatchToURLS"), _T("ver"));
133 m_cTo
.SetWindowText(m_To
);
135 this->CheckRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
,this->m_Radio
);
139 m_spinNum
.SetRange32(1, MAXSHORT
);
141 EnableSaveRestore(_T("FormatPatchDlg"));
144 // CFormatPatchDlg message handlers
146 void CFormatPatchDlg::OnBnClickedButtonDir()
148 CBrowseFolder browseFolder
;
149 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
150 CString strCloneDirectory
;
151 this->UpdateData(TRUE
);
152 strCloneDirectory
=m_Dir
;
153 if (browseFolder
.Show(GetSafeHwnd(), strCloneDirectory
) == CBrowseFolder::OK
)
155 m_Dir
=strCloneDirectory
;
156 this->UpdateData(FALSE
);
160 void CFormatPatchDlg::OnBnClickedButtonFrom()
163 // tell the dialog to use mode for selecting revisions
165 // only one revision must be selected however
166 dlg
.SingleSelection(true);
167 if ( dlg
.DoModal() == IDOK
)
169 // get selected hash if any
170 CString selectedHash
= dlg
.GetSelectedHash();
171 // load into window, do this even if empty so that it is clear that nothing has been selected
172 m_cFrom
.AddString(selectedHash
);
173 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_RANGE
);
178 void CFormatPatchDlg::OnBnClickedButtonTo()
181 // tell the dialog to use mode for selecting revisions
183 // only one revision must be selected however
184 dlg
.SingleSelection(true);
185 if ( dlg
.DoModal() == IDOK
)
187 // get selected hash if any
188 CString selectedHash
= dlg
.GetSelectedHash();
189 // load into window, do this even if empty so that it is clear that nothing has been selected
190 m_cTo
.AddString(selectedHash
);
191 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_RANGE
);
196 void CFormatPatchDlg::OnBnClickedOk()
198 m_cDir
.SaveHistory();
199 m_cFrom
.SaveHistory();
201 this->UpdateData(TRUE
);
202 this->m_Radio
=GetCheckedRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
);
204 m_regSendMail
=this->m_bSendMail
;
208 void CFormatPatchDlg::OnBnClickedRadio()
210 int radio
=this->GetCheckedRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
);
211 m_cSince
.EnableWindow(FALSE
);
212 m_cNum
.EnableWindow(FALSE
);
213 m_cFrom
.EnableWindow(FALSE
);
214 m_cTo
.EnableWindow(FALSE
);
215 GetDlgItem(IDC_BUTTON_REF
)->EnableWindow(FALSE
);
216 GetDlgItem(IDC_BUTTON_FROM
)->EnableWindow(FALSE
);
217 GetDlgItem(IDC_BUTTON_TO
)->EnableWindow(FALSE
);
220 case IDC_RADIO_SINCE
:
221 m_cSince
.EnableWindow(TRUE
);
222 GetDlgItem(IDC_BUTTON_REF
)->EnableWindow(TRUE
);
225 m_cNum
.EnableWindow(TRUE
);
227 case IDC_RADIO_RANGE
:
228 m_cFrom
.EnableWindow(TRUE
);
229 m_cTo
.EnableWindow(TRUE
);
230 GetDlgItem(IDC_BUTTON_FROM
)->EnableWindow(TRUE
);
231 GetDlgItem(IDC_BUTTON_TO
)->EnableWindow(TRUE
);
236 void CFormatPatchDlg::OnBnClickedButtonRef()
238 if(CBrowseRefsDlg::PickRefForCombo(&m_cSince
, gPickRef_NoTag
))
240 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_SINCE
);