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)).
xpce
prolog
The UI components are started asynchronously in the XPCE thread.
61prolog_edit_preferences(What) :- 62 in_pce_thread(pce_edit_preferences(What)). 63 64pce_edit_preferences(What) :- 65 locate_preferences(What, File), 66 auto_call(start_emacs), 67 ( \+ access_file(File, exist) 68 -> send(@display, confirm, 69 'Preferences file %s doesn''t exist.\nCreate it?', File), 70 ( default_preferences(What, DefFile) 71 -> copy_file(DefFile, File) 72 ; true 73 ) 74 ; access_file(File, write) 75 -> true 76 ; send(@display, inform, 77 'You cannot modify the preferences file %s', File) 78 ), 79 send(@emacs, goto_source_location, File). 80 81locate_preferences(xpce, File) :- 82 ensure_xpce_config_dir(Dir), 83 get(string('%s/Defaults', Dir), value, File). 84locate_preferences(prolog, File) :- 85 prolog_init_file(Base), 86 ( absolute_file_name(user_profile(Base), File, 87 [ access(read), 88 file_errors(fail) 89 ]) 90 -> true 91 ; absolute_file_name(app_preferences(Base), File, 92 [ access(write), 93 file_errors(fail) 94 ]) 95 ).
103:- if(current_predicate('$cmd_option_val'/2)). 104prolog_init_file(Base) :- 105 '$cmd_option_val'(init_file, Base). 106:- else. 107prolog_init_file(Base) :- 108 '$option'(init_file, Base). 109:- endif.
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 !.
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)
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.