SyncDlg: Disallow in/out changes to include local context menu
[TortoiseGit.git] / src / TortoiseProc / ExportDlg.cpp
blobd6279bffb1c6ecb25a0ac458fdfab59a8eefd71f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2016 - 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 ((CButton *)GetDlgItem(IDC_WHOLE_PROJECT))->SetCheck(TRUE);
69 AddAnchor(IDC_REPOGROUP, TOP_LEFT, TOP_RIGHT);
70 AddAnchor(IDC_EXPORTFILE_LABEL, TOP_LEFT);
71 AddAnchor(IDC_EXPORTFILE_BROWSE, TOP_RIGHT);
72 AddAnchor(IDC_EXPORTFILE, TOP_LEFT, TOP_RIGHT);
74 AddAnchor(IDOK, BOTTOM_RIGHT);
75 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
76 AddAnchor(IDHELP, BOTTOM_RIGHT);
78 AdjustControlSize(IDC_RADIO_BRANCH);
79 AdjustControlSize(IDC_RADIO_TAGS);
80 AdjustControlSize(IDC_RADIO_VERSION);
82 SetDlgTitle();
84 CHOOSE_VERSION_ADDANCHOR;
85 this->AddOthersToAnchor();
86 InitChooseVersion();
87 if (m_initialRefName.IsEmpty() || m_initialRefName == L"HEAD")
88 SetDefaultChoose(IDC_RADIO_HEAD);
89 else if (CStringUtils::StartsWith(m_initialRefName, L"refs/tags/"))
90 SetDefaultChoose(IDC_RADIO_TAGS);
92 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
93 CString headText;
94 pHead->GetWindowText(headText);
95 pHead->SetWindowText(headText + " (" + g_Git.GetCurrentBranch() + ")");
96 AdjustControlSize(IDC_RADIO_HEAD);
98 m_tooltips.AddTool(IDC_EXPORTFILE, IDS_EXPORTFILE_TT);
100 SHAutoComplete(GetDlgItem(IDC_EXPORTFILE)->m_hWnd, SHACF_FILESYSTEM);
102 if (!m_pParentWnd && hWndExplorer)
103 CenterWindow(CWnd::FromHandle(hWndExplorer));
104 EnableSaveRestore(L"ExportDlg");
105 return TRUE;
108 void CExportDlg::OnOK()
110 if (!UpdateData(TRUE))
111 return; // don't dismiss dialog (error message already shown by MFC framework)
113 // check it the export path is a valid windows path
114 UpdateRevsionName();
116 if (m_VersionName.IsEmpty())
118 m_tooltips.ShowBalloon(IDC_COMBOBOXEX_VERSION, IDS_ERR_INVALIDREV, IDS_ERR_ERROR, TTI_ERROR);
119 return;
122 if(::PathFileExists(m_strFile))
124 if(::PathIsDirectory(m_strFile))
126 CMessageBox::Show(GetSafeHwnd(), IDS_PROCEXPORTERRFOLDER, IDS_APPNAME, MB_OK | MB_ICONERROR);
127 return;
129 CString sMessage;
130 sMessage.Format(IDS_PROC_OVERWRITE_CONFIRM, (LPCTSTR)m_strFile);
131 if (CMessageBox::Show(GetSafeHwnd(), sMessage, L"TortoiseGit", MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) != IDYES)
132 return ;
134 else if (m_strFile.IsEmpty())
136 CMessageBox::Show(GetSafeHwnd(), IDS_PROC_NOZIPFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
137 return;
140 UpdateData(FALSE);
141 CHorizontalResizableStandAloneDialog::OnOK();
144 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
146 m_tooltips.Pop(); // hide the tooltips
148 // Create a folder browser dialog. If the user selects OK, we should update
149 // the local data members with values from the controls, copy the checkout
150 // directory from the browse folder, then restore the local values into the
151 // dialog controls.
153 this->UpdateRevsionName();
154 CString filename = m_VersionName;
155 if (!CAppUtils::FileOpenSave(filename, nullptr, 0, IDS_ARCHIVEFILEFILTER, false, GetSafeHwnd(), L"zip"))
156 return;
158 UpdateData(TRUE);
159 m_strFile = filename;
160 UpdateData(FALSE);
161 OnEnChangeCheckoutdirectory();
164 void CExportDlg::OnEnChangeCheckoutdirectory()
166 UpdateData(TRUE);
167 DialogEnableWindow(IDOK, !m_strFile.IsEmpty());
170 void CExportDlg::OnBnClickedWholeProject()
172 UpdateData(TRUE);
173 SetDlgTitle();
176 void CExportDlg::OnBnClickedShowlog()
178 m_tooltips.Pop(); // hide the tooltips
181 void CExportDlg::OnDestroy()
183 WaitForFinishLoading();
184 __super::OnDestroy();
187 void CExportDlg::SetDlgTitle()
189 if (m_sTitle.IsEmpty())
190 GetWindowText(m_sTitle);
192 if (m_bWholeProject)
193 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
194 else
195 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);