From 82b6b29f0f4aa4e72d7c72ec8e120dd3ee6945d1 Mon Sep 17 00:00:00 2001 From: malc Date: Tue, 9 Aug 2011 11:53:45 +0400 Subject: [PATCH] Add help/info modes (Ab)use outline mode to do that --- KEYS | 4 +++- build.ml | 25 +++++++++++++++++++-- build.sh | 6 ++++- buildall.sh | 10 +++++++-- keystoml.ml | 26 +++++++++++++++++++++ main.ml | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- mkhelp.sh | 3 +++ 7 files changed, 142 insertions(+), 7 deletions(-) create mode 100644 keystoml.ml create mode 100644 mkhelp.sh diff --git a/KEYS b/KEYS index 2860d59..a6f5aef 100644 --- a/KEYS +++ b/KEYS @@ -24,6 +24,8 @@ delete - go to the previous page w - change height to encompass all of the page o - switch to outline mode ' - switch to bookmark mode +h - switch to help mode +i - switch to info mode m - create named bookmark ~ - create quick bookmark z - crop @@ -75,7 +77,7 @@ home/end - go to first/last page enter - select the page and leave bird's eye mode 1st mouse button - select the page under cursor and leave bird's eye mode -outline/bookmark mode +outline/bookmark/help/info mode esc - leave outline/bookmark mode up/down - select previous/next item alpha-numeric - quick search diff --git a/build.ml b/build.ml index 7934fe6..3dc65ab 100644 --- a/build.ml +++ b/build.ml @@ -84,6 +84,25 @@ let bso name objs = let () = boc "-g" "link"; + let _ = + let mkhelp = Filename.concat srcdir "mkhelp.sh" in + let keystoml = Filename.concat srcdir "keystoml.ml" in + let keys = Filename.concat srcdir "KEYS" in + let cmd = "sh " ^ mkhelp ^ " " ^ keystoml ^ " " ^ keys ^ "> help.ml" in + let build = + { get_commands = (fun _ -> [Run cmd]) + ; get_cookie = (fun _ -> "") + ; get_presentation = (fun _ -> "KEYSTOML KEYS") + } + in + put_build_info "help.ml" build; + let sing s = StrSet.singleton s in + add_target + "help.ml" + (sing "KEYS") + (sing "help.ml") + (StrSet.add keys (StrSet.add mkhelp (sing keystoml))) + in let so = bso "link" ["link"] in let prog name cmos = ocaml @@ -96,13 +115,15 @@ let () = StrSet.empty in let mkcmo name = - cmopp ~flags:"-g -w Alze -I +lablGL -thread" ~dirname:srcdir name; + let dirname = if name = "help" then Sys.getcwd () else srcdir in + cmopp ~flags:"-g -w Alze -I +lablGL -thread" ~dirname name; (name ^ ".cmo") in - let cmos = so :: List.map mkcmo ["parser"; "main"] in + let cmos = so :: List.map mkcmo ["help"; "parser"; "main"] in prog "llpp" cmos; ;; let () = + run start jobs ["help.ml"] false dotarlist; run start jobs targets dodeplist dotarlist; ;; diff --git a/build.sh b/build.sh index 70d9377..fcd0436 100644 --- a/build.sh +++ b/build.sh @@ -10,14 +10,18 @@ cclib="-lmupdf -lfitz -lz -ljpeg -lopenjpeg -ljbig2dec -lfreetype" export LIBRARY_PATH=$LIBRARY_PATH:$mupdflibpath export CPATH=$CPATH:$mupdfincpath +sh mkhelp.sh $srcpath/keystoml.ml $srcpath/KEYS > help.ml + ocamlc -c -o link.o -ccopt -O $srcpath/link.c -ocamlc -c -o main.cmo -I +lablGL $srcpath/main.ml +ocamlc -c -o help.cmo $srcpath/help.ml ocamlc -c -o parser.cmo $srcpath/parser.ml +ocamlc -c -o main.cmo -I +lablGL $srcpath/main.ml ocamlc -custom -o llpp \ -I +lablGL \ str.cma unix.cma lablgl.cma lablglut.cma \ link.o \ -cclib "$cclib" \ +help.cmo \ parser.cmo \ main.cmo diff --git a/buildall.sh b/buildall.sh index 8f27395..f8f9f09 100644 --- a/buildall.sh +++ b/buildall.sh @@ -56,22 +56,27 @@ cd .. srcpath=$(dirname $0) +sh mkhelp.sh $srcpath/keystoml.ml $srcpath/KEYS > help.ml + if test "$1" = "opt"; then cclib="-lmupdf -lfitz -lz -ljpeg -lopenjpeg -ljbig2dec -lfreetype -lpthread" ocamlopt -c -o link.o -ccopt -O $srcpath/link.c - ocamlopt -c -o parser.cmo $srcpath/parser.ml - ocamlopt -c -o main.cmo -I $root/lib/ocaml/lablGL $srcpath/main.ml + ocamlopt -c -o help.cmx help.ml + ocamlopt -c -o parser.cmx $srcpath/parser.ml + ocamlopt -c -o main.cmx -I $root/lib/ocaml/lablGL $srcpath/main.ml ocamlopt -o llpp \ -I $root/lib/ocaml/lablGL \ str.cmxa unix.cmxa lablgl.cmxa lablglut.cmxa \ link.o \ -cclib "$cclib" \ + help.cmx \ parser.cmx \ main.cmx else cclib="-lmupdf -lfitz -lz -ljpeg -lopenjpeg -ljbig2dec -lfreetype" ocamlc -c -o link.o -ccopt -O $srcpath/link.c + ocamlc -c -o help.cmo help.ml ocamlc -c -o parser.cmo $srcpath/parser.ml ocamlc -c -o main.cmo -I $root/lib/ocaml/lablGL $srcpath/main.ml @@ -80,6 +85,7 @@ else str.cma unix.cma lablgl.cma lablglut.cma \ link.o \ -cclib "$cclib" \ + help.cmo \ parser.cmo \ main.cmo fi diff --git a/keystoml.ml b/keystoml.ml new file mode 100644 index 0000000..e19e679 --- /dev/null +++ b/keystoml.ml @@ -0,0 +1,26 @@ +open Printf + +let lines = + let lines = + match (try Some (open_in Sys.argv.(1)) with _ -> None) with + | None -> [] + | Some ic -> + let lines = + let rec fold accu = + match (try Some (input_line ic) with _ -> None) with + | Some line -> fold (line :: accu) + | None -> List.rev accu + in + fold [] + in + close_in ic; + lines + in + lines; +;; + +let _ = + printf "let keys = [\n"; + List.iter (fun l -> printf " %S;\n" l) lines; + printf "];;\n" +;; diff --git a/main.ml b/main.ml index 348a328..b0d6ac8 100644 --- a/main.ml +++ b/main.ml @@ -211,6 +211,7 @@ type state = ; mutable gen : gen ; mutable throttle : layout list option ; mutable ascrollstep : int + ; mutable help : string list ; hists : hists } and hists = @@ -287,6 +288,7 @@ let state = ; gen = 0 ; throttle = None ; ascrollstep = 0 + ; help = Help.keys } ;; @@ -1030,7 +1032,7 @@ let setzoom zoom = then state.x <- 0; conf.zoom <- zoom; reshape conf.winw conf.winh; - state.text <- Printf.sprintf "zoom is now %f" (zoom *. 100.0); + state.text <- Printf.sprintf "zoom is now %-5.1f" (zoom *. 100.0); ); ;; @@ -1268,6 +1270,71 @@ let enterbookmarkmode () = enterselector true bookmarks "Document has no bookmarks (yet)" ""; ;; +let enterinfomode () = + let btos = function true -> "on" | _ -> "off" in + let pageno, top = getanchor () in + let help = + let autoscrollstep = + if state.ascrollstep > 0 + then state.ascrollstep + else conf.autoscrollstep + in + ("Current parameters") + :: ("version " ^ Help.version) + :: ("presentation mode " ^ btos conf.presentation) + :: ("case insensitive search " ^ btos conf.icase) + :: ("preload " ^ btos conf.preload) + :: ("page bias " ^ string_of_int conf.pagebias) + :: ("verbose " ^ btos conf.verbose) + :: ("scroll step " ^ string_of_int conf.scrollstep) + :: ("max fit " ^ btos conf.maxhfit) + :: ("crop hack " ^ btos conf.crophack) + :: ("autoscroll step " ^ string_of_int autoscrollstep) + :: ("throttle " ^ btos conf.showall) + :: ("highlight links " ^ btos conf.hlinks) + :: ("under info " ^ btos conf.underinfo) + :: ("veritcal margin " ^ string_of_int conf.interpagespace) + :: ("zoom " ^ Printf.sprintf "%-5.1f" (conf.zoom*.100.)) + :: ("rotation " ^ string_of_int conf.angle) + :: ("persistent bookmarks " ^ btos conf.savebmarks) + :: ("proportional display " ^ btos conf.proportional) + :: ("pixmap cache size " ^ string_of_int conf.memlimit) + :: ("pixmap cache used " ^ string_of_int state.memused) + :: ("thumbnail width " ^ string_of_int conf.thumbw) + :: (Printf.sprintf "window dimensions %dx%d " conf.winw conf.winh) + :: [] + in + let o = + let o = Array.create (List.length help) ("", 0, pageno, top) in + let rec iteri i = function + | [] -> () + | s :: rest -> + o.(i) <- (s, (if i = 0 then 0 else 1), pageno, top); + iteri (i+1) rest + in + iteri 0 help; + o + in + enterselector false o "Info not available" ""; +;; + +let enterhelpmode () = + let pageno, top = getanchor () in + let o = + let help = ("Keys for llpp " ^ Help.version) ::state.help in + let o = Array.create (List.length help) ("", 0, pageno, top) in + let rec iteri i = function + | [] -> () + | s :: rest -> + o.(i) <- (s, (if i = 0 then 0 else 1), pageno, top); + iteri (i+1) rest + in + iteri 0 help; + o + in + enterselector false o "Help not available" ""; +;; + let quickbookmark ?title () = match state.layout with | [] -> () @@ -1505,6 +1572,12 @@ let viewkeyboard ~key ~x ~y = | '\'' -> enterbookmarkmode () + | 'h' -> + enterhelpmode () + + | 'i' -> + enterinfomode () + | 'm' -> let ondone s = match state.layout with diff --git a/mkhelp.sh b/mkhelp.sh new file mode 100644 index 0000000..766a215 --- /dev/null +++ b/mkhelp.sh @@ -0,0 +1,3 @@ +ocaml $1 $2 +v=$(git describe --tags || echo "unknown") +printf 'let version ="%s";;\n' $v -- 2.11.4.GIT