OSDN Git Service

Pull/Fetch Dlg: Used git config to determine default remote and remote branch. Also...
[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           m_bRebase(false)\r
17 {\r
18         m_IsPull=TRUE;\r
19     m_bAutoLoad = CAppUtils::IsSSHPutty();\r
20     m_bAutoLoadEnable=true;\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     this->AddOthersToAnchor();\r
65 \r
66     this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);\r
67 \r
68         CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);\r
69         m_Remote.EnableWindow(TRUE);\r
70         m_Other.EnableWindow(FALSE);\r
71         if(!m_IsPull)\r
72                 m_RemoteBranch.EnableWindow(FALSE);\r
73 \r
74 //      if(!m_IsPull)\r
75                 //Todo: implement rebase option sometime with rebase dialog\r
76                 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);\r
77 \r
78         m_Other.SetURLHistory(TRUE);\r
79         m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));\r
80         CString clippath=CAppUtils::GetClipboardLink();\r
81         if(clippath.IsEmpty())\r
82                 m_Other.SetCurSel(0);\r
83         else\r
84                 m_Other.SetWindowText(clippath);\r
85 \r
86         m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));\r
87         m_RemoteBranch.SetCurSel(0);\r
88 \r
89         CString WorkingDir=g_Git.m_CurrentDir;\r
90 \r
91         if(m_IsPull)\r
92                 this->SetWindowTextW(CString(_T("Pull - "))+WorkingDir);\r
93         else\r
94                 this->SetWindowTextW(CString(_T("Fetch - "))+WorkingDir);\r
95 \r
96         STRING_VECTOR list;\r
97         \r
98         CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));\r
99         m_RemoteReg = remote;\r
100         int sel=0;\r
101 \r
102         //Select pull-remote from current branch\r
103         CString currentBranch = g_Git.GetSymbolicRef();\r
104         CString configName;\r
105         configName.Format(L"branch.%s.remote", currentBranch);\r
106         CString pullRemote = g_Git.GetConfigValue(configName);\r
107 \r
108         //Select pull-branch from current branch\r
109         configName.Format(L"branch.%s.merge", currentBranch);\r
110         CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));\r
111         m_RemoteBranch.AddString(pullBranch);\r
112 \r
113         if(pullRemote.IsEmpty())\r
114                 pullRemote = remote;\r
115 \r
116         if(!g_Git.GetRemoteList(list))\r
117         {       \r
118                 for(unsigned int i=0;i<list.size();i++)\r
119                 {\r
120                         m_Remote.AddString(list[i]);\r
121                         if(list[i] == pullRemote)\r
122                                 sel = i;\r
123                 }\r
124         }\r
125         m_Remote.SetCurSel(sel);\r
126 \r
127         EnableSaveRestore(_T("PullFetchDlg"));\r
128     this->m_RemoteManage.SetURL(CString());\r
129         return TRUE;\r
130 }\r
131 // CPullFetchDlg message handlers\r
132 \r
133 void CPullFetchDlg::OnBnClickedRd()\r
134 {\r
135 \r
136         // TODO: Add your control notification handler code here\r
137         if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)\r
138         {\r
139                 m_Remote.EnableWindow(TRUE);\r
140                 m_Other.EnableWindow(FALSE);\r
141                 if(!m_IsPull)\r
142                         m_RemoteBranch.EnableWindow(FALSE);\r
143         }\r
144         if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)\r
145         {\r
146                 m_Remote.EnableWindow(FALSE);\r
147                 m_Other.EnableWindow(TRUE);;\r
148                 if(!m_IsPull)\r
149                         m_RemoteBranch.EnableWindow(TRUE);\r
150         }\r
151         \r
152 \r
153 }\r
154 \r
155 void CPullFetchDlg::OnBnClickedOk()\r
156 {\r
157         // TODO: Add your control notification handler code here\r
158         if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)\r
159         {\r
160                 m_RemoteURL=m_Remote.GetString();\r
161                 if(!m_IsPull)\r
162                         m_RemoteBranchName.Empty();\r
163                 else\r
164                         m_RemoteBranchName=m_RemoteBranch.GetString();\r
165                 \r
166         }\r
167         if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)\r
168         {\r
169                 m_Other.GetWindowTextW(m_RemoteURL);\r
170                 m_RemoteBranchName=m_RemoteBranch.GetString();\r
171                 \r
172         }\r
173 \r
174         m_RemoteReg = m_Remote.GetString();\r
175 \r
176         m_Other.SaveHistory();\r
177         m_RemoteBranch.SaveHistory();\r
178         this->OnOK();\r
179 }\r
180 \r
181 void CPullFetchDlg::OnStnClickedRemoteManage()\r
182 {\r
183     // TODO: Add your control notification handler code here\r
184     CAppUtils::LaunchRemoteSetting();\r
185 }\r
186 \r
187 void CPullFetchDlg::OnBnClickedButtonBrowseRef()\r
188 {\r
189         CString initialRef;\r
190         initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());\r
191         CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);\r
192         if(selectedRef.Left(13) != "refs/remotes/")\r
193                 return;\r
194 \r
195         selectedRef = selectedRef.Mid(13);\r
196         int ixSlash = selectedRef.Find('/');\r
197 \r
198         CString remoteName   = selectedRef.Left(ixSlash);\r
199         CString remoteBranch = selectedRef.Mid(ixSlash + 1);\r
200         \r
201         int ixFound = m_Remote.FindStringExact(0, remoteName);\r
202         if(ixFound >= 0)\r
203                 m_Remote.SetCurSel(ixFound);\r
204         m_RemoteBranch.AddString(remoteBranch);\r
205 \r
206         CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);\r
207 }\r