Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PluginConfigDialog. #19837

Merged
merged 1 commit into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,18 @@ void EditorNode::_notification(int p_what) {
}
}

void EditorNode::_on_plugin_ready(Object *p_script, const String &p_activate_name) {
Ref<Script> script = Object::cast_to<Script>(p_script);
if (script.is_null())
return;
if (p_activate_name.length()) {
set_addon_plugin_enabled(p_activate_name, true);
}
project_settings->update_plugins();
project_settings->hide();
push_item(script.operator->());
}

void EditorNode::_fs_changed() {

for (Set<FileDialog *>::Element *E = file_dialogs.front(); E; E = E->next()) {
Expand Down Expand Up @@ -2540,6 +2552,7 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled)

EditorPlugin *ep = memnew(EditorPlugin);
ep->set_script(script.get_ref_ptr());
ep->set_dir_cache(p_addon);
plugin_addons[p_addon] = ep;
add_editor_plugin(ep);

Expand Down Expand Up @@ -4520,6 +4533,8 @@ void EditorNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("_resources_reimported"), &EditorNode::_resources_reimported);
ClassDB::bind_method(D_METHOD("_bottom_panel_raise_toggled"), &EditorNode::_bottom_panel_raise_toggled);

ClassDB::bind_method(D_METHOD("_on_plugin_ready"), &EditorNode::_on_plugin_ready);

ClassDB::bind_method(D_METHOD("_video_driver_selected"), &EditorNode::_video_driver_selected);

ADD_SIGNAL(MethodInfo("play_pressed"));
Expand Down Expand Up @@ -5082,6 +5097,10 @@ EditorNode::EditorNode() {
p->connect("id_pressed", this, "_menu_option");
p->add_item(TTR("Export"), FILE_EXPORT_PROJECT);

plugin_config_dialog = memnew(PluginConfigDialog);
plugin_config_dialog->connect("plugin_ready", this, "_on_plugin_ready");
gui_base->add_child(plugin_config_dialog);

tool_menu = memnew(PopupMenu);
tool_menu->set_name("Tools");
tool_menu->connect("index_pressed", this, "_tool_menu_option");
Expand Down
5 changes: 5 additions & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "editor/inspector_dock.h"
#include "editor/node_dock.h"
#include "editor/pane_drag.h"
#include "editor/plugin_config_dialog.h"
#include "editor/progress_dialog.h"
#include "editor/project_export.h"
#include "editor/project_settings_editor.h"
Expand Down Expand Up @@ -256,6 +257,8 @@ class EditorNode : public Node {
ToolButton *search_button;
TextureProgress *audio_vu;

PluginConfigDialog *plugin_config_dialog;

RichTextLabel *load_errors;
AcceptDialog *load_error_dialog;

Expand Down Expand Up @@ -415,6 +418,8 @@ class EditorNode : public Node {
void _tool_menu_option(int p_idx);
void _update_debug_options();

void _on_plugin_ready(Object *p_script, const String &p_activate_name);

void _fs_changed();
void _resources_reimported(const Vector<String> &p_resources);
void _sources_changed(bool p_exist);
Expand Down
6 changes: 6 additions & 0 deletions editor/editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ void EditorPlugin::remove_autoload_singleton(const String &p_name) {
EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_remove(p_name);
}

Ref<ConfigFile> EditorPlugin::get_config() {
Ref<ConfigFile> cf = memnew(ConfigFile);
cf->load(_dir_cache.plus_file("plugin.cfg"));
return cf;
}

ToolButton *EditorPlugin::add_control_to_bottom_panel(Control *p_control, const String &p_title) {
ERR_FAIL_NULL_V(p_control, NULL);
return EditorNode::get_singleton()->add_bottom_panel_item(p_title, p_control);
Expand Down
5 changes: 5 additions & 0 deletions editor/editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class EditorPlugin : public Node {
bool force_draw_over_forwarding_enabled;

String last_main_screen_name;
String _dir_cache;

protected:
static void _bind_methods();
Expand Down Expand Up @@ -223,6 +224,10 @@ class EditorPlugin : public Node {
void add_autoload_singleton(const String &p_name, const String &p_path);
void remove_autoload_singleton(const String &p_name);

void set_dir_cache(const String &p_dir) { _dir_cache = p_dir; }
String get_dir_cache() { return _dir_cache; }
Ref<ConfigFile> get_config();

EditorPlugin();
virtual ~EditorPlugin();
};
Expand Down
36 changes: 35 additions & 1 deletion editor/editor_plugin_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ void EditorPluginSettings::_notification(int p_what) {

if (p_what == MainLoop::NOTIFICATION_WM_FOCUS_IN) {
update_plugins();
} else if (p_what == Node::NOTIFICATION_READY) {
plugin_config_dialog->connect("plugin_ready", EditorNode::get_singleton(), "_on_plugin_ready");
plugin_list->connect("button_pressed", this, "_cell_button_pressed");
}
}

Expand Down Expand Up @@ -124,6 +127,7 @@ void EditorPluginSettings::update_plugins() {
item->set_range_config(3, 0, 1, 1);
item->set_text(3, "Inactive,Active");
item->set_editable(3, true);
item->add_button(4, get_icon("Edit", "EditorIcons"), BUTTON_PLUGIN_EDIT, false, TTR("Edit Plugin"));

if (EditorNode::get_singleton()->is_addon_plugin_enabled(d)) {
item->set_custom_color(3, get_color("success_color", "Editor"));
Expand Down Expand Up @@ -164,37 +168,67 @@ void EditorPluginSettings::_plugin_activity_changed() {
ti->set_custom_color(3, get_color("disabled_font_color", "Editor"));
}

void EditorPluginSettings::_create_clicked() {
plugin_config_dialog->config("");
plugin_config_dialog->popup_centered();
}

void EditorPluginSettings::_cell_button_pressed(Object *p_item, int p_column, int p_id) {
TreeItem *item = Object::cast_to<TreeItem>(p_item);
if (!item)
return;
if (p_id == BUTTON_PLUGIN_EDIT) {
if (p_column == 4) {
String dir = item->get_metadata(0);
plugin_config_dialog->config("res://addons/" + dir + "/plugin.cfg");
plugin_config_dialog->popup_centered();
}
}
}

void EditorPluginSettings::_bind_methods() {

ClassDB::bind_method("update_plugins", &EditorPluginSettings::update_plugins);
ClassDB::bind_method("_create_clicked", &EditorPluginSettings::_create_clicked);
ClassDB::bind_method("_plugin_activity_changed", &EditorPluginSettings::_plugin_activity_changed);
ClassDB::bind_method("_cell_button_pressed", &EditorPluginSettings::_cell_button_pressed);
}

EditorPluginSettings::EditorPluginSettings() {

plugin_config_dialog = memnew(PluginConfigDialog);
plugin_config_dialog->config("");
add_child(plugin_config_dialog);

HBoxContainer *title_hb = memnew(HBoxContainer);
title_hb->add_child(memnew(Label(TTR("Installed Plugins:"))));
title_hb->add_spacer();
create_plugin = memnew(Button(TTR("Create")));
create_plugin->connect("pressed", this, "_create_clicked");
title_hb->add_child(create_plugin);
update_list = memnew(Button(TTR("Update")));
update_list->connect("pressed", this, "update_plugins");
title_hb->add_child(update_list);
add_child(title_hb);

plugin_list = memnew(Tree);
plugin_list->set_v_size_flags(SIZE_EXPAND_FILL);
plugin_list->set_columns(4);
plugin_list->set_columns(5);
plugin_list->set_column_titles_visible(true);
plugin_list->set_column_title(0, TTR("Name:"));
plugin_list->set_column_title(1, TTR("Version:"));
plugin_list->set_column_title(2, TTR("Author:"));
plugin_list->set_column_title(3, TTR("Status:"));
plugin_list->set_column_title(4, TTR("Edit:"));
plugin_list->set_column_expand(0, true);
plugin_list->set_column_expand(1, false);
plugin_list->set_column_expand(2, false);
plugin_list->set_column_expand(3, false);
plugin_list->set_column_expand(4, false);
plugin_list->set_column_min_width(1, 100 * EDSCALE);
plugin_list->set_column_min_width(2, 250 * EDSCALE);
plugin_list->set_column_min_width(3, 80 * EDSCALE);
plugin_list->set_column_min_width(4, 40 * EDSCALE);
plugin_list->set_hide_root(true);
plugin_list->connect("item_edited", this, "_plugin_activity_changed");

Expand Down
9 changes: 9 additions & 0 deletions editor/editor_plugin_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef EDITORPLUGINSETTINGS_H
#define EDITORPLUGINSETTINGS_H

#include "editor/plugin_config_dialog.h";
#include "editor_data.h"
#include "property_editor.h"
#include "scene/gui/dialogs.h"
Expand All @@ -40,11 +41,19 @@ class EditorPluginSettings : public VBoxContainer {

GDCLASS(EditorPluginSettings, VBoxContainer);

enum {
BUTTON_PLUGIN_EDIT
};

PluginConfigDialog *plugin_config_dialog;
Button *create_plugin;
Button *update_list;
Tree *plugin_list;
bool updating;

void _plugin_activity_changed();
void _create_clicked();
void _cell_button_pressed(Object *p_item, int p_column, int p_id);

protected:
void _notification(int p_what);
Expand Down
Loading