Merge pull request #53161 from Duroxxigar/copy-group-name

This commit is contained in:
Rémi Verschelde 2021-10-21 11:22:12 +02:00 committed by GitHub
commit 89b9624733
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 48 deletions

View File

@ -204,7 +204,8 @@ void GroupDialog::_add_group(String p_name) {
TreeItem *new_group = groups->create_item(groups_root);
new_group->set_text(0, name);
new_group->add_button(0, groups->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), 0);
new_group->add_button(0, groups->get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), DELETE_GROUP);
new_group->add_button(0, groups->get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons")), COPY_GROUP);
new_group->set_editable(0, true);
new_group->select(0);
groups->ensure_cursor_is_visible();
@ -297,12 +298,14 @@ void GroupDialog::_load_groups(Node *p_current) {
}
}
void GroupDialog::_delete_group_pressed(Object *p_item, int p_column, int p_id) {
void GroupDialog::_modify_group_pressed(Object *p_item, int p_column, int p_id) {
TreeItem *ti = Object::cast_to<TreeItem>(p_item);
if (!ti) {
return;
}
switch (p_id) {
case DELETE_GROUP: {
String name = ti->get_text(0);
undo_redo->create_action(TTR("Delete Group"));
@ -334,6 +337,11 @@ void GroupDialog::_delete_group_pressed(Object *p_item, int p_column, int p_id)
undo_redo->add_undo_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree");
undo_redo->commit_action();
} break;
case COPY_GROUP: {
DisplayServer::get_singleton()->clipboard_set(ti->get_text(p_column));
} break;
}
}
void GroupDialog::_delete_group_item(const String &p_name) {
@ -437,7 +445,7 @@ GroupDialog::GroupDialog() {
groups->set_v_size_flags(Control::SIZE_EXPAND_FILL);
groups->add_theme_constant_override("draw_guides", 1);
groups->connect("item_selected", callable_mp(this, &GroupDialog::_group_selected));
groups->connect("button_pressed", callable_mp(this, &GroupDialog::_delete_group_pressed));
groups->connect("button_pressed", callable_mp(this, &GroupDialog::_modify_group_pressed));
groups->connect("item_edited", callable_mp(this, &GroupDialog::_group_renamed));
HBoxContainer *chbc = memnew(HBoxContainer);
@ -582,7 +590,7 @@ void GroupsEditor::_add_group(const String &p_group) {
group_name->clear();
}
void GroupsEditor::_remove_group(Object *p_item, int p_column, int p_id) {
void GroupsEditor::_modify_group(Object *p_item, int p_column, int p_id) {
if (!node) {
return;
}
@ -591,9 +599,9 @@ void GroupsEditor::_remove_group(Object *p_item, int p_column, int p_id) {
if (!ti) {
return;
}
switch (p_id) {
case DELETE_GROUP: {
String name = ti->get_text(0);
undo_redo->create_action(TTR("Remove from Group"));
undo_redo->add_do_method(node, "remove_from_group", name);
@ -606,6 +614,11 @@ void GroupsEditor::_remove_group(Object *p_item, int p_column, int p_id) {
undo_redo->add_undo_method(EditorNode::get_singleton()->get_scene_tree_dock()->get_tree_editor(), "update_tree");
undo_redo->commit_action();
} break;
case COPY_GROUP: {
DisplayServer::get_singleton()->clipboard_set(ti->get_text(p_column));
} break;
}
}
struct _GroupInfoComparator {
@ -653,7 +666,8 @@ void GroupsEditor::update_tree() {
TreeItem *item = tree->create_item(root);
item->set_text(0, gi.name);
if (can_be_deleted) {
item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), 0);
item->add_button(0, get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), DELETE_GROUP);
item->add_button(0, get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons")), COPY_GROUP);
} else {
item->set_selectable(0, false);
}
@ -706,7 +720,7 @@ GroupsEditor::GroupsEditor() {
tree->set_hide_root(true);
tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
vbc->add_child(tree);
tree->connect("button_pressed", callable_mp(this, &GroupsEditor::_remove_group));
tree->connect("button_pressed", callable_mp(this, &GroupsEditor::_modify_group));
tree->add_theme_constant_override("draw_guides", 1);
add_theme_constant_override("separation", 3 * EDSCALE);
}

View File

@ -82,7 +82,7 @@ class GroupDialog : public AcceptDialog {
void _rename_group_item(const String &p_old_name, const String &p_new_name);
void _add_group(String p_name);
void _delete_group_pressed(Object *p_item, int p_column, int p_id);
void _modify_group_pressed(Object *p_item, int p_column, int p_id);
void _delete_group_item(const String &p_name);
bool _can_edit(Node *p_node, String p_group);
@ -95,6 +95,11 @@ protected:
static void _bind_methods();
public:
enum ModifyButton {
DELETE_GROUP,
COPY_GROUP,
};
void edit();
void set_undo_redo(UndoRedo *p_undoredo) { undo_redo = p_undoredo; }
@ -116,7 +121,7 @@ class GroupsEditor : public VBoxContainer {
void update_tree();
void _add_group(const String &p_group = "");
void _remove_group(Object *p_item, int p_column, int p_id);
void _modify_group(Object *p_item, int p_column, int p_id);
void _close();
void _show_group_dialog();
@ -125,6 +130,11 @@ protected:
static void _bind_methods();
public:
enum ModifyButton {
DELETE_GROUP,
COPY_GROUP,
};
void set_undo_redo(UndoRedo *p_undoredo) { undo_redo = p_undoredo; }
void set_current(Node *p_node);