Skip to content

Commit 90ef140

Browse files
KoBeWibrno32
andcommitted
Add Copy Script UID option to Script Editor
Co-authored-by: Alex Drozd <[email protected]>
1 parent abf8e1e commit 90ef140

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

editor/plugins/script_editor_plugin.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,15 @@ void ScriptEditor::_copy_script_path() {
986986
}
987987
}
988988

989+
void ScriptEditor::_copy_script_uid() {
990+
ScriptEditorBase *se = _get_current_editor();
991+
if (se) {
992+
Ref<Resource> scr = se->get_edited_resource();
993+
ResourceUID::ID uid = ResourceLoader::get_resource_uid(scr->get_path());
994+
DisplayServer::get_singleton()->clipboard_set(ResourceUID::get_singleton()->id_to_text(uid));
995+
}
996+
}
997+
989998
void ScriptEditor::_close_other_tabs() {
990999
int current_idx = tab_container->get_current_tab();
9911000
for (int i = tab_container->get_tab_count() - 1; i >= 0; i--) {
@@ -1561,6 +1570,9 @@ void ScriptEditor::_menu_option(int p_option) {
15611570
case FILE_COPY_PATH: {
15621571
_copy_script_path();
15631572
} break;
1573+
case FILE_COPY_UID: {
1574+
_copy_script_uid();
1575+
} break;
15641576
case SHOW_IN_FILE_SYSTEM: {
15651577
const Ref<Resource> scr = current->get_edited_resource();
15661578
String path = scr->get_path();
@@ -1706,17 +1718,19 @@ bool ScriptEditor::_has_script_tab() const {
17061718

17071719
void ScriptEditor::_prepare_file_menu() {
17081720
PopupMenu *menu = file_menu->get_popup();
1709-
const bool current_is_doc = _get_current_editor() == nullptr;
1721+
ScriptEditorBase *editor = _get_current_editor();
1722+
const Ref<Resource> res = editor ? editor->get_edited_resource() : Ref<Resource>();
17101723

17111724
menu->set_item_disabled(menu->get_item_index(FILE_REOPEN_CLOSED), previous_scripts.is_empty());
17121725

1713-
menu->set_item_disabled(menu->get_item_index(FILE_SAVE), current_is_doc);
1714-
menu->set_item_disabled(menu->get_item_index(FILE_SAVE_AS), current_is_doc);
1726+
menu->set_item_disabled(menu->get_item_index(FILE_SAVE), res.is_null());
1727+
menu->set_item_disabled(menu->get_item_index(FILE_SAVE_AS), res.is_null());
17151728
menu->set_item_disabled(menu->get_item_index(FILE_SAVE_ALL), !_has_script_tab());
17161729

1717-
menu->set_item_disabled(menu->get_item_index(FILE_TOOL_RELOAD_SOFT), current_is_doc);
1718-
menu->set_item_disabled(menu->get_item_index(FILE_COPY_PATH), current_is_doc);
1719-
menu->set_item_disabled(menu->get_item_index(SHOW_IN_FILE_SYSTEM), current_is_doc);
1730+
menu->set_item_disabled(menu->get_item_index(FILE_TOOL_RELOAD_SOFT), res.is_null());
1731+
menu->set_item_disabled(menu->get_item_index(FILE_COPY_PATH), res.is_null() || res->get_path().is_empty());
1732+
menu->set_item_disabled(menu->get_item_index(FILE_COPY_UID), res.is_null() || ResourceLoader::get_resource_uid(res->get_path()) == ResourceUID::INVALID_ID);
1733+
menu->set_item_disabled(menu->get_item_index(SHOW_IN_FILE_SYSTEM), res.is_null());
17201734

17211735
menu->set_item_disabled(menu->get_item_index(WINDOW_PREV), history_pos <= 0);
17221736
menu->set_item_disabled(menu->get_item_index(WINDOW_NEXT), history_pos >= history.size() - 1);
@@ -1726,7 +1740,7 @@ void ScriptEditor::_prepare_file_menu() {
17261740
menu->set_item_disabled(menu->get_item_index(CLOSE_OTHER_TABS), tab_container->get_tab_count() <= 1);
17271741
menu->set_item_disabled(menu->get_item_index(CLOSE_DOCS), !_has_docs_tab());
17281742

1729-
menu->set_item_disabled(menu->get_item_index(FILE_RUN), current_is_doc);
1743+
menu->set_item_disabled(menu->get_item_index(FILE_RUN), res.is_null());
17301744
}
17311745

17321746
void ScriptEditor::_file_menu_closed() {
@@ -3404,6 +3418,9 @@ void ScriptEditor::_make_script_list_context_menu() {
34043418
context_menu->add_separator();
34053419
}
34063420
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/copy_path"), FILE_COPY_PATH);
3421+
context_menu->set_item_disabled(-1, se->get_edited_resource()->get_path().is_empty());
3422+
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/copy_uid"), FILE_COPY_UID);
3423+
context_menu->set_item_disabled(-1, ResourceLoader::get_resource_uid(se->get_edited_resource()->get_path()) == ResourceUID::INVALID_ID);
34073424
context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/show_in_file_system"), SHOW_IN_FILE_SYSTEM);
34083425
context_menu->add_separator();
34093426
}
@@ -4248,6 +4265,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) {
42484265
file_menu->get_popup()->add_separator();
42494266
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/reload_script_soft", TTRC("Soft Reload Tool Script"), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::ALT | Key::R), FILE_TOOL_RELOAD_SOFT);
42504267
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy_path", TTRC("Copy Script Path")), FILE_COPY_PATH);
4268+
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy_uid", TTRC("Copy Script UID")), FILE_COPY_UID);
42514269
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/show_in_file_system", TTRC("Show in FileSystem")), SHOW_IN_FILE_SYSTEM);
42524270
file_menu->get_popup()->add_separator();
42534271

editor/plugins/script_editor_plugin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class ScriptEditor : public PanelContainer {
253253
TOGGLE_SCRIPTS_PANEL,
254254
SHOW_IN_FILE_SYSTEM,
255255
FILE_COPY_PATH,
256+
FILE_COPY_UID,
256257
FILE_TOOL_RELOAD_SOFT,
257258
SEARCH_IN_FILES,
258259
REPLACE_IN_FILES,
@@ -399,6 +400,7 @@ class ScriptEditor : public PanelContainer {
399400
void _queue_close_tabs();
400401

401402
void _copy_script_path();
403+
void _copy_script_uid();
402404

403405
void _ask_close_current_unsaved_tab(ScriptEditorBase *current);
404406

0 commit comments

Comments
 (0)