示例#1
0
void ResourcesDock::_tool_selected(int p_tool) {

	current_action=p_tool;

	switch(p_tool) {

		case TOOL_NEW: {

			create_dialog->popup_centered_ratio();
		} break;
		case TOOL_OPEN: {
			editor->open_resource();

		} break;
		case TOOL_SAVE: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);


			if (current_res->get_path()!="" && current_res->get_path().find("::")==-1) {
				_file_action(current_res->get_path());
				break;
			};

		}; /* fallthrough */
		case TOOL_SAVE_AS: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;

			save_resource_as(ti->get_metadata(0));


		} break;
		case TOOL_MAKE_LOCAL: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);
			current_res->set_path("");
			_update_name(ti);
		} break;
		case TOOL_COPY: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);
			EditorSettings::get_singleton()->set_resource_clipboard(current_res);

		} break;
		case TOOL_PASTE: {

			add_resource(EditorSettings::get_singleton()->get_resource_clipboard());
		} break;

	}
}
示例#2
0
void ResourcesDock::_tool_selected(int p_tool) {

	current_action=p_tool;

	switch(p_tool) {

		case TOOL_NEW: {

			create_dialog->popup_centered_ratio();
		} break;
		case TOOL_OPEN: {
			editor->open_resource();

		} break;
		case TOOL_SAVE: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);


			if (current_res->get_path()!="" && current_res->get_path().find("::")==-1) {
				_file_action(current_res->get_path());
				break;
			};

		}; /* fallthrough */
		case TOOL_SAVE_AS: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);

			RES res(current_res);

			List<String> extensions;
			ResourceSaver::get_recognized_extensions(res,&extensions);
			file->set_mode(FileDialog::MODE_SAVE_FILE);
			//not for now?

			if (current_res->get_path()!="" && current_res->get_path().find("::")==-1) {

				file->set_current_path(current_res->get_path());
			} else {

				String existing;
				if (extensions.size()) {
					existing="new_"+res->get_type().to_lower()+"."+extensions.front()->get().to_lower();
				}

				file->set_current_file(existing);
			}

			file->clear_filters();
			for(int i=0;i<extensions.size();i++) {

				file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
			}

			//file->set_current_path(current_path);
			file->popup_centered_ratio();


		} break;
		case TOOL_MAKE_LOCAL: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);
			current_res->set_path("");
			_update_name(ti);
		} break;
		case TOOL_COPY: {

			TreeItem *ti = resources->get_selected();
			if (!ti)
				break;
			Ref<Resource> current_res = ti->get_metadata(0);
			EditorSettings::get_singleton()->set_resource_clipboard(current_res);

		} break;
		case TOOL_PASTE: {

			add_resource(EditorSettings::get_singleton()->get_resource_clipboard());
		} break;

	}
}