OSDN Git Service

Show Ignore Sub Menu
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / RevisionGraph / RevisionGraphOptions.h
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 #pragma once\r
20 \r
21 class CFullGraphNode;\r
22 class CVisibleGraph;\r
23 class CVisibleGraphNode;\r
24 \r
25 /**\r
26 * Base interface for all binary options.\r
27 */\r
28 \r
29 class IRevisionGraphOption\r
30 {\r
31 public:\r
32 \r
33     /// make all interface destructors virtual\r
34 \r
35     virtual ~IRevisionGraphOption() {}\r
36 \r
37     /// toolbar button ID\r
38 \r
39     virtual UINT CommandID() const = 0;\r
40 \r
41     /// controls the execution order. \r
42     /// Lower numbers take precedence before higher ones.\r
43 \r
44     virtual int Priority() const = 0; \r
45 \r
46     /// false -> currently grayed out\r
47 \r
48     virtual bool IsAvailable() const = 0;\r
49 \r
50     /// button shown as "pressed"\r
51 \r
52     virtual bool IsSelected() const = 0;\r
53 \r
54     /// The actual option may be "reversed".\r
55     /// IsActive() should either *always* be equal to IsSelected()\r
56     /// or *always* be equal to !IsSelected().\r
57 \r
58     virtual bool IsActive() const = 0; \r
59 \r
60     /// for simple "on-click" handling\r
61 \r
62     virtual void ToggleSelection() = 0;\r
63 \r
64     /// will be called before a new graph gets created.\r
65     /// Use this method to reset internal caches etc.\r
66 \r
67     virtual void Prepare() = 0;\r
68 \r
69     /// required typedef for multi-interface support\r
70 \r
71     typedef IRevisionGraphOption I;\r
72 };\r
73 \r
74 /**\r
75 * Base interface extension for options that must be applied onto\r
76 * the graph nodes in a particular traversal order.\r
77 */\r
78 \r
79 class IOrderedTraversalOption : public IRevisionGraphOption\r
80 {\r
81 public:\r
82 \r
83     /// breadth-first traversal\r
84 \r
85     virtual bool WantsCopiesFirst() const = 0;\r
86 \r
87     /// if false, start with the HEAD / branch end nodes\r
88 \r
89     virtual bool WantsRootFirst() const = 0;\r
90 \r
91 };\r
92 \r
93 /**\r
94 * Container base class for all revision graph options.\r
95 *\r
96 * Options are expected to be created on the heap and\r
97 * to auto-add themselves to an instance of this class.\r
98 * That instance will take over ownership of the options.\r
99 *\r
100 * Every option is expected to provide its own class,\r
101 * i.e. no two options of the same class are allowed\r
102 * in any given CRevisionGraphOptionList instance.\r
103 *\r
104 * Individual options as well as sub-lists are being\r
105 * accessed through RTTI-based filtering.\r
106 */\r
107 \r
108 class CRevisionGraphOptionList\r
109 {\r
110 private:\r
111 \r
112     /// (only) this base class owns all the options\r
113 \r
114     std::vector<IRevisionGraphOption*> options;\r
115 \r
116 protected:\r
117 \r
118     /// options owner and filter management\r
119 \r
120     template<class T, class I> T GetFilteredList() const;\r
121 \r
122     /// utility method\r
123 \r
124     IRevisionGraphOption* GetOptionByID (UINT id) const;\r
125 \r
126     /// construction / destruction (frees all owned options)\r
127 \r
128     CRevisionGraphOptionList();\r
129     virtual ~CRevisionGraphOptionList();\r
130 \r
131 public:\r
132 \r
133     /// member access\r
134 \r
135     size_t count() const;\r
136 \r
137     const IRevisionGraphOption* operator[](size_t index) const;\r
138     IRevisionGraphOption* operator[](size_t index);\r
139 \r
140     /// find a particular option\r
141 \r
142     template<class T> T* GetOption() const;\r
143 \r
144     /// called by CRevisionGraphOption constructor\r
145 \r
146     void Add (IRevisionGraphOption* option);\r
147 \r
148     /// menu interaction\r
149 \r
150     bool IsAvailable (UINT id) const;\r
151     bool IsSelected (UINT id) const;\r
152 \r
153     void ToggleSelection (UINT id);\r
154 \r
155     /// registry encoding\r
156 \r
157     DWORD GetRegistryFlags() const;\r
158     void SetRegistryFlags (DWORD flags, DWORD mask);\r
159 \r
160     /// called before applying the options\r
161 \r
162     void Prepare();\r
163 };\r
164 \r
165 // options owner and filter management\r
166 \r
167 template<class I>\r
168 bool AscendingPriority (I* lhs, I* rhs)\r
169 {\r
170     return lhs->Priority() < rhs->Priority();\r
171 }\r
172 \r
173 template<class T, class I> \r
174 T CRevisionGraphOptionList::GetFilteredList() const\r
175 {\r
176     // get filtered options\r
177 \r
178     std::vector<I*> filteredOptions;\r
179     for (size_t i = 0, count = options.size(); i < count; ++i)\r
180     {\r
181         I* option = dynamic_cast<I*>(options[i]);\r
182         if ((option != NULL) && options[i]->IsActive())\r
183             filteredOptions.push_back (option);\r
184     }\r
185 \r
186     // sort them by priority\r
187 \r
188     std::stable_sort ( filteredOptions.begin()\r
189                      , filteredOptions.end()\r
190                      , AscendingPriority<I>);\r
191 \r
192     // create list\r
193 \r
194     return T (filteredOptions);\r
195 }\r
196 \r
197 // find a particular option\r
198 \r
199 template<class T> \r
200 T* CRevisionGraphOptionList::GetOption() const\r
201 {\r
202     for (size_t i = 0, count = options.size(); i < count; ++i)\r
203     {\r
204         T* result = dynamic_cast<T*>(options[i]);\r
205         if (result != NULL)\r
206             return result;\r
207     }\r
208 \r
209     // should not happen \r
210 \r
211     assert (0);\r
212 \r
213     return NULL;\r
214 }\r