Files
test/scripts/modules/bl_text_utils/external_editor.py
Damien Picard c306677119 I18n: extract and disambiguate a few messages
Extract
- Statuses for the external text editor
- Newly created enum node item
- Newly created plane track data
- Newly created custom orientation data
- Operator names in drag and drop menu (need to use operator's
  translation context)
- GN attribute statistic node inputs

Disambiguate
- Single-letter colors: A and B can mean Alpha and Blue, or simply A
  and B as in two operands in an operation
- Dissolve: issue reported by Tamar Mebonia in #43295
- Translate in the User Preferences. This introduces a new
  BLT_I18NCONTEXT_EDITOR_PREFERENCES ("Preferences") translation
  context
- Planar (reported by deathblood)
  This one is incomplete, because there is currently no way to
  disambiguate presets or GN fields. I don't see how either could be
  achieved cleanly.
  The former would need to define the context inside the preset and
  evaluate the file prior to showing it in the presets menu, which
  sound bad.
  The latter would need to introduce an additional string inside
  `FieldInput`s, which would be controversial given how little it
  would be used.

Remove
- Unused translation `iface_("%s")` in toolbar
- Remove obsolete N_() tags in a few node descriptions.

Pull Request: https://projects.blender.org/blender/blender/pulls/119065
2024-04-15 12:02:17 +02:00

55 lines
1.6 KiB
Python

# SPDX-FileCopyrightText: 2023 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
__all__ = (
"open_external_editor"
)
def open_external_editor(filepath, line, column, /):
# Internal Python implementation for `TEXT_OT_jump_to_file_at_point`.
# Returning a non-empty string represents an error, an empty string for success.
import shlex
import subprocess
from string import Template
from bpy import context
from bpy.app.translations import pgettext_rpt as rpt_
text_editor = context.preferences.filepaths.text_editor
text_editor_args = context.preferences.filepaths.text_editor_args
# The caller should check this.
assert text_editor
if not text_editor_args:
return rpt_(
"Provide text editor argument format in File Paths/Applications Preferences, "
"see input field tool-tip for more information",
)
if "$filepath" not in text_editor_args:
return rpt_("Text Editor Args Format must contain $filepath")
args = [text_editor]
template_vars = {
"filepath": filepath,
"line": line + 1,
"column": column + 1,
"line0": line,
"column0": column,
}
try:
args.extend([Template(arg).substitute(**template_vars) for arg in shlex.split(text_editor_args)])
except BaseException as ex:
return rpt_("Exception parsing template: %r") % ex
try:
# With `check=True` if `process.returncode != 0` an exception will be raised.
subprocess.run(args, check=True)
except BaseException as ex:
return rpt_("Exception running external editor: %r") % ex
return ""