Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Commit

Permalink
* code_map/view_mainmap.ml: highlight currently selected node
Browse files Browse the repository at this point in the history
  • Loading branch information
pad committed Mar 7, 2014
1 parent 967ca3e commit 99a4b8d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
2 changes: 2 additions & 0 deletions code_map/model2.ml
Expand Up @@ -181,6 +181,8 @@ type world = {
treemap_func: Common.path list -> Treemap.treemap_rendering;
(* misc settings, not really used for now *)
settings: settings;

mutable current_node: Graph_code.node option;
}
and settings = {
mutable draw_summary: bool;
Expand Down
2 changes: 2 additions & 0 deletions code_map/model2.mli
Expand Up @@ -133,6 +133,8 @@ type world = {
treemap_func: Common.path list -> Treemap.treemap_rendering;
(* misc settings, not really used for now *)
settings: settings;

mutable current_node: Graph_code.node option;
}
and settings = {
mutable draw_summary: bool;
Expand Down
32 changes: 24 additions & 8 deletions code_map/view_mainmap.ml
Expand Up @@ -226,12 +226,16 @@ let button_action w ev =
glyph_opt >>= (fun glyph ->
M.find_use_entity_at_line_and_glyph_opt line glyph tr dw model))
in

let entity_opt =
match entity_use_opt, entity_def_opt with
| Some e, _ | _, Some e -> Some e
| _ -> None
in

let uses, users =
match entity_def_opt, entity_use_opt with
| None, None -> M.deps_readable_files_of_file file model
| Some n, _ | _, Some n -> M.deps_readable_files_of_node n model
match entity_opt with
| None -> M.deps_readable_files_of_file file model
| Some n -> M.deps_readable_files_of_node n model
in

let paths_of_readables xs =
Expand All @@ -248,24 +252,36 @@ let button_action w ev =
+> List.filter Sys.file_exists
in
let readable = Common.readable ~root:model.root file in
let readable =
match entity_opt with
| None -> readable
| Some n ->
let g = Common2.some model.g in
try Graph_code.file_of_node n g
with Not_found -> readable
in
let entries = [
`I ("go to file", (fun () ->
!Ctl._go_dirs_or_file w (paths_of_readables [readable]);));
`I ("deps inout", (fun () ->
w.current_node <- entity_opt;
!Ctl._go_dirs_or_file w (paths_of_readables
(uses @ users @ [readable]))));
`I ("deps in (users)", (fun () ->
w.current_node <- entity_opt;
!Ctl._go_dirs_or_file w (paths_of_readables
(users @ [readable]))));
`I ("deps out (uses)", (fun () ->
w.current_node <- entity_opt;
!Ctl._go_dirs_or_file w (paths_of_readables
(uses @ [readable]))));
] in
let entries =
entries @
(match entity_def_opt, entity_use_opt, model.g with
| None, None, _ -> []
| Some n, _, Some g | _, Some n, Some g ->
(match entity_opt with
| None -> []
| Some n ->
let g = Common2.some model.g in
[`I ("info entity", (fun () ->
let users = Graph_code.pred n (Graph_code.Use) g in
let str =
Expand All @@ -276,11 +292,11 @@ let button_action w ev =
Gui.dialog_text ~text:str ~title:"Info entity";
));
`I ("goto def", (fun () ->
w.current_node <- entity_opt;
let dest = Graph_code.file_of_node n g in
!Ctl._go_dirs_or_file w (paths_of_readables [dest])
));
]
| _ -> raise Impossible
)
in
GToolbox.popup_menu ~entries ~button:3
Expand Down
14 changes: 10 additions & 4 deletions code_map/view_overlays.ml
Expand Up @@ -286,6 +286,7 @@ let motion_refresher ev w =
r_opt +> Common.do_option (fun (tr, middle, r_englobing) ->
let model = Async.async_get w.model in

(* coupling: similar code in right click handler in View_mainmap *)
let line_opt =
M.find_line_in_rectangle_at_user_point user tr dw in
let glyph_opt =
Expand All @@ -297,6 +298,11 @@ let motion_refresher ev w =
glyph_opt >>= (fun glyph ->
M.find_use_entity_at_line_and_glyph_opt line glyph tr dw model))
in
let entity_opt =
match entity_use_opt, entity_def_opt with
| Some e, _ | _, Some e -> Some e
| _ -> None
in

let statusbar_txt =
tr.T.tr_label ^
Expand All @@ -323,10 +329,10 @@ let motion_refresher ev w =
draw_englobing_rectangles_overlay ~dw (tr, middle, r_englobing);
draw_deps_files tr 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);
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);

if w.settings.draw_searched_rectangles;
then draw_searched_rectangles ~dw;
Expand Down
1 change: 1 addition & 0 deletions main_codemap.ml
Expand Up @@ -380,6 +380,7 @@ let main_action xs =
dw_stack = ref [dw];
model = async_model;
treemap_func;
current_node = None;
settings = { Model.
(* todo: too fuzzy for now *)
draw_summary = false;
Expand Down

0 comments on commit 99a4b8d

Please sign in to comment.