OSDN Git Service

add miss file
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / BranchCombox.h
1 #pragma once\r
2 #include "afxwin.h"\r
3 #include "LogDlg.h"\r
4 #include "BrowseRefsDlg.h"\r
5 #include "HistoryCombo.h"\r
6 #include "Balloon.h"\r
7 #include "HistoryCombo.h"\r
8 #include "AppUtils.h"\r
9 \r
10 class CBranchCombox\r
11 {\r
12 public:\r
13         CBranchCombox()\r
14         {\r
15                 m_LocalBranchFilter = gPickRef_Head;\r
16                 m_RemoteBranchFilter = gPickRef_Remote;\r
17                 m_DialogName=_T("sync");\r
18                 m_pTooltip=NULL;\r
19                 \r
20         }\r
21 protected:\r
22         CHistoryCombo m_ctrlLocalBranch;\r
23         CHistoryCombo m_ctrlRemoteBranch;\r
24         int m_LocalBranchFilter;\r
25         int m_RemoteBranchFilter;\r
26 \r
27         CBalloon *m_pTooltip;\r
28         \r
29         CString m_DialogName;\r
30         \r
31         CString m_RegKeyRemoteBranch;\r
32 \r
33         void  CbnSelchangeLocalBranch()\r
34         {\r
35                 //Select pull-remote from current branch\r
36                 CString configName;\r
37                 CString currentBranch=this->m_ctrlLocalBranch.GetString();\r
38                 configName.Format(L"branch.%s.remote", currentBranch);\r
39                 CString pullRemote = g_Git.GetConfigValue(configName);\r
40 \r
41                 this->SetRemote(pullRemote);\r
42 \r
43                 //Select pull-branch from current branch\r
44                 configName.Format(L"branch.%s.merge", currentBranch);\r
45                 CString pullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));\r
46 \r
47                 CString defaultUpstream;\r
48                 defaultUpstream.Format(L"remotes/%s/%s", pullRemote, pullBranch);\r
49                 int found = m_ctrlRemoteBranch.FindStringExact(0, defaultUpstream);\r
50                 if(found >= 0)\r
51                 {\r
52                         m_ctrlRemoteBranch.SetCurSel(found);\r
53                 }\r
54                 else if(!pullBranch.IsEmpty())\r
55                 {\r
56                         m_ctrlRemoteBranch.AddString(pullBranch);\r
57                 }\r
58                 else if(!this->m_RegKeyRemoteBranch.IsEmpty())\r
59                 {\r
60                         m_ctrlRemoteBranch.AddString(currentBranch);\r
61                 }\r
62                 \r
63                 this->AddBranchToolTips(&this->m_ctrlLocalBranch,this->m_pTooltip);\r
64 \r
65                 LocalBranchChange();\r
66         };\r
67         void  CbnSelchangeRemoteBranch()\r
68         {\r
69                 if(this->m_RegKeyRemoteBranch.IsEmpty())\r
70                         this->AddBranchToolTips(&this->m_ctrlRemoteBranch,this->m_pTooltip);\r
71 \r
72                 RemoteBranchChange();\r
73         }\r
74         void  BnClickedButtonBrowseLocalBranch()\r
75         {\r
76                 if(CBrowseRefsDlg::PickRefForCombo(&m_ctrlLocalBranch, m_LocalBranchFilter))    \r
77                         CbnSelchangeLocalBranch();\r
78         }\r
79         void  BnClickedButtonBrowseRemoteBranch()\r
80         {\r
81                 if(!this->m_RegKeyRemoteBranch.IsEmpty())\r
82                 {\r
83                         CString remoteBranchName;\r
84                         CString remoteName;\r
85                         this->m_ctrlRemoteBranch.GetWindowText(remoteBranchName);\r
86                         //remoteName = m_Remote.GetString();\r
87                         //remoteBranchName = remoteName + '/' + remoteBranchName;\r
88                         remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);\r
89                         if(remoteBranchName.IsEmpty())\r
90                                 return; //Canceled\r
91 \r
92                         remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'\r
93                         int slashPlace = remoteBranchName.Find('/');\r
94                         remoteName = remoteBranchName.Left(slashPlace);\r
95                         remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')\r
96 \r
97                         //Select remote\r
98                         //int remoteSel = m_Remote.FindStringExact(0,remoteName);\r
99                         //if(remoteSel >= 0)\r
100                         //      m_Remote.SetCurSel(remoteSel);\r
101                         this->SetRemote(remoteName);\r
102 \r
103                         //Select branch\r
104                         m_ctrlRemoteBranch.AddString(remoteBranchName);\r
105                         CbnSelchangeRemoteBranch();\r
106 \r
107                 }else\r
108                 {\r
109                         if(CBrowseRefsDlg::PickRefForCombo(&m_ctrlRemoteBranch, m_RemoteBranchFilter))  \r
110                                 CbnSelchangeRemoteBranch();\r
111                 }\r
112         }\r
113 \r
114         virtual void LocalBranchChange(){};\r
115         virtual void RemoteBranchChange(){};\r
116         virtual void SetRemote(CString remote){};\r
117 \r
118         void AddBranchToolTips(CHistoryCombo *pBranch,CBalloon *tip)\r
119         {\r
120                 if(pBranch&&tip)\r
121                 {\r
122                         CString text=pBranch->GetString();\r
123                         CString tooltip;\r
124                         BYTE_VECTOR data;\r
125                         g_Git.GetLog(data,text,NULL,1,0);\r
126                         GitRev rev;\r
127                         rev.ParserFromLog(data);\r
128                         tooltip.Format(_T("CommitHash:%s\nCommit by: %s  %s\n <b>%s</b> \n %s"),\r
129                                 rev.m_CommitHash,\r
130                                 rev.m_AuthorName,\r
131                                 CAppUtils::FormatDateAndTime(rev.m_AuthorDate,DATE_LONGDATE),\r
132                                 rev.m_Subject,\r
133                                 rev.m_Body);\r
134 \r
135                         pBranch->DisableTooltip();\r
136                         \r
137                         tip->AddTool(pBranch->GetComboBoxCtrl(),tooltip);\r
138                 }\r
139         }\r
140                 \r
141         void LoadBranchInfo()\r
142         {\r
143                 m_ctrlLocalBranch.SetMaxHistoryItems(0x7FFFFFFF);\r
144                 m_ctrlRemoteBranch.SetMaxHistoryItems(0x7FFFFFFF);\r
145 \r
146                 STRING_VECTOR list;\r
147                 list.clear();\r
148                 int current;\r
149                 g_Git.GetBranchList(list,&current,CGit::BRANCH_LOCAL);\r
150                 m_ctrlLocalBranch.AddString(list);\r
151 \r
152                 CString currentBranch = g_Git.GetSymbolicRef();\r
153                 \r
154                 if(this->m_RegKeyRemoteBranch.IsEmpty())\r
155                 {\r
156                         list.clear();\r
157                         g_Git.GetBranchList(list,&current,CGit::BRANCH_REMOTE);\r
158                 \r
159                         m_ctrlRemoteBranch.AddString(list);\r
160 \r
161                 }else\r
162                 {\r
163                         m_ctrlRemoteBranch.LoadHistory(m_RegKeyRemoteBranch,_T("sync"));\r
164                 }\r
165 \r
166                 if(!this->m_strLocalBranch.IsEmpty())\r
167                 {\r
168                         m_ctrlLocalBranch.AddString(m_strLocalBranch);\r
169                         currentBranch = m_strLocalBranch;\r
170                 }\r
171                 else\r
172                 {\r
173                         m_ctrlLocalBranch.SetCurSel(current);\r
174                 }\r
175 \r
176                 if(!m_strRemoteBranch.IsEmpty())\r
177                 {\r
178                         m_ctrlRemoteBranch.AddString(m_strRemoteBranch);\r
179                         m_ctrlRemoteBranch.SetCurSel(m_ctrlRemoteBranch.GetCount()-1);\r
180                 }\r
181                 else\r
182                 {\r
183                         CbnSelchangeLocalBranch();\r
184                 }\r
185 \r
186                 this->LocalBranchChange();\r
187                 this->RemoteBranchChange();\r
188         }\r
189         \r
190 public:\r
191         CString m_strLocalBranch;\r
192         CString m_strRemoteBranch;\r
193 };\r
194 \r
195 #define BRANCH_COMBOX_DDX \\r
196         DDX_Control(pDX, IDC_COMBOBOXEX_LOCAL_BRANCH,           m_ctrlLocalBranch);      \\r
197         DDX_Control(pDX, IDC_COMBOBOXEX_REMOTE_BRANCH,          m_ctrlRemoteBranch);     \\r
198 \r
199 #define BRANCH_COMBOX_EVENT \\r
200         ON_CBN_SELCHANGE(IDC_COMBOBOXEX_LOCAL_BRANCH,   OnCbnSelchangeLocalBranch)      \\r
201         ON_CBN_SELCHANGE(IDC_COMBOBOXEX_REMOTE_BRANCH,  OnCbnSelchangeRemoteBranch)     \\r
202         ON_BN_CLICKED(IDC_BUTTON_LOCAL_BRANCH,                  OnBnClickedButtonBrowseLocalBranch) \\r
203         ON_BN_CLICKED(IDC_BUTTON_REMOTE_BRANCH,                 OnBnClickedButtonBrowseRemoteBranch) \\r
204 \r
205 #define BRANCH_COMBOX_ADD_ANCHOR() \\r
206         AddAnchor(IDC_COMBOBOXEX_LOCAL_BRANCH,TOP_LEFT);\\r
207         AddAnchor(IDC_COMBOBOXEX_REMOTE_BRANCH,TOP_RIGHT);\\r
208         AddAnchor(IDC_BUTTON_LOCAL_BRANCH,TOP_LEFT);\\r
209         AddAnchor(IDC_BUTTON_REMOTE_BRANCH,TOP_RIGHT);\\r
210         AddAnchor(IDC_STATIC_REMOTE_BRANCH,TOP_RIGHT);\r
211 \r
212 #define BRANCH_COMBOX_EVENT_HANDLE() \\r
213         afx_msg void OnCbnSelchangeLocalBranch(){CbnSelchangeLocalBranch();} \\r
214         afx_msg void OnCbnSelchangeRemoteBranch(){CbnSelchangeRemoteBranch();}\\r
215         afx_msg void OnBnClickedButtonBrowseLocalBranch(){BnClickedButtonBrowseLocalBranch();}\\r
216         afx_msg void OnBnClickedButtonBrowseRemoteBranch(){BnClickedButtonBrowseRemoteBranch();}\r
217 \r