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.
20 #include "TortoiseProc.h"
21 #include "CheckoutDlg.h"
22 #include "RepositoryBrowser.h"
23 #include "Messagebox.h"
24 #include "PathUtils.h"
25 #include "BrowseFolder.h"
29 IMPLEMENT_DYNAMIC(CCheckoutDlg
, CResizableStandAloneDialog
)
30 CCheckoutDlg::CCheckoutDlg(CWnd
* pParent
/*=NULL*/)
31 : CResizableStandAloneDialog(CCheckoutDlg::IDD
, pParent
)
32 , Revision(_T("HEAD"))
33 , m_strCheckoutDirectory(_T(""))
34 , m_sCheckoutDirOrig(_T(""))
35 , m_bNoExternals(FALSE
)
40 CCheckoutDlg::~CCheckoutDlg()
46 void CCheckoutDlg::DoDataExchange(CDataExchange
* pDX
)
48 CResizableStandAloneDialog::DoDataExchange(pDX
);
49 DDX_Control(pDX
, IDC_URLCOMBO
, m_URLCombo
);
50 DDX_Control(pDX
, IDC_REVISION_NUM
, m_editRevision
);
51 DDX_Control(pDX
, IDC_BROWSE
, m_butBrowse
);
52 DDX_Text(pDX
, IDC_REVISION_NUM
, m_sRevision
);
53 DDX_Text(pDX
, IDC_CHECKOUTDIRECTORY
, m_strCheckoutDirectory
);
54 DDX_Check(pDX
, IDC_NOEXTERNALS
, m_bNoExternals
);
55 DDX_Control(pDX
, IDC_CHECKOUTDIRECTORY
, m_cCheckoutEdit
);
56 DDX_Control(pDX
, IDC_DEPTH
, m_depthCombo
);
60 BEGIN_MESSAGE_MAP(CCheckoutDlg
, CResizableStandAloneDialog
)
61 ON_REGISTERED_MESSAGE(WM_REVSELECTED
, OnRevSelected
)
62 ON_BN_CLICKED(IDC_BROWSE
, OnBnClickedBrowse
)
63 ON_BN_CLICKED(IDC_CHECKOUTDIRECTORY_BROWSE
, OnBnClickedCheckoutdirectoryBrowse
)
64 ON_EN_CHANGE(IDC_CHECKOUTDIRECTORY
, OnEnChangeCheckoutdirectory
)
65 ON_BN_CLICKED(IDHELP
, OnBnClickedHelp
)
66 ON_BN_CLICKED(IDC_SHOW_LOG
, OnBnClickedShowlog
)
67 ON_EN_CHANGE(IDC_REVISION_NUM
, &CCheckoutDlg::OnEnChangeRevisionNum
)
68 ON_CBN_EDITCHANGE(IDC_URLCOMBO
, &CCheckoutDlg::OnCbnEditchangeUrlcombo
)
71 BOOL
CCheckoutDlg::OnInitDialog()
73 CResizableStandAloneDialog::OnInitDialog();
75 AdjustControlSize(IDC_NOEXTERNALS
);
76 AdjustControlSize(IDC_REVISION_HEAD
);
77 AdjustControlSize(IDC_REVISION_N
);
79 m_sCheckoutDirOrig
= m_strCheckoutDirectory
;
81 CString sUrlSave
= m_URL
;
82 m_URLCombo
.SetURLHistory(TRUE
);
83 m_bAutoCreateTargetName
= FALSE
;
84 m_URLCombo
.LoadHistory(_T("Software\\TortoiseGit\\History\\repoURLS"), _T("url"));
85 m_bAutoCreateTargetName
= !PathIsDirectoryEmpty(m_sCheckoutDirOrig
);
86 m_URLCombo
.SetCurSel(0);
88 m_depthCombo
.AddString(CString(MAKEINTRESOURCE(IDS_SVN_DEPTH_INFINITE
)));
89 m_depthCombo
.AddString(CString(MAKEINTRESOURCE(IDS_SVN_DEPTH_IMMEDIATE
)));
90 m_depthCombo
.AddString(CString(MAKEINTRESOURCE(IDS_SVN_DEPTH_FILES
)));
91 m_depthCombo
.AddString(CString(MAKEINTRESOURCE(IDS_SVN_DEPTH_EMPTY
)));
92 m_depthCombo
.SetCurSel(0);
94 // set radio buttons according to the revision
95 SetRevision(Revision
);
97 m_editRevision
.SetWindowText(_T(""));
99 if (!sUrlSave
.IsEmpty())
101 SetDlgItemText(IDC_CHECKOUTDIRECTORY
, m_sCheckoutDirOrig
);
102 m_URLCombo
.SetWindowText(sUrlSave
);
104 m_tooltips
.Create(this);
105 m_tooltips
.AddTool(IDC_CHECKOUTDIRECTORY
, IDS_CHECKOUT_TT_DIR
);
107 SHAutoComplete(GetDlgItem(IDC_CHECKOUTDIRECTORY
)->m_hWnd
, SHACF_FILESYSTEM
);
109 if (!Revision
.IsHead())
112 temp
.Format(_T("%ld"), (LONG
)Revision
);
113 m_editRevision
.SetWindowText(temp
);
114 CheckRadioButton(IDC_REVISION_HEAD
, IDC_REVISION_N
, IDC_REVISION_N
);
116 if (m_strCheckoutDirectory
.IsEmpty())
118 CRegString lastCheckoutPath
= CRegString(_T("Software\\TortoiseGit\\History\\lastCheckoutPath"));
119 m_strCheckoutDirectory
= lastCheckoutPath
;
120 if (m_strCheckoutDirectory
.GetLength() <= 2)
121 m_strCheckoutDirectory
+= _T("\\");
125 AddAnchor(IDC_GROUPTOP
, TOP_LEFT
, TOP_RIGHT
);
126 AddAnchor(IDC_URLOFREPO
, TOP_LEFT
, TOP_RIGHT
);
127 AddAnchor(IDC_URLCOMBO
, TOP_LEFT
, TOP_RIGHT
);
128 AddAnchor(IDC_BROWSE
, TOP_RIGHT
);
129 AddAnchor(IDC_EXPORT_CHECKOUTDIR
, TOP_LEFT
, TOP_RIGHT
);
130 AddAnchor(IDC_CHECKOUTDIRECTORY
, TOP_LEFT
, TOP_RIGHT
);
131 AddAnchor(IDC_CHECKOUTDIRECTORY_BROWSE
, TOP_RIGHT
);
132 AddAnchor(IDC_GROUPMIDDLE
, TOP_LEFT
, TOP_RIGHT
);
133 AddAnchor(IDC_DEPTH
, TOP_LEFT
, TOP_RIGHT
);
134 AddAnchor(IDC_NOEXTERNALS
, TOP_LEFT
);
135 AddAnchor(IDC_GROUPBOTTOM
, TOP_LEFT
, TOP_RIGHT
);
136 AddAnchor(IDC_REVISION_HEAD
, TOP_LEFT
);
137 AddAnchor(IDC_REVISION_N
, TOP_LEFT
);
138 AddAnchor(IDC_REVISION_NUM
, TOP_LEFT
);
139 AddAnchor(IDC_SHOW_LOG
, TOP_LEFT
);
140 AddAnchor(IDOK
, TOP_RIGHT
);
141 AddAnchor(IDCANCEL
, TOP_RIGHT
);
142 AddAnchor(IDHELP
, TOP_RIGHT
);
144 // prevent resizing vertically
146 GetWindowRect(&rect
);
149 size
.cy
= rect
.Height();
150 SetMaxTrackSize(size
);
152 if ((m_pParentWnd
==NULL
)&&(hWndExplorer
))
153 CenterWindow(CWnd::FromHandle(hWndExplorer
));
154 EnableSaveRestore(_T("CheckoutDlg"));
158 void CCheckoutDlg::OnOK()
160 if (!UpdateData(TRUE
))
161 return; // don't dismiss dialog (error message already shown by MFC framework)
163 CTSVNPath checkoutDirectory
;
164 if (::PathIsRelative(m_strCheckoutDirectory
))
166 checkoutDirectory
= CTSVNPath(sOrigCWD
);
167 checkoutDirectory
.AppendPathString(_T("\\") + m_strCheckoutDirectory
);
168 m_strCheckoutDirectory
= checkoutDirectory
.GetWinPathString();
171 checkoutDirectory
= CTSVNPath(m_strCheckoutDirectory
);
172 if (!checkoutDirectory
.IsValidOnWindows())
174 ShowBalloon(IDC_CHECKOUTDIRECTORY
, IDS_ERR_NOVALIDPATH
);
178 if (GetCheckedRadioButton(IDC_REVISION_HEAD
, IDC_REVISION_N
) == IDC_REVISION_HEAD
)
180 Revision
= SVNRev(_T("HEAD"));
183 Revision
= SVNRev(m_sRevision
);
184 if (!Revision
.IsValid())
186 ShowBalloon(IDC_REVISION_NUM
, IDS_ERR_INVALIDREV
);
190 bool bAutoCreateTargetName
= m_bAutoCreateTargetName
;
191 m_bAutoCreateTargetName
= false;
192 m_URLCombo
.SaveHistory();
193 m_URL
= m_URLCombo
.GetString();
195 if (!SVN::PathIsURL(CTSVNPath(m_URL
)))
197 ShowBalloon(IDC_URLCOMBO
, IDS_ERR_MUSTBEURL
, IDI_ERROR
);
198 m_bAutoCreateTargetName
= bAutoCreateTargetName
;
202 if (m_strCheckoutDirectory
.IsEmpty())
204 return; //don't dismiss the dialog
206 if (!PathFileExists(m_strCheckoutDirectory
))
209 temp
.Format(IDS_WARN_FOLDERNOTEXIST
, (LPCTSTR
)m_strCheckoutDirectory
);
210 if (CMessageBox::Show(this->m_hWnd
, temp
, _T("TortoiseSVN"), MB_YESNO
| MB_ICONQUESTION
) == IDYES
)
212 CPathUtils::MakeSureDirectoryPathExists(m_strCheckoutDirectory
);
216 m_bAutoCreateTargetName
= bAutoCreateTargetName
;
217 return; //don't dismiss the dialog
220 if (!PathIsDirectoryEmpty(m_strCheckoutDirectory
))
223 message
.Format(CString(MAKEINTRESOURCE(IDS_WARN_FOLDERNOTEMPTY
)),(LPCTSTR
)m_strCheckoutDirectory
);
224 if (CMessageBox::Show(this->m_hWnd
, message
, _T("TortoiseSVN"), MB_YESNO
| MB_ICONQUESTION
) != IDYES
)
226 m_bAutoCreateTargetName
= bAutoCreateTargetName
;
227 return; //don't dismiss the dialog
230 switch (m_depthCombo
.GetCurSel())
233 m_depth
= svn_depth_infinity
;
236 m_depth
= svn_depth_immediates
;
239 m_depth
= svn_depth_files
;
242 m_depth
= svn_depth_empty
;
245 m_depth
= svn_depth_empty
;
249 CRegString lastCheckoutPath
= CRegString(_T("Software\\TortoiseGit\\History\\lastCheckoutPath"));
250 lastCheckoutPath
= m_strCheckoutDirectory
.Left(m_strCheckoutDirectory
.ReverseFind('\\'));
251 CResizableStandAloneDialog::OnOK();
254 void CCheckoutDlg::OnBnClickedBrowse()
256 m_tooltips
.Pop(); // hide the tooltips
259 if (GetCheckedRadioButton(IDC_REVISION_HEAD
, IDC_REVISION_N
) == IDC_REVISION_HEAD
)
261 rev
= SVNRev(_T("HEAD"));
264 rev
= SVNRev(m_sRevision
);
267 rev
= SVNRev::REV_HEAD
;
268 if (CAppUtils::BrowseRepository(m_URLCombo
, this, rev
))
272 CRegString
regDefCheckoutUrl(_T("Software\\TortoiseGit\\DefaultCheckoutUrl"));
273 CRegString
regDefCheckoutPath(_T("Software\\TortoiseGit\\DefaultCheckoutPath"));
274 if (!CString(regDefCheckoutUrl
).IsEmpty())
276 m_URL
= m_URLCombo
.GetString();
280 m_URLCombo
.GetWindowText(m_URL
);
284 CString name
= CAppUtils::GetProjectNameFromURL(m_URL
);
285 if (CPathUtils::GetFileNameFromPath(m_strCheckoutDirectory
).CompareNoCase(name
))
286 m_strCheckoutDirectory
= m_sCheckoutDirOrig
.TrimRight('\\')+_T('\\')+name
;
287 if (m_strCheckoutDirectory
.IsEmpty())
289 CRegString lastCheckoutPath
= CRegString(_T("Software\\TortoiseGit\\History\\lastCheckoutPath"));
290 m_strCheckoutDirectory
= lastCheckoutPath
;
291 if (m_strCheckoutDirectory
.GetLength() <= 2)
292 m_strCheckoutDirectory
+= _T("\\");
298 void CCheckoutDlg::OnBnClickedCheckoutdirectoryBrowse()
300 m_tooltips
.Pop(); // hide the tooltips
302 // Create a folder browser dialog. If the user selects OK, we should update
303 // the local data members with values from the controls, copy the checkout
304 // directory from the browse folder, then restore the local values into the
307 CBrowseFolder browseFolder
;
308 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
309 CString strCheckoutDirectory
= m_strCheckoutDirectory
;
310 if (browseFolder
.Show(GetSafeHwnd(), strCheckoutDirectory
) == CBrowseFolder::OK
)
313 m_strCheckoutDirectory
= strCheckoutDirectory
;
314 m_sCheckoutDirOrig
= m_strCheckoutDirectory
;
315 m_bAutoCreateTargetName
= !PathIsDirectoryEmpty(m_sCheckoutDirOrig
);
320 BOOL
CCheckoutDlg::PreTranslateMessage(MSG
* pMsg
)
322 m_tooltips
.RelayEvent(pMsg
);
323 return CResizableStandAloneDialog::PreTranslateMessage(pMsg
);
326 void CCheckoutDlg::OnEnChangeCheckoutdirectory()
329 DialogEnableWindow(IDOK
, !m_strCheckoutDirectory
.IsEmpty());
332 void CCheckoutDlg::OnBnClickedHelp()
337 void CCheckoutDlg::OnBnClickedShowlog()
339 m_tooltips
.Pop(); // hide the tooltips
341 m_URL
= m_URLCombo
.GetString();
342 if ((m_pLogDlg
)&&(m_pLogDlg
->IsWindowVisible()))
344 AfxGetApp()->DoWaitCursor(1);
345 //now show the log dialog for working copy
346 if (!m_URL
.IsEmpty())
349 m_pLogDlg
= new CLogDlg();
350 m_pLogDlg
->SetParams(CTSVNPath(m_URL
), SVNRev::REV_HEAD
, SVNRev::REV_HEAD
, 1, (int)(DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100));
351 m_pLogDlg
->m_wParam
= 1;
352 m_pLogDlg
->SetSelect(true);
353 m_pLogDlg
->m_pNotifyWindow
= this;
354 m_pLogDlg
->Create(IDD_LOGMESSAGE
, this);
355 m_pLogDlg
->ShowWindow(SW_SHOW
);
357 AfxGetApp()->DoWaitCursor(-1);
360 LPARAM
CCheckoutDlg::OnRevSelected(WPARAM
/*wParam*/, LPARAM lParam
)
363 temp
.Format(_T("%ld"), lParam
);
364 SetDlgItemText(IDC_REVISION_NUM
, temp
);
365 CheckRadioButton(IDC_REVISION_HEAD
, IDC_REVISION_N
, IDC_REVISION_N
);
369 void CCheckoutDlg::OnEnChangeRevisionNum()
372 if (m_sRevision
.IsEmpty())
373 CheckRadioButton(IDC_REVISION_HEAD
, IDC_REVISION_N
, IDC_REVISION_HEAD
);
375 CheckRadioButton(IDC_REVISION_HEAD
, IDC_REVISION_N
, IDC_REVISION_N
);
378 void CCheckoutDlg::SetRevision(const SVNRev
& rev
)
380 if (rev
.IsHead() || !rev
.IsValid())
381 CheckRadioButton(IDC_REVISION_HEAD
, IDC_REVISION_N
, IDC_REVISION_HEAD
);
384 CheckRadioButton(IDC_REVISION_HEAD
, IDC_REVISION_N
, IDC_REVISION_N
);
386 sRev
.Format(_T("%ld"), (LONG
)rev
);
387 SetDlgItemText(IDC_REVISION_NUM
, sRev
);
391 void CCheckoutDlg::OnCbnEditchangeUrlcombo()
393 if (!m_bAutoCreateTargetName
)
395 if (m_sCheckoutDirOrig
.IsEmpty())
397 // find out what to use as the checkout directory name
399 m_URLCombo
.GetWindowText(m_URL
);
402 CString tempURL
= m_URL
;
403 CString name
= CAppUtils::GetProjectNameFromURL(m_URL
);
404 if (CPathUtils::GetFileNameFromPath(m_strCheckoutDirectory
).CompareNoCase(name
))
405 m_strCheckoutDirectory
= m_sCheckoutDirOrig
.TrimRight('\\')+_T('\\')+name
;
406 if (m_strCheckoutDirectory
.IsEmpty())
408 CRegString lastCheckoutPath
= CRegString(_T("Software\\TortoiseGit\\History\\lastCheckoutPath"));
409 m_strCheckoutDirectory
= lastCheckoutPath
;
410 if (m_strCheckoutDirectory
.GetLength() <= 2)
411 m_strCheckoutDirectory
+= _T("\\");