Make filter structure the same across the projects
[TortoiseGit.git] / src / TortoiseProc / ExportDlg.cpp
blobc6ad8def9d745d5626f128bf575be2d65ee91c93
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2014 - 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"
24 #include "Messagebox.h"
25 #include "PathUtils.h"
26 #include "BrowseFolder.h"
27 #include "AppUtils.h"
30 IMPLEMENT_DYNAMIC(CExportDlg, CHorizontalResizableStandAloneDialog)
31 CExportDlg::CExportDlg(CWnd* pParent /*=NULL*/)
32 : CHorizontalResizableStandAloneDialog(CExportDlg::IDD, pParent)
33 , CChooseVersion(this)
34 , m_bWholeProject(FALSE)
35 , m_Revision(_T("HEAD"))
36 , m_strFile(_T(""))
40 CExportDlg::~CExportDlg()
44 void CExportDlg::DoDataExchange(CDataExchange* pDX)
46 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
47 DDX_Text(pDX, IDC_EXPORTFILE, m_strFile);
48 DDX_Check(pDX, IDC_SHOWWHOLEPROJECT, m_bWholeProject);
49 CHOOSE_VERSION_DDX;
53 BEGIN_MESSAGE_MAP(CExportDlg, CHorizontalResizableStandAloneDialog)
54 ON_BN_CLICKED(IDC_EXPORTFILE_BROWSE, OnBnClickedCheckoutdirectoryBrowse)
55 ON_EN_CHANGE(IDC_EXPORTFILE, OnEnChangeCheckoutdirectory)
56 ON_BN_CLICKED(IDC_SHOWWHOLEPROJECT, OnBnClickedWholeProject)
57 CHOOSE_VERSION_EVENT
58 ON_WM_DESTROY()
59 END_MESSAGE_MAP()
61 BOOL CExportDlg::OnInitDialog()
63 CHorizontalResizableStandAloneDialog::OnInitDialog();
64 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
66 if (g_Git.m_CurrentDir == m_orgPath.GetWinPathString())
68 GetDlgItem(IDC_SHOWWHOLEPROJECT)->EnableWindow(FALSE);
69 ((CButton *)GetDlgItem(IDC_SHOWWHOLEPROJECT))->SetCheck(TRUE);
72 AddAnchor(IDC_REPOGROUP, TOP_LEFT, TOP_RIGHT);
73 AddAnchor(IDC_EXPORTFILE_LABEL, TOP_LEFT);
74 AddAnchor(IDC_EXPORTFILE_BROWSE, TOP_RIGHT);
75 AddAnchor(IDC_EXPORTFILE, TOP_LEFT, TOP_RIGHT);
77 AddAnchor(IDOK, BOTTOM_RIGHT);
78 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
79 AddAnchor(IDHELP, BOTTOM_RIGHT);
81 AdjustControlSize(IDC_RADIO_BRANCH);
82 AdjustControlSize(IDC_RADIO_TAGS);
83 AdjustControlSize(IDC_RADIO_VERSION);
85 SetDlgTitle();
87 CHOOSE_VERSION_ADDANCHOR;
88 this->AddOthersToAnchor();
89 InitChooseVersion();
90 if (m_initialRefName.IsEmpty() || m_initialRefName == _T("HEAD"))
92 SetDefaultChoose(IDC_RADIO_HEAD);
94 else if (m_initialRefName.Left(10) == _T("refs/tags/"))
95 SetDefaultChoose(IDC_RADIO_TAGS);
97 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
98 CString headText;
99 pHead->GetWindowText(headText);
100 pHead->SetWindowText(headText + " (" + g_Git.GetCurrentBranch() + ")");
101 AdjustControlSize(IDC_RADIO_HEAD);
103 m_tooltips.Create(this);
104 m_tooltips.AddTool(IDC_EXPORTFILE, IDS_EXPORTFILE_TT);
106 SHAutoComplete(GetDlgItem(IDC_EXPORTFILE)->m_hWnd, SHACF_FILESYSTEM);
108 if ((m_pParentWnd==NULL)&&(hWndExplorer))
109 CenterWindow(CWnd::FromHandle(hWndExplorer));
110 EnableSaveRestore(_T("ExportDlg"));
111 return TRUE;
114 void CExportDlg::OnOK()
116 if (!UpdateData(TRUE))
117 return; // don't dismiss dialog (error message already shown by MFC framework)
119 // check it the export path is a valid windows path
120 UpdateRevsionName();
122 if (m_VersionName.IsEmpty())
124 m_tooltips.ShowBalloon(IDC_COMBOBOXEX_VERSION, IDS_ERR_INVALIDREV, IDS_ERR_ERROR, TTI_ERROR);
125 return;
128 if(::PathFileExists(m_strFile))
130 if(::PathIsDirectory(m_strFile))
132 CMessageBox::Show(NULL, IDS_PROCEXPORTERRFOLDER, IDS_APPNAME, MB_OK | MB_ICONERROR);
133 return;
135 CString sMessage;
136 sMessage.Format(IDS_PROC_OVERWRITE_CONFIRM, m_strFile);
137 if (CMessageBox::Show(NULL, sMessage, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) != IDYES)
139 return ;
142 else if (m_strFile.IsEmpty())
144 CMessageBox::Show(NULL, IDS_PROC_NOZIPFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
145 return;
148 UpdateData(FALSE);
149 CHorizontalResizableStandAloneDialog::OnOK();
152 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
154 m_tooltips.Pop(); // hide the tooltips
156 // Create a folder browser dialog. If the user selects OK, we should update
157 // the local data members with values from the controls, copy the checkout
158 // directory from the browse folder, then restore the local values into the
159 // dialog controls.
161 this->UpdateRevsionName();
162 CFileDialog dlg(FALSE, _T("zip"), this->m_VersionName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("*.zip"));
164 INT_PTR ret = dlg.DoModal();
165 SetCurrentDirectory(g_Git.m_CurrentDir);
166 if (ret == IDOK)
168 UpdateData(TRUE);
169 m_strFile = dlg.GetPathName();
170 UpdateData(FALSE);
171 OnEnChangeCheckoutdirectory();
175 BOOL CExportDlg::PreTranslateMessage(MSG* pMsg)
177 m_tooltips.RelayEvent(pMsg);
178 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
181 void CExportDlg::OnEnChangeCheckoutdirectory()
183 UpdateData(TRUE);
184 DialogEnableWindow(IDOK, !m_strFile.IsEmpty());
187 void CExportDlg::OnBnClickedWholeProject()
189 UpdateData(TRUE);
190 SetDlgTitle();
193 void CExportDlg::OnBnClickedShowlog()
195 m_tooltips.Pop(); // hide the tooltips
198 void CExportDlg::OnDestroy()
200 WaitForFinishLoading();
201 __super::OnDestroy();
204 void CExportDlg::SetDlgTitle()
206 if (m_sTitle.IsEmpty())
207 GetWindowText(m_sTitle);
209 if (m_bWholeProject)
210 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
211 else
212 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);