[GNAT GPS:添加自定义命令

问题描述 投票:0回答:1

我想知道是否可以向GNAT编程工作室(GPS)添加自定义命令吗?

如果(通过菜单栏上的按钮或键盘快捷键调用了自定义命令,则应使用在编辑器中打开并选择的文件的完整/绝对路径来调用外部Python脚本。

ada gnat gnat-gps
1个回答
0
投票

这是一个简单易懂的脚本,可能会提供一些指导。我在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]));

输出(显示在GPS上名为“ my_script.py的输出”的新选项卡上)

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)文档的一些相关信息:

© www.soinside.com 2019 - 2024. All rights reserved.