Permalink
Browse files

* code_map/view_mainmap.ml: highlight current node just after go to o…

…ther dirs,

have to collaborate with lazy_paint and so do things via a hook
  • Loading branch information...
aryx committed Mar 7, 2014
1 parent 99a4b8d commit 0e69bb64d13d3685d93ce5ba790ad5f45f05bd57
View
@@ -16,6 +16,7 @@
*)
(*e: Facebook copyright *)
+(* refresh drawing area *)
let _refresh_da = ref (fun () ->
failwith "_refresh_da not defined"
)
@@ -24,6 +25,9 @@ let _refresh_legend = ref (fun () ->
)
let current_rects_to_draw = ref []
+let hook_finish_paint = ref (fun () ->
+ ()
+)
let current_r = ref None
View
@@ -17,6 +17,7 @@ val current_rects_to_draw:
(Treemap.treemap_rectangle list) ref
val current_r:
Treemap.treemap_rectangle option ref
+val hook_finish_paint: (unit -> unit) ref
val paint_content_maybe_refresher:
GMain.Idle.id option ref
@@ -25,9 +25,9 @@ module Controller = Controller2
(* Prelude *)
(*****************************************************************************)
-(* ---------------------------------------------------------------------- *)
+(*****************************************************************************)
(* Navigation *)
-(* ---------------------------------------------------------------------- *)
+(*****************************************************************************)
(*s: go_back *)
let go_back w =
@@ -52,7 +52,7 @@ let go_dirs_or_file ?(current_entity=None) ?(current_grep_query=None) w paths =
let root = Common2.common_prefix_of_files_or_dirs paths in
pr2 (spf "zooming in %s" (Common.join "|" paths));
- (* reset the painter ? not needed because will call draw below
+ (* reset the painter? not needed because will call draw below
* which will reset it
*)
let dw = w.dw in
@@ -76,6 +76,7 @@ let go_dirs_or_file ?(current_entity=None) ?(current_grep_query=None) w paths =
* is still there *)
| None -> w.dw.current_grep_query <- dw.current_grep_query;
);
+ View_overlays.paint_initial w.dw;
View_mainmap.paint w.dw w.model;
!Controller._refresh_da ();
()
View
@@ -69,7 +69,7 @@ let pr2, _pr2_once = Common2.mk_pr2_wrappers Flag.verbose_visual
*
* The final target is the actual gtk window which is represented by cr_final.
* We copy the pixels from the pixmap dw.pm on the window. Then
- * we copy the pixels from the pixmap dw.overlay on the windown
+ * we copy the pixels from the pixmap dw.overlay on the window
* getting the final result.
*)
let assemble_layers cr_final dw =
@@ -519,6 +519,9 @@ let mk_gui ~screen_size ~legend test_mode w =
);
Controller._go_back := Ui_navigation.go_back;
Controller._go_dirs_or_file := Ui_navigation.go_dirs_or_file;
+ Controller.hook_finish_paint := (fun () ->
+ View_overlays.hook_finish_paint w
+ );
(*-------------------------------------------------------------------*)
(* status bar *)
View
@@ -102,7 +102,7 @@ let paint_content_maybe_rect ~user_rect dw model rect =
)
(* todo: deadlock: M.locked (fun () -> ) dw.M.model.M.m *)
-let lazy_paint ~user_rect dw model () =
+let lazy_paint user_rect dw model () =
pr2 "Lazy Paint";
let start = Unix.gettimeofday () in
while Unix.gettimeofday () - start < 0.3 do
@@ -115,7 +115,12 @@ let lazy_paint ~user_rect dw model () =
done;
!Ctl._refresh_da ();
if !Ctl.current_rects_to_draw = []
- then false
+ then begin
+ !Ctl.hook_finish_paint ();
+ !Ctl._refresh_da ();
+ false
+ end
+ (* call me again *)
else true
let paint2 dw model =
@@ -150,13 +155,8 @@ let paint2 dw model =
then begin
Ctl.current_rects_to_draw := rects;
Ctl.paint_content_maybe_refresher :=
- Some (Gui.gmain_idle_add ~prio:3000 (lazy_paint ~user_rect dw model));
- end;
-
- (* also clear the overlay *)
- let cr_overlay = Cairo.create dw.overlay in
- CairoH.clear cr_overlay;
- ()
+ Some (Gui.gmain_idle_add ~prio:3000 (lazy_paint user_rect dw model));
+ end
let paint a b =
Common.profile_code "View.paint" (fun () -> paint2 a b)
View
@@ -271,11 +271,28 @@ let draw_searched_rectangles ~dw =
(* Assembling overlays *)
(*****************************************************************************)
+let paint_initial dw =
+ let cr_overlay = Cairo.create dw.overlay in
+ CairoH.clear cr_overlay
+ (* can't do draw_deps_entities w.current_node here because
+ * of lazy_paint(), the file content will not be ready yet
+ *)
+
+(* a bit ugly, but have to because of lazy_paint optimization *)
+let hook_finish_paint w =
+ pr2 "Hook_finish_paint";
+ let dw = w.dw in
+ w.current_node +> Common.do_option (fun n ->
+ let model = Async.async_get w.model in
+ draw_deps_entities n dw model
+ )
+
(*s: motion_refresher *)
let motion_refresher ev w =
+ paint_initial w.dw;
+ hook_finish_paint w;
let dw = w.dw in
let cr_overlay = Cairo.create dw.overlay in
- CairoH.clear cr_overlay;
(* some similarity with View_mainmap.button_action handler *)
let x, y = GdkEvent.Motion.x ev, GdkEvent.Motion.y ev in
@@ -330,7 +347,6 @@ let motion_refresher ev w =
draw_deps_files tr dw model;
entity_opt +> Common.do_option (fun _n -> w.current_node <- None);
- w.current_node +> Common.do_option (fun n -> draw_deps_entities n dw model);
entity_def_opt +> Common.do_option (fun n -> draw_deps_entities n dw model);
entity_use_opt +> Common.do_option (fun n -> draw_deps_entities n dw model);
@@ -6,4 +6,9 @@ val draw_searched_rectangles:
val motion_notify:
Model2.world -> GdkEvent.Motion.t -> bool
+val paint_initial:
+ Model2.drawing -> unit
+val hook_finish_paint:
+ Model2.world -> unit
+
(*e: view_overlays.mli *)

0 comments on commit 0e69bb6

Please sign in to comment.