ON_BN_CLICKED(IDHELP, OnBnClickedHelp) is already implemented in CResizableStandAlone...
[TortoiseGit.git] / src / TortoiseProc / ExportDlg.cpp
blob8d5356c482247aa38825bf8b0924c1df48228cba
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2013 - 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_Revision(_T("HEAD"))
35 , m_strFile(_T(""))
39 CExportDlg::~CExportDlg()
43 void CExportDlg::DoDataExchange(CDataExchange* pDX)
45 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
46 DDX_Text(pDX, IDC_EXPORTFILE, m_strFile);
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 CHOOSE_VERSION_EVENT
55 ON_WM_DESTROY()
56 END_MESSAGE_MAP()
58 BOOL CExportDlg::OnInitDialog()
60 CHorizontalResizableStandAloneDialog::OnInitDialog();
61 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
63 AddAnchor(IDC_REPOGROUP, TOP_LEFT, TOP_RIGHT);
64 AddAnchor(IDC_EXPORTFILE_LABEL, TOP_LEFT);
65 AddAnchor(IDC_EXPORTFILE_BROWSE, TOP_RIGHT);
66 AddAnchor(IDC_EXPORTFILE, TOP_LEFT, TOP_RIGHT);
68 AddAnchor(IDOK, BOTTOM_RIGHT);
69 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
70 AddAnchor(IDHELP, BOTTOM_RIGHT);
72 AdjustControlSize(IDC_RADIO_HEAD);
73 AdjustControlSize(IDC_RADIO_BRANCH);
74 AdjustControlSize(IDC_RADIO_TAGS);
75 AdjustControlSize(IDC_RADIO_VERSION);
77 CString sWindowTitle;
78 GetWindowText(sWindowTitle);
79 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
81 CHOOSE_VERSION_ADDANCHOR;
82 this->AddOthersToAnchor();
83 Init();
84 if(this->m_Revision.IsEmpty())
86 SetDefaultChoose(IDC_RADIO_HEAD);
88 else
90 SetDefaultChoose(IDC_RADIO_VERSION);
91 this->GetDlgItem(IDC_COMBOBOXEX_VERSION)->SetWindowTextW(m_Revision);
94 m_tooltips.Create(this);
95 m_tooltips.AddTool(IDC_EXPORTFILE, IDS_EXPORTFILE_TT);
97 SHAutoComplete(GetDlgItem(IDC_EXPORTFILE)->m_hWnd, SHACF_FILESYSTEM);
99 if ((m_pParentWnd==NULL)&&(hWndExplorer))
100 CenterWindow(CWnd::FromHandle(hWndExplorer));
101 EnableSaveRestore(_T("ExportDlg"));
102 return TRUE;
105 void CExportDlg::OnOK()
107 if (!UpdateData(TRUE))
108 return; // don't dismiss dialog (error message already shown by MFC framework)
110 // check it the export path is a valid windows path
111 UpdateRevsionName();
113 if (m_VersionName.IsEmpty())
115 m_tooltips.ShowBalloon(IDC_COMBOBOXEX_VERSION, IDS_ERR_INVALIDREV, IDS_ERR_ERROR, TTI_ERROR);
116 return;
119 if(::PathFileExists(m_strFile))
121 if(::PathIsDirectory(m_strFile))
123 CMessageBox::Show(NULL, IDS_PROCEXPORTERRFOLDER, IDS_APPNAME, MB_OK | MB_ICONERROR);
124 return;
126 CString sMessage;
127 sMessage.Format(IDS_PROC_OVERWRITE_CONFIRM, m_strFile);
128 if (CMessageBox::Show(NULL, sMessage, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) != IDYES)
130 return ;
133 else if (m_strFile.IsEmpty())
135 CMessageBox::Show(NULL, IDS_PROC_NOZIPFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
136 return;
139 UpdateData(FALSE);
140 CHorizontalResizableStandAloneDialog::OnOK();
143 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
145 m_tooltips.Pop(); // hide the tooltips
147 // Create a folder browser dialog. If the user selects OK, we should update
148 // the local data members with values from the controls, copy the checkout
149 // directory from the browse folder, then restore the local values into the
150 // dialog controls.
152 this->UpdateRevsionName();
153 CFileDialog dlg(FALSE, _T("zip"), this->m_VersionName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("*.zip"));
155 INT_PTR ret = dlg.DoModal();
156 SetCurrentDirectory(g_Git.m_CurrentDir);
157 if (ret == IDOK)
159 UpdateData(TRUE);
160 m_strFile = dlg.GetPathName();
161 UpdateData(FALSE);
165 BOOL CExportDlg::PreTranslateMessage(MSG* pMsg)
167 m_tooltips.RelayEvent(pMsg);
168 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
171 void CExportDlg::OnEnChangeCheckoutdirectory()
173 UpdateData(TRUE);
174 DialogEnableWindow(IDOK, !m_strFile.IsEmpty());
177 void CExportDlg::OnBnClickedShowlog()
179 m_tooltips.Pop(); // hide the tooltips
182 void CExportDlg::OnDestroy()
184 WaitForFinishLoading();
185 __super::OnDestroy();