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.psy.uva.nl/projects/xpce/
    6    Copyright (c)  2002-2015, 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(prolog_preferences,
   37          [ prolog_edit_preferences/1   % +What
   38          ]).   39:- use_module(library(pce)).   40:- use_module(library(pce_tick_box)).   41:- autoload(library(lists), [member/2]).   42:- autoload(library(pce_emacs), [start_emacs/0]).   43:- autoload(library(swi_compatibility), [auto_call/1]).

Edit preferences files

This module provides prolog_edit_preferences/1, which is used to simplify locating the preference files and provide a default if the user has no such file.

See also
- library(win_menu) binds this to the Settings menu of the console on the MS-Windows version. */
 prolog_edit_preferences(+What) is det
Edit the specified user preference file. What is one of

The UI components are started asynchronously in the XPCE thread.

   64prolog_edit_preferences(What) :-
   65    in_pce_thread(pce_edit_preferences(What)).
   66
   67pce_edit_preferences(What) :-
   68    locate_preferences(What, File),
   69    auto_call(start_emacs),
   70    (   \+ access_file(File, exist)
   71    ->  send(@display, confirm,
   72             'Preferences file %s doesn''t exist.\nCreate it?', File),
   73        (   default_preferences(What, DefFile)
   74        ->  copy_file(DefFile, File)
   75        ;   true
   76        )
   77    ;   access_file(File, write)
   78    ->  true
   79    ;   send(@display, inform,
   80             'You cannot modify the preferences file %s', File)
   81    ),
   82    send(@emacs, goto_source_location, File).
   83
   84locate_preferences(xpce, File) :-
   85    ensure_xpce_config_dir(Dir),
   86    get(string('%s/Defaults', Dir), value, File).
   87locate_preferences(prolog, File) :-
   88    prolog_init_file(Base),
   89    member(Access, [read,write]),
   90    absolute_file_name(user_app_config(Base), File,
   91                       [ access(Access),
   92                         file_errors(fail)
   93                       ]),
   94    !.
 prolog_init_file(-Base)
Get the base-name of the Prolog user initialization file.
To be done
- This should have a public interface.
  102:- if(current_predicate('$cmd_option_val'/2)).  103prolog_init_file(Base) :-
  104    '$cmd_option_val'(init_file, Base).
  105:- else.  106prolog_init_file(Base) :-
  107    '$option'(init_file, Base).
  108:- endif.  109prolog_init_file('init.pl').
 default_preferences(+Id, -File)
If there is a default file for the preferences, return a path to it, so the user can be presented a starting point.
  117default_preferences(prolog, File) :-
  118    member(Location,
  119           [ swi('customize/swipl.ini'),
  120             swi('customize/dotswiplrc')
  121           ]),
  122    absolute_file_name(Location, File,
  123                       [ access(read),
  124                         file_errors(fail)
  125                       ]),
  126    !.
  127default_preferences(xpce, File) :-
  128    absolute_file_name(pce('Defaults.user'), File,
  129                       [ access(read),
  130                         file_errors(fail)
  131                       ]),
  132    !.
 ensure_xpce_config_dir(-Dir:atom)
Ensure existence of the personal XPCE config directory.
  139ensure_xpce_config_dir(Dir) :-
  140    get(@pce, application_data, AppDir),
  141    (   send(AppDir, exists)
  142    ->  true
  143    ;   send(AppDir, make)
  144    ),
  145    get(AppDir, path, Dir).
  146
  147
  148copy_file(From, To) :-
  149    send(file(To), copy, From)