OSDN Git Service

Show Ignore Sub Menu
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RevisionGraph / StandardLayoutNodeList.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "StdAfx.h"\r
20 #include "resource.h"\r
21 #include "StandardLayoutNodeList.h"\r
22 #include "VisibleGraphNode.h"\r
23 #include "CachedLogInfo.h"\r
24 #include "SVN.h"\r
25 #include "UnicodeUtils.h"\r
26 \r
27 /// utilities\r
28 \r
29 index_t CStandardLayoutNodeList::GetStyle \r
30         (const CVisibleGraphNode* node) const\r
31 {\r
32         CNodeClassification classification = node->GetClassification();\r
33 \r
34         if (classification.Is (CNodeClassification::IS_ADDED))\r
35                 return ILayoutNodeList::SNode::STYLE_ADDED;\r
36         else if (classification.Is (CNodeClassification::IS_DELETED))\r
37                 return ILayoutNodeList::SNode::STYLE_DELETED;\r
38         else if (classification.Is (CNodeClassification::IS_RENAMED))\r
39                 return ILayoutNodeList::SNode::STYLE_RENAMED;\r
40         else if (classification.Is (CNodeClassification::IS_LAST))\r
41                 return ILayoutNodeList::SNode::STYLE_LAST;\r
42     else if (classification.Is (CNodeClassification::IS_MODIFIED))\r
43                 return ILayoutNodeList::SNode::STYLE_MODIFIED;\r
44         else\r
45                 return ILayoutNodeList::SNode::STYLE_DEFAULT;\r
46 }\r
47 \r
48 DWORD CStandardLayoutNodeList::GetStyleFlags \r
49         (const CVisibleGraphNode* /*node*/) const\r
50 {\r
51         return 0;\r
52 }\r
53 \r
54 // construction\r
55 \r
56 CStandardLayoutNodeList::CStandardLayoutNodeList \r
57     ( const std::vector<CStandardLayoutNodeInfo>& nodes\r
58     , const CCachedLogInfo* cache)\r
59     : cache (cache)\r
60     , nodes (nodes)\r
61 {\r
62 }\r
63 \r
64 // implement ILayoutItemList\r
65 \r
66 index_t CStandardLayoutNodeList::GetCount() const\r
67 {\r
68     return static_cast<index_t>(nodes.size());\r
69 }\r
70 \r
71 CString CStandardLayoutNodeList::GetToolTip (index_t index) const\r
72 {\r
73     CString strTipText;\r
74 \r
75     const CRevisionIndex& revisions = cache->GetRevisions();\r
76     const CRevisionInfoContainer& revisionInfo = cache->GetLogInfo();\r
77 \r
78     const CVisibleGraphNode* node = nodes[index].node;\r
79 \r
80     // find the revision in our cache. \r
81     // May not be present if this is the WC / HEAD revision.\r
82 \r
83     revision_t revision = node->GetRevision();\r
84     index_t revisionIndex = revisions [revision];\r
85     if (revisionIndex == NO_INDEX)\r
86         return strTipText;\r
87 \r
88     // get standard revprops\r
89 \r
90         TCHAR date[SVN_DATE_BUFFER];\r
91         apr_time_t timeStamp = revisionInfo.GetTimeStamp (revisionIndex);\r
92         SVN::formatDate(date, timeStamp);\r
93 \r
94     CString realPath \r
95         = CUnicodeUtils::StdGetUnicode \r
96             (node->GetRealPath().GetPath()).c_str();\r
97     CString author \r
98         = CUnicodeUtils::StdGetUnicode \r
99             (revisionInfo.GetAuthor (revisionIndex)).c_str();\r
100     CString comment \r
101         = CUnicodeUtils::StdGetUnicode \r
102             (revisionInfo.GetComment (revisionIndex)).c_str();\r
103 \r
104     // construct the tooltip\r
105 \r
106     if (node->GetFirstTag() == NULL)\r
107     {\r
108             strTipText.Format ( IDS_REVGRAPH_BOXTOOLTIP\r
109                           , revision, (LPCTSTR)realPath, (LPCTSTR)author\r
110                           , date, (LPCTSTR)comment);\r
111     }\r
112     else\r
113     {\r
114         CString tags;\r
115         int tagCount = 0;\r
116         for ( const CVisibleGraphNode::CFoldedTag* tag = node->GetFirstTag()\r
117             ; tag != NULL\r
118             ; tag = tag->GetNext())\r
119         {\r
120             ++tagCount;\r
121 \r
122             CString attributes;\r
123             if (tag->IsModified())\r
124                 attributes.LoadString (IDS_REVGRAPH_TAGMODIFIED);\r
125 \r
126             if (tag->IsDeleted())\r
127             {\r
128                 CString attribute;\r
129                 attribute.LoadString (IDS_REVGRAPH_TAGDELETED);\r
130                 if (attributes.IsEmpty())\r
131                     attributes = attribute;\r
132                 else\r
133                     attributes += _T(", ") + attribute;\r
134             }\r
135 \r
136             CString tagInfo;\r
137             std::string tagPath = tag->GetTag()->GetPath().GetPath();\r
138 \r
139             if (attributes.IsEmpty())\r
140             {\r
141                 tagInfo.Format (   tag->IsAlias() \r
142                                  ? IDS_REVGRAPH_TAGALIAS \r
143                                  : IDS_REVGRAPH_TAG\r
144                                , CUnicodeUtils::StdGetUnicode (tagPath).c_str());\r
145             }\r
146             else\r
147             {\r
148                 tagInfo.Format (   tag->IsAlias() \r
149                                  ? IDS_REVGRAPH_TAGALIASATTRIBUTED\r
150                                  : IDS_REVGRAPH_TAGATTRIBUTED\r
151                                , (LPCTSTR)attributes\r
152                                , CUnicodeUtils::StdGetUnicode (tagPath).c_str());\r
153             }\r
154 \r
155             tags +=   _T("\r\n")\r
156                     + CString (' ', tag->GetDepth() * 6) \r
157                     + tagInfo;\r
158         }\r
159 \r
160             strTipText.Format ( IDS_REVGRAPH_BOXTOOLTIP_TAGGED\r
161                           , revision, (LPCTSTR)realPath, (LPCTSTR)author\r
162                           , date, tagCount, (LPCTSTR)tags, (LPCTSTR)comment);\r
163     }\r
164 \r
165     // ready\r
166 \r
167     return strTipText;\r
168 }\r
169 \r
170 index_t CStandardLayoutNodeList::GetFirstVisible (const CRect& viewRect) const\r
171 {\r
172     return GetNextVisible (static_cast<index_t>(-1), viewRect);\r
173 }\r
174 \r
175 index_t CStandardLayoutNodeList::GetNextVisible ( index_t prev\r
176                                                 , const CRect& viewRect) const\r
177 {\r
178     for (size_t i = prev+1, count = nodes.size(); i < count; ++i)\r
179         if (FALSE != CRect().IntersectRect (nodes[i].rect, viewRect))\r
180             return static_cast<index_t>(i);\r
181 \r
182     return static_cast<index_t>(NO_INDEX);\r
183 }\r
184 \r
185 index_t CStandardLayoutNodeList::GetAt (const CPoint& point, long delta) const\r
186 {\r
187     for (size_t i = 0, count = nodes.size(); i < count; ++i)\r
188     {\r
189         const CRect& rect = nodes[i].rect;\r
190         if (   (rect.top - point.y <= delta)\r
191             && (rect.left - point.x <= delta)\r
192             && (point.y - rect.bottom <= delta)\r
193             && (point.x - rect.right <= delta))\r
194         {\r
195             return static_cast<index_t>(i);\r
196         }\r
197     }\r
198 \r
199     return static_cast<index_t>(NO_INDEX);\r
200 }\r
201 \r
202 // implement ILayoutNodeList\r
203 \r
204 CStandardLayoutNodeList::SNode \r
205 CStandardLayoutNodeList::GetNode (index_t index) const\r
206 {\r
207     SNode result;\r
208 \r
209         const CVisibleGraphNode* node = nodes[index].node;\r
210 \r
211     result.rect = nodes[index].rect;\r
212     result.node = node;\r
213     result.style = GetStyle (node);\r
214     result.styleFlags = GetStyleFlags (node);\r
215 \r
216     return result;\r
217 }\r