Commit 26d12d39 authored by bguillaum's avatar bguillaum

version 2.22.1: fix option "-s"

git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/semagramme/dep2pict/trunk@8915 7838e531-6607-4d57-9587-6c381814729c
parent 2bed2c4d
......@@ -54,7 +54,7 @@ module Format = struct
match get_suffix file with
| None -> Log.fwarning "Cannot guess format (no suffix) for file \"%s\"" file; No_suff
| Some suff ->
try List.assoc suff [ (".dep",Dep); (".conll",Conll); (".png",Png); (".svg",Svg); (".pdf",Pdf)]
try List.assoc suff [ (".dep",Dep); (".conll",Conll); (".conllu",Conll); (".png",Png); (".svg",Svg); (".pdf",Pdf)]
with Not_found -> Log.fwarning "Unkwnow file extension \"%s\" for file \"%s\"" suff file; Unk suff
let to_string = function
......@@ -93,34 +93,28 @@ let get_id () =
| _ -> Log.critical "[get_id] can be use only with CONLL data"
(* -------------------------------------------------------------------------------- *)
exception Found of int
let array_assoc key array =
let len = Array.length array in
let rec loop i =
if i = len
then raise Not_found
else
match array.(i) with
| (k,v) when k=key -> (i,v)
| _ -> loop (i+1)
in loop 0
try
Array.iteri (fun i (k,_) -> if k = key then raise (Found i)) array;
None
with Found i -> Some i
(* -------------------------------------------------------------------------------- *)
let search_sentid sentid =
match !current_data with
| Conll arr ->
let (new_pos,_) = array_assoc sentid arr in current_position := new_pos
begin
match array_assoc sentid arr with
| Some p -> current_position := p
| None -> Log.fwarning "No conll struct with name \"%s\"" sentid
end
| _ -> Log.critical "[search_sentid] can be use only with CONLL data"
(* -------------------------------------------------------------------------------- *)
let set_position () =
match (!current_data, !current_position, !requested_sentid) with
| (Conll _, _, Some sentid) -> (
try search_sentid sentid
with Not_found ->
Log.fwarning "sentid %s cannot be found, set position to 0" sentid;
current_position := 0
)
| (Conll _, _, Some sentid) -> search_sentid sentid
| (Conll arr, p, None) when p < 0 || p >= (Array.length arr) ->
Log.fwarning "position %d is out of bounds, set position to 0" p;
current_position := 0
......
......@@ -75,8 +75,9 @@ let main () =
then (ui#scroll#hadjustment#set_value !user_hpos; user_hpos := 0.);
true) in
let reload () =
let reload first =
load !input_file;
if first then set_position ();
input_last_modifaction_time := (let stat = Unix.stat !input_file in stat.Unix.st_mtime);
user_hpos := ui#scroll#hadjustment#value; (* Hack (cf above) *)
refresh_view () in
......@@ -86,15 +87,10 @@ let main () =
~ms:1000
~callback:
(fun () ->
(* begin
match !input_file with
| None -> ()
| Some filename ->
let stat = Unix.stat filename in
if stat.Unix.st_mtime > !input_last_modifaction_time
then reload ()
end;
*) true
let stat = Unix.stat !input_file in
if stat.Unix.st_mtime > !input_last_modifaction_time
then reload false;
true
) in
(* -------------------------------------------------------------------------------- *)
......@@ -111,7 +107,7 @@ let main () =
match dialog#run () with
| `OPEN ->
(match dialog#filename with
| Some f -> input_file := f; reload ();
| Some f -> input_file := f; reload false;
| None -> ())
| `DELETE_EVENT | `CANCEL -> ()
end ;
......@@ -149,7 +145,7 @@ let main () =
() in
let _ = ui#reload#connect#clicked ~callback:reload in
let _ = ui#reload#connect#clicked ~callback:(fun () -> reload false) in
let _ = GMisc.image ~stock:`REFRESH ~packing: ui#reload_box#pack () in
let _ = ui#open_button#connect#clicked ~callback:open_dep in
......@@ -187,7 +183,7 @@ let main () =
let modif = GdkEvent.Key.state ev in
begin
match modif with
| [`CONTROL] when key = _r -> reload ()
| [`CONTROL] when key = _r -> reload false
| [`CONTROL] when key = _o -> open_dep ()
| [] when key = _Left ->
......@@ -207,6 +203,6 @@ let main () =
ui#check_widgets ();
ui#toplevel#show ();
reload ();
reload true;
GMain.Main.main ()
......@@ -8,7 +8,7 @@ open Global
let version = VERSION
let _ =
Log.set_active_levels [`INFO];
Log.set_active_levels [`INFO; `WARNING];
Log.set_info_label "DEP2PICT";
Log.set_critical_label "DEP2PICT";
Log.set_write_to_log_file false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment