Merge pull request #23802 from JFonS/add_save_option

Add Save option to resource property menu
This commit is contained in:
Rémi Verschelde 2018-11-20 14:15:31 +01:00 committed by GitHub
commit 90dd3774a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 12 deletions

View File

@ -637,6 +637,7 @@ void EditorNode::save_resource(const Ref<Resource> &p_resource) {
void EditorNode::save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path) {
file->set_mode(EditorFileDialog::MODE_SAVE_FILE);
saving_resource = p_resource;
current_option = RESOURCE_SAVE_AS;
List<String> extensions;
@ -1263,15 +1264,13 @@ void EditorNode::_dialog_action(String p_file) {
case RESOURCE_SAVE:
case RESOURCE_SAVE_AS: {
uint32_t current = editor_history.get_current();
ERR_FAIL_COND(saving_resource.is_null())
save_resource_in_path(saving_resource, p_file);
saving_resource = Ref<Resource>();
ObjectID current = editor_history.get_current();
Object *current_obj = current > 0 ? ObjectDB::get_instance(current) : NULL;
ERR_FAIL_COND(!Object::cast_to<Resource>(current_obj))
RES current_res = RES(Object::cast_to<Resource>(current_obj));
save_resource_in_path(current_res, p_file);
ERR_FAIL_COND(!current_obj);
current_obj->_change_notify();
} break;
case SETTINGS_LAYOUT_SAVE: {
@ -5777,6 +5776,7 @@ EditorNode::EditorNode() {
_edit_current();
current = NULL;
saving_resource = Ref<Resource>();
reference_resource_mem = true;
save_external_resources_mem = true;

View File

@ -356,6 +356,7 @@ private:
EditorExport *editor_export;
Object *current;
Ref<Resource> saving_resource;
bool _playing_edited;
String run_custom_filename;

View File

@ -2016,6 +2016,13 @@ void EditorPropertyResource::_menu_option(int p_which) {
} break;
case OBJ_MENU_SAVE: {
RES res = get_edited_object()->get(get_edited_property());
if (res.is_null())
return;
EditorNode::get_singleton()->save_resource(res);
} break;
case OBJ_MENU_COPY: {
RES res = get_edited_object()->get(get_edited_property());
@ -2233,6 +2240,7 @@ void EditorPropertyResource::_update_menu_items() {
menu->add_icon_item(get_icon("Edit", "EditorIcons"), TTR("Edit"), OBJ_MENU_EDIT);
menu->add_icon_item(get_icon("Clear", "EditorIcons"), TTR("Clear"), OBJ_MENU_CLEAR);
menu->add_icon_item(get_icon("Duplicate", "EditorIcons"), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE);
menu->add_icon_item(get_icon("Save", "EditorIcons"), TTR("Save"), OBJ_MENU_SAVE);
RES r = res;
if (r.is_valid() && r->get_path().is_resource_file()) {
menu->add_separator();

View File

@ -522,10 +522,11 @@ class EditorPropertyResource : public EditorProperty {
OBJ_MENU_EDIT = 1,
OBJ_MENU_CLEAR = 2,
OBJ_MENU_MAKE_UNIQUE = 3,
OBJ_MENU_COPY = 4,
OBJ_MENU_PASTE = 5,
OBJ_MENU_NEW_SCRIPT = 6,
OBJ_MENU_SHOW_IN_FILE_SYSTEM = 7,
OBJ_MENU_SAVE = 4,
OBJ_MENU_COPY = 5,
OBJ_MENU_PASTE = 6,
OBJ_MENU_NEW_SCRIPT = 7,
OBJ_MENU_SHOW_IN_FILE_SYSTEM = 8,
TYPE_BASE_ID = 100,
CONVERT_BASE_ID = 1000