OSDN Git Service

Add launch rebase option at fetch dialog.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / PullFetchDlg.cpp
1 // PullFetchDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "PullFetchDlg.h"\r
7 #include "Git.h"\r
8 #include "AppUtils.h"\r
9 #include "BrowseRefsDlg.h"\r
10 // CPullFetchDlg dialog\r
11 \r
12 IMPLEMENT_DYNAMIC(CPullFetchDlg, CResizableStandAloneDialog)\r
13 \r
14 CPullFetchDlg::CPullFetchDlg(CWnd* pParent /*=NULL*/)\r
15         : CResizableStandAloneDialog(CPullFetchDlg::IDD, pParent)\r
16 {\r
17         m_IsPull=TRUE;\r
18     m_bAutoLoad = CAppUtils::IsSSHPutty();\r
19     m_bAutoLoadEnable=true;\r
20         m_regRebase = false;\r
21 }\r
22 \r
23 CPullFetchDlg::~CPullFetchDlg()\r
24 {\r
25 }\r
26 \r
27 void CPullFetchDlg::DoDataExchange(CDataExchange* pDX)\r
28 {\r
29         CDialog::DoDataExchange(pDX);\r
30         DDX_Control(pDX, IDC_REMOTE_COMBO, this->m_Remote);\r
31         DDX_Control(pDX, IDC_OTHER, this->m_Other);\r
32         DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);\r
33     DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);\r
34     DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);\r
35     DDX_Check(pDX,IDC_CHECK_REBASE,m_bRebase);\r
36 \r
37 }\r
38 \r
39 \r
40 BEGIN_MESSAGE_MAP(CPullFetchDlg,CResizableStandAloneDialog )\r
41         ON_BN_CLICKED(IDC_REMOTE_RD, &CPullFetchDlg::OnBnClickedRd)\r
42         ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)\r
43         ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)\r
44     ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)\r
45         ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CPullFetchDlg::OnBnClickedButtonBrowseRef)\r
46 END_MESSAGE_MAP()\r
47 \r
48 BOOL CPullFetchDlg::OnInitDialog()\r
49 {\r
50         CResizableStandAloneDialog::OnInitDialog();\r
51         AddAnchor(IDC_REMOTE_COMBO, TOP_LEFT, TOP_RIGHT);\r
52         AddAnchor(IDC_OTHER, TOP_LEFT,TOP_RIGHT);\r
53 \r
54         AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);\r
55         \r
56         AddAnchor(IDOK,BOTTOM_RIGHT);\r
57         AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
58     AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,BOTTOM_RIGHT);\r
59     AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);\r
60         AddAnchor(IDC_CHECK_REBASE,BOTTOM_LEFT);\r
61     AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);\r
62         AddAnchor(IDHELP, BOTTOM_RIGHT);\r
63 \r
64         CString WorkingDir=g_Git.m_CurrentDir;\r
65         WorkingDir.Replace(_T(':'),_T('_'));\r
66 \r
67         CString regkey ;\r
68         regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir,this->m_IsPull);\r
69         m_regRebase=CRegDWORD(regkey,false);\r
70 \r
71         this->m_bRebase = m_regRebase;\r
72 \r
73         this->UpdateData(FALSE);\r
74 \r
75     this->AddOthersToAnchor();\r
76 \r
77     this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);\r
78 \r
79         CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);\r
80         m_Remote.EnableWindow(TRUE);\r
81         m_Other.EnableWindow(FALSE);\r
82         if(!m_IsPull)\r
83                 m_RemoteBranch.EnableWindow(FALSE);\r
84 \r
85         if(m_IsPull)\r
86                 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);\r
87 \r
88         m_Other.SetURLHistory(TRUE);\r
89         m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));\r
90         CString clippath=CAppUtils::GetClipboardLink();\r
91         if(clippath.IsEmpty())\r
92                 m_Other.SetCurSel(0);\r
93         else\r
94                 m_Other.SetWindowText(clippath);\r
95 \r
96         m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));\r
97         m_RemoteBranch.SetCurSel(0);\r
98 \r
99         if(m_IsPull)\r
100                 this->SetWindowTextW(CString(_T("Pull - "))+WorkingDir);\r
101         else\r
102                 this->SetWindowTextW(CString(_T("Fetch - "))+WorkingDir);\r
103 \r
104         STRING_VECTOR list;\r
105         \r
106         CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));\r
107         m_RemoteReg = remote;\r
108         int sel=0;\r
109 \r
110         //Select pull-remote from current branch\r
111         CString currentBranch = g_Git.GetSymbolicRef();\r
112         CString configName;\r
113         configName.Format(L"branch.%s.remote", currentBranch);\r
114         CString pullRemote = m_configPullRemote = g_Git.GetConfigValue(configName);\r
115 \r
116         //Select pull-branch from current branch\r
117         configName.Format(L"branch.%s.merge", currentBranch);\r
118         CString pullBranch = m_configPullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));\r
119         m_RemoteBranch.AddString(pullBranch);\r
120 \r
121         if(pullRemote.IsEmpty())\r
122                 pullRemote = remote;\r
123 \r
124         if(!g_Git.GetRemoteList(list))\r
125         {       \r
126                 for(unsigned int i=0;i<list.size();i++)\r
127                 {\r
128                         m_Remote.AddString(list[i]);\r
129                         if(list[i] == pullRemote)\r
130                                 sel = i;\r
131                 }\r
132         }\r
133         m_Remote.SetCurSel(sel);\r
134 \r
135         EnableSaveRestore(_T("PullFetchDlg"));\r
136     this->m_RemoteManage.SetURL(CString());\r
137         return TRUE;\r
138 }\r
139 // CPullFetchDlg message handlers\r
140 \r
141 void CPullFetchDlg::OnBnClickedRd()\r
142 {\r
143 \r
144         // TODO: Add your control notification handler code here\r
145         if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)\r
146         {\r
147                 m_Remote.EnableWindow(TRUE);\r
148                 m_Other.EnableWindow(FALSE);\r
149                 if(!m_IsPull)\r
150                         m_RemoteBranch.EnableWindow(FALSE);\r
151         }\r
152         if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)\r
153         {\r
154                 m_Remote.EnableWindow(FALSE);\r
155                 m_Other.EnableWindow(TRUE);;\r
156                 if(!m_IsPull)\r
157                         m_RemoteBranch.EnableWindow(TRUE);\r
158         }\r
159         \r
160 \r
161 }\r
162 \r
163 void CPullFetchDlg::OnBnClickedOk()\r
164 {\r
165         this->UpdateData();\r
166         // TODO: Add your control notification handler code here\r
167         if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)\r
168         {\r
169                 m_RemoteURL=m_Remote.GetString();\r
170                 if( !m_IsPull ||\r
171                         (m_configPullRemote == m_RemoteURL && m_configPullBranch == m_RemoteBranch.GetString() ))\r
172                         //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,\r
173                         //because otherwise git will not update the remote tracking branches.\r
174                         m_RemoteBranchName.Empty();\r
175                 else\r
176                         m_RemoteBranchName=m_RemoteBranch.GetString();\r
177                 \r
178         }\r
179         if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)\r
180         {\r
181                 m_Other.GetWindowTextW(m_RemoteURL);\r
182                 m_RemoteBranchName=m_RemoteBranch.GetString();\r
183                 \r
184         }\r
185         \r
186         m_RemoteReg = m_Remote.GetString();\r
187 \r
188         m_Other.SaveHistory();\r
189         m_RemoteBranch.SaveHistory();\r
190         this->m_regRebase=this->m_bRebase;\r
191 \r
192         this->OnOK();\r
193 }\r
194 \r
195 void CPullFetchDlg::OnStnClickedRemoteManage()\r
196 {\r
197     // TODO: Add your control notification handler code here\r
198     CAppUtils::LaunchRemoteSetting();\r
199 }\r
200 \r
201 void CPullFetchDlg::OnBnClickedButtonBrowseRef()\r
202 {\r
203         CString initialRef;\r
204         initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());\r
205         CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);\r
206         if(selectedRef.Left(13) != "refs/remotes/")\r
207                 return;\r
208 \r
209         selectedRef = selectedRef.Mid(13);\r
210         int ixSlash = selectedRef.Find('/');\r
211 \r
212         CString remoteName   = selectedRef.Left(ixSlash);\r
213         CString remoteBranch = selectedRef.Mid(ixSlash + 1);\r
214         \r
215         int ixFound = m_Remote.FindStringExact(0, remoteName);\r
216         if(ixFound >= 0)\r
217                 m_Remote.SetCurSel(ixFound);\r
218         m_RemoteBranch.AddString(remoteBranch);\r
219 \r
220         CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);\r
221 }\r