OSDN Git Service

f24931af906c10a9bccfb94ceb45ed058c8aab32
[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, CResizableStandAloneDialog)\r
12 \r
13 CBrowseRefsDlg::CBrowseRefsDlg(CWnd* pParent /*=NULL*/)\r
14         : CResizableStandAloneDialog(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, CResizableStandAloneDialog)\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         CResizableStandAloneDialog::OnInitDialog();\r
45 \r
46         AddAnchor(IDC_TREE_REF, TOP_LEFT, BOTTOM_RIGHT);\r
47 \r
48         AddAnchor(IDOK,BOTTOM_RIGHT);\r
49         AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
50 \r
51         Refresh();\r
52 \r
53 \r
54         return TRUE;  // return TRUE unless you set the focus to a control\r
55         // EXCEPTION: OCX Property Pages should return FALSE\r
56 }\r
57 \r
58 CShadowTree* CShadowTree::GetNextSub(CString& nameLeft)\r
59 {\r
60         int posSlash=nameLeft.Find('/');\r
61         CString nameSub;\r
62         if(posSlash<0)\r
63         {\r
64                 nameSub=nameLeft;\r
65                 nameLeft.Empty();//Nothing left\r
66         }\r
67         else\r
68         {\r
69                 nameSub=nameLeft.Left(posSlash);\r
70                 nameLeft=nameLeft.Mid(posSlash+1);\r
71         }\r
72         if(nameSub.IsEmpty())\r
73                 return NULL;\r
74 \r
75         CShadowTree& nextNode=m_ShadowTree[nameSub];\r
76         nextNode.m_csName=nameSub;\r
77         nextNode.m_pParent=this;\r
78         return &nextNode;\r
79 }\r
80 \r
81 typedef std::map<CString,CString> MAP_STRING_STRING;\r
82 \r
83 void CBrowseRefsDlg::Refresh()\r
84 {\r
85         m_RefMap.clear();\r
86         g_Git.GetMapHashToFriendName(m_RefMap);\r
87 \r
88         m_RefTreeCtrl.DeleteAllItems();\r
89         m_TreeRoot.m_ShadowTree.clear();\r
90         m_TreeRoot.m_csName="Refs";\r
91         m_TreeRoot.m_hTree=m_RefTreeCtrl.InsertItem(L"Refs",NULL,NULL);\r
92         m_RefTreeCtrl.SetItemData(m_TreeRoot.m_hTree,(DWORD_PTR)&m_TreeRoot);\r
93 \r
94 \r
95         MAP_STRING_STRING refName;\r
96 \r
97         //First sort on ref name\r
98         for(MAP_HASH_NAME::iterator iterRef=m_RefMap.begin();iterRef!=m_RefMap.end();++iterRef)\r
99                 for(STRING_VECTOR::iterator iterRefName=iterRef->second.begin();iterRefName!=iterRef->second.end();++iterRefName)\r
100                         refName[*iterRefName]=iterRef->first;\r
101 \r
102         //Populate ref tree\r
103         for(MAP_STRING_STRING::iterator iterRefName=refName.begin();iterRefName!=refName.end();++iterRefName)\r
104         {\r
105                 CShadowTree& treeLeaf=GetTreeNode(iterRefName->first);\r
106                 treeLeaf.m_csRef=iterRefName->second;\r
107         }\r
108 \r
109         m_RefTreeCtrl.Expand(m_TreeRoot.m_hTree,TVE_EXPAND);\r
110 \r
111 }\r
112 \r
113 CShadowTree& CBrowseRefsDlg::GetTreeNode(CString refName, CShadowTree* pTreePos)\r
114 {\r
115         if(pTreePos==NULL)\r
116         {\r
117                 if(wcsnicmp(refName,L"refs/",5)==0)\r
118                         refName=refName.Mid(5);\r
119                 pTreePos=&m_TreeRoot;\r
120         }\r
121         if(refName.IsEmpty())\r
122                 return *pTreePos;//Found leaf\r
123 \r
124         CShadowTree* pNextTree=pTreePos->GetNextSub(refName);\r
125         if(pNextTree==NULL)\r
126         {\r
127                 //Should not occur when all ref-names are valid.\r
128                 ASSERT(FALSE);\r
129                 return *pTreePos;\r
130         }\r
131         if(pNextTree->m_hTree==NULL)\r
132         {\r
133                 //New tree. Create node in control.\r
134                 pNextTree->m_hTree=m_RefTreeCtrl.InsertItem(pNextTree->m_csName,pTreePos->m_hTree,NULL);\r
135                 m_RefTreeCtrl.SetItemData(pNextTree->m_hTree,(DWORD_PTR)pNextTree);\r
136         }\r
137 \r
138         return GetTreeNode(refName,pNextTree);\r
139 }\r
140 \r