View source with raw comments or as raw
    1/*  Part of XPCE --- The SWI-Prolog GUI toolkit
    2
    3    Author:        Jan Wielemaker and Anjo Anjewierden
    4    E-mail:        J.Wielemaker@cs.vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2002-2020, University of Amsterdam
    7                              VU University Amsterdam
    8                              CWI, Amsterdam
    9    All rights reserved.
   10
   11    Redistribution and use in source and binary forms, with or without
   12    modification, are permitted provided that the following conditions
   13    are met:
   14
   15    1. Redistributions of source code must retain the above copyright
   16       notice, this list of conditions and the following disclaimer.
   17
   18    2. Redistributions in binary form must reproduce the above copyright
   19       notice, this list of conditions and the following disclaimer in
   20       the documentation and/or other materials provided with the
   21       distribution.
   22
   23    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   24    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   25    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   26    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   27    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   28    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   29    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   30    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   31    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   32    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   33    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   34    POSSIBILITY OF SUCH DAMAGE.
   35*/
   36
   37:- module(swi_ide,
   38          [ prolog_ide/0,               %
   39            prolog_ide/1                % +Action
   40          ]).   41:- use_module(library(pce)).   42:- require([ pce_image_directory/1,
   43	     file_directory_name/2
   44	   ]).

SWI-Prolog IDE controller

This module defines the application @prolog_ide and the predicate prolog_ide(+Action). The major motivation is be able to delay loading the IDE components to the autoloading of one single predicate. */

   53                 /*******************************
   54                 *    AUTOLOAD OF COMPONENTS    *
   55                 *******************************/
   56
   57:- pce_image_directory(library('trace/icons')).   58
   59:- pce_autoload(swi_console,            library('swi/swi_console')).   60:- pce_autoload(prolog_debug_status,    library('trace/status')).   61:- pce_autoload(prolog_navigator,       library('trace/browse')).   62:- pce_autoload(prolog_query_frame,     library('trace/query')).   63:- pce_autoload(prolog_trace_exception, library('trace/exceptions')).   64:- pce_autoload(prolog_thread_monitor,  library('swi/thread_monitor')).   65:- pce_autoload(prolog_debug_monitor,   library('swi/pce_debug_monitor')).   66:- pce_autoload(xref_frame,             library('pce_xref')).   67
   68                 /*******************************
   69                 *            TOPLEVEL          *
   70                 *******************************/
 prolog_ide(+Action)
Invoke an action on the (SWI-)Prolog IDE application. This is a predicate to ensure optimal delaying of loading and object creation for accessing the various components of the Prolog Integrated Development Environment.
   79prolog_ide :-
   80    prolog_ide(open_console).
   81
   82prolog_ide(Action) :-
   83    in_pce_thread(send(@prolog_ide, Action)).
   84
   85
   86                 /*******************************
   87                 *         THE IDE CLASS        *
   88                 *******************************/
   89
   90:- pce_global(@prolog_ide, new(prolog_ide)).
   91:- pce_global(@prolog_exception_window, new(prolog_trace_exception)).
   92
   93:- pce_begin_class(prolog_ide, application, "Prolog IDE application").
   94
   95initialise(IDE) :->
   96    "Create as service application"::
   97    send_super(IDE, initialise, prolog_ide),
   98    send(IDE, kind, service).
   99
  100open_console(IDE) :->
  101    "Open SWI-Prolog Cross-Referencer frontend"::
  102    (   get(IDE, member, swi_console, Console)
  103    ->  send(Console, open)
  104    ;   new(Console, swi_console),
  105        send(Console, application, IDE),
  106        send(Console, wait)
  107    ).
  108
  109open_debug_status(IDE) :->
  110    "Open/show the status of the debugger"::
  111    (   get(IDE, member, prolog_debug_status, W)
  112    ->  send(W, expose)
  113    ;   send(prolog_debug_status(IDE), open)
  114    ).
  115
  116open_exceptions(IDE, Gui:[bool]) :->
  117    "Open/show exceptions"::
  118    W = @prolog_exception_window,
  119    (   object(W)
  120    ->  send(W, expose)
  121    ;   (   Gui == @on
  122        ->  catch(tdebug, _, guitracer)
  123        ;   true
  124        ),
  125        send(W, application, IDE),
  126        send(W, open)
  127    ).
  128
  129open_navigator(IDE, Where:[directory|source_location]) :->
  130    "Open Source Navigator"::
  131    (   send(Where, instance_of, directory)
  132    ->  get(IDE, navigator, Where, Navigator),
  133        send(Navigator, directory, Where)
  134    ;   send(Where, instance_of, source_location)
  135    ->  get(Where, file_name, File),
  136        file_directory_name(File, Dir),
  137        get(Where, line_no, Line),
  138        (   integer(Line)
  139        ->  LineNo = Line
  140        ;   LineNo = 1
  141        ),
  142        get(IDE, navigator, Dir, Navigator),
  143        send(Navigator, goto, File, LineNo)
  144    ;   get(IDE, navigator, directory('.'), Navigator)
  145    ),
  146    send(Navigator, expose).
  147
  148
  149navigator(IDE, Dir:[directory], Navigator:prolog_navigator) :<-
  150    "Create or return existing navigator"::
  151    (   get(IDE, member, prolog_navigator, Navigator)
  152    ->  true
  153    ;   new(Navigator, prolog_navigator(Dir)),
  154        send(Navigator, application, IDE)
  155    ).
  156
  157open_query_window(IDE) :->
  158    "Open window to enter a query"::
  159    (   get(IDE, member, prolog_query_frame, QF)
  160    ->  true
  161    ;   new(QF, prolog_query_frame),
  162        send(QF, application, IDE)
  163    ),
  164    send(QF, expose).
  165
  166open_interactor(_) :->
  167    "Create a new interactor window"::
  168    auto_call(interactor).
  169
  170thread_monitor(IDE) :->
  171    "Open a monitor for running threads"::
  172    (   current_prolog_flag(threads, true)
  173    ->  (   get(IDE, member, prolog_thread_monitor, Monitor)
  174        ->  true
  175        ;   new(Monitor, prolog_thread_monitor),
  176            send(Monitor, application, IDE)
  177        ),
  178        send(Monitor, open)
  179    ;   send(@display, report, error,
  180             'This version of SWI-Prolog is not built \n\c
  181                  with thread-support')
  182    ).
  183
  184debug_monitor(IDE) :->
  185    "Open monitor for debug messages"::
  186    (   get(IDE, member, prolog_debug_monitor, Monitor)
  187    ->  true
  188    ;   new(Monitor, prolog_debug_monitor),
  189        send(Monitor, application, IDE)
  190    ),
  191    send(Monitor, open).
  192
  193xref(IDE) :->
  194    "Open Cross-Referencer frontend"::
  195    (   get(IDE, member, xref_frame, XREF)
  196    ->  send(XREF, open)
  197    ;   new(XREF, xref_frame),
  198        send(XREF, application, IDE),
  199        send(XREF, wait),
  200        send(XREF, update)
  201    ).
  202
  203:- pce_end_class(prolog_ide)