View source with formatted 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.nl/projects/xpce/
    6    Copyright (c)  2011-2013, University of Amsterdam
    7                              VU University Amsterdam
    8    All rights reserved.
    9
   10    Redistribution and use in source and binary forms, with or without
   11    modification, are permitted provided that the following conditions
   12    are met:
   13
   14    1. Redistributions of source code must retain the above copyright
   15       notice, this list of conditions and the following disclaimer.
   16
   17    2. Redistributions in binary form must reproduce the above copyright
   18       notice, this list of conditions and the following disclaimer in
   19       the documentation and/or other materials provided with the
   20       distribution.
   21
   22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   23    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   25    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   26    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   27    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   28    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   29    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   30    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   32    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33    POSSIBILITY OF SUCH DAMAGE.
   34*/
   35
   36:- module(link_xpce, []).   37:- set_prolog_flag(generate_debug_info, true).   38
   39/** <module> Associate XPCE with SWI-Prolog
   40
   41This  file  initialises  XPCE,  the  SWI-Prolog   native  GUI.  XPCE  is
   42initialised only if it is detected.
   43
   44The source-location of this file  is packages/xpce/swipl/swipl-rc. It is
   45installed as <plbase>/<exe-base>.rc, where   <exe-base> is =|swipl-win|=
   46to associate with the SWI-Prolog gui  application on Windows and =swipl=
   47on Unix/X11 platforms.
   48*/
   49
   50:- multifile
   51	user:file_search_path/2.   52
   53:- dynamic
   54	pcehomestore_/1.   55:- volatile
   56	pcehomestore_/1.   57
   58pcehome_(Home) :-
   59	pcehomestore_(Home), !.
   60pcehome_(Home) :-
   61	(   getenv('XPCEHOME', RawHome)
   62	;   current_prolog_flag(home, PlHome),
   63	    (   current_prolog_flag(xpce_version, Version),
   64		atom_concat('/xpce-', Version, Suffix)
   65	    ;   Suffix = '/xpce'
   66	    ),
   67	    atom_concat(PlHome, Suffix, RawHome)
   68	),
   69	exists_directory(RawHome), !,
   70	absolute_file_name(RawHome, Home),
   71	asserta(pcehomestore_(Home)).
   72
   73user:file_search_path(pce, PceHome) :-
   74	current_prolog_flag(xpce, true),
   75	pcehome_(PceHome).
   76user:file_search_path(library, pce('prolog/lib')).
   77user:file_search_path(foreign, pce(ArchLib)) :-
   78	current_prolog_flag(arch, Arch),
   79	atom_concat('lib/', Arch, ArchLib).
   80
   81% We added a directory to the autoload directories: force reloading the
   82% index
   83:- reload_library_index.   84
   85gui_setup_ :-
   86	current_prolog_flag(gui, true), !.
   87gui_setup_ :-
   88	(   getenv('DISPLAY', D), D \== ''
   89	;   current_prolog_flag(windows, true)
   90	), !,
   91	create_prolog_flag(gui, true, []),
   92	menu_setup_,
   93	editor_setup,
   94	load_files(user:library(swi_hooks), [silent(true)]).	% help, etc.
   95
   96menu_setup_ :-					% plwin.exe menus
   97	current_prolog_flag(console_menu, true),
   98	load_files(user:library(win_menu), [silent(true)]).
   99menu_setup_.
  100
  101editor_setup :-
  102	current_prolog_flag(editor, default), !,
  103	set_prolog_flag(editor, pce_emacs).
  104editor_setup.
  105
  106:- dynamic
  107	pce_setup_done/0.  108
  109pce_setup_ :-
  110	pce_setup_done, !.
  111pce_setup_ :-
  112	current_prolog_flag(xpce, false), !.
  113pce_setup_ :-
  114	pcehome_(PceHome),
  115	exists_directory(PceHome),
  116	(   current_prolog_flag(xpce, true)
  117	->  Preload = true
  118	;   Preload = false
  119	),
  120	set_prolog_flag(xpce, true),
  121	gui_setup_,
  122	!,
  123	asserta(pce_setup_done),
  124	(   (   Preload == true
  125	    ;	current_prolog_flag(executable, Executable),
  126		file_base_name(Executable, Base),
  127		sub_atom_icasechk(Base, _, pce)
  128	    )
  129	->  ensure_loaded(user:library(pce))
  130	;   true
  131	).
  132pce_setup_ :-
  133	asserta(pce_setup_done).
  134
  135:- initialization pce_setup_.