Add open scene feature to dependency_editor.cpp

This commit is contained in:
sersoong 2017-11-15 15:50:32 +08:00
parent fbb0732a36
commit 886aac981c
3 changed files with 66 additions and 4 deletions

View file

@ -281,6 +281,47 @@ DependencyEditor::DependencyEditor() {
}
/////////////////////////////////////
void DependencyEditorOwners::_list_rmb_select(int p_item, const Vector2 &p_pos) {
file_options->clear();
file_options->set_size(Size2(1, 1));
if (p_item >= 0) {
file_options->add_item(TTR("Open"), FILE_OPEN);
}
file_options->set_pos(owners->get_global_pos() + p_pos);
file_options->popup();
}
void DependencyEditorOwners::_select_file(int p_idx) {
String fpath = owners->get_item_text(p_idx);
if (ResourceLoader::get_resource_type(fpath) == "PackedScene") {
editor->open_request(fpath);
hide();
emit_signal("confirmed");
}
}
void DependencyEditorOwners::_file_option(int p_option) {
switch (p_option) {
case FILE_OPEN: {
int idx = owners->get_current();
if (idx < 0 || idx >= owners->get_item_count())
break;
_select_file(idx);
} break;
}
}
void DependencyEditorOwners::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_list_rmb_select"), &DependencyEditorOwners::_list_rmb_select);
ObjectTypeDB::bind_method(_MD("_file_option"), &DependencyEditorOwners::_file_option);
ObjectTypeDB::bind_method(_MD("_select_file"), &DependencyEditorOwners::_select_file);
}
void DependencyEditorOwners::_fill_owners(EditorFileSystemDirectory *efsd) {
@ -329,9 +370,20 @@ void DependencyEditorOwners::show(const String &p_path) {
set_title(TTR("Owners Of:") + " " + p_path.get_file());
}
DependencyEditorOwners::DependencyEditorOwners() {
DependencyEditorOwners::DependencyEditorOwners(EditorNode *p_editor) {
editor = p_editor;
file_options = memnew(PopupMenu);
add_child(file_options);
file_options->connect("item_pressed", this, "_file_option");
owners = memnew(ItemList);
owners->set_select_mode(ItemList::SELECT_SINGLE);
owners->connect("item_rmb_selected", this, "_list_rmb_select");
owners->connect("item_activated", this, "_select_file");
owners->set_allow_rmb_select(true);
add_child(owners);
set_child_rect(owners);
}

View file

@ -36,7 +36,7 @@
#include "scene/gui/tree.h"
class EditorFileSystemDirectory;
class EditorNode;
class DependencyEditor : public AcceptDialog {
OBJ_TYPE(DependencyEditor, AcceptDialog);
@ -71,12 +71,22 @@ class DependencyEditorOwners : public AcceptDialog {
OBJ_TYPE(DependencyEditorOwners, AcceptDialog);
ItemList *owners;
PopupMenu *file_options;
EditorNode *editor;
String editing;
void _fill_owners(EditorFileSystemDirectory *efsd);
static void _bind_methods();
void _list_rmb_select(int p_item, const Vector2 &p_pos);
void _select_file(int p_idx);
void _file_option(int p_option);
private:
enum FileMenu {
FILE_OPEN
};
public:
void show(const String &p_path);
DependencyEditorOwners();
DependencyEditorOwners(EditorNode *p_editor);
};
class DependencyRemoveDialog : public ConfirmationDialog {

View file

@ -1665,7 +1665,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
deps_editor = memnew(DependencyEditor);
add_child(deps_editor);
owners_editor = memnew(DependencyEditorOwners);
owners_editor = memnew(DependencyEditorOwners(editor));
add_child(owners_editor);
remove_dialog = memnew(DependencyRemoveDialog);