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:- if(\+current_prolog_flag(xpce,false)).   38:- set_prolog_flag(generate_debug_info, true).   39
   40/** <module> Associate XPCE with SWI-Prolog
   41
   42This  file  initialises  XPCE,  the  SWI-Prolog   native  GUI.  XPCE  is
   43initialised only if it is detected.
   44
   45The source-location of this file  is packages/xpce/swipl/swipl-rc. It is
   46installed as <plbase>/<exe-base>.rc, where   <exe-base> is =|swipl-win|=
   47to associate with the SWI-Prolog gui  application on Windows and =swipl=
   48on Unix/X11 platforms.
   49*/
   50
   51:- multifile
   52	user:file_search_path/2.   53
   54:- dynamic
   55	pcehomestore_/1.   56:- volatile
   57	pcehomestore_/1.   58
   59pcehome_(Home) :-
   60	pcehomestore_(Home), !.
   61pcehome_(Home) :-
   62	(   getenv('XPCEHOME', RawHome)
   63	;   current_prolog_flag(home, PlHome),
   64	    (   current_prolog_flag(xpce_version, Version),
   65		atom_concat('/xpce-', Version, Suffix)
   66	    ;   Suffix = '/xpce'
   67	    ),
   68	    atom_concat(PlHome, Suffix, RawHome)
   69	),
   70	exists_directory(RawHome), !,
   71	absolute_file_name(RawHome, Home),
   72	asserta(pcehomestore_(Home)).
   73
   74user:file_search_path(pce, PceHome) :-
   75	current_prolog_flag(xpce, true),
   76	pcehome_(PceHome).
   77user:file_search_path(library, pce('prolog/lib')).
   78user:file_search_path(foreign, pce(ArchLib)) :-
   79	current_prolog_flag(arch, Arch),
   80	atom_concat('lib/', Arch, ArchLib).
   81
   82% We added a directory to the autoload directories: force reloading the
   83% index
   84:- reload_library_index.   85
   86gui_setup_ :-
   87	current_prolog_flag(gui, true), !.
   88gui_setup_ :-
   89	(   getenv('DISPLAY', D), D \== ''
   90	;   current_prolog_flag(windows, true)
   91	), !,
   92	create_prolog_flag(gui, true, []),
   93	menu_setup_,
   94	editor_setup,
   95	load_files(user:library(swi_hooks), [silent(true)]).	% help, etc.
   96
   97menu_setup_ :-					% plwin.exe menus
   98	current_prolog_flag(console_menu, true),
   99	load_files(user:library(win_menu), [silent(true)]).
  100menu_setup_.
  101
  102editor_setup :-
  103	current_prolog_flag(editor, default), !,
  104	set_prolog_flag(editor, pce_emacs).
  105editor_setup.
  106
  107:- dynamic
  108	pce_setup_done/0.  109
  110pce_setup_ :-
  111	pce_setup_done, !.
  112pce_setup_ :-
  113	current_prolog_flag(xpce, false), !.
  114pce_setup_ :-
  115	pcehome_(PceHome),
  116	exists_directory(PceHome),
  117	(   current_prolog_flag(xpce, true)
  118	->  Preload = true
  119	;   Preload = false
  120	),
  121	set_prolog_flag(xpce, true),
  122	gui_setup_,
  123	!,
  124	asserta(pce_setup_done),
  125	(   (   Preload == true
  126	    ;	current_prolog_flag(executable, Executable),
  127		file_base_name(Executable, Base),
  128		sub_atom_icasechk(Base, _, pce)
  129	    )
  130	->  ensure_loaded(user:library(pce))
  131	;   true
  132	).
  133pce_setup_ :-
  134	asserta(pce_setup_done).
  135
  136:- initialization pce_setup_.  137:- endif. % \+ current_prolog_flag(xpce,false)