Add Daemon Shell Context Menu
[TortoiseGit.git] / src / TortoiseProc / RequestPullDlg.cpp
blobea18baaac939ae18294e7ef187c6b670ac6e1db5
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2013 - TortoiseGit
4 // Copyright (C) 2011-2013 Sven Strickroth, <email@cs-ware.de>
6 // with code of PullFetchDlg.cpp
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software Foundation,
20 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "stdafx.h"
24 #include "TortoiseProc.h"
25 #include "RequestPullDlg.h"
26 #include "git.h"
27 #include "LogDlg.h"
28 #include "MessageBox.h"
29 #include "AppUtils.h"
31 IMPLEMENT_DYNAMIC(CRequestPullDlg, CHorizontalResizableStandAloneDialog)
33 CRequestPullDlg::CRequestPullDlg(CWnd* pParent /*=NULL*/)
34 : CHorizontalResizableStandAloneDialog(CRequestPullDlg::IDD, pParent)
35 , m_regSendMail(_T("Software\\TortoiseGit\\TortoiseProc\\RequestPull\\SendMail"), FALSE)
37 m_bSendMail = m_regSendMail;
40 CRequestPullDlg::~CRequestPullDlg()
44 void CRequestPullDlg::DoDataExchange(CDataExchange* pDX)
46 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
47 DDX_Control(pDX, IDC_COMBOBOXEX_LOCAL_BRANCH, m_cStartRevision);
48 DDX_Control(pDX, IDC_COMBOBOXEX_URL, m_cRepositoryURL);
49 DDX_Control(pDX, IDC_REMOTE_BRANCH, m_cEndRevision);
50 DDX_Check(pDX, IDC_CHECK_SENDMAIL, m_bSendMail);
54 BEGIN_MESSAGE_MAP(CRequestPullDlg, CHorizontalResizableStandAloneDialog)
55 ON_BN_CLICKED(IDOK, &CRequestPullDlg::OnBnClickedOk)
56 ON_BN_CLICKED(IDC_BUTTON_LOCAL_BRANCH, &CRequestPullDlg::OnBnClickedButtonLocalBranch)
57 END_MESSAGE_MAP()
59 BOOL CRequestPullDlg::OnInitDialog()
61 CHorizontalResizableStandAloneDialog::OnInitDialog();
62 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
64 AddAnchor(IDOK,BOTTOM_RIGHT);
65 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
66 AddAnchor(IDHELP,BOTTOM_RIGHT);
68 AddAnchor(IDC_BUTTON_LOCAL_BRANCH, TOP_RIGHT);
69 AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH, TOP_LEFT,TOP_RIGHT);
70 AddAnchor(IDC_COMBOBOXEX_URL, TOP_LEFT,TOP_RIGHT);
71 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
73 EnableSaveRestore(_T("RequestPullDlg"));
75 CString sWindowTitle;
76 GetWindowText(sWindowTitle);
77 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
79 STRING_VECTOR list;
80 g_Git.GetBranchList(list, NULL, CGit::BRANCH_ALL);
81 m_cStartRevision.SetMaxHistoryItems(0x7FFFFFFF);
82 for (unsigned int i = 0; i < list.size(); ++i)
84 m_cStartRevision.AddString(list[i]);
87 CString WorkingDir=g_Git.m_CurrentDir;
88 WorkingDir.Replace(_T(':'), _T('_'));
90 m_RegStartRevision = CRegString(_T("Software\\TortoiseGit\\History\\RequestPull\\")+WorkingDir+_T("\\startrevision"));
91 if(m_StartRevision.IsEmpty()) {
92 m_StartRevision = m_RegStartRevision;
94 m_cStartRevision.SetWindowTextW(m_StartRevision);
96 // store URLs in global history, but save last used local url separately,
97 // because one normally has only one writable repository
98 m_cRepositoryURL.SetURLHistory(TRUE);
99 m_cRepositoryURL.LoadHistory(_T("Software\\TortoiseGit\\History\\RequestPull"), _T("url"));
100 m_RegRepositoryURL = CRegString(_T("Software\\TortoiseGit\\History\\RequestPull\\")+WorkingDir+_T("\\repositoryurl"));
101 if(m_RepositoryURL.IsEmpty())
103 m_RepositoryURL = m_RegRepositoryURL;
105 m_cRepositoryURL.SetWindowTextW(m_RepositoryURL);
107 m_RegEndRevision = CRegString(_T("Software\\TortoiseGit\\History\\RequestPull\\")+WorkingDir+_T("\\endrevision"), _T("HEAD"));
108 if(m_EndRevision.IsEmpty()) {
109 m_EndRevision = m_RegEndRevision;
111 m_cEndRevision.SetWindowTextW(m_EndRevision);
113 this->UpdateData(FALSE);
115 return TRUE;
118 void CRequestPullDlg::OnBnClickedOk()
120 CHorizontalResizableStandAloneDialog::UpdateData(TRUE);
122 m_cRepositoryURL.SaveHistory();
124 m_cStartRevision.GetWindowTextW(m_StartRevision);
125 m_RepositoryURL = m_cRepositoryURL.GetString();
126 m_cEndRevision.GetWindowTextW(m_EndRevision);
128 m_RegStartRevision = m_StartRevision;
129 m_RegRepositoryURL = m_RepositoryURL;
130 m_RegEndRevision = m_EndRevision.Trim();
132 if(!g_Git.IsBranchNameValid(m_EndRevision))
134 CMessageBox::Show(NULL, IDS_B_T_NOTEMPTY, IDS_APPNAME, MB_OK);
135 return;
138 if(m_StartRevision.Find(_T("remotes/")) == 0)
139 m_StartRevision = m_StartRevision.Mid(8);
141 m_regSendMail = m_bSendMail;
143 CHorizontalResizableStandAloneDialog::OnOK();
146 void CRequestPullDlg::OnBnClickedButtonLocalBranch()
148 // use the git log to allow selection of a version
149 CLogDlg dlg;
150 // tell the dialog to use mode for selecting revisions
151 dlg.SetSelect(true);
152 // only one revision must be selected however
153 dlg.SingleSelection(true);
154 if ( dlg.DoModal() == IDOK )
156 // get selected hash if any
157 CString selectedHash = dlg.GetSelectedHash();
158 // load into window, do this even if empty so that it is clear that nothing has been selected
159 m_cStartRevision.SetWindowText( selectedHash );