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.
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
/*=NULL*/)
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"))
89 SetDefaultChoose(IDC_RADIO_HEAD
);
91 else if (m_initialRefName
.Left(10) == _T("refs/tags/"))
92 SetDefaultChoose(IDC_RADIO_TAGS
);
94 CWnd
* pHead
= GetDlgItem(IDC_RADIO_HEAD
);
96 pHead
->GetWindowText(headText
);
97 pHead
->SetWindowText(headText
+ " (" + g_Git
.GetCurrentBranch() + ")");
98 AdjustControlSize(IDC_RADIO_HEAD
);
100 m_tooltips
.AddTool(IDC_EXPORTFILE
, IDS_EXPORTFILE_TT
);
102 SHAutoComplete(GetDlgItem(IDC_EXPORTFILE
)->m_hWnd
, SHACF_FILESYSTEM
);
104 if ((m_pParentWnd
==NULL
)&&(hWndExplorer
))
105 CenterWindow(CWnd::FromHandle(hWndExplorer
));
106 EnableSaveRestore(_T("ExportDlg"));
110 void CExportDlg::OnOK()
112 if (!UpdateData(TRUE
))
113 return; // don't dismiss dialog (error message already shown by MFC framework)
115 // check it the export path is a valid windows path
118 if (m_VersionName
.IsEmpty())
120 m_tooltips
.ShowBalloon(IDC_COMBOBOXEX_VERSION
, IDS_ERR_INVALIDREV
, IDS_ERR_ERROR
, TTI_ERROR
);
124 if(::PathFileExists(m_strFile
))
126 if(::PathIsDirectory(m_strFile
))
128 CMessageBox::Show(NULL
, IDS_PROCEXPORTERRFOLDER
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
132 sMessage
.Format(IDS_PROC_OVERWRITE_CONFIRM
, (LPCTSTR
)m_strFile
);
133 if (CMessageBox::Show(NULL
, sMessage
, _T("TortoiseGit"), MB_YESNO
| MB_ICONQUESTION
| MB_DEFBUTTON2
) != IDYES
)
138 else if (m_strFile
.IsEmpty())
140 CMessageBox::Show(NULL
, IDS_PROC_NOZIPFILE
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
145 CHorizontalResizableStandAloneDialog::OnOK();
148 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
150 m_tooltips
.Pop(); // hide the tooltips
152 // Create a folder browser dialog. If the user selects OK, we should update
153 // the local data members with values from the controls, copy the checkout
154 // directory from the browse folder, then restore the local values into the
157 this->UpdateRevsionName();
158 CFileDialog
dlg(FALSE
, _T("zip"), this->m_VersionName
, OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
, _T("*.zip"));
160 INT_PTR ret
= dlg
.DoModal();
161 SetCurrentDirectory(g_Git
.m_CurrentDir
);
165 m_strFile
= dlg
.GetPathName();
167 OnEnChangeCheckoutdirectory();
171 void CExportDlg::OnEnChangeCheckoutdirectory()
174 DialogEnableWindow(IDOK
, !m_strFile
.IsEmpty());
177 void CExportDlg::OnBnClickedWholeProject()
183 void CExportDlg::OnBnClickedShowlog()
185 m_tooltips
.Pop(); // hide the tooltips
188 void CExportDlg::OnDestroy()
190 WaitForFinishLoading();
191 __super::OnDestroy();
194 void CExportDlg::SetDlgTitle()
196 if (m_sTitle
.IsEmpty())
197 GetWindowText(m_sTitle
);
200 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, m_sTitle
);
202 CAppUtils::SetWindowTitle(m_hWnd
, m_orgPath
.GetWinPathString(), m_sTitle
);