Skip to content

Commit

Permalink
feat: copy selected attribute tagname on click
Browse files Browse the repository at this point in the history
  • Loading branch information
OctoD committed Jan 30, 2024
1 parent 7be6f2e commit fc1b5ee
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <godot_cpp/classes/display_server.hpp>

#include "attribute_container_inspector_editor.h"
#include "system/attribute/attribute_manager.h"

Expand All @@ -7,6 +9,7 @@ using namespace ggs::editor_plugin;
void AttributeContainerInspectorEditor::_bind_methods()
{
ClassDB::bind_method(D_METHOD("_handle_item_edited"), &AttributeContainerInspectorEditor::_handle_item_edited);
ClassDB::bind_method(D_METHOD("_handle_item_selected"), &AttributeContainerInspectorEditor::_handle_item_selected);
ClassDB::bind_method(D_METHOD("_handle_dictionary_changed", "previous", "current"), &AttributeContainerInspectorEditor::_handle_dictionary_changed);
}

Expand All @@ -29,6 +32,16 @@ void AttributeContainerInspectorEditor::_handle_item_edited()
}
}

void AttributeContainerInspectorEditor::_handle_item_selected()
{
TreeItem *item = get_selected();

if (item)
{
DisplayServer::get_singleton()->clipboard_set(item->get_text(0));
}
}

void AttributeContainerInspectorEditor::_handle_dictionary_changed(TagDictionary *previous, TagDictionary *current)
{
clear();
Expand All @@ -55,11 +68,17 @@ void AttributeContainerInspectorEditor::_ready()

attribute_container->ensure_attributes(attrs);

Callable callable = Callable(this, "_handle_item_edited");
Callable handle_item_edited_callable = Callable(this, "_handle_item_edited");
Callable handle_item_selected_callable = Callable(this, "_handle_item_selected");

if (!is_connected("item_edited", handle_item_edited_callable))
{
connect("item_edited", handle_item_edited_callable);
}

if (!is_connected("item_edited", callable))
if (!is_connected("item_selected", handle_item_selected_callable))
{
connect("item_edited", callable);
connect("item_selected", handle_item_selected_callable);
}

set_columns(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace ggs::editor_plugin
AttributeContainer *attribute_container;
void _handle_item_edited();

void _handle_item_selected();

void _handle_dictionary_changed(TagDictionary *previous, TagDictionary *current);

protected:
Expand Down
7 changes: 7 additions & 0 deletions src/system/tag/tag_tree.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <godot_cpp/classes/label.hpp>
#include <godot_cpp/classes/display_server.hpp>

#include "system/tag/tag_dictionary.h"
#include "tag_tree.h"
Expand Down Expand Up @@ -37,6 +38,8 @@ void TagTree::_handle_item_edited()
{
String tag_path = item->get_meta(TAG_PATH_META_KEY);

DisplayServer::get_singleton()->clipboard_set(tag_path);

bool checked = item->is_checked(0);

item->set_checked(0, !checked);
Expand Down Expand Up @@ -72,6 +75,10 @@ void TagTree::_handle_item_edited()
emit_signal("tags_selected", tags);
}
}
else
{
DisplayServer::get_singleton()->clipboard_set(item->get_meta(TAG_PATH_META_KEY));
}
}

void TagTree::render_dictionary(Dictionary p_dictionary, TreeItem *p_parent, String p_current_path)
Expand Down

0 comments on commit fc1b5ee

Please sign in to comment.