1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2016 - 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.
21 #include "TortoiseProc.h"
22 #include "ExportDlg.h"
23 #include "MessageBox.h"
24 #include "BrowseFolder.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(_T("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
);
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
)
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 AddAnchor(IDC_REPOGROUP
, TOP_LEFT
, TOP_RIGHT
);
70 AddAnchor(IDC_EXPORTFILE_LABEL
, TOP_LEFT
);
71 AddAnchor(IDC_EXPORTFILE_BROWSE
, TOP_RIGHT
);
72 AddAnchor(IDC_EXPORTFILE
, TOP_LEFT
, TOP_RIGHT
);
74 AddAnchor(IDOK
, BOTTOM_RIGHT
);
75 AddAnchor(IDCANCEL
, BOTTOM_RIGHT
);
76 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
78 AdjustControlSize(IDC_RADIO_BRANCH
);
79 AdjustControlSize(IDC_RADIO_TAGS
);
80 AdjustControlSize(IDC_RADIO_VERSION
);
84 CHOOSE_VERSION_ADDANCHOR
;
85 this->AddOthersToAnchor();
87 if (m_initialRefName
.IsEmpty() || m_initialRefName
== _T("HEAD"))
88 SetDefaultChoose(IDC_RADIO_HEAD
);
89 else if (m_initialRefName
.Left(10) == _T("refs/tags/"))
90 SetDefaultChoose(IDC_RADIO_TAGS
);
92 CWnd
* pHead
= GetDlgItem(IDC_RADIO_HEAD
);
94 pHead
->GetWindowText(headText
);
95 pHead
->SetWindowText(headText
+ " (" + g_Git
.GetCurrentBranch() + ")");
96 AdjustControlSize(IDC_RADIO_HEAD
);
98 m_tooltips
.AddTool(IDC_EXPORTFILE
, IDS_EXPORTFILE_TT
);
100 SHAutoComplete(GetDlgItem(IDC_EXPORTFILE
)->m_hWnd
, SHACF_FILESYSTEM
);
102 if (!m_pParentWnd
&& hWndExplorer
)
103 CenterWindow(CWnd::FromHandle(hWndExplorer
));
104 EnableSaveRestore(_T("ExportDlg"));
108 void CExportDlg::OnOK()
110 if (!UpdateData(TRUE
))
111 return; // don't dismiss dialog (error message already shown by MFC framework)
113 // check it the export path is a valid windows path
116 if (m_VersionName
.IsEmpty())
118 m_tooltips
.ShowBalloon(IDC_COMBOBOXEX_VERSION
, IDS_ERR_INVALIDREV
, IDS_ERR_ERROR
, TTI_ERROR
);
122 if(::PathFileExists(m_strFile
))
124 if(::PathIsDirectory(m_strFile
))
126 CMessageBox::Show(GetSafeHwnd(), IDS_PROCEXPORTERRFOLDER
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
130 sMessage
.Format(IDS_PROC_OVERWRITE_CONFIRM
, (LPCTSTR
)m_strFile
);
131 if (CMessageBox::Show(GetSafeHwnd(), sMessage
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
| MB_DEFBUTTON2
) != IDYES
)
134 else if (m_strFile
.IsEmpty())
136 CMessageBox::Show(GetSafeHwnd(), IDS_PROC_NOZIPFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
141 CHorizontalResizableStandAloneDialog::OnOK();
144 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
146 m_tooltips
.Pop(); // hide the tooltips
148 // Create a folder browser dialog. If the user selects OK, we should update
149 // the local data members with values from the controls, copy the checkout
150 // directory from the browse folder, then restore the local values into the
153 this->UpdateRevsionName();
154 CFileDialog
dlg(FALSE
, _T("zip"), this->m_VersionName
, OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
, _T("*.zip"));
156 INT_PTR ret
= dlg
.DoModal();
157 SetCurrentDirectory(g_Git
.m_CurrentDir
);
161 m_strFile
= dlg
.GetPathName();
163 OnEnChangeCheckoutdirectory();
167 void CExportDlg::OnEnChangeCheckoutdirectory()
170 DialogEnableWindow(IDOK
, !m_strFile
.IsEmpty());
173 void CExportDlg::OnBnClickedWholeProject()
179 void CExportDlg::OnBnClickedShowlog()
181 m_tooltips
.Pop(); // hide the tooltips
184 void CExportDlg::OnDestroy()
186 WaitForFinishLoading();
187 __super::OnDestroy();
190 void CExportDlg::SetDlgTitle()
192 if (m_sTitle
.IsEmpty())
193 GetWindowText(m_sTitle
);
196 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, m_sTitle
);
198 CAppUtils::SetWindowTitle(m_hWnd
, m_orgPath
.GetWinPathString(), m_sTitle
);