action.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* action.h - ui action
  2. * Copyright (C) 2017 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef STUDIO_GENERIC_ACTION_H_EAC1E4D4_361B_5C94_BB73_9EB2953E2613
  18. #define STUDIO_GENERIC_ACTION_H_EAC1E4D4_361B_5C94_BB73_9EB2953E2613
  19. #include <core/util/class_init.h>
  20. #include "context_listener.h"
  21. class QMenu;
  22. class QErrorMessage;
  23. namespace rainynite::studio {
  24. class ContextListener;
  25. class UiAction {
  26. public:
  27. virtual void process() = 0;
  28. };
  29. inline map<string,UiAction*> const& get_all_actions() {
  30. return class_init::string_registry<UiAction>();
  31. }
  32. /**
  33. * Add all registered actions to QMenu.
  34. *
  35. * `menu` and `error_box` should never outlive `parent`
  36. *
  37. * TODO: better error-reporting
  38. */
  39. void add_all_actions_to_menu(ContextListener const& parent, QMenu& menu, QErrorMessage& error_box);
  40. #define REGISTERED_ACTION(Self) \
  41. private class_init::StringRegistered<Self, UiAction>
  42. #define CONTEXT_ACTION(Self) \
  43. public UiAction, \
  44. public ContextListener, \
  45. REGISTERED_ACTION(Self)
  46. #define ACTION_NAME(name_) \
  47. public: \
  48. static string name() { return name_; }
  49. } // namespace rainynite::studio
  50. #endif