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 cacb511 commit 5be524c
Show file tree
Hide file tree
Showing 3 changed files with 33 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", self._on_single_ctx_menu_clicked.bind(comp))

func _on_single_ctx_menu_clicked(vals: PackedStringArray, comp: Component) -> void:
print(comp.name)
9 changes: 9 additions & 0 deletions addons/licenses/internal/plugin/licenses_interface.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ func sort_custom(fn: Callable) -> void:
func count() -> int:
return len(self._components)

func get_components_in_path(path: String) -> Array[Component]:
var res: Array[Component] = []
for comp: Component in self._components:
for idx: int in range(comp.paths.size()):
if comp.paths[idx].begins_with(path):
res.append(comp)
break
return res

static func create_interface() -> void:
var li: Node = new()
li.name = "kenyoni_licenses_interface"
Expand Down
5 changes: 5 additions & 0 deletions addons/licenses/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ const LicensesDialog := preload("res://addons/licenses/internal/licenses_dialog.
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 _licenses_dialog: LicensesDialog
var _file_watcher: FileSystemWatcher

Expand All @@ -26,8 +28,11 @@ func _enter_tree() -> void:
self._licenses_dialog = LicensesDialogScene.instantiate()
EditorInterface.get_base_control().add_child(self._licenses_dialog)
self.add_tool_menu_item(self._get_plugin_name() + "...", self._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._licenses_dialog.queue_free()
self.remove_export_plugin(self._export_plugin)
Expand Down

0 comments on commit 5be524c

Please sign in to comment.