aboutsummaryrefslogtreecommitdiff
path: root/ide
diff options
context:
space:
mode:
authorHugo Herbelin2018-11-03 15:52:23 +0100
committerHugo Herbelin2019-09-10 12:03:18 +0200
commit968f9b59f390182c3123217dd5b13f80a2ee08c2 (patch)
tree700d389448be144740749e58fc208e8d441d3598 /ide
parent9ef674aff93396262966de8f9a583e1eae7889b9 (diff)
Being more informative on the steps of selection of the preference file.
Diffstat (limited to 'ide')
-rw-r--r--ide/coqide_main.ml4
-rw-r--r--ide/minilib.ml12
-rw-r--r--ide/minilib.mli15
-rw-r--r--ide/preferences.ml83
-rw-r--r--ide/preferences.mli2
5 files changed, 86 insertions, 30 deletions
diff --git a/ide/coqide_main.ml b/ide/coqide_main.ml
index f2ce2e8bd9..6f4c0ece31 100644
--- a/ide/coqide_main.ml
+++ b/ide/coqide_main.ml
@@ -49,9 +49,7 @@ let catch_gtk_messages () =
let () = catch_gtk_messages ()
let load_prefs () =
- try Preferences.load_pref ()
- with e -> Ideutils.flash_info
- ("Could not load preferences ("^Printexc.to_string e^").")
+ Preferences.load_pref ~warn:(fun ~delay -> Ideutils.flash_info ~delay)
let () =
load_prefs ();
diff --git a/ide/minilib.ml b/ide/minilib.ml
index 09a7112098..04beb212ab 100644
--- a/ide/minilib.ml
+++ b/ide/minilib.ml
@@ -58,10 +58,16 @@ let coqide_data_dirs () =
:: List.map coqify (Glib.get_system_data_dirs ())
@ [Envars.datadir ()]
+let coqide_system_config_dirs () =
+ List.map coqify (Glib.get_system_config_dirs ())
+
+let coqide_default_config_dir () =
+ Envars.configdir ()
+
let coqide_config_dirs () =
- coqide_config_home ()
- :: List.map coqify (Glib.get_system_config_dirs ())
- @ [Envars.configdir ()]
+ coqide_config_home () ::
+ coqide_system_config_dirs () @
+ [coqide_default_config_dir ()]
let is_prefix_of pre s =
let i = ref 0 in
diff --git a/ide/minilib.mli b/ide/minilib.mli
index c5849cc2c9..7022d7d256 100644
--- a/ide/minilib.mli
+++ b/ide/minilib.mli
@@ -27,7 +27,22 @@ val debug : bool ref
val log_pp : ?level:level -> Pp.t -> unit
val log : ?level:level -> string -> unit
+(* The directory where user config files are conventionally *)
+(* installed on the current platform (as given by Glib) *)
val coqide_config_home : unit -> string
+
+(* The directories where system-wide config files are conventionally *)
+(* installed on the current platform (as given by Glib) *)
+val coqide_system_config_dirs : unit -> string list
+
+(* The directory where default config files are installed at installation time *)
+val coqide_default_config_dir : unit -> string
+
+(* The ordered list of directories where a config file is searched by default *)
val coqide_config_dirs : unit -> string list
+
+(* The ordered list of directories where a data file is searched by default *)
val coqide_data_dirs : unit -> string list
+
+(* Misc *)
val is_prefix_of : string -> string -> bool
diff --git a/ide/preferences.ml b/ide/preferences.ml
index 52122441a1..10d779263b 100644
--- a/ide/preferences.ml
+++ b/ide/preferences.ml
@@ -10,8 +10,6 @@
open Configwin
-let pref_file = Filename.concat (Minilib.coqide_config_home ()) "coqiderc"
-let accel_file = Filename.concat (Minilib.coqide_config_home ()) "coqide.keys"
let lang_manager = GSourceView3.source_language_manager ~default:true
let () = lang_manager#set_search_path
((Minilib.coqide_data_dirs ())@lang_manager#search_path)
@@ -235,22 +233,13 @@ end
end
-let get_config_file name =
+let get_config_file dirs name =
let find_config dir = Sys.file_exists (Filename.concat dir name) in
- let config_dir = List.find find_config (Minilib.coqide_config_dirs ()) in
+ let config_dir = List.find find_config dirs in
Filename.concat config_dir name
-(* Small hack to handle v8.3 to v8.4 change in configuration file *)
-let loaded_pref_file =
- try get_config_file "coqiderc"
- with Not_found -> Filename.concat (Option.default "" (Glib.get_home_dir ())) ".coqiderc"
-
-let loaded_accel_file =
- try get_config_file "coqide.keys"
- with Not_found -> Filename.concat (Option.default "" (Glib.get_home_dir ())) ".coqide.keys"
-
let get_unicode_bindings_local_file () =
- try Some (get_config_file "coqide.bindings")
+ try Some (get_config_file [Minilib.coqide_config_home ()] "coqide.bindings")
with Not_found -> None
let get_unicode_bindings_default_file () =
@@ -648,30 +637,78 @@ let tag_button () =
let box = GPack.hbox () in
new tag_button (Gobject.unsafe_cast box#as_widget)
-let save_pref () =
+(** Loading/saving preferences *)
+
+let pref_file = Filename.concat (Minilib.coqide_config_home ()) "coqiderc"
+let accel_file = Filename.concat (Minilib.coqide_config_home ()) "coqide.keys"
+
+let save_accel_pref () =
+ if not (Sys.file_exists (Minilib.coqide_config_home ()))
+ then Unix.mkdir (Minilib.coqide_config_home ()) 0o700;
+ GtkData.AccelMap.save accel_file
+
+let save_rc_pref () =
if not (Sys.file_exists (Minilib.coqide_config_home ()))
then Unix.mkdir (Minilib.coqide_config_home ()) 0o700;
- let () = try GtkData.AccelMap.save accel_file with _ -> () in
let add = Util.String.Map.add in
let fold key obj accu = add key (obj.get ()) accu in
let prefs = Util.String.Map.fold fold !preferences Util.String.Map.empty in
let prefs = Util.String.Map.fold Util.String.Map.add !unknown_preferences prefs in
Config_lexer.print_file pref_file prefs
-let load_pref () =
- (* Load main preference file *)
- let () =
- let m = Config_lexer.load_file loaded_pref_file in
+let save_pref () =
+ save_accel_pref ();
+ save_rc_pref ()
+
+let try_load_pref_file loader warn file =
+ try
+ loader file
+ with
+ e -> warn ~delay:5000 ("Could not load " ^ file ^ " ("^Printexc.to_string e^")")
+
+let load_pref_file loader warn name =
+ try
+ let user_file = get_config_file [Minilib.coqide_config_home ()] name in
+ warn ~delay:2000 ("Loading " ^ user_file);
+ try_load_pref_file loader warn user_file
+ with Not_found ->
+ try
+ let system_wide_file = get_config_file (Minilib.coqide_system_config_dirs ()) name in
+ warn ~delay:5000 ("No user " ^ name ^ ", using system wide configuration");
+ try_load_pref_file loader warn system_wide_file
+ with Not_found ->
+ (* Compatibility with oldest versions of CoqIDE (<= 8.4) *)
+ try
+ let old_user_file = get_config_file [Option.default "" (Glib.get_home_dir ())] ("."^name) in
+ warn ~delay:5000 ("No " ^ name ^ ", trying to recover from an older version of CoqIDE");
+ try_load_pref_file loader warn old_user_file
+ with Not_found ->
+ (* Built-in configuration *)
+ try
+ let default_file = get_config_file [Minilib.coqide_default_config_dir ()] name in
+ warn ~delay:5000 ("No " ^ name ^ ", using default configuration file");
+ try_load_pref_file loader warn default_file
+ with Not_found ->
+ warn ~delay:5000 ("No " ^ name ^ ", using default internal configuration")
+
+let load_accel_pref ~warn =
+ load_pref_file GtkData.AccelMap.load warn "coqide.keys"
+
+let load_rc_pref ~warn =
+ let loader file =
+ let m = Config_lexer.load_file file in
let iter name v =
if Util.String.Map.mem name !preferences then
try (Util.String.Map.find name !preferences).set v with _ -> ()
else unknown_preferences := Util.String.Map.add name v !unknown_preferences
in
Util.String.Map.iter iter m in
- (* Load file for bindings *)
+ load_pref_file loader warn "coqiderc";
attach_modifiers_callback ()
- let () = try GtkData.AccelMap.load loaded_accel_file with _ -> () in
- ()
+
+let load_pref ~warn =
+ load_rc_pref ~warn;
+ load_accel_pref ~warn
let pstring name p = string ~f:p#set name p#get
let pbool name p = bool ~f:p#set name p#get
diff --git a/ide/preferences.mli b/ide/preferences.mli
index 490756d4f2..6da6228545 100644
--- a/ide/preferences.mli
+++ b/ide/preferences.mli
@@ -107,7 +107,7 @@ val user_queries : (string * string) list preference
val diffs : string preference
val save_pref : unit -> unit
-val load_pref : unit -> unit
+val load_pref : warn:(delay:int -> string -> unit) -> unit
val configure : ?apply:(unit -> unit) -> GWindow.window -> unit