BrowseRefs: Context menu enhancements
[TortoiseGit.git] / src / TortoiseProc / ExportDlg.cpp
blob97330a00aba6e42c80194300b7b586dad9630032
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "ExportDlg.h"
23 #include "Messagebox.h"
24 #include "PathUtils.h"
25 #include "BrowseFolder.h"
26 #include "AppUtils.h"
29 IMPLEMENT_DYNAMIC(CExportDlg, CResizableStandAloneDialog)
30 CExportDlg::CExportDlg(CWnd* pParent /*=NULL*/)
31 : CResizableStandAloneDialog(CExportDlg::IDD, pParent)
32 , CChooseVersion(this)
33 , m_Revision(_T("HEAD"))
34 , m_strExportDirectory(_T(""))
35 , m_sExportDirOrig(_T(""))
36 , m_bNoExternals(FALSE)
37 , m_pLogDlg(NULL)
41 CExportDlg::~CExportDlg()
43 if (m_pLogDlg)
44 delete m_pLogDlg;
47 void CExportDlg::DoDataExchange(CDataExchange* pDX)
49 CResizableStandAloneDialog::DoDataExchange(pDX);
50 DDX_Text(pDX, IDC_CHECKOUTDIRECTORY, m_strExportDirectory);
51 DDX_Control(pDX, IDC_CHECKOUTDIRECTORY, m_cCheckoutEdit);
53 CHOOSE_VERSION_DDX;
58 BEGIN_MESSAGE_MAP(CExportDlg, CResizableStandAloneDialog)
59 ON_REGISTERED_MESSAGE(WM_REVSELECTED, OnRevSelected)
60 ON_BN_CLICKED(IDC_CHECKOUTDIRECTORY_BROWSE, OnBnClickedCheckoutdirectoryBrowse)
61 ON_EN_CHANGE(IDC_CHECKOUTDIRECTORY, OnEnChangeCheckoutdirectory)
62 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
64 CHOOSE_VERSION_EVENT
65 END_MESSAGE_MAP()
67 BOOL CExportDlg::OnInitDialog()
69 CResizableStandAloneDialog::OnInitDialog();
71 m_sExportDirOrig = m_strExportDirectory;
72 m_bAutoCreateTargetName = !PathIsDirectoryEmpty(m_sExportDirOrig);
74 AddAnchor(IDC_REPOGROUP, TOP_LEFT, TOP_RIGHT);
75 AddAnchor(IDC_EXPORT_CHECKOUTDIR, TOP_LEFT);
76 AddAnchor(IDC_CHECKOUTDIRECTORY, TOP_LEFT, TOP_RIGHT);
78 AddAnchor(IDOK, BOTTOM_RIGHT);
79 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
80 AddAnchor(IDHELP, BOTTOM_RIGHT);
82 CHOOSE_VERSION_ADDANCHOR;
83 Init();
84 if(this->m_Revision.IsEmpty())
86 SetDefaultChoose(IDC_RADIO_HEAD);
88 else
90 SetDefaultChoose(IDC_RADIO_VERSION);
91 this->GetDlgItem(IDC_COMBOBOXEX_VERSION)->SetWindowTextW(m_Revision);
94 m_tooltips.Create(this);
95 m_tooltips.AddTool(IDC_CHECKOUTDIRECTORY, IDS_CHECKOUT_TT_DIR);
97 SHAutoComplete(GetDlgItem(IDC_CHECKOUTDIRECTORY)->m_hWnd, SHACF_FILESYSTEM);
99 if ((m_pParentWnd==NULL)&&(hWndExplorer))
100 CenterWindow(CWnd::FromHandle(hWndExplorer));
101 EnableSaveRestore(_T("ExportDlg"));
102 return TRUE;
105 void CExportDlg::OnOK()
107 if (!UpdateData(TRUE))
108 return; // don't dismiss dialog (error message already shown by MFC framework)
110 // check it the export path is a valid windows path
111 UpdateRevsionName();
113 if (m_VersionName.IsEmpty())
115 ShowBalloon(IDC_REVISION_NUM, IDS_ERR_INVALIDREV);
116 return;
119 m_bAutoCreateTargetName = false;
121 // m_URLCombo.SaveHistory();
122 // m_URL = m_URLCombo.GetString();
125 UpdateData(FALSE);
126 CResizableStandAloneDialog::OnOK();
129 void CExportDlg::OnBnClickedBrowse()
131 m_tooltips.Pop(); // hide the tooltips
135 void CExportDlg::OnBnClickedCheckoutdirectoryBrowse()
137 m_tooltips.Pop(); // hide the tooltips
139 // Create a folder browser dialog. If the user selects OK, we should update
140 // the local data members with values from the controls, copy the checkout
141 // directory from the browse folder, then restore the local values into the
142 // dialog controls.
144 this->UpdateRevsionName();
145 CFileDialog dlg(FALSE,_T("Zip"),this->m_VersionName,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
146 _T("*.Zip"));
148 if(dlg.DoModal()==IDOK)
150 UpdateData(TRUE);
151 m_strExportDirectory = dlg.GetPathName();
152 UpdateData(FALSE);
156 BOOL CExportDlg::PreTranslateMessage(MSG* pMsg)
158 m_tooltips.RelayEvent(pMsg);
159 return CResizableStandAloneDialog::PreTranslateMessage(pMsg);
162 void CExportDlg::OnEnChangeCheckoutdirectory()
164 UpdateData(TRUE);
165 DialogEnableWindow(IDOK, !m_strExportDirectory.IsEmpty());
168 void CExportDlg::OnBnClickedHelp()
170 OnHelp();
173 void CExportDlg::OnBnClickedShowlog()
175 m_tooltips.Pop(); // hide the tooltips
179 LPARAM CExportDlg::OnRevSelected(WPARAM /*wParam*/, LPARAM lParam)
181 CString temp;
182 temp.Format(_T("%ld"), lParam);
183 SetDlgItemText(IDC_REVISION_NUM, temp);
184 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_N);
185 return 0;
188 void CExportDlg::OnEnChangeRevisionNum()
190 UpdateData();
191 if (m_sRevision.IsEmpty())
192 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_HEAD);
193 else
194 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_N);
197 void CExportDlg::OnCbnSelchangeEolcombo()
201 void CExportDlg::SetRevision(const CString& rev)
203 if (rev==_T("HEAD"))
204 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_HEAD);
205 else
207 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_N);
208 CString sRev;
209 sRev.Format(_T("%s"), rev);
210 SetDlgItemText(IDC_REVISION_NUM, sRev);
214 void CExportDlg::OnCbnEditchangeUrlcombo()
216 if (!m_bAutoCreateTargetName)
217 return;
218 if (m_sExportDirOrig.IsEmpty())
219 return;
220 // find out what to use as the checkout directory name
221 UpdateData();
222 m_URLCombo.GetWindowText(m_URL);
223 if (m_URL.IsEmpty())
224 return;
225 CString name = CAppUtils::GetProjectNameFromURL(m_URL);
226 m_strExportDirectory = m_sExportDirOrig+_T('\\')+name;
227 UpdateData(FALSE);