Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions addons/launchy/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var interface = get_editor_interface()
var editor_settings = interface.get_editor_settings()
var current_object #currently selected object in the editor
var settings = editor_settings.get_setting('editors/external/associations') #Dict
var custom_type_cache: Dictionary = {}

const MENU_LABEL = "Launchy: Edit Associations..."

Expand Down Expand Up @@ -70,7 +71,7 @@ func handles(object):
#When choosing the application to launch, we should probably
#go through the entire set of keys to check for if an exact class is found.
for type in settings.keys():
if object.is_class(type):
if object.is_class(type) or get_object_type(object) == type:
return true
return false

Expand All @@ -81,15 +82,41 @@ func make_visible(visible):
if visible == true:
if current_object is Resource: b.res = current_object
#Set the launch exe to the most specific class we can get.
if settings.has(current_object.get_class()):
b.exe = settings[current_object.get_class()]
if settings.has(get_object_type(current_object)):
b.exe = settings[get_object_type(current_object)]
else: #Exact match not found. Search for a base class.
#TODO: Maybe walk the inheretance tree recursively up to find the
# subclass which matches the closest to current_object type
for type in settings.keys():
if current_object.is_class(type):
b.exe = settings[type]

func get_object_type(object: Object):

var script: Script = object.get_script()
if script != null:

# Check cache for this object type
if script.resource_path in custom_type_cache:
return custom_type_cache[script.resource_path]

if script is GDScript:

# Parse source code to find class_name
for line in script.source_code.split("\n"):
if line.begins_with("class_name "):
custom_type_cache[script.resource_path] = line.trim_prefix("class_name ").strip_edges()
return custom_type_cache[script.resource_path]

# If script has no class_name, return file name instead
var name: String = script.resource_path.get_basename().get_file()
if name in settings:
custom_type_cache[script.resource_path] = name
return name

else:
return object.get_class()

func launchConfigPopup(param=null):
if param is bool:
c.popup_exclusive = param
Expand Down