Path: blob/master/editor/scene/packed_scene_editor_plugin.cpp
9903 views
/**************************************************************************/1/* packed_scene_editor_plugin.cpp */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#include "packed_scene_editor_plugin.h"3132#include "editor/editor_node.h"33#include "scene/resources/packed_scene.h"3435void PackedSceneEditor::_on_open_scene_pressed() {36// Using deferred call because changing scene updates the Inspector and thus destroys this plugin.37callable_mp(EditorNode::get_singleton(), &EditorNode::load_scene).call_deferred(packed_scene->get_path(), false, false, false, false);38}3940PackedSceneEditor::PackedSceneEditor(Ref<PackedScene> &p_packed_scene) {41packed_scene = p_packed_scene;4243EditorInspectorActionButton *open_scene_button = memnew(EditorInspectorActionButton(TTRC("Open Scene"), SNAME("PackedScene")));44open_scene_button->connect(SceneStringName(pressed), callable_mp(this, &PackedSceneEditor::_on_open_scene_pressed));45open_scene_button->set_disabled(!packed_scene->get_path().get_file().is_valid_filename());46add_child(open_scene_button);4748add_child(memnew(Control)); // Add padding before the regular properties.49}5051///////////////////////5253bool EditorInspectorPluginPackedScene::can_handle(Object *p_object) {54return Object::cast_to<PackedScene>(p_object) != nullptr;55}5657void EditorInspectorPluginPackedScene::parse_begin(Object *p_object) {58Ref<PackedScene> packed_scene(p_object);59PackedSceneEditor *editor = memnew(PackedSceneEditor(packed_scene));60add_custom_control(editor);61}6263///////////////////////6465PackedSceneEditorPlugin::PackedSceneEditorPlugin() {66Ref<EditorInspectorPluginPackedScene> plugin;67plugin.instantiate();68add_inspector_plugin(plugin);69}707172