Initial version of BrowseRefsDlg
[TortoiseGit.git] / src / TortoiseProc / UrlDiffDlg.cpp
blobd6cb5f48afac7e8de601351880d032f4fe36cc01
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2007-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 "UrlDiffDlg.h"
22 #include "RepositoryBrowser.h"
23 #include "BrowseFolder.h"
24 #include "TSVNPath.h"
25 #include "AppUtils.h"
27 IMPLEMENT_DYNAMIC(CUrlDiffDlg, CResizableStandAloneDialog)
28 CUrlDiffDlg::CUrlDiffDlg(CWnd* pParent /*=NULL*/)
29 : CResizableStandAloneDialog(CUrlDiffDlg::IDD, pParent)
30 , m_URL(_T(""))
31 , Revision(_T("HEAD"))
32 , m_pLogDlg(NULL)
36 CUrlDiffDlg::~CUrlDiffDlg()
38 if (m_pLogDlg)
39 delete m_pLogDlg;
42 void CUrlDiffDlg::DoDataExchange(CDataExchange* pDX)
44 CResizableStandAloneDialog::DoDataExchange(pDX);
45 DDX_Control(pDX, IDC_URLCOMBO, m_URLCombo);
46 DDX_Text(pDX, IDC_REVISION_NUM, m_rev);
50 BEGIN_MESSAGE_MAP(CUrlDiffDlg, CResizableStandAloneDialog)
51 ON_BN_CLICKED(IDC_BROWSE, OnBnClickedBrowse)
52 ON_BN_CLICKED(IDHELP, OnBnClickedHelp)
53 ON_EN_CHANGE(IDC_REVISION_NUM, &CUrlDiffDlg::OnEnChangeRevisionNum)
54 ON_BN_CLICKED(IDC_LOG, &CUrlDiffDlg::OnBnClickedLog)
55 ON_REGISTERED_MESSAGE(WM_REVSELECTED, &CUrlDiffDlg::OnRevSelected)
56 END_MESSAGE_MAP()
59 BOOL CUrlDiffDlg::OnInitDialog()
61 CResizableStandAloneDialog::OnInitDialog();
63 CTSVNPath svnPath(m_path);
64 m_bFolder = svnPath.IsDirectory();
65 SVN svn;
66 CString url = svn.GetURLFromPath(svnPath);
67 CString sUUID = svn.GetUUIDFromPath(svnPath);
68 m_URLCombo.SetURLHistory(TRUE);
69 m_URLCombo.LoadHistory(_T("Software\\TortoiseGit\\History\\repoURLS\\")+sUUID, _T("url"));
70 m_URLCombo.SetCurSel(0);
72 if (!url.IsEmpty())
74 m_path = url;
75 m_URLCombo.AddString(CTSVNPath(url).GetUIPathString(), 0);
76 m_URLCombo.SelectString(-1, CTSVNPath(url).GetUIPathString());
77 m_URL = m_path;
80 // set head revision as default revision
81 SetRevision(SVNRev::REV_HEAD);
83 AddAnchor(IDC_URLLABEL, TOP_LEFT, TOP_RIGHT);
84 AddAnchor(IDC_URLCOMBO, TOP_LEFT, TOP_RIGHT);
85 AddAnchor(IDC_BROWSE, TOP_RIGHT);
86 AddAnchor(IDC_REVGROUP, TOP_LEFT, BOTTOM_RIGHT);
87 AddAnchor(IDC_REVISION_HEAD, TOP_LEFT);
88 AddAnchor(IDC_REVISION_N, TOP_LEFT);
89 AddAnchor(IDC_REVISION_NUM, TOP_LEFT);
90 AddAnchor(IDC_LOG, TOP_LEFT);
91 AddAnchor(IDOK, BOTTOM_RIGHT);
92 AddAnchor(IDCANCEL, BOTTOM_RIGHT);
93 AddAnchor(IDHELP, BOTTOM_RIGHT);
95 if ((m_pParentWnd==NULL)&&(hWndExplorer))
96 CenterWindow(CWnd::FromHandle(hWndExplorer));
97 EnableSaveRestore(_T("SwitchDlg"));
98 return TRUE;
101 void CUrlDiffDlg::OnBnClickedBrowse()
103 UpdateData();
104 SVNRev rev;
105 if (GetCheckedRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N) == IDC_REVISION_HEAD)
107 rev = SVNRev::REV_HEAD;
109 else
110 rev = SVNRev(m_rev);
111 if (!rev.IsValid())
112 rev = SVNRev::REV_HEAD;
113 CAppUtils::BrowseRepository(m_URLCombo, this, rev);
114 SetRevision(rev);
117 void CUrlDiffDlg::OnOK()
119 if (!UpdateData(TRUE))
120 return; // don't dismiss dialog (error message already shown by MFC framework)
122 // if head revision, set revision as -1
123 if (GetCheckedRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N) == IDC_REVISION_HEAD)
125 m_rev = _T("HEAD");
127 Revision = SVNRev(m_rev);
128 if (!Revision.IsValid())
130 ShowBalloon(IDC_REVISION_NUM, IDS_ERR_INVALIDREV);
131 return;
134 m_URLCombo.SaveHistory();
135 m_URL = m_URLCombo.GetString();
137 UpdateData(FALSE);
138 CResizableStandAloneDialog::OnOK();
141 void CUrlDiffDlg::OnBnClickedHelp()
143 OnHelp();
146 void CUrlDiffDlg::OnEnChangeRevisionNum()
148 UpdateData();
149 if (m_rev.IsEmpty())
150 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_HEAD);
151 else
152 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_N);
155 void CUrlDiffDlg::SetRevision(const SVNRev& rev)
157 if (rev.IsHead())
158 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_HEAD);
159 else
161 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_N);
162 m_rev = rev.ToString();
163 UpdateData(FALSE);
167 void CUrlDiffDlg::OnBnClickedLog()
169 UpdateData(TRUE);
170 if (::IsWindow(m_pLogDlg->GetSafeHwnd())&&(m_pLogDlg->IsWindowVisible()))
171 return;
172 if (!m_path.IsEmpty())
174 delete m_pLogDlg;
175 m_pLogDlg = new CLogDlg();
176 CRegDWORD reg = CRegDWORD(_T("Software\\TortoiseGit\\NumberOfLogs"), 100);
177 int limit = (int)(LONG)reg;
178 m_pLogDlg->SetSelect(true);
179 m_pLogDlg->m_pNotifyWindow = this;
180 m_pLogDlg->m_wParam = 0;
181 m_pLogDlg->SetParams(CTSVNPath(m_path), SVNRev::REV_HEAD, SVNRev::REV_HEAD, 1, limit, TRUE);
182 m_pLogDlg->ContinuousSelection(true);
183 m_pLogDlg->Create(IDD_LOGMESSAGE, this);
184 m_pLogDlg->ShowWindow(SW_SHOW);
186 AfxGetApp()->DoWaitCursor(-1);
189 LPARAM CUrlDiffDlg::OnRevSelected(WPARAM /*wParam*/, LPARAM lParam)
191 CString temp;
192 temp.Format(_T("%ld"), lParam);
193 SetDlgItemText(IDC_REVISION_NUM, temp);
194 CheckRadioButton(IDC_REVISION_HEAD, IDC_REVISION_N, IDC_REVISION_N);
195 return 0;