Skip to content

Commit

Permalink
Expose ImportDock and its children
Browse files Browse the repository at this point in the history
  • Loading branch information
trollodel committed Aug 25, 2021
1 parent 0df9895 commit e66a805
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 12 deletions.
6 changes: 6 additions & 0 deletions doc/classes/EditorInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@
Returns the editor's [FileSystemDock] instance.
</description>
</method>
<method name="get_import_dock">
<return type="ImportDock" />
<description>
Returns the editor's [ImportDock] instance.
</description>
</method>
<method name="get_inspector" qualifiers="const">
<return type="EditorInspector" />
<description>
Expand Down
41 changes: 41 additions & 0 deletions doc/classes/ImportDock.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="ImportDock" inherits="VBoxContainer" version="4.0">
<brief_description>
The Import dock.
</brief_description>
<description>
The Import dock shows import settings for one or more files through an [EditorInspector].
</description>
<tutorials>
</tutorials>
<methods>
<method name="get_edited_paths">
<return type="Array" />
<description>
Returns the paths currently edited.
</description>
</method>
<method name="get_editor_inspector">
<return type="EditorInspector" />
<description>
Returns the [EditorInspector] where import settings are listed.
</description>
</method>
<method name="set_edited_paths">
<return type="void" />
<argument index="0" name="paths" type="PackedStringArray" />
<description>
Sets the current edited paths and replace the old ones.
</description>
</method>
</methods>
<signals>
<signal name="edited_paths_changed">
<description>
Emitted when the edited paths changes.
</description>
</signal>
</signals>
<constants>
</constants>
</class>
6 changes: 5 additions & 1 deletion editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,10 @@ void EditorNode::_edit_current() {
scene_tree_dock->set_selected(nullptr);
node_dock->set_node(nullptr);
inspector_dock->update(nullptr);
EditorNode::get_singleton()->get_import_dock()->set_edit_path(current_res->get_path());

Vector<String> edit_paths;
edit_paths.push_back(current_res->get_path());
EditorNode::get_singleton()->get_import_dock()->set_edited_paths(edit_paths);

int subr_idx = current_res->get_path().find("::");
if (subr_idx != -1) {
Expand Down Expand Up @@ -3822,6 +3825,7 @@ void EditorNode::register_editor_types() {
GDREGISTER_CLASS(EditorSceneImporterMeshNode3D);

GDREGISTER_VIRTUAL_CLASS(FileSystemDock);
GDREGISTER_VIRTUAL_CLASS(ImportDock);

// FIXME: Is this stuff obsolete, or should it be ported to new APIs?
GDREGISTER_CLASS(EditorScenePostImport);
Expand Down
6 changes: 6 additions & 0 deletions editor/editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "editor/editor_paths.h"
#include "editor/editor_settings.h"
#include "editor/filesystem_dock.h"
#include "editor/import_dock.h"
#include "editor/project_settings_editor.h"
#include "editor_resource_preview.h"
#include "main/main.h"
Expand Down Expand Up @@ -251,6 +252,10 @@ FileSystemDock *EditorInterface::get_file_system_dock() {
return EditorNode::get_singleton()->get_filesystem_dock();
}

ImportDock *EditorInterface::get_import_dock() {
return EditorNode::get_singleton()->get_import_dock();
}

EditorSelection *EditorInterface::get_selection() {
return EditorNode::get_singleton()->get_editor_selection();
}
Expand Down Expand Up @@ -343,6 +348,7 @@ void EditorInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_selected_path"), &EditorInterface::get_selected_path);
ClassDB::bind_method(D_METHOD("get_current_path"), &EditorInterface::get_current_path);
ClassDB::bind_method(D_METHOD("get_file_system_dock"), &EditorInterface::get_file_system_dock);
ClassDB::bind_method(D_METHOD("get_import_dock"), &EditorInterface::get_import_dock);
ClassDB::bind_method(D_METHOD("get_editor_paths"), &EditorInterface::get_editor_paths);
ClassDB::bind_method(D_METHOD("get_command_palette"), &EditorInterface::get_command_palette);

Expand Down
2 changes: 2 additions & 0 deletions editor/editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class EditorFileSystem;
class EditorToolAddons;
class EditorPaths;
class FileSystemDock;
class ImportDock;
class ScriptEditor;

class EditorInterface : public Node {
Expand Down Expand Up @@ -104,6 +105,7 @@ class EditorInterface : public Node {
EditorFileSystem *get_resource_file_system();

FileSystemDock *get_file_system_dock();
ImportDock *get_import_dock();

Control *get_base_control();
float get_editor_scale() const;
Expand Down
8 changes: 1 addition & 7 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2689,13 +2689,7 @@ void FileSystemDock::_update_import_dock() {
imports.push_back(fpath);
}

if (imports.size() == 0) {
EditorNode::get_singleton()->get_import_dock()->clear();
} else if (imports.size() == 1) {
EditorNode::get_singleton()->get_import_dock()->set_edit_path(imports[0]);
} else {
EditorNode::get_singleton()->get_import_dock()->set_edit_multiple_paths(imports);
}
EditorNode::get_singleton()->get_import_dock()->set_edited_paths(imports);

import_dock_needs_update = false;
}
Expand Down
36 changes: 34 additions & 2 deletions editor/import_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ImportDockParameters : public Object {
}
};

void ImportDock::set_edit_path(const String &p_path) {
void ImportDock::_set_single_edit_path(const String &p_path) {
Ref<ConfigFile> config;
config.instantiate();
Error err = config->load(p_path + ".import");
Expand Down Expand Up @@ -174,9 +174,20 @@ void ImportDock::_update_options(const Ref<ConfigFile> &p_config) {
}
}

void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) {
void ImportDock::set_edited_paths(const Vector<String> &p_paths) {
current_paths = p_paths;
emit_signal("edited_paths_changed");
if (p_paths.size() == 1) {
_set_single_edit_path(p_paths[0]);
return;
}

clear();

if (p_paths.is_empty()) {
return;
}

// Use the value that is repeated the most.
Map<String, Dictionary> value_frequency;

Expand Down Expand Up @@ -401,6 +412,7 @@ void ImportDock::clear() {
import_as->clear();
import_as->set_disabled(true);
preset->set_disabled(true);
current_paths.clear();
params->values.clear();
params->properties.clear();
params->update();
Expand Down Expand Up @@ -552,6 +564,13 @@ void ImportDock::_property_toggled(const StringName &p_prop, bool p_checked) {

void ImportDock::_bind_methods() {
ClassDB::bind_method(D_METHOD("_reimport"), &ImportDock::_reimport);

ClassDB::bind_method(D_METHOD("get_editor_inspector"), &ImportDock::get_editor_inspector);
ClassDB::bind_method(D_METHOD("get_edited_paths"), &ImportDock::get_edited_paths);

ClassDB::bind_method(D_METHOD("set_edited_paths", "paths"), &ImportDock::set_edited_paths);

ADD_SIGNAL(MethodInfo("edited_paths_changed"));
}

void ImportDock::initialize_import_options() const {
Expand All @@ -560,6 +579,19 @@ void ImportDock::initialize_import_options() const {
import_opts->edit(params);
}

EditorInspector *ImportDock::get_editor_inspector() {
return import_opts;
}

Array ImportDock::get_edited_paths() {
Array arr;
arr.resize(current_paths.size());
for (int i = 0; i < current_paths.size(); i++) {
arr[i] = current_paths[i];
}
return arr;
}

ImportDock::ImportDock() {
set_name("Import");
imported = memnew(Label);
Expand Down
10 changes: 8 additions & 2 deletions editor/import_dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ImportDock : public VBoxContainer {
MenuButton *preset;
EditorInspector *import_opts;

Vector<String> current_paths;
List<PropertyInfo> properties;
Map<StringName, Variant> property_values;

Expand All @@ -72,6 +73,8 @@ class ImportDock : public VBoxContainer {
void _reimport_and_restart();
void _reimport();

void _set_single_edit_path(const String &p_path);

void _advanced_options();
enum {
ITEM_SET_AS_DEFAULT = 100,
Expand All @@ -84,9 +87,12 @@ class ImportDock : public VBoxContainer {
void _notification(int p_what);

public:
void set_edit_path(const String &p_path);
void set_edit_multiple_paths(const Vector<String> &p_paths);
void initialize_import_options() const;

EditorInspector *get_editor_inspector();
Array get_edited_paths();

void set_edited_paths(const Vector<String> &p_paths);
void clear();

ImportDock();
Expand Down

0 comments on commit e66a805

Please sign in to comment.