1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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
)
78 ON_BN_CLICKED(IDC_BUTTON_UNIFIEDDIFF
, &CFormatPatchDlg::OnBnClickedButtonUnifieddiff
)
81 BOOL
CFormatPatchDlg::OnInitDialog()
83 CHorizontalResizableStandAloneDialog::OnInitDialog();
84 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
86 AddAnchor(IDC_GROUP_DIR
, TOP_LEFT
, TOP_RIGHT
);
87 AddAnchor(IDC_COMBOBOXEX_DIR
,TOP_LEFT
, TOP_RIGHT
);
88 AddAnchor(IDC_BUTTON_DIR
, TOP_RIGHT
);
90 AddAnchor(IDC_GROUP_VERSION
, TOP_LEFT
, TOP_RIGHT
);
91 AddAnchor(IDC_COMBOBOXEX_SINCE
, TOP_LEFT
, TOP_RIGHT
);
92 AddAnchor(IDC_EDIT_NUM
, TOP_LEFT
, TOP_RIGHT
);
93 AddAnchor(IDC_SPIN_NUM
, TOP_RIGHT
);
95 AddAnchor(IDC_COMBOBOXEX_FROM
, TOP_LEFT
, TOP_RIGHT
);
96 AddAnchor(IDC_COMBOBOXEX_TO
, TOP_LEFT
, TOP_RIGHT
);
98 AddAnchor(IDC_BUTTON_FROM
, TOP_RIGHT
);
99 AddAnchor(IDC_BUTTON_TO
, TOP_RIGHT
);
100 AddAnchor(IDC_CHECK_SENDMAIL
,BOTTOM_LEFT
);
101 AddAnchor(IDOK
,BOTTOM_RIGHT
);
102 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
103 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
104 AddAnchor(IDC_BUTTON_REF
,TOP_RIGHT
);
106 AdjustControlSize(IDC_RADIO_SINCE
);
107 AdjustControlSize(IDC_RADIO_NUM
);
108 AdjustControlSize(IDC_RADIO_RANGE
);
109 AdjustControlSize(IDC_CHECK_SENDMAIL
);
111 this->AddOthersToAnchor();
113 CString sWindowTitle
;
114 GetWindowText(sWindowTitle
);
115 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
117 m_cDir
.SetPathHistory(TRUE
);
118 m_cDir
.LoadHistory(_T("Software\\TortoiseGit\\History\\FormatPatchURLS"), _T("path"));
119 m_cDir
.AddString(g_Git
.m_CurrentDir
);
122 g_Git
.GetBranchList(list
,NULL
,CGit::BRANCH_ALL_F
);
123 m_cSince
.SetMaxHistoryItems((int)list
.size());
124 m_cSince
.AddString(list
);
126 if(!m_Since
.IsEmpty())
127 m_cSince
.SetWindowText(m_Since
);
129 m_cFrom
.LoadHistory(_T("Software\\TortoiseGit\\History\\FormatPatchFromURLS"), _T("ver"));
130 m_cFrom
.SetCurSel(0);
132 if(!m_From
.IsEmpty())
133 m_cFrom
.SetWindowText(m_From
);
135 m_cTo
.LoadHistory(_T("Software\\TortoiseGit\\History\\FormatPatchToURLS"), _T("ver"));
139 m_cTo
.SetWindowText(m_To
);
141 this->CheckRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
,this->m_Radio
);
145 m_spinNum
.SetRange32(1, MAXSHORT
);
147 EnableSaveRestore(_T("FormatPatchDlg"));
150 // CFormatPatchDlg message handlers
152 void CFormatPatchDlg::OnBnClickedButtonDir()
154 CBrowseFolder browseFolder
;
155 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
156 CString strCloneDirectory
;
157 this->UpdateData(TRUE
);
158 strCloneDirectory
=m_Dir
;
159 if (browseFolder
.Show(GetSafeHwnd(), strCloneDirectory
) == CBrowseFolder::OK
)
161 m_Dir
=strCloneDirectory
;
162 this->UpdateData(FALSE
);
166 void CFormatPatchDlg::OnBnClickedButtonFrom()
169 // tell the dialog to use mode for selecting revisions
171 // only one revision must be selected however
172 dlg
.SingleSelection(true);
173 if ( dlg
.DoModal() == IDOK
)
175 // get selected hash if any
176 CString selectedHash
= dlg
.GetSelectedHash();
177 // load into window, do this even if empty so that it is clear that nothing has been selected
178 m_cFrom
.AddString(selectedHash
);
179 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_RANGE
);
184 void CFormatPatchDlg::OnBnClickedButtonTo()
187 // tell the dialog to use mode for selecting revisions
189 // only one revision must be selected however
190 dlg
.SingleSelection(true);
191 if ( dlg
.DoModal() == IDOK
)
193 // get selected hash if any
194 CString selectedHash
= dlg
.GetSelectedHash();
195 // load into window, do this even if empty so that it is clear that nothing has been selected
196 m_cTo
.AddString(selectedHash
);
197 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_RANGE
);
202 void CFormatPatchDlg::OnBnClickedOk()
204 m_cDir
.SaveHistory();
205 m_cFrom
.SaveHistory();
207 this->UpdateData(TRUE
);
208 this->m_Radio
=GetCheckedRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
);
210 m_regSendMail
=this->m_bSendMail
;
214 void CFormatPatchDlg::OnBnClickedRadio()
216 int radio
=this->GetCheckedRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
);
217 m_cSince
.EnableWindow(FALSE
);
218 m_cNum
.EnableWindow(FALSE
);
219 m_cFrom
.EnableWindow(FALSE
);
220 m_cTo
.EnableWindow(FALSE
);
221 GetDlgItem(IDC_BUTTON_REF
)->EnableWindow(FALSE
);
222 GetDlgItem(IDC_BUTTON_FROM
)->EnableWindow(FALSE
);
223 GetDlgItem(IDC_BUTTON_TO
)->EnableWindow(FALSE
);
226 case IDC_RADIO_SINCE
:
227 m_cSince
.EnableWindow(TRUE
);
228 GetDlgItem(IDC_BUTTON_REF
)->EnableWindow(TRUE
);
231 m_cNum
.EnableWindow(TRUE
);
233 case IDC_RADIO_RANGE
:
234 m_cFrom
.EnableWindow(TRUE
);
235 m_cTo
.EnableWindow(TRUE
);
236 GetDlgItem(IDC_BUTTON_FROM
)->EnableWindow(TRUE
);
237 GetDlgItem(IDC_BUTTON_TO
)->EnableWindow(TRUE
);
242 void CFormatPatchDlg::OnBnClickedButtonRef()
244 if(CBrowseRefsDlg::PickRefForCombo(&m_cSince
, gPickRef_NoTag
))
246 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_SINCE
);
250 void CFormatPatchDlg::OnBnClickedButtonUnifieddiff()
252 CTGitPath commonDirectory
= CTGitPath(g_Git
.m_CurrentDir
);
253 CAppUtils::StartShowUnifiedDiff(m_hWnd
, commonDirectory
, GitRev::GetHead(), commonDirectory
, GitRev::GetWorkingCopy());