Skip to content

Commit

Permalink
[licenses] Add filesystem context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
IceflowRE committed Nov 11, 2024
1 parent 93b4533 commit 5508b68
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions addons/licenses/internal/plugin/context_menu_filesystem.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
extends EditorContextMenuPlugin

const Component := preload("res://addons/licenses/component.gd")
const LicensesInterface := preload("res://addons/licenses/internal/plugin/licenses_interface.gd")

var _li: LicensesInterface

func _init() -> void:
self._li = LicensesInterface.get_interface()

func _popup_menu(paths: PackedStringArray) -> void:
if paths.size() == 1:
var comps: Array[Component] = self._li.get_components_in_path(paths[0])
if comps.size() > 0:
for comp: Component in comps:
self.add_context_menu_item("Show license (" + comp.name + ")", self._on_single_ctx_menu_clicked.bind(comp))

func _on_single_ctx_menu_clicked(_paths: PackedStringArray, comp: Component) -> void:
self._li.show_popup(comp)
5 changes: 5 additions & 0 deletions addons/licenses/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ extends EditorPlugin
const Licenses := preload("res://addons/licenses/licenses.gd")
const ExportPlugin := preload("res://addons/licenses/internal/plugin/export_plugin.gd")
const LicensesInterface := preload("res://addons/licenses/internal/plugin/licenses_interface.gd")
const ContextMenuFilesystem := preload("res://addons/licenses/internal/plugin/context_menu_filesystem.gd")
const FileSystemWatcher := preload("res://addons/licenses/internal/plugin/file_system_watcher.gd")

var _export_plugin: ExportPlugin
var _context_menu_filesystem: ContextMenuFilesystem
var _file_watcher: FileSystemWatcher

func _get_plugin_name() -> String:
Expand All @@ -22,8 +24,11 @@ func _enter_tree() -> void:
self.add_export_plugin(self._export_plugin)

self.add_tool_menu_item(self._get_plugin_name() + "...", LicensesInterface.get_interface().show_popup)
self._context_menu_filesystem = ContextMenuFilesystem.new()
self.add_context_menu_plugin(EditorContextMenuPlugin.CONTEXT_SLOT_FILESYSTEM, self._context_menu_filesystem)

func _exit_tree() -> void:
self.remove_context_menu_plugin(self._context_menu_filesystem)
self.remove_tool_menu_item(self._get_plugin_name() + "...")
self.remove_export_plugin(self._export_plugin)
self._file_watcher = null
Expand Down

0 comments on commit 5508b68

Please sign in to comment.