1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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
.SetList(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 m_spinNum
.SetRange32(1, INT_MAX
);
142 this->CheckRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
,this->m_Radio
);
146 if (g_Git
.IsInitRepos())
147 DialogEnableWindow(IDOK
, FALSE
);
149 EnableSaveRestore(_T("FormatPatchDlg"));
152 // CFormatPatchDlg message handlers
154 void CFormatPatchDlg::OnBnClickedButtonDir()
156 CBrowseFolder browseFolder
;
157 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
158 CString strCloneDirectory
;
159 this->UpdateData(TRUE
);
160 strCloneDirectory
=m_Dir
;
161 if (browseFolder
.Show(GetSafeHwnd(), strCloneDirectory
) == CBrowseFolder::OK
)
163 m_Dir
=strCloneDirectory
;
164 this->UpdateData(FALSE
);
168 void CFormatPatchDlg::OnBnClickedButtonFrom()
172 m_cFrom
.GetWindowText(revision
);
173 dlg
.SetParams(CTGitPath(), CTGitPath(), revision
, revision
, 0);
174 // tell the dialog to use mode for selecting revisions
176 // only one revision must be selected however
177 dlg
.SingleSelection(true);
178 if ( dlg
.DoModal() == IDOK
)
180 // get selected hash if any
181 CString selectedHash
= dlg
.GetSelectedHash();
182 // load into window, do this even if empty so that it is clear that nothing has been selected
183 m_cFrom
.AddString(selectedHash
);
184 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_RANGE
);
189 void CFormatPatchDlg::OnBnClickedButtonTo()
193 m_cTo
.GetWindowText(revision
);
194 dlg
.SetParams(CTGitPath(), CTGitPath(), revision
, revision
, 0);
195 // tell the dialog to use mode for selecting revisions
197 // only one revision must be selected however
198 dlg
.SingleSelection(true);
199 if ( dlg
.DoModal() == IDOK
)
201 // get selected hash if any
202 CString selectedHash
= dlg
.GetSelectedHash();
203 // load into window, do this even if empty so that it is clear that nothing has been selected
204 m_cTo
.AddString(selectedHash
);
205 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_RANGE
);
210 void CFormatPatchDlg::OnBnClickedOk()
212 m_cDir
.SaveHistory();
213 m_cFrom
.SaveHistory();
215 this->UpdateData(TRUE
);
216 this->m_Radio
=GetCheckedRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
);
218 m_regSendMail
=this->m_bSendMail
;
222 void CFormatPatchDlg::OnBnClickedRadio()
224 int radio
=this->GetCheckedRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
);
225 m_cSince
.EnableWindow(FALSE
);
226 m_cNum
.EnableWindow(FALSE
);
227 m_cFrom
.EnableWindow(FALSE
);
228 m_cTo
.EnableWindow(FALSE
);
229 GetDlgItem(IDC_BUTTON_REF
)->EnableWindow(FALSE
);
230 GetDlgItem(IDC_BUTTON_FROM
)->EnableWindow(FALSE
);
231 GetDlgItem(IDC_BUTTON_TO
)->EnableWindow(FALSE
);
234 case IDC_RADIO_SINCE
:
235 m_cSince
.EnableWindow(TRUE
);
236 GetDlgItem(IDC_BUTTON_REF
)->EnableWindow(TRUE
);
239 m_cNum
.EnableWindow(TRUE
);
241 case IDC_RADIO_RANGE
:
242 m_cFrom
.EnableWindow(TRUE
);
243 m_cTo
.EnableWindow(TRUE
);
244 GetDlgItem(IDC_BUTTON_FROM
)->EnableWindow(TRUE
);
245 GetDlgItem(IDC_BUTTON_TO
)->EnableWindow(TRUE
);
250 void CFormatPatchDlg::OnBnClickedButtonRef()
252 if(CBrowseRefsDlg::PickRefForCombo(&m_cSince
, gPickRef_NoTag
))
254 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_SINCE
);
258 void CFormatPatchDlg::OnBnClickedButtonUnifieddiff()
260 CTGitPath commonDirectory
= CTGitPath(g_Git
.m_CurrentDir
);
261 CAppUtils::StartShowUnifiedDiff(m_hWnd
, commonDirectory
, GitRev::GetHead(), commonDirectory
, GitRev::GetWorkingCopy());