1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014, 2016-2017, 2019-2020, 2024 - 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"
30 #include "MessageBox.h"
32 // CFormatPatchDlg dialog
34 IMPLEMENT_DYNAMIC(CFormatPatchDlg
, CHorizontalResizableStandAloneDialog
)
36 CFormatPatchDlg::CFormatPatchDlg(CWnd
* pParent
/*=nullptr*/)
37 : CHorizontalResizableStandAloneDialog(CFormatPatchDlg::IDD
, pParent
)
38 , m_regSendMail(L
"Software\\TortoiseGit\\TortoiseProc\\FormatPatch\\SendMail", 0)
39 , m_regNoPrefix(L
"Software\\TortoiseGit\\TortoiseProc\\FormatPatch\\NoPrefix", FALSE
)
42 this->m_bSendMail
= m_regSendMail
;
43 this->m_Radio
= IDC_RADIO_SINCE
;
44 m_bNoPrefix
= m_regNoPrefix
;
46 CString workingDir
= g_Git
.m_CurrentDir
;
47 workingDir
.Replace(L
':', L
'_');
48 m_regSince
= CRegString(L
"Software\\TortoiseGit\\History\\FormatPatch\\" + workingDir
+ L
"\\Since");
51 CFormatPatchDlg::~CFormatPatchDlg()
55 void CFormatPatchDlg::DoDataExchange(CDataExchange
* pDX
)
57 CDialog::DoDataExchange(pDX
);
58 DDX_Control(pDX
, IDC_COMBOBOXEX_DIR
, m_cDir
);
59 DDX_Control(pDX
, IDC_COMBOBOXEX_SINCE
, m_cSince
);
60 DDX_Control(pDX
, IDC_COMBOBOXEX_FROM
, m_cFrom
);
61 DDX_Control(pDX
, IDC_COMBOBOXEX_TO
, m_cTo
);
62 DDX_Control(pDX
, IDC_EDIT_NUM
, m_cNum
);
63 DDX_Control(pDX
, IDC_SPIN_NUM
, m_spinNum
);
65 DDX_Text(pDX
,IDC_EDIT_NUM
,m_Num
);
67 DDX_Text(pDX
, IDC_COMBOBOXEX_DIR
, m_Dir
);
68 DDX_Text(pDX
, IDC_COMBOBOXEX_SINCE
, m_Since
);
69 DDX_Text(pDX
, IDC_COMBOBOXEX_FROM
, m_From
);
70 DDX_Text(pDX
, IDC_COMBOBOXEX_TO
, m_To
);
72 DDX_Check(pDX
, IDC_CHECK_SENDMAIL
, m_bSendMail
);
73 DDX_Check(pDX
, IDC_CHECK_NOPREFIX
, m_bNoPrefix
);
77 BEGIN_MESSAGE_MAP(CFormatPatchDlg
, CHorizontalResizableStandAloneDialog
)
78 ON_BN_CLICKED(IDC_BUTTON_DIR
, &CFormatPatchDlg::OnBnClickedButtonDir
)
79 ON_BN_CLICKED(IDC_BUTTON_FROM
, &CFormatPatchDlg::OnBnClickedButtonFrom
)
80 ON_BN_CLICKED(IDC_BUTTON_TO
, &CFormatPatchDlg::OnBnClickedButtonTo
)
81 ON_BN_CLICKED(IDOK
, &CFormatPatchDlg::OnBnClickedOk
)
82 ON_BN_CLICKED(IDC_RADIO_SINCE
, &CFormatPatchDlg::OnBnClickedRadio
)
83 ON_BN_CLICKED(IDC_RADIO_NUM
, &CFormatPatchDlg::OnBnClickedRadio
)
84 ON_BN_CLICKED(IDC_RADIO_RANGE
, &CFormatPatchDlg::OnBnClickedRadio
)
85 ON_BN_CLICKED(IDC_BUTTON_REF
, &CFormatPatchDlg::OnBnClickedButtonRef
)
86 ON_BN_CLICKED(IDC_BUTTON_UNIFIEDDIFF
, &CFormatPatchDlg::OnBnClickedButtonUnifieddiff
)
89 BOOL
CFormatPatchDlg::OnInitDialog()
91 CHorizontalResizableStandAloneDialog::OnInitDialog();
92 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
94 AdjustControlSize(IDC_RADIO_SINCE
);
95 AdjustControlSize(IDC_RADIO_NUM
);
96 AdjustControlSize(IDC_RADIO_RANGE
);
97 AdjustControlSize(IDC_CHECK_SENDMAIL
);
98 AdjustControlSize(IDC_CHECK_NOPREFIX
);
100 AddAnchor(IDC_GROUP_DIR
, TOP_LEFT
, TOP_RIGHT
);
101 AddAnchor(IDC_COMBOBOXEX_DIR
,TOP_LEFT
, TOP_RIGHT
);
102 AddAnchor(IDC_BUTTON_DIR
, TOP_RIGHT
);
104 AddAnchor(IDC_GROUP_VERSION
, TOP_LEFT
, TOP_RIGHT
);
105 AddAnchor(IDC_COMBOBOXEX_SINCE
, TOP_LEFT
, TOP_RIGHT
);
106 AddAnchor(IDC_EDIT_NUM
, TOP_LEFT
, TOP_RIGHT
);
107 AddAnchor(IDC_SPIN_NUM
, TOP_RIGHT
);
109 AddAnchor(IDC_COMBOBOXEX_FROM
, TOP_LEFT
, TOP_RIGHT
);
110 AddAnchor(IDC_COMBOBOXEX_TO
, TOP_LEFT
, TOP_RIGHT
);
112 AddAnchor(IDC_BUTTON_FROM
, TOP_RIGHT
);
113 AddAnchor(IDC_BUTTON_TO
, TOP_RIGHT
);
114 AddAnchor(IDC_CHECK_SENDMAIL
,BOTTOM_LEFT
);
115 AddAnchor(IDC_CHECK_NOPREFIX
, BOTTOM_LEFT
);
116 AddAnchor(IDOK
,BOTTOM_RIGHT
);
117 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
118 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
119 AddAnchor(IDC_BUTTON_REF
,TOP_RIGHT
);
121 this->AddOthersToAnchor();
123 CAppUtils::SetWindowTitle(*this, g_Git
.m_CurrentDir
);
125 m_cDir
.SetPathHistory(TRUE
);
126 m_cDir
.LoadHistory(L
"Software\\TortoiseGit\\History\\FormatPatchURLS", L
"path");
127 m_cDir
.AddString(g_Git
.m_CurrentDir
);
130 g_Git
.GetBranchList(list
, nullptr, CGit::BRANCH_ALL_F
);
131 m_cSince
.SetMaxHistoryItems(static_cast<int>(list
.size()));
132 m_cSince
.SetList(list
);
134 if (!m_Since
.IsEmpty())
135 m_cSince
.SetWindowText(m_Since
);
137 m_cSince
.SetWindowText(static_cast<CString
>(m_regSince
));
139 m_cFrom
.LoadHistory(L
"Software\\TortoiseGit\\History\\FormatPatchFromURLS", L
"ver");
140 m_cFrom
.SetCurSel(0);
142 if(!m_From
.IsEmpty())
143 m_cFrom
.SetWindowText(m_From
);
145 m_cTo
.LoadHistory(L
"Software\\TortoiseGit\\History\\FormatPatchToURLS", L
"ver");
149 m_cTo
.SetWindowText(m_To
);
151 m_spinNum
.SetRange32(1, INT_MAX
);
152 this->CheckRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
,this->m_Radio
);
156 if (g_Git
.IsInitRepos())
157 DialogEnableWindow(IDOK
, FALSE
);
159 EnableSaveRestore(L
"FormatPatchDlg");
160 SetTheme(CTheme::Instance().IsDarkTheme());
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()
182 if (dlg
.IsThreadRunning())
184 CMessageBox::Show(GetSafeHwnd(), IDS_PROC_LOG_ONLYONCE
, IDS_APPNAME
, MB_ICONEXCLAMATION
);
188 m_cFrom
.GetWindowText(revision
);
189 dlg
.SetParams(CTGitPath(), CTGitPath(), revision
, revision
, 0);
190 // tell the dialog to use mode for selecting revisions
192 dlg
.ShowWorkingTreeChanges(false);
193 // only one revision must be selected however
194 dlg
.SingleSelection(true);
195 if (dlg
.DoModal() == IDOK
&& !dlg
.GetSelectedHash().empty())
197 m_cFrom
.AddString(dlg
.GetSelectedHash().at(0).ToString());
198 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_RANGE
);
201 BringWindowToTop(); /* cf. issue #3493 */
204 void CFormatPatchDlg::OnBnClickedButtonTo()
207 if (dlg
.IsThreadRunning())
209 CMessageBox::Show(GetSafeHwnd(), IDS_PROC_LOG_ONLYONCE
, IDS_APPNAME
, MB_ICONEXCLAMATION
);
213 m_cTo
.GetWindowText(revision
);
214 dlg
.SetParams(CTGitPath(), CTGitPath(), revision
, revision
, 0);
215 // tell the dialog to use mode for selecting revisions
217 // only one revision must be selected however
218 dlg
.SingleSelection(true);
219 if (dlg
.DoModal() == IDOK
&& !dlg
.GetSelectedHash().empty())
221 m_cTo
.AddString(dlg
.GetSelectedHash().at(0).ToString());
222 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_RANGE
);
225 BringWindowToTop(); /* cf. issue #3493 */
228 void CFormatPatchDlg::OnBnClickedOk()
230 m_cDir
.SaveHistory();
231 m_cFrom
.SaveHistory();
233 this->UpdateData(TRUE
);
234 this->m_Radio
=GetCheckedRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
);
236 if (m_Radio
== IDC_RADIO_SINCE
&& !m_Since
.IsEmpty())
237 m_regSince
= m_Since
;
239 m_regSendMail
=this->m_bSendMail
;
240 m_regNoPrefix
= m_bNoPrefix
;
244 void CFormatPatchDlg::OnBnClickedRadio()
246 int radio
=this->GetCheckedRadioButton(IDC_RADIO_SINCE
,IDC_RADIO_RANGE
);
247 m_cSince
.EnableWindow(FALSE
);
248 m_cNum
.EnableWindow(FALSE
);
249 m_cFrom
.EnableWindow(FALSE
);
250 m_cTo
.EnableWindow(FALSE
);
251 GetDlgItem(IDC_BUTTON_REF
)->EnableWindow(FALSE
);
252 GetDlgItem(IDC_BUTTON_FROM
)->EnableWindow(FALSE
);
253 GetDlgItem(IDC_BUTTON_TO
)->EnableWindow(FALSE
);
256 case IDC_RADIO_SINCE
:
257 m_cSince
.EnableWindow(TRUE
);
258 GetDlgItem(IDC_BUTTON_REF
)->EnableWindow(TRUE
);
261 m_cNum
.EnableWindow(TRUE
);
263 case IDC_RADIO_RANGE
:
264 m_cFrom
.EnableWindow(TRUE
);
265 m_cTo
.EnableWindow(TRUE
);
266 GetDlgItem(IDC_BUTTON_FROM
)->EnableWindow(TRUE
);
267 GetDlgItem(IDC_BUTTON_TO
)->EnableWindow(TRUE
);
272 void CFormatPatchDlg::OnBnClickedButtonRef()
274 if (CBrowseRefsDlg::PickRefForCombo(m_cSince
, gPickRef_NoTag
))
276 CheckRadioButton(IDC_RADIO_SINCE
, IDC_RADIO_RANGE
, IDC_RADIO_SINCE
);
280 void CFormatPatchDlg::OnBnClickedButtonUnifieddiff()
283 m_regNoPrefix
= m_bNoPrefix
;
284 CAppUtils::StartShowUnifiedDiff(m_hWnd
, CTGitPath(), GitRev::GetHead(), CTGitPath(), GitRev::GetWorkingCopy(), !!(GetAsyncKeyState(VK_SHIFT
) & 0x8000), false, false, false, false, !!m_bNoPrefix
);