removing entries and creating subtrees kinda works
This commit is contained in:
198
main.ml
198
main.ml
@ -1012,8 +1012,9 @@ module Panel = struct
|
|||||||
add [([], Code Enter)]
|
add [([], Code Enter)]
|
||||||
[ Custom
|
[ Custom
|
||||||
(fun () ->
|
(fun () ->
|
||||||
me.handle (Textedit.contents me.te) ;
|
(* set input first so a modal can trigger another modal *)
|
||||||
me.input <- None ) ]
|
me.input <- None ;
|
||||||
|
me.handle (Textedit.contents me.te) ) ]
|
||||||
Textedit.bindings in
|
Textedit.bindings in
|
||||||
me.te.keybind.bindings <- keybinds ;
|
me.te.keybind.bindings <- keybinds ;
|
||||||
{ act=
|
{ act=
|
||||||
@ -1167,61 +1168,14 @@ module Store = struct
|
|||||||
|
|
||||||
let editor ?(branch = "current") storepath : Panel.t =
|
let editor ?(branch = "current") storepath : Panel.t =
|
||||||
let sv = make_storeview storepath branch in
|
let sv = make_storeview storepath branch in
|
||||||
let te = Panel.Textedit.make "" () in
|
|
||||||
let top = Toplevel.init () in
|
let top = Toplevel.init () in
|
||||||
let modalstate = Panel.Modal.make () in
|
let modalstate = Panel.Modal.make () in
|
||||||
directives top sv ;
|
let te = Panel.Textedit.make "" () in
|
||||||
let save store path content =
|
let save store path content =
|
||||||
Lwt_main.run
|
Lwt_main.run
|
||||||
(Istore.set_exn store
|
(Istore.set_exn store
|
||||||
~info:(Irmin_unix.info "editor-save")
|
~info:(Irmin_unix.info "editor-save")
|
||||||
path content ) in
|
path content ) in
|
||||||
let navbinds =
|
|
||||||
let open Input.Bind in
|
|
||||||
let new_contents name content =
|
|
||||||
Lwt_main.run
|
|
||||||
(let s =
|
|
||||||
match Istore.Key.rdecons sv.selection with
|
|
||||||
| Some (t, _) -> t
|
|
||||||
| None -> Istore.Key.empty in
|
|
||||||
Istore.get_tree sv.store (sv.view @ s)
|
|
||||||
>>= fun tree ->
|
|
||||||
Istore.Tree.add tree name content
|
|
||||||
>>= fun newtree ->
|
|
||||||
Istore.set_tree_exn
|
|
||||||
~info:(Irmin_unix.info "new Contents")
|
|
||||||
sv.store sv.view newtree ) in
|
|
||||||
add [([], Char 'n')] [Custom (navigate sv `Next)]
|
|
||||||
@@ add [([], Char 'p')] [Custom (navigate sv `Prev)]
|
|
||||||
@@ add [([], Char 'w')] [Custom (navigate sv `Prev)]
|
|
||||||
@@ add [([], Char 's')] [Custom (navigate sv `Next)]
|
|
||||||
@@ add [([], Char 'd')] [Custom (navigate sv `Sub)]
|
|
||||||
@@ add [([], Char 'a')] [Custom (navigate sv `Sup)]
|
|
||||||
@@ add [([], Char 'e')]
|
|
||||||
[Custom (fun () -> sv.editmode <- not sv.editmode)]
|
|
||||||
@@ add
|
|
||||||
[([], Char 'f')] (* find: enter path in modal *)
|
|
||||||
[Custom (fun () -> ())]
|
|
||||||
@@ add
|
|
||||||
[([], Char 'c')] (* contents: create new contents node *)
|
|
||||||
[ Custom
|
|
||||||
(fun () ->
|
|
||||||
Panel.Modal.start ~prompt:"Contents name > "
|
|
||||||
modalstate "" (fun name ->
|
|
||||||
new_contents (Istore.Key.v [name]) "" ) ) ]
|
|
||||||
@@ add [([], Char 't')]
|
|
||||||
[ Custom
|
|
||||||
(fun () ->
|
|
||||||
Panel.Modal.start ~prompt:"Node name := " modalstate
|
|
||||||
"" (fun nodename ->
|
|
||||||
Panel.Modal.start
|
|
||||||
~prompt:"Initial Contents name > " modalstate
|
|
||||||
"" (fun contentsname ->
|
|
||||||
new_contents
|
|
||||||
(Istore.Key.v [nodename; contentsname])
|
|
||||||
"" ) ) ) ]
|
|
||||||
(* tree: create new subtree *)
|
|
||||||
empty in
|
|
||||||
let editbinds =
|
let editbinds =
|
||||||
let open Input.Bind in
|
let open Input.Bind in
|
||||||
add
|
add
|
||||||
@ -1245,28 +1199,111 @@ module Store = struct
|
|||||||
(fun () ->
|
(fun () ->
|
||||||
Toplevel.eval top (Panel.Textedit.contents te) ) ]
|
Toplevel.eval top (Panel.Textedit.contents te) ) ]
|
||||||
Panel.Textedit.bindings in
|
Panel.Textedit.bindings in
|
||||||
|
te.keybind.bindings <- editbinds ;
|
||||||
|
let is_node path =
|
||||||
|
Lwt_main.run
|
||||||
|
( Istore.get_tree sv.store sv.view
|
||||||
|
>>= fun t ->
|
||||||
|
Istore.Tree.kind t path
|
||||||
|
>>= function
|
||||||
|
| Some `Node -> Lwt.return_true | _ -> Lwt.return_false )
|
||||||
|
in
|
||||||
|
let update_textedit () =
|
||||||
|
Panel.Textedit.clear te ;
|
||||||
|
Lwt_main.run
|
||||||
|
( Istore.get_tree sv.store sv.view
|
||||||
|
>>= fun t ->
|
||||||
|
Istore.Tree.kind t sv.selection
|
||||||
|
>>= function
|
||||||
|
| Some `Contents ->
|
||||||
|
Istore.Tree.get t sv.selection
|
||||||
|
>>= fun content ->
|
||||||
|
Panel.Textedit.insert te content ;
|
||||||
|
Lwt.return_unit
|
||||||
|
| Some `Node ->
|
||||||
|
Panel.Textedit.insert te "Node..." ;
|
||||||
|
Lwt.return_unit
|
||||||
|
| None -> Lwt.return_unit ) in
|
||||||
|
let navbinds =
|
||||||
|
let open Input.Bind in
|
||||||
|
let new_contents name content =
|
||||||
|
Lwt_main.run
|
||||||
|
(let s =
|
||||||
|
match Istore.Key.rdecons sv.selection with
|
||||||
|
| Some (t, _) -> t
|
||||||
|
| None -> Istore.Key.empty in
|
||||||
|
Istore.get_tree sv.store (sv.view @ s)
|
||||||
|
>>= fun tree ->
|
||||||
|
Istore.Tree.add tree name content
|
||||||
|
>>= fun newtree ->
|
||||||
|
Istore.set_tree_exn
|
||||||
|
~info:(Irmin_unix.info "new Contents")
|
||||||
|
sv.store sv.view newtree ) in
|
||||||
|
add [([], Char 'n')] [Custom (navigate sv `Next)]
|
||||||
|
@@ add [([], Char 'p')] [Custom (navigate sv `Prev)]
|
||||||
|
@@ add [([], Char 'w')] [Custom (navigate sv `Prev)]
|
||||||
|
@@ add [([], Char 's')] [Custom (navigate sv `Next)]
|
||||||
|
@@ add [([], Char 'd')] [Custom (navigate sv `Sub)]
|
||||||
|
@@ add [([], Char 'a')] [Custom (navigate sv `Sup)]
|
||||||
|
@@ add [([], Char 'e')]
|
||||||
|
[ Custom
|
||||||
|
(fun () ->
|
||||||
|
if not (is_node sv.selection) then
|
||||||
|
sv.editmode <- not sv.editmode ) ]
|
||||||
|
@@ add
|
||||||
|
[([], Char 'f')] (* find: enter path in modal *)
|
||||||
|
[Custom (fun () -> ())]
|
||||||
|
@@ add
|
||||||
|
[([], Char 'c')] (* contents: create new contents node *)
|
||||||
|
[ Custom
|
||||||
|
(fun () ->
|
||||||
|
Panel.Modal.start ~prompt:"Contents name > "
|
||||||
|
modalstate "" (fun name ->
|
||||||
|
new_contents (Istore.Key.v [name]) "" ) ) ]
|
||||||
|
@@ add
|
||||||
|
[([], Char 't')] (* tree: create new subtree *)
|
||||||
|
[ Custom
|
||||||
|
(fun () ->
|
||||||
|
Panel.Modal.start ~prompt:"Node name > " modalstate
|
||||||
|
"" (fun nodename ->
|
||||||
|
Panel.Modal.start
|
||||||
|
~prompt:"Initial Contents name > " modalstate
|
||||||
|
"" (fun contentsname ->
|
||||||
|
new_contents
|
||||||
|
(Istore.Key.v [nodename; contentsname])
|
||||||
|
"" ) ) ) ]
|
||||||
|
@@ add
|
||||||
|
[([], Char 'r')] (* remove contents/node *)
|
||||||
|
[ Custom
|
||||||
|
(fun () ->
|
||||||
|
let selection = sv.selection in
|
||||||
|
navigate sv `Next () ;
|
||||||
|
Lwt_main.run
|
||||||
|
( Istore.get_tree sv.store sv.view
|
||||||
|
>>= fun tree ->
|
||||||
|
Istore.Tree.remove tree selection
|
||||||
|
>>= fun newtree ->
|
||||||
|
Istore.set_tree_exn
|
||||||
|
~info:(Irmin_unix.info "remove Contents/Node")
|
||||||
|
sv.store sv.view newtree ) ) ]
|
||||||
|
@@ add
|
||||||
|
[([], Char 'x')] (* execute contents/node *)
|
||||||
|
[ Custom
|
||||||
|
(fun () ->
|
||||||
|
Panel.Modal.start ~prompt:"!!Not implemented!!"
|
||||||
|
modalstate "" (fun _ -> ()) ) ]
|
||||||
|
empty in
|
||||||
let bindstate = Input.Bind.init navbinds in
|
let bindstate = Input.Bind.init navbinds in
|
||||||
{ act=
|
{ act=
|
||||||
(fun panel events ->
|
(fun panel events ->
|
||||||
if sv.editmode then bindstate.bindings <- editbinds
|
if
|
||||||
else bindstate.bindings <- navbinds ;
|
(not sv.editmode)
|
||||||
List.iter
|
&& not (Panel.Modal.is_active modalstate)
|
||||||
Input.Bind.(function Custom f -> f () | _ -> ())
|
then (
|
||||||
(Event.actions_of_events bindstate events) ;
|
List.iter
|
||||||
if not sv.editmode then (
|
Input.Bind.(function Custom f -> f () | _ -> ())
|
||||||
let contents =
|
(Event.actions_of_events bindstate events) ;
|
||||||
Lwt_main.run
|
update_textedit () ) ;
|
||||||
( Istore.get_tree sv.store sv.view
|
|
||||||
>>= fun t ->
|
|
||||||
Istore.Tree.kind t sv.selection
|
|
||||||
>>= function
|
|
||||||
| Some a -> (
|
|
||||||
match a with
|
|
||||||
| `Contents -> Istore.Tree.get t sv.selection
|
|
||||||
| `Node -> Lwt.return "Node..." )
|
|
||||||
| None -> Lwt.return "Invalid Selection..." ) in
|
|
||||||
Panel.Textedit.clear te ;
|
|
||||||
Panel.Textedit.insert te contents ) ;
|
|
||||||
(Panel.vbox panel.subpanels).act panel events )
|
(Panel.vbox panel.subpanels).act panel events )
|
||||||
; subpanels=
|
; subpanels=
|
||||||
[ Panel.filter_events
|
[ Panel.filter_events
|
||||||
@ -1279,7 +1316,7 @@ module Store = struct
|
|||||||
(tree : Istore.tree) (sel : Istore.key) =
|
(tree : Istore.tree) (sel : Istore.key) =
|
||||||
List.iteri
|
List.iteri
|
||||||
(fun _i (step, node) ->
|
(fun _i (step, node) ->
|
||||||
Format.pp_open_hovbox pp indent ;
|
Format.pp_open_box pp indent ;
|
||||||
if sel = [step] then (
|
if sel = [step] then (
|
||||||
Format.pp_open_stag pp
|
Format.pp_open_stag pp
|
||||||
Display.(
|
Display.(
|
||||||
@ -1308,16 +1345,17 @@ module Store = struct
|
|||||||
Lwt_main.run (Istore.get_tree sv.store sv.view)
|
Lwt_main.run (Istore.get_tree sv.store sv.view)
|
||||||
in
|
in
|
||||||
draw_levels root sv.selection )
|
draw_levels root sv.selection )
|
||||||
; Panel.filter_events
|
; Panel.vbox
|
||||||
(fun ev -> if sv.editmode then ev else [])
|
[ Panel.filter_events
|
||||||
(Panel.Textedit.panel te)
|
(fun ev -> if sv.editmode then ev else [])
|
||||||
; Panel.prettyprint (fun pp ->
|
(Panel.Textedit.panel te)
|
||||||
Format.pp_open_hovbox pp 0 ;
|
; Panel.prettyprint (fun pp ->
|
||||||
Panel.format_symbolic_output_buffer pp
|
Format.pp_open_hovbox pp 0 ;
|
||||||
(Format.get_symbolic_output_buffer
|
Panel.format_symbolic_output_buffer pp
|
||||||
(Toplevel.result_sob top) ) ;
|
(Format.get_symbolic_output_buffer
|
||||||
Format.pp_close_box pp () ;
|
(Toplevel.result_sob top) ) ;
|
||||||
F.flush pp () ) ]
|
Format.pp_close_box pp () ;
|
||||||
|
F.flush pp () ) ] ]
|
||||||
; Panel.Textedit.bindingstate bindstate
|
; Panel.Textedit.bindingstate bindstate
|
||||||
; Panel.prettyprint (fun pp ->
|
; Panel.prettyprint (fun pp ->
|
||||||
Format.fprintf pp "sv.editmode = %b @." sv.editmode ) ]
|
Format.fprintf pp "sv.editmode = %b @." sv.editmode ) ]
|
||||||
|
|||||||
Reference in New Issue
Block a user