Extend static functions in CAppUtils with a window handle parameter
[TortoiseGit.git] / src / TortoiseProc / ExportDlg.cpp
blob8eb874343b63f572156f78f8e20d8c1a3a624c86
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2017 - 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 InitChooseVersion();
70 if (m_initialRefName.IsEmpty() || m_initialRefName == L"HEAD")
71 SetDefaultChoose(IDC_RADIO_HEAD);
72 else if (CStringUtils::StartsWith(m_initialRefName, L"refs/tags/"))
73 SetDefaultChoose(IDC_RADIO_TAGS);
75 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
76 CString headText;
77 pHead->GetWindowText(headText);
78 pHead->SetWindowText(headText + " (" + g_Git.GetCurrentBranch() + ")");
80 AdjustControlSize(IDC_RADIO_BRANCH);
81 AdjustControlSize(IDC_RADIO_TAGS);
82 AdjustControlSize(IDC_RADIO_VERSION);
83 AdjustControlSize(IDC_RADIO_HEAD);
85 AddAnchor(IDC_REPOGROUP, TOP_LEFT, TOP_RIGHT);
86 AddAnchor(IDC_EXPORTFILE_LABEL, TOP_LEFT);
87 AddAnchor(IDC_EXPORTFILE_BROWSE, TOP_RIGHT);
88 AddAnchor(IDC_EXPORTFILE, TOP_LEFT, TOP_RIGHT);
90 AddAnchor(IDOK, BOTTOM_RIGHT);
91 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
92 AddAnchor(IDHELP, BOTTOM_RIGHT);
94 SetDlgTitle();
96 CHOOSE_VERSION_ADDANCHOR;
97 AddOthersToAnchor();
99 m_tooltips.AddTool(IDC_EXPORTFILE, IDS_EXPORTFILE_TT);
101 SHAutoComplete(GetDlgItem(IDC_EXPORTFILE)->m_hWnd, SHACF_FILESYSTEM);
103 if (!m_pParentWnd && hWndExplorer)
104 CenterWindow(CWnd::FromHandle(hWndExplorer));
105 EnableSaveRestore(L"ExportDlg");
106 return TRUE;
109 void CExportDlg::OnOK()
111 if (!UpdateData(TRUE))
112 return; // don't dismiss dialog (error message already shown by MFC framework)
114 // check it the export path is a valid windows path
115 UpdateRevsionName();
117 if (m_VersionName.IsEmpty())
119 m_tooltips.ShowBalloon(IDC_COMBOBOXEX_VERSION, IDS_ERR_INVALIDREV, IDS_ERR_ERROR, TTI_ERROR);
120 return;
123 if(::PathFileExists(m_strFile))
125 if(::PathIsDirectory(m_strFile))
127 CMessageBox::Show(GetSafeHwnd(), IDS_PROCEXPORTERRFOLDER, IDS_APPNAME, MB_OK | MB_ICONERROR);
128 return;
130 CString sMessage;
131 sMessage.Format(IDS_PROC_OVERWRITE_CONFIRM, (LPCTSTR)m_strFile);
132 if (CMessageBox::Show(GetSafeHwnd(), sMessage, L"TortoiseGit", MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) != IDYES)
133 return ;
135 else if (m_strFile.IsEmpty())
137 CMessageBox::Show(GetSafeHwnd(), IDS_PROC_NOZIPFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
138 return;
141 UpdateData(FALSE);
142 CHorizontalResizableStandAloneDialog::OnOK();
145 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
147 m_tooltips.Pop(); // hide the tooltips
149 // Create a folder browser dialog. If the user selects OK, we should update
150 // the local data members with values from the controls, copy the checkout
151 // directory from the browse folder, then restore the local values into the
152 // dialog controls.
154 this->UpdateRevsionName();
155 CString filename = m_VersionName;
156 if (!CAppUtils::FileOpenSave(filename, nullptr, 0, IDS_ARCHIVEFILEFILTER, false, GetSafeHwnd(), L"zip"))
157 return;
159 UpdateData(TRUE);
160 m_strFile = filename;
161 UpdateData(FALSE);
162 OnEnChangeCheckoutdirectory();
165 void CExportDlg::OnEnChangeCheckoutdirectory()
167 UpdateData(TRUE);
168 DialogEnableWindow(IDOK, !m_strFile.IsEmpty());
171 void CExportDlg::OnBnClickedWholeProject()
173 UpdateData(TRUE);
174 SetDlgTitle();
177 void CExportDlg::OnBnClickedShowlog()
179 m_tooltips.Pop(); // hide the tooltips
182 void CExportDlg::OnDestroy()
184 WaitForFinishLoading();
185 __super::OnDestroy();
188 void CExportDlg::SetDlgTitle()
190 if (m_sTitle.IsEmpty())
191 GetWindowText(m_sTitle);
193 if (m_bWholeProject)
194 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
195 else
196 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);