mirror of
https://github.com/fergalmoran/picard.git
synced 2025-12-22 09:18:18 +00:00
Merge pull request #2497 from phw/missing-function-tooltip
PICARD-2912: Show a tooltip for missing functions in script editor
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#
|
||||
# Copyright (C) 2006-2009, 2012 Lukáš Lalinský
|
||||
# Copyright (C) 2007 Javier Kohen
|
||||
# Copyright (C) 2008-2011, 2014-2015, 2018-2021, 2023 Philipp Wolfer
|
||||
# Copyright (C) 2008-2011, 2014-2015, 2018-2021, 2023-2024 Philipp Wolfer
|
||||
# Copyright (C) 2009 Carlin Mangar
|
||||
# Copyright (C) 2009 Nikolai Prokoschenko
|
||||
# Copyright (C) 2011-2012 Michael Wiencek
|
||||
@@ -70,18 +70,26 @@ class ScriptFunctionDocError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ScriptFunctionDocUnknownFunctionError(ScriptFunctionDocError):
|
||||
pass
|
||||
|
||||
|
||||
class ScriptFunctionDocNoDocumentationError(ScriptFunctionDocError):
|
||||
pass
|
||||
|
||||
|
||||
def script_function_documentation(name, fmt, functions=None, postprocessor=None):
|
||||
if functions is None:
|
||||
functions = dict(script_functions.ext_point_script_functions)
|
||||
if name not in functions:
|
||||
raise ScriptFunctionDocError("no such function: %s (known functions: %r)" % (name, [name for name in functions]))
|
||||
raise ScriptFunctionDocUnknownFunctionError("no such function: %s (known functions: %r)" % (name, [name for name in functions]))
|
||||
|
||||
if fmt == 'html':
|
||||
return functions[name].htmldoc(postprocessor)
|
||||
elif fmt == 'markdown':
|
||||
return functions[name].markdowndoc(postprocessor)
|
||||
else:
|
||||
raise ScriptFunctionDocError("no such documentation format: %s (known formats: html, markdown)" % fmt)
|
||||
raise ScriptFunctionDocNoDocumentationError("no such documentation format: %s (known formats: html, markdown)" % fmt)
|
||||
|
||||
|
||||
def script_function_names(functions=None):
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#
|
||||
# Copyright (C) 2006-2007, 2009 Lukáš Lalinský
|
||||
# Copyright (C) 2014 m42i
|
||||
# Copyright (C) 2020-2023 Philipp Wolfer
|
||||
# Copyright (C) 2020-2024 Philipp Wolfer
|
||||
# Copyright (C) 2020-2024 Laurent Monin
|
||||
# Copyright (C) 2021-2022 Bob Swift
|
||||
#
|
||||
@@ -48,6 +48,7 @@ from picard.const.sys import IS_MACOS
|
||||
from picard.i18n import gettext as _
|
||||
from picard.script import (
|
||||
ScriptFunctionDocError,
|
||||
ScriptFunctionDocUnknownFunctionError,
|
||||
script_function_documentation,
|
||||
script_function_names,
|
||||
)
|
||||
@@ -279,6 +280,12 @@ class FunctionScriptToken(DocumentedScriptToken):
|
||||
function = self._read_allowed_chars(position + 1)
|
||||
try:
|
||||
return script_function_documentation(function, 'html')
|
||||
except ScriptFunctionDocUnknownFunctionError:
|
||||
return _(
|
||||
'<em>Function <code>$%s</code> does not exist.<br>'
|
||||
'<br>'
|
||||
'Are you missing a plugin?'
|
||||
'</em>') % function
|
||||
except ScriptFunctionDocError:
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user