##----------------------------------------------------------------------------
##                                                                          --
##                An Ada2005 binding to the Qt C++ framework                --
##                                                                          --
##----------------------------------------------------------------------------
##                                                                          --
## Copyright (C) 2008-2011 Vadim Godunko <vgodunko@gmail.com>               --
##                                                                          --
## QtAda is free software;  you can  redistribute it and/or modify it under --
## terms of the  GNU General Public License as published  by the Free Soft- --
## ware  Foundation;  either version 2,  or (at your option) any later ver- --
## sion. QtAda is distributed in the hope that it will be useful, but WITH- --
## OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
## for  more details.  You should have  received  a copy of the GNU General --
## Public License distributed with QtAda;  see file COPYING.  If not, write --
## to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
## Boston, MA 02110-1301, USA.                                              --
##                                                                          --
##----------------------------------------------------------------------------
##  $Revision: 3860 $ $Date: 2011-08-27 10:09:26 +0400 (Sat, 27 Aug 2011) $
##----------------------------------------------------------------------------
import GPS

def on_compilation_starting(name, category, quiet, shadow):
    #  Runs amoc automatically before build of application (or main).

    if category == "Build All" or category == "Build Main":
        switch = GPS.Project.root ().get_attribute_as_string \
                  ("QtAda_Amoc_Invocation_Switch", "IDE")

        if switch != "":
            GPS.BuildTarget ("Generate All Metadata").execute \
             (synchronous = False)

    return True

GPS.parse_xml ("""
  <action name="run_designer" show-command="false">
    <external>designer</external>
  </action>

  <action name="run_linguist" show-command="false">
    <external>linguist</external>
  </action>

  <action name="run_assistant" show-command="false">
    <external>assistant</external>
  </action>

  <action name="run_assistant_qtada" show-command="false">
    <external>assistant -collectionFile /usr/local/share/doc/qtada/qch/qtada.qhc</external>
  </action>

  <!--
  <action name="run_class_wizard" show-command="false">
    <external>/usr/local/libexec/qtada/class_wizard</external>
  </action>
  -->

  <submenu>
    <title>Tools</title>

    <submenu before="Views">
      <title>QtAda</title>

      <menu action="run_designer">
        <title>Interface Designer (Qt Designer)</title>
      </menu>

      <menu action="run_linguist">
        <title>Translation Tool (Qt Linguist)</title>
      </menu>

      <!--
      <menu action="run_class_wizard">
        <title>Class Wizard...</title>
      </menu>
      -->

      <!--
      <menu action="run_assistant">
        <title>Document Browser (Qt Assistant)</title>
      </menu>
      -->
    </submenu>
  </submenu>

  <submenu>
    <title>Help</title>

    <submenu before="About">
      <title>QtAda</title>

      <menu action="run_assistant">
        <title>Qt Reference Documentation</title>
      </menu>

      <menu action="run_assistant_qtada">
        <title>QtAda Reference Documentation</title>
      </menu>
    </submenu>
  </submenu>

  <!--  Register language for amoc  -->

  <Language>
    <Name>Amoc</Name>
    <Body_Suffix>.ads</Body_Suffix>
    <Parent>Ada</Parent>
    <!--  XXX GPS 5.0: It looks like language inheritance doesn't work right,
          at least Body_Suffix is not inherited.  -->
    <Extension>.ads</Extension>
  </Language>

  <!--  Register amoc as tool and define its switches  -->

  <tool name="amoc" package="Compiler">
    <language>Amoc</language>
    <switches lines="1" columns="1">
      <check label="Verbose output" switch="-v" line="1"/>
    </switches>
  </tool>

  <!--  Project attribute to specify grpbuild's switch to invoke amoc  -->

  <project_attribute
      package="IDE"
      name="QtAda_Amoc_Invocation_Switch"
      editor_page="QtAda"
      editor_section="Amoc invocation"
      label="Switch to invoke Amoc"
      description="gprbuild's switch to invoke Amoc">
    <string default="-XBUILD_MODE=Metadata" allow_empty="False"/>
  </project_attribute>

  <!--  Target to generate metadata for the selected source file  -->

  <target model="gprbuild" category="_File_" name="_Generate Metadata">
    <icon>gps-compile</icon>
    <in-toolbar>TRUE</in-toolbar>
    <launch-mode>MANUALLY_WITH_NO_DIALOG</launch-mode>
    <read-only>TRUE</read-only>
    <command-line>
      <arg>%builder</arg>
      <arg>-p</arg>
      <arg>-c</arg>
      <arg>-u</arg>
      <arg>-P%PP</arg>
      <arg>%X</arg>
      <arg>%attr(IDE'QtAda_Amoc_Invocation_Switch)</arg>
      <arg>%fp</arg>
    </command-line>
  </target>

  <!--  Target to generate metadata for project  -->

  <target model="gprbuild" category="_Project" name="_Generate All Metadata">
    <icon>gps-compile</icon>
    <in-toolbar>TRUE</in-toolbar>
    <launch-mode>MANUALLY_WITH_NO_DIALOG</launch-mode>
    <read-only>TRUE</read-only>
    <command-line>
      <arg>%builder</arg>
      <arg>-p</arg>
      <arg>-P%PP</arg>
      <arg>%X</arg>
      <arg>%attr(IDE'QtAda_Amoc_Invocation_Switch)</arg>
    </command-line>
  </target>

""")
GPS.Hook ("compilation_starting").add (on_compilation_starting)
