Do not report libgit2 warnings
[TortoiseGit.git] / src / TortoiseProc / ExportDlg.cpp
blob0fcde2c780f37b0a834b18fff1ff572717cca511
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.AddTool(IDC_EXPORTFILE, IDS_EXPORTFILE_TT);
103 SHAutoComplete(GetDlgItem(IDC_EXPORTFILE)->m_hWnd, SHACF_FILESYSTEM);
105 if ((m_pParentWnd==NULL)&&(hWndExplorer))
106 CenterWindow(CWnd::FromHandle(hWndExplorer));
107 EnableSaveRestore(_T("ExportDlg"));
108 return TRUE;
111 void CExportDlg::OnOK()
113 if (!UpdateData(TRUE))
114 return; // don't dismiss dialog (error message already shown by MFC framework)
116 // check it the export path is a valid windows path
117 UpdateRevsionName();
119 if (m_VersionName.IsEmpty())
121 m_tooltips.ShowBalloon(IDC_COMBOBOXEX_VERSION, IDS_ERR_INVALIDREV, IDS_ERR_ERROR, TTI_ERROR);
122 return;
125 if(::PathFileExists(m_strFile))
127 if(::PathIsDirectory(m_strFile))
129 CMessageBox::Show(NULL, IDS_PROCEXPORTERRFOLDER, IDS_APPNAME, MB_OK | MB_ICONERROR);
130 return;
132 CString sMessage;
133 sMessage.Format(IDS_PROC_OVERWRITE_CONFIRM, m_strFile);
134 if (CMessageBox::Show(NULL, sMessage, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) != IDYES)
136 return ;
139 else if (m_strFile.IsEmpty())
141 CMessageBox::Show(NULL, IDS_PROC_NOZIPFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
142 return;
145 UpdateData(FALSE);
146 CHorizontalResizableStandAloneDialog::OnOK();
149 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
151 m_tooltips.Pop(); // hide the tooltips
153 // Create a folder browser dialog. If the user selects OK, we should update
154 // the local data members with values from the controls, copy the checkout
155 // directory from the browse folder, then restore the local values into the
156 // dialog controls.
158 this->UpdateRevsionName();
159 CFileDialog dlg(FALSE, _T("zip"), this->m_VersionName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("*.zip"));
161 INT_PTR ret = dlg.DoModal();
162 SetCurrentDirectory(g_Git.m_CurrentDir);
163 if (ret == IDOK)
165 UpdateData(TRUE);
166 m_strFile = dlg.GetPathName();
167 UpdateData(FALSE);
168 OnEnChangeCheckoutdirectory();
172 void CExportDlg::OnEnChangeCheckoutdirectory()
174 UpdateData(TRUE);
175 DialogEnableWindow(IDOK, !m_strFile.IsEmpty());
178 void CExportDlg::OnBnClickedWholeProject()
180 UpdateData(TRUE);
181 SetDlgTitle();
184 void CExportDlg::OnBnClickedShowlog()
186 m_tooltips.Pop(); // hide the tooltips
189 void CExportDlg::OnDestroy()
191 WaitForFinishLoading();
192 __super::OnDestroy();
195 void CExportDlg::SetDlgTitle()
197 if (m_sTitle.IsEmpty())
198 GetWindowText(m_sTitle);
200 if (m_bWholeProject)
201 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
202 else
203 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);