From 2095acb4c3ef6396097868d30594a8b22050d835 Mon Sep 17 00:00:00 2001 From: malc Date: Mon, 8 Aug 2011 16:54:10 +0400 Subject: [PATCH] Refactoring #3 --- main.ml | 84 ++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 41 insertions(+), 43 deletions(-) diff --git a/main.ml b/main.ml index d22831c..67d9c51 100644 --- a/main.ml +++ b/main.ml @@ -1528,52 +1528,50 @@ let textentrykeyboard ~key ~x ~y (c, text, opthist, onkey, ondone) = enttext (); Glut.postRedisplay () in - if key = 8 - then - let len = String.length text in - if len = 0 - then ( - state.mode <- View; - Glut.postRedisplay (); - ) - else ( - let s = String.sub text 0 (len - 1) in - enttext (c, s, opthist, onkey, ondone) - ) - else ( - match Char.unsafe_chr key with - | '\r' | '\n' -> - ondone text; + match Char.unsafe_chr key with + | '\008' -> + let len = String.length text in + if len = 0 + then ( state.mode <- View; - Glut.postRedisplay () + Glut.postRedisplay (); + ) + else ( + let s = String.sub text 0 (len - 1) in + enttext (c, s, opthist, onkey, ondone) + ) - | '\027' -> - begin match opthist with - | None -> () - | Some (_, onhistcancel) -> onhistcancel () - end; - state.mode <- View; - Glut.postRedisplay () + | '\r' | '\n' -> + ondone text; + state.mode <- View; + Glut.postRedisplay () - | _ -> - begin match onkey text key with - | TEdone text -> - state.mode <- View; - ondone text; - Glut.postRedisplay () - - | TEcont text -> - enttext (c, text, opthist, onkey, ondone); - - | TEstop -> - state.mode <- View; - Glut.postRedisplay () - - | TEswitch te -> - state.mode <- Textentry te; - Glut.postRedisplay () - end; - ); + | '\027' -> + begin match opthist with + | None -> () + | Some (_, onhistcancel) -> onhistcancel () + end; + state.mode <- View; + Glut.postRedisplay () + + | _ -> + begin match onkey text key with + | TEdone text -> + state.mode <- View; + ondone text; + Glut.postRedisplay () + + | TEcont text -> + enttext (c, text, opthist, onkey, ondone); + + | TEstop -> + state.mode <- View; + Glut.postRedisplay () + + | TEswitch te -> + state.mode <- Textentry te; + Glut.postRedisplay () + end; ;; let birdseyekeyboard ~key ~x ~y ((c, leftx, pageno, hooverpageno) as beye) = -- 2.11.4.GIT