| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/object/gdvirtual.gen.inc" |
| 34 |
#include "core/object/ref_counted.h" |
| 35 |
|
| 36 |
class InputEvent; |
| 37 |
class PopupMenu; |
| 38 |
class Shortcut; |
| 39 |
class Texture2D; |
| 40 |
|
| 41 |
class EditorContextMenuPlugin : public RefCounted { |
| 42 |
GDCLASS(EditorContextMenuPlugin, RefCounted); |
| 43 |
|
| 44 |
friend class EditorContextMenuPluginManager; |
| 45 |
|
| 46 |
static constexpr int MAX_ITEMS = 100; |
| 47 |
|
| 48 |
public: |
| 49 |
enum ContextMenuSlot { |
| 50 |
CONTEXT_SLOT_SCENE_TREE, |
| 51 |
CONTEXT_SLOT_FILESYSTEM, |
| 52 |
CONTEXT_SLOT_SCRIPT_EDITOR, |
| 53 |
CONTEXT_SLOT_FILESYSTEM_CREATE, |
| 54 |
CONTEXT_SLOT_SCRIPT_EDITOR_CODE, |
| 55 |
CONTEXT_SLOT_SCENE_TABS, |
| 56 |
CONTEXT_SLOT_2D_EDITOR, |
| 57 |
}; |
| 58 |
static constexpr int BASE_ID = 2000; |
| 59 |
|
| 60 |
private: |
| 61 |
int slot = -1; |
| 62 |
|
| 63 |
public: |
| 64 |
struct ContextMenuItem { |
| 65 |
int id = 0; |
| 66 |
String item_name; |
| 67 |
Callable callable; |
| 68 |
Ref<Texture2D> icon; |
| 69 |
Ref<Shortcut> shortcut; |
| 70 |
PopupMenu *submenu = nullptr; |
| 71 |
}; |
| 72 |
HashMap<String, ContextMenuItem> context_menu_items; |
| 73 |
HashMap<Ref<Shortcut>, Callable> context_menu_shortcuts; |
| 74 |
|
| 75 |
protected: |
| 76 |
static void _bind_methods(); |
| 77 |
|
| 78 |
GDVIRTUAL1(_popup_menu, Vector<String>); |
| 79 |
|
| 80 |
public: |
| 81 |
virtual void get_options(const Vector<String> &p_paths); |
| 82 |
|
| 83 |
void add_menu_shortcut(const Ref<Shortcut> &p_shortcut, const Callable &p_callable); |
| 84 |
void add_context_menu_item(const String &p_name, const Callable &p_callable, const Ref<Texture2D> &p_texture); |
| 85 |
void add_context_menu_item_from_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut, const Ref<Texture2D> &p_texture); |
| 86 |
void add_context_submenu_item(const String &p_name, PopupMenu *p_menu, const Ref<Texture2D> &p_texture); |
| 87 |
}; |
| 88 |
|
| 89 |
VARIANT_ENUM_CAST(EditorContextMenuPlugin::ContextMenuSlot); |
| 90 |
|
| 91 |
class EditorContextMenuPluginManager : public Object { |
| 92 |
GDCLASS(EditorContextMenuPluginManager, Object); |
| 93 |
|
| 94 |
using ContextMenuSlot = EditorContextMenuPlugin::ContextMenuSlot; |
| 95 |
static inline EditorContextMenuPluginManager *singleton = nullptr; |
| 96 |
|
| 97 |
LocalVector<Ref<EditorContextMenuPlugin>> plugin_list; |
| 98 |
|
| 99 |
public: |
| 100 |
static EditorContextMenuPluginManager *get_singleton() { return singleton; } |
| 101 |
|
| 102 |
void add_plugin(ContextMenuSlot p_slot, const Ref<EditorContextMenuPlugin> &p_plugin); |
| 103 |
void remove_plugin(const Ref<EditorContextMenuPlugin> &p_plugin); |
| 104 |
|
| 105 |
bool has_plugins_for_slot(ContextMenuSlot p_slot); |
| 106 |
void add_options_from_plugins(PopupMenu *p_popup, ContextMenuSlot p_slot, const Vector<String> &p_paths, int p_id_offset = 0); |
| 107 |
Callable match_custom_shortcut(ContextMenuSlot p_slot, const Ref<InputEvent> &p_event); |
| 108 |
bool activate_custom_option(ContextMenuSlot p_slot, int p_option, const Variant &p_arg); |
| 109 |
|
| 110 |
void invoke_callback(const Callable &p_callback, const Variant &p_arg); |
| 111 |
|
| 112 |
static void create(); |
| 113 |
static void cleanup(); |
| 114 |
}; |