Debian Codegraph @

src/Gui/Workbench.h

raw
1 /***************************************************************************
2 * Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef GUI_WORKBENCH_H
25 #define GUI_WORKBENCH_H
26
27 #include <list>
28 #include <string>
29 #include <Base/BaseClass.h>
30 #include <Base/Parameter.h>
31 #include <Gui/TaskView/TaskWatcher.h>
32
33 namespace Base
34 {
35 class PyObjectBase;
36 }
37
38 namespace Gui
39 {
40
41 class MenuItem;
42 class ToolBarItem;
43 class DockWindowItems;
44 class WorkbenchManager;
45
46 /**
47 * This is the base class for the workbench facility. Each FreeCAD module can provide its own
48 * workbench implementation. The workbench defines which GUI elements (such as toolbars, menus,
49 * dockable windows, ...) are added to the mainwindow and which gets removed or hidden.
50 * When a workbench object gets activated the first time the module - it stands for - gets
51 * loaded into RAM.
52 * @author Werner Mayer
53 */
54 class GuiExport Workbench: public Base::BaseClass
55 {
56 TYPESYSTEM_HEADER_WITH_OVERRIDE();
57
58 public:
59 /** Constructs a workbench object. */
60 Workbench();
61 ~Workbench() override;
62 /**
63 * Returns the name of the workbench object.
64 */
65 std::string name() const;
66 /**
67 * Set the name to the workbench object.
68 */
69 void setName(const std::string&);
70 /**
71 * The default implementation returns an instance of @ref WorkbenchPy.
72 */
73 PyObject* getPyObject() override;
74 /** Sets up the contextmenu for this workbench.
75 */
76 void createContextMenu(const char* recipient, MenuItem*) const;
77 /** Sets up the contextmenu for the main window for this workbench.
78 * The default implementation does nothing.
79 */
80 virtual void createMainWindowPopupMenu(MenuItem*) const;
81 /**
82 * Activates the workbench and adds/removes GUI elements.
83 */
84 bool activate();
85 /**
86 * Translates the window titles of all menus, toolbars and dock windows.
87 */
88 void retranslate() const;
89 /** Run some actions when the workbench gets activated. */
90 virtual void activated();
91 /** Run some actions when the workbench gets deactivated. */
92 virtual void deactivated();
93
94 /// helper to add TaskWatcher to the TaskView
95 void addTaskWatcher(const std::vector<Gui::TaskView::TaskWatcher*>& Watcher);
96 /// remove the added TaskWatcher
97 void removeTaskWatcher();
98
99 static void createLinkMenu(MenuItem*);
100
101 //// Shows a list of all toolbars
102 std::list<std::string> listToolbars() const;
103 /// Shows a list of all toolbars and their commands
104 std::list<std::pair<std::string, std::list<std::string>>> getToolbarItems() const;
105 //// Shows a list of all menus
106 std::list<std::string> listMenus() const;
107 //// Shows a list of all command bars
108 std::list<std::string> listCommandbars() const;
109 /// Add a permanent menu item \a cmd after an existing command \a after.
110 /// Permanent menu items are always added independent of what the active workbench is.
111 /// Adding it will only fail if the item \a after doesn't exist.
112 static void addPermanentMenuItem(const std::string& cmd, const std::string& after);
113 /// Removes the command \a cmd from the permanent menu items.
114 static void removePermanentMenuItem(const std::string& cmd);
115
116 protected:
117 /** Returns a MenuItem tree structure of menus for this workbench. */
118 virtual MenuItem* setupMenuBar() const = 0;
119 /** Returns a ToolBarItem tree structure of toolbars for this workbench. */
120 virtual ToolBarItem* setupToolBars() const = 0;
121 /** Returns a ToolBarItem tree structure of command bars for this workbench. */
122 virtual ToolBarItem* setupCommandBars() const = 0;
123 /** Returns a DockWindowItems structure of dock windows this workbench. */
124 virtual DockWindowItems* setupDockWindows() const = 0;
125 /** Sets up the contextmenu for this workbench.
126 * The default implementation does nothing.
127 */
128 virtual void setupContextMenu(const char* recipient, MenuItem*) const;
129 /** Add permanent menu items to the structure */
130 void addPermanentMenuItems(MenuItem*) const;
131
132 private:
133 /**
134 * The method imports the user defined toolbars or toolbox bars and creates
135 * a ToolBarItem tree structure.
136 */
137 void setupCustomToolbars(ToolBarItem* root, const char* toolbar) const;
138 void setupCustomToolbars(ToolBarItem* root, const Base::Reference<ParameterGrp> hGrp) const;
139 void setupCustomShortcuts() const;
140
141 private:
142 std::string _name;
143 static std::vector<std::pair<std::string, std::string>> staticMenuItems;
144 };
145
146 /**
147 * The StdWorkbench class defines the standard menus, toolbars, commandbars etc.
148 * To define own workbenches you should inherit from StdWorkbench instead of Workbench
149 * to have defined the standard GUI elements.
150 * @author Werner Mayer
151 */
152 class GuiExport StdWorkbench: public Workbench
153 {
154 TYPESYSTEM_HEADER_WITH_OVERRIDE();
155
156 public:
157 StdWorkbench();
158 ~StdWorkbench() override;
159
160 public:
161 /** Defines the standard context menu. */
162 void setupContextMenu(const char* recipient, MenuItem*) const override;
163 void createMainWindowPopupMenu(MenuItem*) const override;
164
165 protected:
166 /** Defines the standard menus. */
167 MenuItem* setupMenuBar() const override;
168 /** Defines the standard toolbars. */
169 ToolBarItem* setupToolBars() const override;
170 /** Defines the standard command bars. */
171 ToolBarItem* setupCommandBars() const override;
172 /** Returns a DockWindowItems structure of dock windows this workbench. */
173 DockWindowItems* setupDockWindows() const override;
174
175 friend class PythonWorkbench;
176 };
177
178 /**
179 * The BlankWorkbench class defines a complete empty workbench.
180 * @author Werner Mayer
181 */
182 class GuiExport BlankWorkbench: public Workbench
183 {
184 TYPESYSTEM_HEADER_WITH_OVERRIDE();
185
186 public:
187 BlankWorkbench();
188 ~BlankWorkbench() override;
189
190 /** Defines the standard context menu. */
191 void setupContextMenu(const char* recipient, MenuItem*) const override;
192 /** Run some actions when the workbench gets activated. */
193 void activated() override;
194 /** Run some actions when the workbench gets deactivated. */
195 void deactivated() override;
196
197 protected:
198 /** Defines the standard menus. */
199 MenuItem* setupMenuBar() const override;
200 /** Defines the standard toolbars. */
201 ToolBarItem* setupToolBars() const override;
202 /** Defines the standard command bars. */
203 ToolBarItem* setupCommandBars() const override;
204 /** Returns a DockWindowItems structure of dock windows this workbench. */
205 DockWindowItems* setupDockWindows() const override;
206 };
207
208 /**
209 * The NoneWorkbench class defines a slim workbench.
210 * @author Werner Mayer
211 */
212 class GuiExport NoneWorkbench: public StdWorkbench
213 {
214 TYPESYSTEM_HEADER_WITH_OVERRIDE();
215
216 public:
217 NoneWorkbench();
218 ~NoneWorkbench() override;
219
220 /** Defines the standard context menu. */
221 void setupContextMenu(const char* recipient, MenuItem*) const override;
222
223 protected:
224 /** Defines the standard menus. */
225 MenuItem* setupMenuBar() const override;
226 /** Defines the standard toolbars. */
227 ToolBarItem* setupToolBars() const override;
228 /** Defines the standard command bars. */
229 ToolBarItem* setupCommandBars() const override;
230 /** Returns a DockWindowItems structure of dock windows this workbench. */
231 DockWindowItems* setupDockWindows() const override;
232 };
233
234 class GuiExport TestWorkbench: public StdWorkbench
235 {
236 TYPESYSTEM_HEADER_WITH_OVERRIDE();
237
238 public:
239 TestWorkbench();
240 ~TestWorkbench() override;
241
242 protected:
243 MenuItem* setupMenuBar() const override;
244 ToolBarItem* setupToolBars() const override;
245 ToolBarItem* setupCommandBars() const override;
246 };
247
248 /**
249 * The PythonBaseWorkbench class allows the manipulation of the workbench from Python.
250 * Therefore PythonWorkbenchPy provides the required Python interface.
251 * @author Werner Mayer
252 */
253 class GuiExport PythonBaseWorkbench: public Workbench
254 {
255 TYPESYSTEM_HEADER_WITH_OVERRIDE();
256
257 public:
258 PythonBaseWorkbench();
259 ~PythonBaseWorkbench() override;
260 /**
261 * Creates and returns immediately the corresponding Python workbench object.
262 */
263 PyObject* getPyObject() override;
264
265 /** @name Manipulation methods */
266 //@{
267 /// Appends a new menu
268 void appendMenu(const std::list<std::string>& menu, const std::list<std::string>& items) const;
269 /// Removes a menu
270 void removeMenu(const std::string& menu) const;
271
272 /// Appends new context menu items
273 void appendContextMenu(const std::list<std::string>& menu, const std::list<std::string>& items) const;
274 /// Removes a context menu
275 void removeContextMenu(const std::string& menu) const;
276 void setupContextMenu(const char* recipient, MenuItem*) const override;
277 void clearContextMenu();
278
279 /// Appends a new toolbar
280 void appendToolbar(const std::string& bar, const std::list<std::string>& items) const;
281 /// Removes a toolbar
282 void removeToolbar(const std::string& bar) const;
283
284 /// Appends a new command bar
285 void appendCommandbar(const std::string& bar, const std::list<std::string>& items) const;
286 /// Removes a command bar
287 void removeCommandbar(const std::string& bar) const;
288 //@}
289
290 protected:
291 MenuItem* setupMenuBar() const override;
292 ToolBarItem* setupToolBars() const override;
293 ToolBarItem* setupCommandBars() const override;
294 DockWindowItems* setupDockWindows() const override;
295
296 protected:
297 MenuItem* _menuBar {nullptr};
298 MenuItem* _contextMenu {nullptr};
299 ToolBarItem* _toolBar {nullptr};
300 ToolBarItem* _commandBar {nullptr};
301 Base::PyObjectBase* _workbenchPy {nullptr};
302 };
303
304 class GuiExport PythonBlankWorkbench: public PythonBaseWorkbench
305 {
306 TYPESYSTEM_HEADER_WITH_OVERRIDE();
307
308 public:
309 PythonBlankWorkbench();
310 ~PythonBlankWorkbench() override;
311 };
312
313 /**
314 * The PythonWorkbench class allows the manipulation of the workbench from Python.
315 * Therefore PythonWorkbenchPy provides the required Python interface.
316 * @author Werner Mayer
317 */
318 class GuiExport PythonWorkbench: public PythonBaseWorkbench
319 {
320 TYPESYSTEM_HEADER_WITH_OVERRIDE();
321
322 public:
323 PythonWorkbench();
324 ~PythonWorkbench() override;
325
326 /** Defines the standard context menu. */
327 void setupContextMenu(const char* recipient, MenuItem*) const override;
328 void createMainWindowPopupMenu(MenuItem*) const override;
329
330 protected:
331 MenuItem* setupMenuBar() const override;
332 ToolBarItem* setupToolBars() const override;
333 ToolBarItem* setupCommandBars() const override;
334 DockWindowItems* setupDockWindows() const override;
335 };
336
337 } // namespace Gui
338
339
340 #endif // GUI_WORKBENCH_H