some spaces-tabs code cleanup
[TortoiseGit.git] / src / TortoiseProc / ExportDlg.cpp
blob4fd612bfb08a8332c31d87d95879a5ff208877be
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2011 - 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_Revision(_T("HEAD"))
35 , m_strExportDirectory(_T(""))
36 , m_sExportDirOrig(_T(""))
37 , m_bNoExternals(FALSE)
38 , m_pLogDlg(NULL)
42 CExportDlg::~CExportDlg()
44 if (m_pLogDlg)
45 delete m_pLogDlg;
48 void CExportDlg::DoDataExchange(CDataExchange* pDX)
50 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
51 DDX_Text(pDX, IDC_CHECKOUTDIRECTORY, m_strExportDirectory);
52 DDX_Control(pDX, IDC_CHECKOUTDIRECTORY, m_cCheckoutEdit);
54 CHOOSE_VERSION_DDX;
59 BEGIN_MESSAGE_MAP(CExportDlg, CHorizontalResizableStandAloneDialog)
60 ON_REGISTERED_MESSAGE(WM_REVSELECTED, OnRevSelected)
61 ON_BN_CLICKED(IDC_CHECKOUTDIRECTORY_BROWSE, OnBnClickedCheckoutdirectoryBrowse)
62 ON_EN_CHANGE(IDC_CHECKOUTDIRECTORY, OnEnChangeCheckoutdirectory)
63 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
65 CHOOSE_VERSION_EVENT
66 ON_WM_DESTROY()
67 END_MESSAGE_MAP()
69 BOOL CExportDlg::OnInitDialog()
71 CHorizontalResizableStandAloneDialog::OnInitDialog();
72 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
74 m_sExportDirOrig = m_strExportDirectory;
75 m_bAutoCreateTargetName = !PathIsDirectoryEmpty(m_sExportDirOrig);
77 AddAnchor(IDC_REPOGROUP, TOP_LEFT, TOP_RIGHT);
78 AddAnchor(IDC_EXPORT_CHECKOUTDIR, TOP_LEFT);
79 AddAnchor(IDC_CHECKOUTDIRECTORY_BROWSE, TOP_RIGHT);
80 AddAnchor(IDC_CHECKOUTDIRECTORY, TOP_LEFT, TOP_RIGHT);
82 AddAnchor(IDOK, BOTTOM_RIGHT);
83 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
84 AddAnchor(IDHELP, BOTTOM_RIGHT);
86 CString sWindowTitle;
87 GetWindowText(sWindowTitle);
88 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
90 CHOOSE_VERSION_ADDANCHOR;
91 Init();
92 if(this->m_Revision.IsEmpty())
94 SetDefaultChoose(IDC_RADIO_HEAD);
96 else
98 SetDefaultChoose(IDC_RADIO_VERSION);
99 this->GetDlgItem(IDC_COMBOBOXEX_VERSION)->SetWindowTextW(m_Revision);
102 m_tooltips.Create(this);
103 m_tooltips.AddTool(IDC_CHECKOUTDIRECTORY, IDS_CHECKOUT_TT_DIR);
105 SHAutoComplete(GetDlgItem(IDC_CHECKOUTDIRECTORY)->m_hWnd, SHACF_FILESYSTEM);
107 if ((m_pParentWnd==NULL)&&(hWndExplorer))
108 CenterWindow(CWnd::FromHandle(hWndExplorer));
109 EnableSaveRestore(_T("ExportDlg"));
110 return TRUE;
113 void CExportDlg::OnOK()
115 if (!UpdateData(TRUE))
116 return; // don't dismiss dialog (error message already shown by MFC framework)
118 // check it the export path is a valid windows path
119 UpdateRevsionName();
121 if (m_VersionName.IsEmpty())
123 ShowBalloon(IDC_REVISION_NUM, IDS_ERR_INVALIDREV);
124 return;
127 m_bAutoCreateTargetName = false;
129 // m_URLCombo.SaveHistory();
130 // m_URL = m_URLCombo.GetString();
133 if(::PathFileExists(this->m_strExportDirectory))
135 if(::PathIsDirectory(m_strExportDirectory))
137 CMessageBox::Show(NULL,_T("The folder is invalidate\r\n Export file must be a zip file\r\n"),
138 _T("TortoiseGit"), MB_OK|MB_ICONERROR);
139 return;
141 if( CMessageBox::Show(NULL,m_strExportDirectory+_T(" is exist\r\nDo you want to overwire it?"),
142 _T("TortoiseGit"), MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2) != IDYES)
144 return ;
148 UpdateData(FALSE);
149 CHorizontalResizableStandAloneDialog::OnOK();
152 void CExportDlg::OnBnClickedBrowse()
154 m_tooltips.Pop(); // hide the tooltips
158 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
160 m_tooltips.Pop(); // hide the tooltips
162 // Create a folder browser dialog. If the user selects OK, we should update
163 // the local data members with values from the controls, copy the checkout
164 // directory from the browse folder, then restore the local values into the
165 // dialog controls.
167 this->UpdateRevsionName();
168 CFileDialog dlg(FALSE,_T("Zip"),this->m_VersionName,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
169 _T("*.Zip"));
171 if(dlg.DoModal()==IDOK)
173 UpdateData(TRUE);
174 m_strExportDirectory = dlg.GetPathName();
175 UpdateData(FALSE);
179 BOOL CExportDlg::PreTranslateMessage(MSG* pMsg)
181 m_tooltips.RelayEvent(pMsg);
182 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
185 void CExportDlg::OnEnChangeCheckoutdirectory()
187 UpdateData(TRUE);
188 DialogEnableWindow(IDOK, !m_strExportDirectory.IsEmpty());
191 void CExportDlg::OnBnClickedHelp()
193 OnHelp();
196 void CExportDlg::OnBnClickedShowlog()
198 m_tooltips.Pop(); // hide the tooltips
202 LPARAM CExportDlg::OnRevSelected(WPARAM /*wParam*/, LPARAM lParam)
204 CString temp;
205 temp.Format(_T("%ld"), lParam);
206 SetDlgItemText(IDC_REVISION_NUM, temp);
207 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_N);
208 return 0;
211 void CExportDlg::OnEnChangeRevisionNum()
213 UpdateData();
214 if (m_sRevision.IsEmpty())
215 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_HEAD);
216 else
217 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_N);
220 void CExportDlg::OnCbnSelchangeEolcombo()
224 void CExportDlg::SetRevision(const CString& rev)
226 if (rev==_T("HEAD"))
227 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_HEAD);
228 else
230 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_N);
231 CString sRev;
232 sRev.Format(_T("%s"), rev);
233 SetDlgItemText(IDC_REVISION_NUM, sRev);
237 void CExportDlg::OnCbnEditchangeUrlcombo()
239 if (!m_bAutoCreateTargetName)
240 return;
241 if (m_sExportDirOrig.IsEmpty())
242 return;
243 // find out what to use as the checkout directory name
244 UpdateData();
245 m_URLCombo.GetWindowText(m_URL);
246 if (m_URL.IsEmpty())
247 return;
248 CString name = CAppUtils::GetProjectNameFromURL(m_URL);
249 m_strExportDirectory = m_sExportDirOrig+_T('\\')+name;
250 UpdateData(FALSE);
253 void CExportDlg::OnDestroy()
255 WaitForFinishLoading();
256 __super::OnDestroy();