Allow to commit to super project after push in submodule
[TortoiseGit.git] / src / TortoiseProc / ExportDlg.cpp
blobc549d313b6c37907e8bd30c1f18f9f700f3b425e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2014 - 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_bWholeProject(FALSE)
35 , m_Revision(_T("HEAD"))
36 , m_strFile(_T(""))
40 CExportDlg::~CExportDlg()
44 void CExportDlg::DoDataExchange(CDataExchange* pDX)
46 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
47 DDX_Text(pDX, IDC_EXPORTFILE, m_strFile);
48 DDX_Check(pDX, IDC_SHOWWHOLEPROJECT, m_bWholeProject);
49 CHOOSE_VERSION_DDX;
53 BEGIN_MESSAGE_MAP(CExportDlg, CHorizontalResizableStandAloneDialog)
54 ON_BN_CLICKED(IDC_EXPORTFILE_BROWSE, OnBnClickedCheckoutdirectoryBrowse)
55 ON_EN_CHANGE(IDC_EXPORTFILE, OnEnChangeCheckoutdirectory)
56 ON_BN_CLICKED(IDC_SHOWWHOLEPROJECT, OnBnClickedWholeProject)
57 CHOOSE_VERSION_EVENT
58 ON_WM_DESTROY()
59 END_MESSAGE_MAP()
61 BOOL CExportDlg::OnInitDialog()
63 CHorizontalResizableStandAloneDialog::OnInitDialog();
64 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
66 if (g_Git.m_CurrentDir == m_orgPath.GetWinPathString())
68 GetDlgItem(IDC_SHOWWHOLEPROJECT)->EnableWindow(FALSE);
69 ((CButton *)GetDlgItem(IDC_SHOWWHOLEPROJECT))->SetCheck(TRUE);
72 AddAnchor(IDC_REPOGROUP, TOP_LEFT, TOP_RIGHT);
73 AddAnchor(IDC_EXPORTFILE_LABEL, TOP_LEFT);
74 AddAnchor(IDC_EXPORTFILE_BROWSE, TOP_RIGHT);
75 AddAnchor(IDC_EXPORTFILE, TOP_LEFT, TOP_RIGHT);
77 AddAnchor(IDOK, BOTTOM_RIGHT);
78 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
79 AddAnchor(IDHELP, BOTTOM_RIGHT);
81 AdjustControlSize(IDC_RADIO_BRANCH);
82 AdjustControlSize(IDC_RADIO_TAGS);
83 AdjustControlSize(IDC_RADIO_VERSION);
85 SetDlgTitle();
87 CHOOSE_VERSION_ADDANCHOR;
88 this->AddOthersToAnchor();
89 InitChooseVersion();
90 if (m_Revision.IsEmpty() || m_Revision == _T("HEAD"))
92 SetDefaultChoose(IDC_RADIO_HEAD);
94 else
96 SetDefaultChoose(IDC_RADIO_VERSION);
97 this->GetDlgItem(IDC_COMBOBOXEX_VERSION)->SetWindowTextW(m_Revision);
100 CWnd* pHead = GetDlgItem(IDC_RADIO_HEAD);
101 CString headText;
102 pHead->GetWindowText(headText);
103 pHead->SetWindowText(headText + " (" + g_Git.GetCurrentBranch() + ")");
104 AdjustControlSize(IDC_RADIO_HEAD);
106 m_tooltips.Create(this);
107 m_tooltips.AddTool(IDC_EXPORTFILE, IDS_EXPORTFILE_TT);
109 SHAutoComplete(GetDlgItem(IDC_EXPORTFILE)->m_hWnd, SHACF_FILESYSTEM);
111 if ((m_pParentWnd==NULL)&&(hWndExplorer))
112 CenterWindow(CWnd::FromHandle(hWndExplorer));
113 EnableSaveRestore(_T("ExportDlg"));
114 return TRUE;
117 void CExportDlg::OnOK()
119 if (!UpdateData(TRUE))
120 return; // don't dismiss dialog (error message already shown by MFC framework)
122 // check it the export path is a valid windows path
123 UpdateRevsionName();
125 if (m_VersionName.IsEmpty())
127 m_tooltips.ShowBalloon(IDC_COMBOBOXEX_VERSION, IDS_ERR_INVALIDREV, IDS_ERR_ERROR, TTI_ERROR);
128 return;
131 if(::PathFileExists(m_strFile))
133 if(::PathIsDirectory(m_strFile))
135 CMessageBox::Show(NULL, IDS_PROCEXPORTERRFOLDER, IDS_APPNAME, MB_OK | MB_ICONERROR);
136 return;
138 CString sMessage;
139 sMessage.Format(IDS_PROC_OVERWRITE_CONFIRM, m_strFile);
140 if (CMessageBox::Show(NULL, sMessage, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) != IDYES)
142 return ;
145 else if (m_strFile.IsEmpty())
147 CMessageBox::Show(NULL, IDS_PROC_NOZIPFILE, IDS_APPNAME, MB_OK | MB_ICONERROR);
148 return;
151 UpdateData(FALSE);
152 CHorizontalResizableStandAloneDialog::OnOK();
155 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
157 m_tooltips.Pop(); // hide the tooltips
159 // Create a folder browser dialog. If the user selects OK, we should update
160 // the local data members with values from the controls, copy the checkout
161 // directory from the browse folder, then restore the local values into the
162 // dialog controls.
164 this->UpdateRevsionName();
165 CFileDialog dlg(FALSE, _T("zip"), this->m_VersionName, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("*.zip"));
167 INT_PTR ret = dlg.DoModal();
168 SetCurrentDirectory(g_Git.m_CurrentDir);
169 if (ret == IDOK)
171 UpdateData(TRUE);
172 m_strFile = dlg.GetPathName();
173 UpdateData(FALSE);
174 OnEnChangeCheckoutdirectory();
178 BOOL CExportDlg::PreTranslateMessage(MSG* pMsg)
180 m_tooltips.RelayEvent(pMsg);
181 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
184 void CExportDlg::OnEnChangeCheckoutdirectory()
186 UpdateData(TRUE);
187 DialogEnableWindow(IDOK, !m_strFile.IsEmpty());
190 void CExportDlg::OnBnClickedWholeProject()
192 UpdateData(TRUE);
193 SetDlgTitle();
196 void CExportDlg::OnBnClickedShowlog()
198 m_tooltips.Pop(); // hide the tooltips
201 void CExportDlg::OnDestroy()
203 WaitForFinishLoading();
204 __super::OnDestroy();
207 void CExportDlg::SetDlgTitle()
209 if (m_sTitle.IsEmpty())
210 GetWindowText(m_sTitle);
212 if (m_bWholeProject)
213 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, m_sTitle);
214 else
215 CAppUtils::SetWindowTitle(m_hWnd, m_orgPath.GetWinPathString(), m_sTitle);