Includes cleanup
[TortoiseGit.git] / src / TortoiseProc / ExportDlg.cpp
blobec2b502686af37eb7d6f1909283b35b1d983be92
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2015 - 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 /*=NULL*/)
30 : CHorizontalResizableStandAloneDialog(CExportDlg::IDD, pParent)
31 , CChooseVersion(this)
32 , m_bWholeProject(FALSE)
33 , m_Revision(_T("HEAD"))
34 , m_strFile(_T(""))
38 CExportDlg::~CExportDlg()
42 void CExportDlg::DoDataExchange(CDataExchange* pDX)
44 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
45 DDX_Text(pDX, IDC_EXPORTFILE, m_strFile);
46 DDX_Check(pDX, IDC_SHOWWHOLEPROJECT, m_bWholeProject);
47 CHOOSE_VERSION_DDX;
51 BEGIN_MESSAGE_MAP(CExportDlg, CHorizontalResizableStandAloneDialog)
52 ON_BN_CLICKED(IDC_EXPORTFILE_BROWSE, OnBnClickedCheckoutdirectoryBrowse)
53 ON_EN_CHANGE(IDC_EXPORTFILE, OnEnChangeCheckoutdirectory)
54 ON_BN_CLICKED(IDC_SHOWWHOLEPROJECT, OnBnClickedWholeProject)
55 CHOOSE_VERSION_EVENT
56 ON_WM_DESTROY()
57 END_MESSAGE_MAP()
59 BOOL CExportDlg::OnInitDialog()
61 CHorizontalResizableStandAloneDialog::OnInitDialog();
62 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
64 if (g_Git.m_CurrentDir == m_orgPath.GetWinPathString())
66 GetDlgItem(IDC_SHOWWHOLEPROJECT)->EnableWindow(FALSE);
67 ((CButton *)GetDlgItem(IDC_SHOWWHOLEPROJECT))->SetCheck(TRUE);
70 AddAnchor(IDC_REPOGROUP, TOP_LEFT, TOP_RIGHT);
71 AddAnchor(IDC_EXPORTFILE_LABEL, TOP_LEFT);
72 AddAnchor(IDC_EXPORTFILE_BROWSE, TOP_RIGHT);
73 AddAnchor(IDC_EXPORTFILE, TOP_LEFT, TOP_RIGHT);
75 AddAnchor(IDOK, BOTTOM_RIGHT);
76 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
77 AddAnchor(IDHELP, BOTTOM_RIGHT);
79 AdjustControlSize(IDC_RADIO_BRANCH);
80 AdjustControlSize(IDC_RADIO_TAGS);
81 AdjustControlSize(IDC_RADIO_VERSION);
83 SetDlgTitle();
85 CHOOSE_VERSION_ADDANCHOR;
86 this->AddOthersToAnchor();
87 InitChooseVersion();
88 if (m_initialRefName.IsEmpty() || m_initialRefName == _T("HEAD"))
90 SetDefaultChoose(IDC_RADIO_HEAD);
92 else if (m_initialRefName.Left(10) == _T("refs/tags/"))
93 SetDefaultChoose(IDC_RADIO_TAGS);
95 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
96 CString headText;
97 pHead->GetWindowText(headText);
98 pHead->SetWindowText(headText + " (" + g_Git.GetCurrentBranch() + ")");
99 AdjustControlSize(IDC_RADIO_HEAD);
101 m_tooltips.Create(this);
102 m_tooltips.AddTool(IDC_EXPORTFILE, IDS_EXPORTFILE_TT);
104 SHAutoComplete(GetDlgItem(IDC_EXPORTFILE)->m_hWnd, SHACF_FILESYSTEM);
106 if ((m_pParentWnd==NULL)&&(hWndExplorer))
107 CenterWindow(CWnd::FromHandle(hWndExplorer));
108 EnableSaveRestore(_T("ExportDlg"));
109 return TRUE;
112 void CExportDlg::OnOK()
114 if (!UpdateData(TRUE))
115 return; // don't dismiss dialog (error message already shown by MFC framework)
117 // check it the export path is a valid windows path
118 UpdateRevsionName();
120 if (m_VersionName.IsEmpty())
122 m_tooltips.ShowBalloon(IDC_COMBOBOXEX_VERSION, IDS_ERR_INVALIDREV, IDS_ERR_ERROR, TTI_ERROR);
123 return;
126 if(::PathFileExists(m_strFile))
128 if(::PathIsDirectory(m_strFile))
130 CMessageBox::Show(NULL, IDS_PROCEXPORTERRFOLDER, IDS_APPNAME, MB_OK | MB_ICONERROR);
131 return;
133 CString sMessage;
134 sMessage.Format(IDS_PROC_OVERWRITE_CONFIRM, m_strFile);
135 if (CMessageBox::Show(NULL, sMessage, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) != IDYES)
137 return ;
140 else if (m_strFile.IsEmpty())
142 CMessageBox::Show(NULL, IDS_PROC_NOZIPFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
143 return;
146 UpdateData(FALSE);
147 CHorizontalResizableStandAloneDialog::OnOK();
150 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
152 m_tooltips.Pop(); // hide the tooltips
154 // Create a folder browser dialog. If the user selects OK, we should update
155 // the local data members with values from the controls, copy the checkout
156 // directory from the browse folder, then restore the local values into the
157 // dialog controls.
159 this->UpdateRevsionName();
160 CFileDialog dlg(FALSE, _T("zip"), this->m_VersionName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("*.zip"));
162 INT_PTR ret = dlg.DoModal();
163 SetCurrentDirectory(g_Git.m_CurrentDir);
164 if (ret == IDOK)
166 UpdateData(TRUE);
167 m_strFile = dlg.GetPathName();
168 UpdateData(FALSE);
169 OnEnChangeCheckoutdirectory();
173 BOOL CExportDlg::PreTranslateMessage(MSG* pMsg)
175 m_tooltips.RelayEvent(pMsg);
176 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
179 void CExportDlg::OnEnChangeCheckoutdirectory()
181 UpdateData(TRUE);
182 DialogEnableWindow(IDOK, !m_strFile.IsEmpty());
185 void CExportDlg::OnBnClickedWholeProject()
187 UpdateData(TRUE);
188 SetDlgTitle();
191 void CExportDlg::OnBnClickedShowlog()
193 m_tooltips.Pop(); // hide the tooltips
196 void CExportDlg::OnDestroy()
198 WaitForFinishLoading();
199 __super::OnDestroy();
202 void CExportDlg::SetDlgTitle()
204 if (m_sTitle.IsEmpty())
205 GetWindowText(m_sTitle);
207 if (m_bWholeProject)
208 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
209 else
210 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);