Path: blob/master/editor/inspector/editor_context_menu_plugin.h
9896 views
/**************************************************************************/1/* editor_context_menu_plugin.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/object/gdvirtual.gen.inc"33#include "core/object/ref_counted.h"3435class InputEvent;36class PopupMenu;37class Shortcut;38class Texture2D;3940class EditorContextMenuPlugin : public RefCounted {41GDCLASS(EditorContextMenuPlugin, RefCounted);4243friend class EditorContextMenuPluginManager;4445static constexpr int MAX_ITEMS = 100;4647public:48enum ContextMenuSlot {49CONTEXT_SLOT_SCENE_TREE,50CONTEXT_SLOT_FILESYSTEM,51CONTEXT_SLOT_SCRIPT_EDITOR,52CONTEXT_SLOT_FILESYSTEM_CREATE,53CONTEXT_SLOT_SCRIPT_EDITOR_CODE,54CONTEXT_SLOT_SCENE_TABS,55CONTEXT_SLOT_2D_EDITOR,56};57static constexpr int BASE_ID = 2000;5859private:60int slot = -1;6162public:63struct ContextMenuItem {64int id = 0;65String item_name;66Callable callable;67Ref<Texture2D> icon;68Ref<Shortcut> shortcut;69PopupMenu *submenu = nullptr;70};71HashMap<String, ContextMenuItem> context_menu_items;72HashMap<Ref<Shortcut>, Callable> context_menu_shortcuts;7374protected:75static void _bind_methods();7677GDVIRTUAL1(_popup_menu, Vector<String>);7879public:80virtual void get_options(const Vector<String> &p_paths);8182void add_menu_shortcut(const Ref<Shortcut> &p_shortcut, const Callable &p_callable);83void add_context_menu_item(const String &p_name, const Callable &p_callable, const Ref<Texture2D> &p_texture);84void add_context_menu_item_from_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut, const Ref<Texture2D> &p_texture);85void add_context_submenu_item(const String &p_name, PopupMenu *p_menu, const Ref<Texture2D> &p_texture);86};8788VARIANT_ENUM_CAST(EditorContextMenuPlugin::ContextMenuSlot);8990class EditorContextMenuPluginManager : public Object {91GDCLASS(EditorContextMenuPluginManager, Object);9293using ContextMenuSlot = EditorContextMenuPlugin::ContextMenuSlot;94static inline EditorContextMenuPluginManager *singleton = nullptr;9596LocalVector<Ref<EditorContextMenuPlugin>> plugin_list;9798public:99static EditorContextMenuPluginManager *get_singleton() { return singleton; }100101void add_plugin(ContextMenuSlot p_slot, const Ref<EditorContextMenuPlugin> &p_plugin);102void remove_plugin(const Ref<EditorContextMenuPlugin> &p_plugin);103104bool has_plugins_for_slot(ContextMenuSlot p_slot);105void add_options_from_plugins(PopupMenu *p_popup, ContextMenuSlot p_slot, const Vector<String> &p_paths);106Callable match_custom_shortcut(ContextMenuSlot p_slot, const Ref<InputEvent> &p_event);107bool activate_custom_option(ContextMenuSlot p_slot, int p_option, const Variant &p_arg);108109void invoke_callback(const Callable &p_callback, const Variant &p_arg);110111static void create();112static void cleanup();113};114115116