Skip to content

Commit 3394988

Browse files
committed
Merge pull request #100276 from Arnklit/spriteframes-show-in-filesystem
Add Show in FileSystem right click option to SpriteFrames
2 parents 9d2798d + ebf9681 commit 3394988

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

editor/plugins/sprite_frames_editor_plugin.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "editor/editor_settings.h"
3939
#include "editor/editor_string_names.h"
4040
#include "editor/editor_undo_redo_manager.h"
41+
#include "editor/filesystem_dock.h"
4142
#include "editor/gui/editor_bottom_panel.h"
4243
#include "editor/gui/editor_file_dialog.h"
4344
#include "editor/scene_tree_dock.h"
@@ -1309,10 +1310,39 @@ void SpriteFramesEditor::_frame_list_gui_input(const Ref<InputEvent> &p_event) {
13091310
_zoom_out();
13101311
// Don't scroll down after zooming out.
13111312
accept_event();
1313+
} else if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) {
1314+
Point2 pos = mb->get_position();
1315+
right_clicked_frame = frame_list->get_item_at_position(pos, true);
1316+
if (right_clicked_frame != -1) {
1317+
if (!menu) {
1318+
menu = memnew(PopupMenu);
1319+
add_child(menu);
1320+
menu->connect(SceneStringName(id_pressed), callable_mp(this, &SpriteFramesEditor::_menu_selected));
1321+
menu->add_icon_item(get_editor_theme_icon(SNAME("ShowInFileSystem")), TTRC("Show in FileSystem"));
1322+
}
1323+
1324+
menu->set_position(get_screen_position() + get_local_mouse_position());
1325+
menu->popup();
1326+
}
13121327
}
13131328
}
13141329
}
13151330

1331+
void SpriteFramesEditor::_menu_selected(int p_index) {
1332+
switch (p_index) {
1333+
case MENU_SHOW_IN_FILESYSTEM: {
1334+
String path = frames->get_frame_texture(edited_anim, right_clicked_frame)->get_path();
1335+
// Check if the file is an atlas resource, if it is find the source texture.
1336+
Ref<AtlasTexture> at = frames->get_frame_texture(edited_anim, right_clicked_frame);
1337+
while (at.is_valid() && at->get_atlas().is_valid()) {
1338+
path = at->get_atlas()->get_path();
1339+
at = at->get_atlas();
1340+
}
1341+
FileSystemDock::get_singleton()->navigate_to_path(path);
1342+
} break;
1343+
}
1344+
}
1345+
13161346
void SpriteFramesEditor::_frame_list_item_selected(int p_index, bool p_selected) {
13171347
if (updating) {
13181348
return;

editor/plugins/sprite_frames_editor_plugin.h

+10
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ class SpriteFramesEditor : public HSplitContainer {
8787
FRAME_ORDER_BOTTOM_TOP_RIGHT_LEFT,
8888
};
8989

90+
enum {
91+
MENU_SHOW_IN_FILESYSTEM,
92+
};
93+
94+
int right_clicked_frame = -1;
95+
9096
bool read_only = false;
9197

9298
Ref<Texture2D> autoplay_icon;
@@ -137,6 +143,8 @@ class SpriteFramesEditor : public HSplitContainer {
137143

138144
AcceptDialog *dialog = nullptr;
139145

146+
PopupMenu *menu = nullptr;
147+
140148
StringName edited_anim;
141149

142150
ConfirmationDialog *delete_dialog = nullptr;
@@ -219,6 +227,8 @@ class SpriteFramesEditor : public HSplitContainer {
219227
void _frame_list_gui_input(const Ref<InputEvent> &p_event);
220228
void _frame_list_item_selected(int p_index, bool p_selected);
221229

230+
void _menu_selected(int p_index);
231+
222232
void _zoom_in();
223233
void _zoom_out();
224234
void _zoom_reset();

0 commit comments

Comments
 (0)