OSDN Git Service

beaf97e4228132314282c0f67e82f7a6c02285f4
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / BrowseRefsDlg.cpp
1 // BrowseRefsDlg.cpp : implementation file\r
2 //\r
3 \r
4 #include "stdafx.h"\r
5 #include "TortoiseProc.h"\r
6 #include "BrowseRefsDlg.h"\r
7 \r
8 \r
9 // CBrowseRefsDlg dialog\r
10 \r
11 IMPLEMENT_DYNAMIC(CBrowseRefsDlg, CDialog)\r
12 \r
13 CBrowseRefsDlg::CBrowseRefsDlg(CWnd* pParent /*=NULL*/)\r
14         : CDialog(CBrowseRefsDlg::IDD, pParent)\r
15 {\r
16 \r
17 }\r
18 \r
19 CBrowseRefsDlg::~CBrowseRefsDlg()\r
20 {\r
21 }\r
22 \r
23 void CBrowseRefsDlg::DoDataExchange(CDataExchange* pDX)\r
24 {\r
25         CDialog::DoDataExchange(pDX);\r
26         DDX_Control(pDX, IDC_TREE_REF, m_RefTreeCtrl);\r
27 }\r
28 \r
29 \r
30 BEGIN_MESSAGE_MAP(CBrowseRefsDlg, CDialog)\r
31         ON_BN_CLICKED(IDOK, &CBrowseRefsDlg::OnBnClickedOk)\r
32 END_MESSAGE_MAP()\r
33 \r
34 \r
35 // CBrowseRefsDlg message handlers\r
36 \r
37 void CBrowseRefsDlg::OnBnClickedOk()\r
38 {\r
39         OnOK();\r
40 }\r
41 \r
42 BOOL CBrowseRefsDlg::OnInitDialog()\r
43 {\r
44         CDialog::OnInitDialog();\r
45 \r
46         Refresh();\r
47 \r
48 \r
49         return TRUE;  // return TRUE unless you set the focus to a control\r
50         // EXCEPTION: OCX Property Pages should return FALSE\r
51 }\r
52 \r
53 CShadowTree* CShadowTree::GetNextSub(CString& nameLeft)\r
54 {\r
55         int posSlash=nameLeft.Find('/');\r
56         CString nameSub;\r
57         if(posSlash<0)\r
58         {\r
59                 nameSub=nameLeft;\r
60                 nameLeft.Empty();//Nothing left\r
61         }\r
62         else\r
63         {\r
64                 nameSub=nameLeft.Left(posSlash);\r
65                 nameLeft=nameLeft.Mid(posSlash+1);\r
66         }\r
67         if(nameSub.IsEmpty())\r
68                 return NULL;\r
69 \r
70         CShadowTree& nextNode=m_ShadowTree[nameSub];\r
71         nextNode.m_csName=nameSub;\r
72         nextNode.m_pParent=this;\r
73         return &nextNode;\r
74 }\r
75 \r
76 typedef std::map<CString,CString> MAP_STRING_STRING;\r
77 \r
78 void CBrowseRefsDlg::Refresh()\r
79 {\r
80         m_RefMap.clear();\r
81         g_Git.GetMapHashToFriendName(m_RefMap);\r
82 \r
83         m_RefTreeCtrl.DeleteAllItems();\r
84         m_TreeRoot.m_ShadowTree.clear();\r
85         m_TreeRoot.m_csName="Refs";\r
86         m_TreeRoot.m_hTree=m_RefTreeCtrl.InsertItem(L"Refs",NULL,NULL);\r
87         m_RefTreeCtrl.SetItemData(m_TreeRoot.m_hTree,(DWORD_PTR)&m_TreeRoot);\r
88 \r
89 \r
90         MAP_STRING_STRING refName;\r
91 \r
92         //First sort on ref name\r
93         for(MAP_HASH_NAME::iterator iterRef=m_RefMap.begin();iterRef!=m_RefMap.end();++iterRef)\r
94                 for(STRING_VECTOR::iterator iterRefName=iterRef->second.begin();iterRefName!=iterRef->second.end();++iterRefName)\r
95                         refName[*iterRefName]=iterRef->first;\r
96 \r
97         //Populate ref tree\r
98         for(MAP_STRING_STRING::iterator iterRefName=refName.begin();iterRefName!=refName.end();++iterRefName)\r
99         {\r
100                 CShadowTree& treeLeaf=GetTreeNode(iterRefName->first);\r
101                 treeLeaf.m_csRef=iterRefName->second;\r
102         }\r
103 \r
104         m_RefTreeCtrl.Expand(m_TreeRoot.m_hTree,TVE_EXPAND);\r
105 \r
106 }\r
107 \r
108 CShadowTree& CBrowseRefsDlg::GetTreeNode(CString refName, CShadowTree* pTreePos)\r
109 {\r
110         if(pTreePos==NULL)\r
111         {\r
112                 if(wcsnicmp(refName,L"refs/",5)==0)\r
113                         refName=refName.Mid(5);\r
114                 pTreePos=&m_TreeRoot;\r
115         }\r
116         if(refName.IsEmpty())\r
117                 return *pTreePos;//Found leaf\r
118 \r
119         CShadowTree* pNextTree=pTreePos->GetNextSub(refName);\r
120         if(pNextTree==NULL)\r
121         {\r
122                 //Should not occur when all ref-names are valid.\r
123                 ASSERT(FALSE);\r
124                 return *pTreePos;\r
125         }\r
126         if(pNextTree->m_hTree==NULL)\r
127         {\r
128                 //New tree. Create node in control.\r
129                 pNextTree->m_hTree=m_RefTreeCtrl.InsertItem(pNextTree->m_csName,pTreePos->m_hTree,NULL);\r
130                 m_RefTreeCtrl.SetItemData(pNextTree->m_hTree,(DWORD_PTR)pNextTree);\r
131         }\r
132 \r
133         return GetTreeNode(refName,pNextTree);\r
134 }\r
135 \r