mirror of
https://github.com/godotengine/godot.git
synced 2024-11-10 14:12:51 +00:00
Refactor inspector code for getting resource
This commit is contained in:
parent
dc3175e4cd
commit
48f60ef1cd
@ -256,12 +256,8 @@ void InspectorDock::_resource_file_selected(String p_file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InspectorDock::_save_resource(bool save_as) {
|
void InspectorDock::_save_resource(bool save_as) {
|
||||||
ObjectID current_id = EditorNode::get_singleton()->get_editor_selection_history()->get_current();
|
Ref<Resource> current_res = _get_current_resource();
|
||||||
Object *current_obj = current_id.is_valid() ? ObjectDB::get_instance(current_id) : nullptr;
|
ERR_FAIL_COND(current_res.is_null());
|
||||||
|
|
||||||
ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj));
|
|
||||||
|
|
||||||
Ref<Resource> current_res = Ref<Resource>(Object::cast_to<Resource>(current_obj));
|
|
||||||
|
|
||||||
if (save_as) {
|
if (save_as) {
|
||||||
EditorNode::get_singleton()->save_resource_as(current_res);
|
EditorNode::get_singleton()->save_resource_as(current_res);
|
||||||
@ -271,24 +267,15 @@ void InspectorDock::_save_resource(bool save_as) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InspectorDock::_unref_resource() {
|
void InspectorDock::_unref_resource() {
|
||||||
ObjectID current_id = EditorNode::get_singleton()->get_editor_selection_history()->get_current();
|
Ref<Resource> current_res = _get_current_resource();
|
||||||
Object *current_obj = current_id.is_valid() ? ObjectDB::get_instance(current_id) : nullptr;
|
ERR_FAIL_COND(current_res.is_null());
|
||||||
|
|
||||||
ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj));
|
|
||||||
|
|
||||||
Ref<Resource> current_res = Ref<Resource>(Object::cast_to<Resource>(current_obj));
|
|
||||||
current_res->set_path("");
|
current_res->set_path("");
|
||||||
EditorNode::get_singleton()->edit_current();
|
EditorNode::get_singleton()->edit_current();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectorDock::_copy_resource() {
|
void InspectorDock::_copy_resource() {
|
||||||
ObjectID current_id = EditorNode::get_singleton()->get_editor_selection_history()->get_current();
|
Ref<Resource> current_res = _get_current_resource();
|
||||||
Object *current_obj = current_id.is_valid() ? ObjectDB::get_instance(current_id) : nullptr;
|
ERR_FAIL_COND(current_res.is_null());
|
||||||
|
|
||||||
ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj));
|
|
||||||
|
|
||||||
Ref<Resource> current_res = Ref<Resource>(Object::cast_to<Resource>(current_obj));
|
|
||||||
|
|
||||||
EditorSettings::get_singleton()->set_resource_clipboard(current_res);
|
EditorSettings::get_singleton()->set_resource_clipboard(current_res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,6 +292,12 @@ void InspectorDock::_prepare_resource_extra_popup() {
|
|||||||
popup->set_item_disabled(popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), r.is_null());
|
popup->set_item_disabled(popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), r.is_null());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ref<Resource> InspectorDock::_get_current_resource() const {
|
||||||
|
ObjectID current_id = EditorNode::get_singleton()->get_editor_selection_history()->get_current();
|
||||||
|
Object *current_obj = current_id.is_valid() ? ObjectDB::get_instance(current_id) : nullptr;
|
||||||
|
return Ref<Resource>(Object::cast_to<Resource>(current_obj));
|
||||||
|
}
|
||||||
|
|
||||||
void InspectorDock::_prepare_history() {
|
void InspectorDock::_prepare_history() {
|
||||||
EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history();
|
EditorSelectionHistory *editor_history = EditorNode::get_singleton()->get_editor_selection_history();
|
||||||
|
|
||||||
|
@ -118,6 +118,7 @@ class InspectorDock : public VBoxContainer {
|
|||||||
void _copy_resource();
|
void _copy_resource();
|
||||||
void _paste_resource();
|
void _paste_resource();
|
||||||
void _prepare_resource_extra_popup();
|
void _prepare_resource_extra_popup();
|
||||||
|
Ref<Resource> _get_current_resource() const;
|
||||||
|
|
||||||
void _info_pressed();
|
void _info_pressed();
|
||||||
void _resource_created();
|
void _resource_created();
|
||||||
|
Loading…
Reference in New Issue
Block a user