Explorar el Código

Add Show in FileSystem right click option to SpriteFrames

Kasper Arnklit Frandsen hace 9 meses
padre
commit
ebf9681668

+ 30 - 0
editor/plugins/sprite_frames_editor_plugin.cpp

@@ -38,6 +38,7 @@
 #include "editor/editor_settings.h"
 #include "editor/editor_settings.h"
 #include "editor/editor_string_names.h"
 #include "editor/editor_string_names.h"
 #include "editor/editor_undo_redo_manager.h"
 #include "editor/editor_undo_redo_manager.h"
+#include "editor/filesystem_dock.h"
 #include "editor/gui/editor_bottom_panel.h"
 #include "editor/gui/editor_bottom_panel.h"
 #include "editor/gui/editor_file_dialog.h"
 #include "editor/gui/editor_file_dialog.h"
 #include "editor/scene_tree_dock.h"
 #include "editor/scene_tree_dock.h"
@@ -1309,10 +1310,39 @@ void SpriteFramesEditor::_frame_list_gui_input(const Ref<InputEvent> &p_event) {
 			_zoom_out();
 			_zoom_out();
 			// Don't scroll down after zooming out.
 			// Don't scroll down after zooming out.
 			accept_event();
 			accept_event();
+		} else if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) {
+			Point2 pos = mb->get_position();
+			right_clicked_frame = frame_list->get_item_at_position(pos, true);
+			if (right_clicked_frame != -1) {
+				if (!menu) {
+					menu = memnew(PopupMenu);
+					add_child(menu);
+					menu->connect(SceneStringName(id_pressed), callable_mp(this, &SpriteFramesEditor::_menu_selected));
+					menu->add_icon_item(get_editor_theme_icon(SNAME("ShowInFileSystem")), TTRC("Show in FileSystem"));
+				}
+
+				menu->set_position(get_screen_position() + get_local_mouse_position());
+				menu->popup();
+			}
 		}
 		}
 	}
 	}
 }
 }
 
 
+void SpriteFramesEditor::_menu_selected(int p_index) {
+	switch (p_index) {
+		case MENU_SHOW_IN_FILESYSTEM: {
+			String path = frames->get_frame_texture(edited_anim, right_clicked_frame)->get_path();
+			// Check if the file is an atlas resource, if it is find the source texture.
+			Ref<AtlasTexture> at = frames->get_frame_texture(edited_anim, right_clicked_frame);
+			while (at.is_valid() && at->get_atlas().is_valid()) {
+				path = at->get_atlas()->get_path();
+				at = at->get_atlas();
+			}
+			FileSystemDock::get_singleton()->navigate_to_path(path);
+		} break;
+	}
+}
+
 void SpriteFramesEditor::_frame_list_item_selected(int p_index, bool p_selected) {
 void SpriteFramesEditor::_frame_list_item_selected(int p_index, bool p_selected) {
 	if (updating) {
 	if (updating) {
 		return;
 		return;

+ 10 - 0
editor/plugins/sprite_frames_editor_plugin.h

@@ -87,6 +87,12 @@ class SpriteFramesEditor : public HSplitContainer {
 		FRAME_ORDER_BOTTOM_TOP_RIGHT_LEFT,
 		FRAME_ORDER_BOTTOM_TOP_RIGHT_LEFT,
 	};
 	};
 
 
+	enum {
+		MENU_SHOW_IN_FILESYSTEM,
+	};
+
+	int right_clicked_frame = -1;
+
 	bool read_only = false;
 	bool read_only = false;
 
 
 	Ref<Texture2D> autoplay_icon;
 	Ref<Texture2D> autoplay_icon;
@@ -137,6 +143,8 @@ class SpriteFramesEditor : public HSplitContainer {
 
 
 	AcceptDialog *dialog = nullptr;
 	AcceptDialog *dialog = nullptr;
 
 
+	PopupMenu *menu = nullptr;
+
 	StringName edited_anim;
 	StringName edited_anim;
 
 
 	ConfirmationDialog *delete_dialog = nullptr;
 	ConfirmationDialog *delete_dialog = nullptr;
@@ -219,6 +227,8 @@ class SpriteFramesEditor : public HSplitContainer {
 	void _frame_list_gui_input(const Ref<InputEvent> &p_event);
 	void _frame_list_gui_input(const Ref<InputEvent> &p_event);
 	void _frame_list_item_selected(int p_index, bool p_selected);
 	void _frame_list_item_selected(int p_index, bool p_selected);
 
 
+	void _menu_selected(int p_index);
+
 	void _zoom_in();
 	void _zoom_in();
 	void _zoom_out();
 	void _zoom_out();
 	void _zoom_reset();
 	void _zoom_reset();