1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014, 2016-2017 - 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
/*=nullptr*/)
36 : CHorizontalResizableStandAloneDialog(CFormatPatchDlg::IDD
, pParent
)
37 , m_regSendMail(L
"Software\\TortoiseGit\\TortoiseProc\\FormatPatch\\SendMail", 0)
38 , m_regNoPrefix(L
"Software\\TortoiseGit\\TortoiseProc\\FormatPatch\\NoPrefix", FALSE
)
41 this->m_bSendMail
= m_regSendMail
;
42 this->m_Radio
= IDC_RADIO_SINCE
;
43 m_bNoPrefix
= m_regNoPrefix
;
45 CString workingDir
= g_Git
.m_CurrentDir
;
46 workingDir
.Replace(L
':', L
'_');
47 m_regSince
= CRegString(L
"Software\\TortoiseGit\\History\\FormatPatch\\" + workingDir
+ L
"\\Since");
50 CFormatPatchDlg::~CFormatPatchDlg()
54 void CFormatPatchDlg::DoDataExchange(CDataExchange
* pDX
)
56 CDialog::DoDataExchange(pDX
);
57 DDX_Control(pDX
, IDC_COMBOBOXEX_DIR
, m_cDir
);
58 DDX_Control(pDX
, IDC_COMBOBOXEX_SINCE
, m_cSince
);
59 DDX_Control(pDX
, IDC_COMBOBOXEX_FROM
, m_cFrom
);
60 DDX_Control(pDX
, IDC_COMBOBOXEX_TO
, m_cTo
);
61 DDX_Control(pDX
, IDC_EDIT_NUM
, m_cNum
);
62 DDX_Control(pDX
, IDC_SPIN_NUM
, m_spinNum
);
64 DDX_Text(pDX
,IDC_EDIT_NUM
,m_Num
);
66 DDX_Text(pDX
, IDC_COMBOBOXEX_DIR
, m_Dir
);
67 DDX_Text(pDX
, IDC_COMBOBOXEX_SINCE
, m_Since
);
68 DDX_Text(pDX
, IDC_COMBOBOXEX_FROM
, m_From
);
69 DDX_Text(pDX
, IDC_COMBOBOXEX_TO
, m_To
);
71 DDX_Check(pDX
, IDC_CHECK_SENDMAIL
, m_bSendMail
);
72 DDX_Check(pDX
, IDC_CHECK_NOPREFIX
, m_bNoPrefix
);
76 BEGIN_MESSAGE_MAP(CFormatPatchDlg
, CHorizontalResizableStandAloneDialog
)
77 ON_BN_CLICKED(IDC_BUTTON_DIR
, &CFormatPatchDlg::OnBnClickedButtonDir
)
78 ON_BN_CLICKED(IDC_BUTTON_FROM
, &CFormatPatchDlg::OnBnClickedButtonFrom
)
79 ON_BN_CLICKED(IDC_BUTTON_TO
, &CFormatPatchDlg::OnBnClickedButtonTo
)
80 ON_BN_CLICKED(IDOK
, &CFormatPatchDlg::OnBnClickedOk
)
81 ON_BN_CLICKED(IDC_RADIO_SINCE
, &CFormatPatchDlg::OnBnClickedRadio
)
82 ON_BN_CLICKED(IDC_RADIO_NUM
, &CFormatPatchDlg::OnBnClickedRadio
)
83 ON_BN_CLICKED(IDC_RADIO_RANGE
, &CFormatPatchDlg::OnBnClickedRadio
)
84 ON_BN_CLICKED(IDC_BUTTON_REF
, &CFormatPatchDlg::OnBnClickedButtonRef
)
85 ON_BN_CLICKED(IDC_BUTTON_UNIFIEDDIFF
, &CFormatPatchDlg::OnBnClickedButtonUnifieddiff
)
88 BOOL
CFormatPatchDlg::OnInitDialog()
90 CHorizontalResizableStandAloneDialog::OnInitDialog();
91 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
93 AdjustControlSize(IDC_RADIO_SINCE
);
94 AdjustControlSize(IDC_RADIO_NUM
);
95 AdjustControlSize(IDC_RADIO_RANGE
);
96 AdjustControlSize(IDC_CHECK_SENDMAIL
);
97 AdjustControlSize(IDC_CHECK_NOPREFIX
);
99 AddAnchor(IDC_GROUP_DIR
, TOP_LEFT
, TOP_RIGHT
);
100 AddAnchor(IDC_COMBOBOXEX_DIR
,TOP_LEFT
, TOP_RIGHT
);
101 AddAnchor(IDC_BUTTON_DIR
, TOP_RIGHT
);
103 AddAnchor(IDC_GROUP_VERSION
, TOP_LEFT
, TOP_RIGHT
);
104 AddAnchor(IDC_COMBOBOXEX_SINCE
, TOP_LEFT
, TOP_RIGHT
);
105 AddAnchor(IDC_EDIT_NUM
, TOP_LEFT
, TOP_RIGHT
);
106 AddAnchor(IDC_SPIN_NUM
, TOP_RIGHT
);
108 AddAnchor(IDC_COMBOBOXEX_FROM
, TOP_LEFT
, TOP_RIGHT
);
109 AddAnchor(IDC_COMBOBOXEX_TO
, TOP_LEFT
, TOP_RIGHT
);
111 AddAnchor(IDC_BUTTON_FROM
, TOP_RIGHT
);
112 AddAnchor(IDC_BUTTON_TO
, TOP_RIGHT
);
113 AddAnchor(IDC_CHECK_SENDMAIL
,BOTTOM_LEFT
);
114 AddAnchor(IDC_CHECK_NOPREFIX
, BOTTOM_LEFT
);
115 AddAnchor(IDOK
,BOTTOM_RIGHT
);
116 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
117 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
118 AddAnchor(IDC_BUTTON_REF
,TOP_RIGHT
);
120 this->AddOthersToAnchor();
122 CString sWindowTitle
;
123 GetWindowText(sWindowTitle
);
124 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
126 m_cDir
.SetPathHistory(TRUE
);
127 m_cDir
.LoadHistory(L
"Software\\TortoiseGit\\History\\FormatPatchURLS", L
"path");
128 m_cDir
.AddString(g_Git
.m_CurrentDir
);
131 g_Git
.GetBranchList(list
, nullptr, CGit::BRANCH_ALL_F
);
132 m_cSince
.SetMaxHistoryItems((int)list
.size());
133 m_cSince
.SetList(list
);
135 if (!m_Since
.IsEmpty())
136 m_cSince
.SetWindowText(m_Since
);
138 m_cSince
.SetWindowText((CString
)m_regSince
);
140 m_cFrom
.LoadHistory(L
"Software\\TortoiseGit\\History\\FormatPatchFromURLS", L
"ver");
141 m_cFrom
.SetCurSel(0);
143 if(!m_From
.IsEmpty())
144 m_cFrom
.SetWindowText(m_From
);
146 m_cTo
.LoadHistory(L
"Software\\TortoiseGit\\History\\FormatPatchToURLS", L
"ver");
150 m_cTo
.SetWindowText(m_To
);
152 m_spinNum
.SetRange32(1, INT_MAX
);
153 this->CheckRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
,this->m_Radio
);
157 if (g_Git
.IsInitRepos())
158 DialogEnableWindow(IDOK
, FALSE
);
160 EnableSaveRestore(L
"FormatPatchDlg");
163 // CFormatPatchDlg message handlers
165 void CFormatPatchDlg::OnBnClickedButtonDir()
167 CBrowseFolder browseFolder
;
168 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
169 CString strCloneDirectory
;
170 this->UpdateData(TRUE
);
171 strCloneDirectory
=m_Dir
;
172 if (browseFolder
.Show(GetSafeHwnd(), strCloneDirectory
) == CBrowseFolder::OK
)
174 m_Dir
=strCloneDirectory
;
175 this->UpdateData(FALSE
);
179 void CFormatPatchDlg::OnBnClickedButtonFrom()
183 m_cFrom
.GetWindowText(revision
);
184 dlg
.SetParams(CTGitPath(), CTGitPath(), revision
, revision
, 0);
185 // tell the dialog to use mode for selecting revisions
187 dlg
.ShowWorkingTreeChanges(false);
188 // only one revision must be selected however
189 dlg
.SingleSelection(true);
190 if (dlg
.DoModal() == IDOK
&& !dlg
.GetSelectedHash().empty())
192 m_cFrom
.AddString(dlg
.GetSelectedHash().at(0).ToString());
193 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_RANGE
);
198 void CFormatPatchDlg::OnBnClickedButtonTo()
202 m_cTo
.GetWindowText(revision
);
203 dlg
.SetParams(CTGitPath(), CTGitPath(), revision
, revision
, 0);
204 // tell the dialog to use mode for selecting revisions
206 // only one revision must be selected however
207 dlg
.SingleSelection(true);
208 if (dlg
.DoModal() == IDOK
&& !dlg
.GetSelectedHash().empty())
210 m_cTo
.AddString(dlg
.GetSelectedHash().at(0).ToString());
211 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_RANGE
);
216 void CFormatPatchDlg::OnBnClickedOk()
218 m_cDir
.SaveHistory();
219 m_cFrom
.SaveHistory();
221 this->UpdateData(TRUE
);
222 this->m_Radio
=GetCheckedRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
);
224 if (m_Radio
== IDC_RADIO_SINCE
&& !m_Since
.IsEmpty())
225 m_regSince
= m_Since
;
227 m_regSendMail
=this->m_bSendMail
;
228 m_regNoPrefix
= m_bNoPrefix
;
232 void CFormatPatchDlg::OnBnClickedRadio()
234 int radio
=this->GetCheckedRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
);
235 m_cSince
.EnableWindow(FALSE
);
236 m_cNum
.EnableWindow(FALSE
);
237 m_cFrom
.EnableWindow(FALSE
);
238 m_cTo
.EnableWindow(FALSE
);
239 GetDlgItem(IDC_BUTTON_REF
)->EnableWindow(FALSE
);
240 GetDlgItem(IDC_BUTTON_FROM
)->EnableWindow(FALSE
);
241 GetDlgItem(IDC_BUTTON_TO
)->EnableWindow(FALSE
);
244 case IDC_RADIO_SINCE
:
245 m_cSince
.EnableWindow(TRUE
);
246 GetDlgItem(IDC_BUTTON_REF
)->EnableWindow(TRUE
);
249 m_cNum
.EnableWindow(TRUE
);
251 case IDC_RADIO_RANGE
:
252 m_cFrom
.EnableWindow(TRUE
);
253 m_cTo
.EnableWindow(TRUE
);
254 GetDlgItem(IDC_BUTTON_FROM
)->EnableWindow(TRUE
);
255 GetDlgItem(IDC_BUTTON_TO
)->EnableWindow(TRUE
);
260 void CFormatPatchDlg::OnBnClickedButtonRef()
262 if(CBrowseRefsDlg::PickRefForCombo(&m_cSince
, gPickRef_NoTag
))
264 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_SINCE
);
268 void CFormatPatchDlg::OnBnClickedButtonUnifieddiff()
271 m_regNoPrefix
= m_bNoPrefix
;
272 CAppUtils::StartShowUnifiedDiff(m_hWnd
, CTGitPath(), GitRev::GetHead(), CTGitPath(), GitRev::GetWorkingCopy(), !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000), false, false, false, false, !!m_bNoPrefix
);