Merge pull request #1346 from Nulifier/import-plugin
Added the ability to add and remove editor import plugins.
This commit is contained in:
commit
7f88df73be
|
@ -130,7 +130,7 @@ void ResourceImportMetadata::_bind_methods() {
|
|||
|
||||
ObjectTypeDB::bind_method(_MD("set_editor","name"),&ResourceImportMetadata::set_editor);
|
||||
ObjectTypeDB::bind_method(_MD("get_editor"),&ResourceImportMetadata::get_editor);
|
||||
ObjectTypeDB::bind_method(_MD("add_source","path","md5"),&ResourceImportMetadata::add_source);
|
||||
ObjectTypeDB::bind_method(_MD("add_source","path","md5"),&ResourceImportMetadata::add_source, "");
|
||||
ObjectTypeDB::bind_method(_MD("get_source_path","idx"),&ResourceImportMetadata::get_source_path);
|
||||
ObjectTypeDB::bind_method(_MD("get_source_md5","idx"),&ResourceImportMetadata::get_source_md5);
|
||||
ObjectTypeDB::bind_method(_MD("remove_source","idx"),&ResourceImportMetadata::remove_source);
|
||||
|
|
|
@ -1141,10 +1141,36 @@ EditorImportExport* EditorImportExport::singleton=NULL;
|
|||
|
||||
void EditorImportExport::add_import_plugin(const Ref<EditorImportPlugin>& p_plugin) {
|
||||
|
||||
// Need to make sure the name is unique if we are going to lookup by it
|
||||
ERR_FAIL_COND(by_idx.has(p_plugin->get_name()));
|
||||
|
||||
by_idx[ p_plugin->get_name() ]=plugins.size();
|
||||
plugins.push_back(p_plugin);
|
||||
}
|
||||
|
||||
void EditorImportExport::remove_import_plugin(const Ref<EditorImportPlugin>& p_plugin) {
|
||||
|
||||
String plugin_name = p_plugin->get_name();
|
||||
|
||||
// Keep the indices the same
|
||||
// Find the index of the target plugin
|
||||
ERR_FAIL_COND(!by_idx.has(plugin_name));
|
||||
int idx = by_idx[plugin_name];
|
||||
int last_idx = plugins.size() - 1;
|
||||
|
||||
// Swap the last plugin and the target one
|
||||
SWAP(plugins[idx], plugins[last_idx]);
|
||||
|
||||
// Update the index of the old last one
|
||||
by_idx[plugins[idx]->get_name()] = idx;
|
||||
|
||||
// Remove the target plugin's by_idx entry
|
||||
by_idx.erase(plugin_name);
|
||||
|
||||
// Erase the plugin
|
||||
plugins.remove(last_idx);
|
||||
}
|
||||
|
||||
int EditorImportExport::get_import_plugin_count() const{
|
||||
|
||||
return plugins.size();
|
||||
|
|
|
@ -270,6 +270,7 @@ public:
|
|||
static EditorImportExport* get_singleton() { return singleton; }
|
||||
|
||||
void add_import_plugin(const Ref<EditorImportPlugin>& p_plugin);
|
||||
void remove_import_plugin(const Ref<EditorImportPlugin>& p_plugin);
|
||||
int get_import_plugin_count() const;
|
||||
Ref<EditorImportPlugin> get_import_plugin(int p_idx) const;
|
||||
Ref<EditorImportPlugin> get_import_plugin_by_name(const String& p_string) const;
|
||||
|
|
|
@ -336,6 +336,19 @@ void EditorNode::_vp_resized() {
|
|||
|
||||
}
|
||||
|
||||
void EditorNode::_rebuild_import_menu()
|
||||
{
|
||||
PopupMenu* p = import_menu->get_popup();
|
||||
p->clear();
|
||||
p->add_item("Sub-Scene", FILE_IMPORT_SUBSCENE);
|
||||
p->add_separator();
|
||||
for (int i = 0; i < editor_import_export->get_import_plugin_count(); i++) {
|
||||
p->add_item(editor_import_export->get_import_plugin(i)->get_visible_name(), IMPORT_PLUGIN_BASE + i);
|
||||
}
|
||||
p->add_separator();
|
||||
p->add_item("Re-Import..", SETTINGS_IMPORT);
|
||||
}
|
||||
|
||||
void EditorNode::_node_renamed() {
|
||||
|
||||
if (property_editor)
|
||||
|
@ -2407,6 +2420,19 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor) {
|
|||
}
|
||||
|
||||
|
||||
void EditorNode::add_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) {
|
||||
|
||||
editor_import_export->add_import_plugin(p_editor_import);
|
||||
_rebuild_import_menu();
|
||||
}
|
||||
|
||||
void EditorNode::remove_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) {
|
||||
|
||||
editor_import_export->remove_import_plugin(p_editor_import);
|
||||
_rebuild_import_menu();
|
||||
}
|
||||
|
||||
|
||||
void EditorNode::set_edited_scene(Node *p_scene) {
|
||||
|
||||
if (edited_scene) {
|
||||
|
@ -3171,6 +3197,9 @@ void EditorNode::_bind_methods() {
|
|||
ObjectTypeDB::bind_method("_sources_changed",&EditorNode::_sources_changed);
|
||||
ObjectTypeDB::bind_method("_fs_changed",&EditorNode::_fs_changed);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("add_editor_import_plugin", "plugin"), &EditorNode::add_editor_import_plugin);
|
||||
ObjectTypeDB::bind_method(_MD("remove_editor_import_plugin", "plugin"), &EditorNode::remove_editor_import_plugin);
|
||||
ObjectTypeDB::bind_method(_MD("get_gui_base"), &EditorNode::get_gui_base);
|
||||
|
||||
ADD_SIGNAL( MethodInfo("play_pressed") );
|
||||
ADD_SIGNAL( MethodInfo("pause_pressed") );
|
||||
|
@ -3534,8 +3563,6 @@ EditorNode::EditorNode() {
|
|||
left_menu_hb->add_child( import_menu );
|
||||
|
||||
p=import_menu->get_popup();
|
||||
p->add_item("Sub-Scene",FILE_IMPORT_SUBSCENE);
|
||||
p->add_separator();
|
||||
p->connect("item_pressed",this,"_menu_option");
|
||||
|
||||
export_button = memnew( ToolButton );
|
||||
|
@ -4044,11 +4071,6 @@ EditorNode::EditorNode() {
|
|||
editor_import_export->add_import_plugin( Ref<EditorSampleImportPlugin>( memnew(EditorSampleImportPlugin(this))));
|
||||
editor_import_export->add_import_plugin( Ref<EditorTranslationImportPlugin>( memnew(EditorTranslationImportPlugin(this))));
|
||||
|
||||
|
||||
for(int i=0;i<editor_import_export->get_import_plugin_count();i++) {
|
||||
import_menu->get_popup()->add_item(editor_import_export->get_import_plugin(i)->get_visible_name(),IMPORT_PLUGIN_BASE+i);
|
||||
}
|
||||
|
||||
editor_import_export->add_export_plugin( Ref<EditorTextureExportPlugin>( memnew(EditorTextureExportPlugin)));
|
||||
|
||||
add_editor_plugin( memnew( CanvasItemEditorPlugin(this) ) );
|
||||
|
@ -4093,9 +4115,7 @@ EditorNode::EditorNode() {
|
|||
circle_step_frame=OS::get_singleton()->get_frames_drawn();;
|
||||
circle_step=0;
|
||||
|
||||
|
||||
import_menu->get_popup()->add_separator();
|
||||
import_menu->get_popup()->add_item("Re-Import..",SETTINGS_IMPORT);
|
||||
_rebuild_import_menu();
|
||||
|
||||
editor_plugin_screen=NULL;
|
||||
editor_plugin_over=NULL;
|
||||
|
|
|
@ -340,6 +340,8 @@ class EditorNode : public Node {
|
|||
void _show_messages();
|
||||
void _vp_resized();
|
||||
|
||||
void _rebuild_import_menu();
|
||||
|
||||
void _save_scene(String p_file);
|
||||
|
||||
|
||||
|
@ -421,6 +423,9 @@ public:
|
|||
static void add_editor_plugin(EditorPlugin *p_editor);
|
||||
static void remove_editor_plugin(EditorPlugin *p_editor);
|
||||
|
||||
void add_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import);
|
||||
void remove_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import);
|
||||
|
||||
|
||||
void edit_node(Node *p_node);
|
||||
void edit_resource(const Ref<Resource>& p_resource);
|
||||
|
|
Loading…
Reference in New Issue