1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2008 - TortoiseSVN
\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
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
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
21 class CFullGraphNode;
\r
22 class CVisibleGraph;
\r
23 class CVisibleGraphNode;
\r
26 * Base interface for all binary options.
\r
29 class IRevisionGraphOption
\r
33 /// make all interface destructors virtual
\r
35 virtual ~IRevisionGraphOption() {}
\r
37 /// toolbar button ID
\r
39 virtual UINT CommandID() const = 0;
\r
41 /// controls the execution order.
\r
42 /// Lower numbers take precedence before higher ones.
\r
44 virtual int Priority() const = 0;
\r
46 /// false -> currently grayed out
\r
48 virtual bool IsAvailable() const = 0;
\r
50 /// button shown as "pressed"
\r
52 virtual bool IsSelected() const = 0;
\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
58 virtual bool IsActive() const = 0;
\r
60 /// for simple "on-click" handling
\r
62 virtual void ToggleSelection() = 0;
\r
64 /// will be called before a new graph gets created.
\r
65 /// Use this method to reset internal caches etc.
\r
67 virtual void Prepare() = 0;
\r
69 /// required typedef for multi-interface support
\r
71 typedef IRevisionGraphOption I;
\r
75 * Base interface extension for options that must be applied onto
\r
76 * the graph nodes in a particular traversal order.
\r
79 class IOrderedTraversalOption : public IRevisionGraphOption
\r
83 /// breadth-first traversal
\r
85 virtual bool WantsCopiesFirst() const = 0;
\r
87 /// if false, start with the HEAD / branch end nodes
\r
89 virtual bool WantsRootFirst() const = 0;
\r
94 * Container base class for all revision graph options.
\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
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
104 * Individual options as well as sub-lists are being
\r
105 * accessed through RTTI-based filtering.
\r
108 class CRevisionGraphOptionList
\r
112 /// (only) this base class owns all the options
\r
114 std::vector<IRevisionGraphOption*> options;
\r
118 /// options owner and filter management
\r
120 template<class T, class I> T GetFilteredList() const;
\r
124 IRevisionGraphOption* GetOptionByID (UINT id) const;
\r
126 /// construction / destruction (frees all owned options)
\r
128 CRevisionGraphOptionList();
\r
129 virtual ~CRevisionGraphOptionList();
\r
135 size_t count() const;
\r
137 const IRevisionGraphOption* operator[](size_t index) const;
\r
138 IRevisionGraphOption* operator[](size_t index);
\r
140 /// find a particular option
\r
142 template<class T> T* GetOption() const;
\r
144 /// called by CRevisionGraphOption constructor
\r
146 void Add (IRevisionGraphOption* option);
\r
148 /// menu interaction
\r
150 bool IsAvailable (UINT id) const;
\r
151 bool IsSelected (UINT id) const;
\r
153 void ToggleSelection (UINT id);
\r
155 /// registry encoding
\r
157 DWORD GetRegistryFlags() const;
\r
158 void SetRegistryFlags (DWORD flags, DWORD mask);
\r
160 /// called before applying the options
\r
165 // options owner and filter management
\r
168 bool AscendingPriority (I* lhs, I* rhs)
\r
170 return lhs->Priority() < rhs->Priority();
\r
173 template<class T, class I>
\r
174 T CRevisionGraphOptionList::GetFilteredList() const
\r
176 // get filtered options
\r
178 std::vector<I*> filteredOptions;
\r
179 for (size_t i = 0, count = options.size(); i < count; ++i)
\r
181 I* option = dynamic_cast<I*>(options[i]);
\r
182 if ((option != NULL) && options[i]->IsActive())
\r
183 filteredOptions.push_back (option);
\r
186 // sort them by priority
\r
188 std::stable_sort ( filteredOptions.begin()
\r
189 , filteredOptions.end()
\r
190 , AscendingPriority<I>);
\r
194 return T (filteredOptions);
\r
197 // find a particular option
\r
200 T* CRevisionGraphOptionList::GetOption() const
\r
202 for (size_t i = 0, count = options.size(); i < count; ++i)
\r
204 T* result = dynamic_cast<T*>(options[i]);
\r
205 if (result != NULL)
\r
209 // should not happen
\r