Fixed issue #3668: "Revert to revision" fails for added files
[TortoiseGit.git] / src / TortoiseProc / ExportDlg.cpp
blob7cfb591effc67ebd4b9aa88c61e199ca3ac8b7f4
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2020 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "ExportDlg.h"
23 #include "MessageBox.h"
24 #include "BrowseFolder.h"
25 #include "AppUtils.h"
28 IMPLEMENT_DYNAMIC(CExportDlg, CHorizontalResizableStandAloneDialog)
29 CExportDlg::CExportDlg(CWnd* pParent /*=nullptr*/)
30 : CHorizontalResizableStandAloneDialog(CExportDlg::IDD, pParent)
31 , CChooseVersion(this)
32 , m_bWholeProject(FALSE)
33 , m_Revision(L"HEAD")
37 CExportDlg::~CExportDlg()
41 void CExportDlg::DoDataExchange(CDataExchange* pDX)
43 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
44 DDX_Text(pDX, IDC_EXPORTFILE, m_strFile);
45 DDX_Check(pDX, IDC_WHOLE_PROJECT, m_bWholeProject);
46 CHOOSE_VERSION_DDX;
50 BEGIN_MESSAGE_MAP(CExportDlg, CHorizontalResizableStandAloneDialog)
51 ON_BN_CLICKED(IDC_EXPORTFILE_BROWSE, OnBnClickedCheckoutdirectoryBrowse)
52 ON_EN_CHANGE(IDC_EXPORTFILE, OnEnChangeCheckoutdirectory)
53 ON_BN_CLICKED(IDC_WHOLE_PROJECT, OnBnClickedWholeProject)
54 CHOOSE_VERSION_EVENT
55 ON_WM_DESTROY()
56 END_MESSAGE_MAP()
58 BOOL CExportDlg::OnInitDialog()
60 CHorizontalResizableStandAloneDialog::OnInitDialog();
61 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
63 if (g_Git.m_CurrentDir == m_orgPath.GetWinPathString())
65 GetDlgItem(IDC_WHOLE_PROJECT)->EnableWindow(FALSE);
66 static_cast<CButton*>(GetDlgItem(IDC_WHOLE_PROJECT))->SetCheck(TRUE);
69 InitChooseVersion();
70 if (m_initialRefName.IsEmpty() || m_initialRefName == L"HEAD")
71 SetDefaultChoose(IDC_RADIO_HEAD);
72 else if (CStringUtils::StartsWith(m_initialRefName, L"refs/tags/"))
73 SetDefaultChoose(IDC_RADIO_TAGS);
75 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
76 CString headText;
77 pHead->GetWindowText(headText);
78 pHead->SetWindowText(headText + " (" + g_Git.GetCurrentBranch() + ")");
80 AdjustControlSize(IDC_RADIO_BRANCH);
81 AdjustControlSize(IDC_RADIO_TAGS);
82 AdjustControlSize(IDC_RADIO_VERSION);
83 AdjustControlSize(IDC_RADIO_HEAD);
85 AddAnchor(IDC_REPOGROUP, TOP_LEFT, TOP_RIGHT);
86 AddAnchor(IDC_EXPORTFILE_LABEL, TOP_LEFT);
87 AddAnchor(IDC_EXPORTFILE_BROWSE, TOP_RIGHT);
88 AddAnchor(IDC_EXPORTFILE, TOP_LEFT, TOP_RIGHT);
90 AddAnchor(IDOK, BOTTOM_RIGHT);
91 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
92 AddAnchor(IDHELP, BOTTOM_RIGHT);
94 SetDlgTitle();
96 CHOOSE_VERSION_ADDANCHOR;
97 AddOthersToAnchor();
99 m_tooltips.AddTool(IDC_EXPORTFILE, IDS_EXPORTFILE_TT);
101 SHAutoComplete(GetDlgItem(IDC_EXPORTFILE)->m_hWnd, SHACF_FILESYSTEM);
103 if (!m_pParentWnd && GetExplorerHWND())
104 CenterWindow(CWnd::FromHandle(GetExplorerHWND()));
105 EnableSaveRestore(L"ExportDlg");
106 SetTheme(CTheme::Instance().IsDarkTheme());
107 return TRUE;
110 void CExportDlg::OnOK()
112 if (!UpdateData(TRUE))
113 return; // don't dismiss dialog (error message already shown by MFC framework)
115 // check it the export path is a valid windows path
116 UpdateRevsionName();
118 if (m_VersionName.IsEmpty())
120 m_tooltips.ShowBalloon(IDC_COMBOBOXEX_VERSION, IDS_ERR_INVALIDREV, IDS_ERR_ERROR, TTI_ERROR);
121 return;
124 if (!*::PathFindExtension(m_strFile)) // no extension
125 m_strFile += L".zip";
126 if(::PathFileExists(m_strFile))
128 if(::PathIsDirectory(m_strFile))
130 CMessageBox::Show(GetSafeHwnd(), IDS_PROCEXPORTERRFOLDER, IDS_APPNAME, MB_OK | MB_ICONERROR);
131 return;
133 CString sMessage;
134 sMessage.Format(IDS_PROC_OVERWRITE_CONFIRM, static_cast<LPCTSTR>(m_strFile));
135 if (CMessageBox::Show(GetSafeHwnd(), sMessage, L"TortoiseGit", MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) != IDYES)
136 return ;
138 else if (m_strFile.IsEmpty())
140 CMessageBox::Show(GetSafeHwnd(), IDS_PROC_NOZIPFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
141 return;
144 UpdateData(FALSE);
145 CHorizontalResizableStandAloneDialog::OnOK();
148 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
150 m_tooltips.Pop(); // hide the tooltips
152 // Create a folder browser dialog. If the user selects OK, we should update
153 // the local data members with values from the controls, copy the checkout
154 // directory from the browse folder, then restore the local values into the
155 // dialog controls.
157 this->UpdateRevsionName();
158 CString filename = m_VersionName;
159 if (!CAppUtils::FileOpenSave(filename, nullptr, 0, IDS_ARCHIVEFILEFILTER, false, GetSafeHwnd(), L"zip"))
160 return;
162 UpdateData(TRUE);
163 m_strFile = filename;
164 UpdateData(FALSE);
165 OnEnChangeCheckoutdirectory();
168 void CExportDlg::OnEnChangeCheckoutdirectory()
170 UpdateData(TRUE);
171 DialogEnableWindow(IDOK, !m_strFile.IsEmpty());
174 void CExportDlg::OnBnClickedWholeProject()
176 UpdateData(TRUE);
177 SetDlgTitle();
180 void CExportDlg::OnBnClickedShowlog()
182 m_tooltips.Pop(); // hide the tooltips
185 void CExportDlg::OnDestroy()
187 WaitForFinishLoading();
188 __super::OnDestroy();
191 void CExportDlg::SetDlgTitle()
193 if (m_sTitle.IsEmpty())
194 GetWindowText(m_sTitle);
196 if (m_bWholeProject)
197 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
198 else
199 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);