ada - GNAT GPS:添加自定义命令
问题描述
我想知道是否可以向 GNAT Programming Studio (GPS) 添加自定义命令?
如果调用自定义命令(通过菜单栏中的按钮或键盘快捷键),则应使用在编辑器中打开和选择的文件的完整/绝对路径调用外部 Python 脚本。
解决方案
这是一个快速而肮脏的脚本,可能会给出一些方向。我在 Linux 上对其进行了测试,但它也应该可以在 Windows 上运行。更改接近尾声的操作以调用您喜欢的脚本。要实际使用它,您必须将它放在.gps/plug-ins
可以在您的主目录中找到的(隐藏)目录中。可以从源代码窗口中的上下文菜单调用实际操作。
run_my_script.py
"""Run Python Script
This plug-in executes a python script.
"""
###########################################################################
# No user customization below this line
###########################################################################
import os, sys
import GPS
from gps_utils import interactive
def __contextualMenuFilter(context):
# Check if the context is generated by the source editor
if not (context.module_name == "Source_Editor"):
return False
# If all OK, show the menu item in the context menu.
return True
def __contextualMenuLabel(context):
# Get current buffer
name = context.file().name()
basename = os.path.basename(name)
# Name of the menu item.
return "Run Python script for <b>{}</b>".format(basename)
@interactive(
name ="Run Python script",
contextual = __contextualMenuLabel,
filter = __contextualMenuFilter)
def on_activate():
# If modified, then save before proceeding.
eb = GPS.EditorBuffer.get()
if eb.is_modified:
eb.save()
# Run the action (defined below).
GPS.execute_action("my_script")
GPS.parse_xml ("""
<action name="my_script">
<external output="Output of my_script">python3 /home/deedee/my_script.py %F</external>
</action>""")
my_script.py(一些测试脚本)
import sys
print ("Running script {0} for {1}".format(sys.argv[0], sys.argv[1]));
输出(显示在名为“my_script 输出”的新选项卡上的 GPS 中)
python3 /home/deedee/my_script.py /home/deedee/example/src/main.adb
Running script /home/deedee/my_script.py for /home/deedee/example/src/main.adb
GNAT Studio(以前称为 GPS)文档中的一些相关信息:
推荐阅读
- php - 如果 meta_key = Delivery Date 和 meta_value = this day,则每天 23:00 在 WooCommerce 中将订单状态从自定义状态更新为已完成
- linux - 如何在主机上的容器内或不在同一 Docker 网络上的容器上挂载由 NFS 服务器共享的文件夹
- powerbi - 查询编辑器 - 根据参数值执行步骤
- mongodb - @nestjs/mongoose 的文档
- flask - 如何在 Flask 中使用 request.args.get() 获取斜杠 (/)?
- java - Blockhound Gradle:'您需要添加 '-XX:+AllowRedefinitionToAddDeleteMethods' JVM 标志。
- django - Django中视图函数的请求参数变灰
- python - TypeError: 不支持的操作数类型 -: 'datetime.datetime' 和 'str'
- swift - NSView(AppKit)开始动画之前的延迟
- mysql - 如何在销售趋势 mysql 查询中包括所有客户,即使是销售额为零的客户