aboutsummaryrefslogtreecommitdiff
path: root/src/sheet.mli
blob: 14856d49f7eab008e12208cfb0d8225f460b9d3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(** This module represent a sheet *)

type cell = int * int
  
module Raw: sig

  type t
  
  (** An empty sheet *)
  val empty: t
  
  (** Add a new value in the sheet. The previous value is replaced 
    @return All the successors to update and the new sheet.
  *)
  val add: cell -> Expression.t -> Functions.C.t -> t -> Cell.Set.t * t
  
  val remove: cell -> Functions.C.t -> t -> Cell.Set.t * t

  (** Get the value content. 
      @return None if the cell is not defined
   *)
  val get_value: cell -> t -> ScTypes.Result.t option
  
  val get_expr: cell -> t -> Expression.t

  val get_sink: cell -> t -> Cell.Set.t
  
  (** Fold over all the defined values *)
  val fold: ('a -> cell -> (Expression.t * ScTypes.Result.t ) -> 'a) -> 'a -> t -> 'a

end

type yank
type history

type t = {
  selected: Selection.t;    (* The selected cell *)
  data: Raw.t;
  history: history;    (* Unlimited history *)
  yank: yank list;           (* All the selected cells *)
  catalog: Functions.C.t
}

type search = [
  | `Pattern of ScTypes.Result.t option
  | `Next
  | `Previous
]

(** Undo the last action and return the previous state, if any *)
val undo: t -> t option

(** Move the cursor in one direction, return the state updated if the move is
    allowed *) 
val move: Actions.direction -> t -> t option

(** Delete the content of selected cells.
    @return The sheet and the number of cells deleted
*)
val delete: t -> t * int

(** Copy the selected cells 
    @return The sheet and the number of cells deleted
*)
val yank: t -> t * int

(** Search for a pattern on the sheet 
    @return The state updated if the pattern has been found. *)
val search: search -> t -> t option

val paste: t -> t * int

(** Add or update the sheet.
    The expression is added at current selection.
    @return A set containing all updated cells, and the tree updated. *)
val add: Expression.t -> t -> Cell.Set.t * t

(** Create an empty sheet *)
val create: Functions.C.t -> Raw.t -> t