Can run cleanup without using recycle bin and add dry run option
[TortoiseGit.git] / src / TortoiseProc / RequestPullDlg.cpp
blob527f6fa1b1d0aa5972666ad4c5805a5db864d8ca
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2012 Sven Strickroth, <email@cs-ware.de>
5 // with code of PullFetchDlg.cpp
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "stdafx.h"
23 #include "TortoiseProc.h"
24 #include "RequestPullDlg.h"
25 #include "git.h"
26 #include "LogDlg.h"
27 #include "MessageBox.h"
28 #include "AppUtils.h"
30 IMPLEMENT_DYNAMIC(CRequestPullDlg, CHorizontalResizableStandAloneDialog)
32 CRequestPullDlg::CRequestPullDlg(CWnd* pParent /*=NULL*/)
33 : CHorizontalResizableStandAloneDialog(CRequestPullDlg::IDD, pParent)
37 CRequestPullDlg::~CRequestPullDlg()
41 void CRequestPullDlg::DoDataExchange(CDataExchange* pDX)
43 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
44 DDX_Control(pDX, IDC_COMBOBOXEX_LOCAL_BRANCH, m_cStartRevision);
45 DDX_Control(pDX, IDC_COMBOBOXEX_URL, m_cRepositoryURL);
46 DDX_Control(pDX, IDC_REMOTE_BRANCH, m_cEndRevision);
50 BEGIN_MESSAGE_MAP(CRequestPullDlg, CHorizontalResizableStandAloneDialog)
51 ON_BN_CLICKED(IDOK, &CRequestPullDlg::OnBnClickedOk)
52 ON_BN_CLICKED(IDC_BUTTON_LOCAL_BRANCH, &CRequestPullDlg::OnBnClickedButtonLocalBranch)
53 END_MESSAGE_MAP()
55 BOOL CRequestPullDlg::OnInitDialog()
57 CHorizontalResizableStandAloneDialog::OnInitDialog();
58 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
60 AddAnchor(IDOK,BOTTOM_RIGHT);
61 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
62 AddAnchor(IDHELP,BOTTOM_RIGHT);
64 AddAnchor(IDC_BUTTON_LOCAL_BRANCH, TOP_RIGHT);
65 AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH, TOP_LEFT,TOP_RIGHT);
66 AddAnchor(IDC_COMBOBOXEX_URL, TOP_LEFT,TOP_RIGHT);
67 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
69 EnableSaveRestore(_T("RequestPullDlg"));
71 CString sWindowTitle;
72 GetWindowText(sWindowTitle);
73 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
75 STRING_VECTOR list;
76 g_Git.GetBranchList(list, NULL, CGit::BRANCH_ALL);
77 m_cStartRevision.SetMaxHistoryItems(0x7FFFFFFF);
78 for (unsigned int i = 0; i < list.size(); i++)
80 m_cStartRevision.AddString(list[i]);
83 CString WorkingDir=g_Git.m_CurrentDir;
84 WorkingDir.Replace(_T(':'), _T('_'));
86 m_RegStartRevision = CRegString(_T("Software\\TortoiseGit\\History\\RequestPull\\")+WorkingDir+_T("\\startrevision"));
87 if(m_StartRevision.IsEmpty()) {
88 m_StartRevision = m_RegStartRevision;
90 m_cStartRevision.SetWindowTextW(m_StartRevision);
92 // store URLs in global history, but save last used local url separately,
93 // because one normally has only one writable repository
94 m_cRepositoryURL.SetURLHistory(TRUE);
95 m_cRepositoryURL.LoadHistory(_T("Software\\TortoiseGit\\History\\RequestPull"), _T("url"));
96 m_RegRepositoryURL = CRegString(_T("Software\\TortoiseGit\\History\\RequestPull\\")+WorkingDir+_T("\\repositoryurl"));
97 if(m_RepositoryURL.IsEmpty())
99 m_RepositoryURL = m_RegRepositoryURL;
101 m_cRepositoryURL.SetWindowTextW(m_RepositoryURL);
103 m_RegEndRevision = CRegString(_T("Software\\TortoiseGit\\History\\RequestPull\\")+WorkingDir+_T("\\endrevision"), _T("HEAD"));
104 if(m_EndRevision.IsEmpty()) {
105 m_EndRevision = m_RegEndRevision;
107 m_cEndRevision.SetWindowTextW(m_EndRevision);
109 this->UpdateData(FALSE);
111 return TRUE;
114 void CRequestPullDlg::OnBnClickedOk()
116 CHorizontalResizableStandAloneDialog::UpdateData(TRUE);
118 m_cRepositoryURL.SaveHistory();
120 m_cStartRevision.GetWindowTextW(m_StartRevision);
121 m_RepositoryURL = m_cRepositoryURL.GetString();
122 m_cEndRevision.GetWindowTextW(m_EndRevision);
124 m_RegStartRevision = m_StartRevision;
125 m_RegRepositoryURL = m_RepositoryURL;
126 m_RegEndRevision = m_EndRevision.Trim();
128 if(!g_Git.IsBranchNameValid(m_EndRevision))
130 CMessageBox::Show(NULL, IDS_B_T_NOTEMPTY, IDS_APPNAME, MB_OK);
131 return;
134 if(m_StartRevision.Find(_T("remotes/")) == 0)
135 m_StartRevision = m_StartRevision.Mid(8);
137 CHorizontalResizableStandAloneDialog::OnOK();
140 void CRequestPullDlg::OnBnClickedButtonLocalBranch()
142 // use the git log to allow selection of a version
143 CLogDlg dlg;
144 // tell the dialog to use mode for selecting revisions
145 dlg.SetSelect(true);
146 // only one revision must be selected however
147 dlg.SingleSelection(true);
148 if ( dlg.DoModal() == IDOK )
150 // get selected hash if any
151 CString selectedHash = dlg.GetSelectedHash();
152 // load into window, do this even if empty so that it is clear that nothing has been selected
153 m_cStartRevision.SetWindowText( selectedHash );