| 1 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
|
| 3 |
/*************************************************************************** |
| 4 |
* Copyright (c) 2023 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 5 |
* * |
| 6 |
* This file is part of FreeCAD. * |
| 7 |
* * |
| 8 |
* FreeCAD is free software: you can redistribute it and/or modify it * |
| 9 |
* under the terms of the GNU Lesser General Public License as * |
| 10 |
* published by the Free Software Foundation, either version 2.1 of the * |
| 11 |
* License, or (at your option) any later version. * |
| 12 |
* * |
| 13 |
* FreeCAD is distributed in the hope that it will be useful, but * |
| 14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 16 |
* Lesser General Public License for more details. * |
| 17 |
* * |
| 18 |
* You should have received a copy of the GNU Lesser General Public * |
| 19 |
* License along with FreeCAD. If not, see * |
| 20 |
* <https://www.gnu.org/licenses/>. * |
| 21 |
* * |
| 22 |
**************************************************************************/ |
| 23 |
|
| 24 |
|
| 25 |
#ifndef GUI_WORKBENCHMANIPULATOR_H |
| 26 |
#define GUI_WORKBENCHMANIPULATOR_H |
| 27 |
|
| 28 |
#include <memory> |
| 29 |
#include <set> |
| 30 |
#include <map> |
| 31 |
#include <string> |
| 32 |
#include <FCGlobal.h> |
| 33 |
|
| 34 |
namespace Gui |
| 35 |
{ |
| 36 |
|
| 37 |
class DockWindowItems; |
| 38 |
class MenuItem; |
| 39 |
class ToolBarItem; |
| 40 |
|
| 41 |
/** |
| 42 |
* The WorkbenchManipulator is a class that allows one to modify the workbench |
| 43 |
* by adding or removing commands. |
| 44 |
* WorkbenchManipulator provides methods to manipulate the MenuItem, ToolBarItem or |
| 45 |
* DockWindowItems structure before setting up the workbench. |
| 46 |
* @author Werner Mayer |
| 47 |
*/ |
| 48 |
class GuiExport WorkbenchManipulator |
| 49 |
{ |
| 50 |
public: |
| 51 |
using Ptr = std::shared_ptr<WorkbenchManipulator>; |
| 52 |
/*! |
| 53 |
* \brief installManipulator |
| 54 |
* Installs a new instance of WorkbenchManipulator |
| 55 |
*/ |
| 56 |
static void installManipulator(const WorkbenchManipulator::Ptr&); |
| 57 |
/*! |
| 58 |
* \brief removeManipulator |
| 59 |
* Removes an installed instance of WorkbenchManipulator |
| 60 |
*/ |
| 61 |
static void removeManipulator(const WorkbenchManipulator::Ptr&); |
| 62 |
/*! |
| 63 |
* \brief clear |
| 64 |
* Removes all instances of WorkbenchManipulator |
| 65 |
*/ |
| 66 |
static void removeAll(); |
| 67 |
/*! |
| 68 |
* \brief changeMenuBar |
| 69 |
* Calls \ref modifyMenuBar for every installed WorkbenchManipulator |
| 70 |
*/ |
| 71 |
static void changeMenuBar(MenuItem* menuBar); |
| 72 |
/*! |
| 73 |
* \brief changeContextMenu |
| 74 |
* Calls \ref modifyContextMenu for every installed WorkbenchManipulator |
| 75 |
*/ |
| 76 |
static void changeContextMenu(const char* recipient, MenuItem* menuBar); |
| 77 |
/*! |
| 78 |
* \brief changeToolBars |
| 79 |
* Calls \ref modifyToolBars for every installed WorkbenchManipulator |
| 80 |
*/ |
| 81 |
static void changeToolBars(ToolBarItem* toolBar); |
| 82 |
/*! |
| 83 |
* \brief changeDockWindows |
| 84 |
* Calls \ref modifyDockWindows for every installed WorkbenchManipulator |
| 85 |
*/ |
| 86 |
static void changeDockWindows(DockWindowItems* dockWindow); |
| 87 |
|
| 88 |
WorkbenchManipulator() = default; |
| 89 |
virtual ~WorkbenchManipulator() = default; |
| 90 |
|
| 91 |
protected: |
| 92 |
/*! |
| 93 |
* \brief modifyMenuBar |
| 94 |
* Method to manipulate the menu structure of a workbench. |
| 95 |
* The default implementation doesn't change anything. |
| 96 |
*/ |
| 97 |
virtual void modifyMenuBar([[maybe_unused]] MenuItem* menuBar); |
| 98 |
/*! |
| 99 |
* \brief modifyContextMenu |
| 100 |
* Method to manipulate the contextmenu structure of a workbench. |
| 101 |
* The default implementation doesn't change anything. |
| 102 |
*/ |
| 103 |
virtual void modifyContextMenu( |
| 104 |
[[maybe_unused]] const char* recipient, |
| 105 |
[[maybe_unused]] MenuItem* menuBar |
| 106 |
); |
| 107 |
/*! |
| 108 |
* \brief modifyToolBars |
| 109 |
* Method to manipulate the toolbar structure of a workbench |
| 110 |
* The default implementation doesn't change anything. |
| 111 |
*/ |
| 112 |
virtual void modifyToolBars([[maybe_unused]] ToolBarItem* toolBar); |
| 113 |
/*! |
| 114 |
* \brief modifyDockWindows |
| 115 |
* Method to manipulate the dock window structure of a workbench |
| 116 |
* The default implementation doesn't change anything. |
| 117 |
*/ |
| 118 |
virtual void modifyDockWindows([[maybe_unused]] DockWindowItems* dockWindow); |
| 119 |
|
| 120 |
public: |
| 121 |
WorkbenchManipulator(const WorkbenchManipulator&) = delete; |
| 122 |
WorkbenchManipulator(WorkbenchManipulator&&) = delete; |
| 123 |
WorkbenchManipulator& operator=(const WorkbenchManipulator&) = delete; |
| 124 |
WorkbenchManipulator& operator=(WorkbenchManipulator&&) = delete; |
| 125 |
|
| 126 |
protected: |
| 127 |
static std::set<WorkbenchManipulator::Ptr> getManipulators(); |
| 128 |
|
| 129 |
private: |
| 130 |
static std::set<WorkbenchManipulator::Ptr> manipulators; // NOLINT |
| 131 |
}; |
| 132 |
|
| 133 |
} // namespace Gui |
| 134 |
|
| 135 |
|
| 136 |
#endif // GUI_WORKBENCHMANIPULATOR_H |