author | wenzelm |
Thu, 12 Jan 2012 21:50:00 +0100 | |
changeset 46198 | cd040c5772de |
parent 46178 | 1c5c88f6feb5 |
child 46208 | 4cab63a6dc16 |
permissions | -rw-r--r-- |
36676 | 1 |
/* Title: Pure/PIDE/document.scala |
2 |
Author: Makarius |
|
3 |
||
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
4 |
Document as collection of named nodes, each consisting of an editable |
38418
9a7af64d71bb
more explicit / functional ML version of document model;
wenzelm
parents:
38417
diff
changeset
|
5 |
list of commands, associated with asynchronous execution process. |
36676 | 6 |
*/ |
34407 | 7 |
|
34871
e596a0b71f3c
incorporate "proofdocument" part into main Isabelle/Pure.jar -- except for html_panel.scala, which depends on external library (Lobo/Cobra browser);
wenzelm
parents:
34868
diff
changeset
|
8 |
package isabelle |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
9 |
|
34760 | 10 |
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
11 |
import scala.collection.mutable |
37073 | 12 |
|
13 |
||
34823 | 14 |
object Document |
34483 | 15 |
{ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
16 |
/* formal identifiers */ |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
17 |
|
38363
af7f41a8a0a8
clarified "state" (accumulated data) vs. "exec" (execution that produces data);
wenzelm
parents:
38361
diff
changeset
|
18 |
type ID = Long |
43780 | 19 |
val ID = Properties.Value.Long |
38414
49f1f657adc2
more basic Markup.parse_int/print_int (using signed_string_of_int) (ML);
wenzelm
parents:
38374
diff
changeset
|
20 |
|
38373 | 21 |
type Version_ID = ID |
38363
af7f41a8a0a8
clarified "state" (accumulated data) vs. "exec" (execution that produces data);
wenzelm
parents:
38361
diff
changeset
|
22 |
type Command_ID = ID |
38373 | 23 |
type Exec_ID = ID |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
24 |
|
43662
e3175ec00311
Document.no_id/new_id as in ML (new_id *could* be session-specific but it isn't right now);
wenzelm
parents:
43427
diff
changeset
|
25 |
val no_id: ID = 0 |
45243 | 26 |
val new_id = Counter() |
38355
8cb265fb12fe
represent document ids by (long) int, to benefit from the somewhat faster Inttab in ML (LinearSet in Scala is invariably indexed by native object ids);
wenzelm
parents:
38227
diff
changeset
|
27 |
|
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
28 |
|
34818
7df68a8f0e3e
register Proof_Document instances as session entities -- handle Markup.EDIT messages locally;
wenzelm
parents:
34815
diff
changeset
|
29 |
|
38424 | 30 |
/** document structure **/ |
31 |
||
32 |
/* named nodes -- development graph */ |
|
33 |
||
44615 | 34 |
type Edit[A, B] = (Node.Name, Node.Edit[A, B]) |
44384 | 35 |
type Edit_Text = Edit[Text.Edit, Text.Perspective] |
36 |
type Edit_Command = Edit[(Option[Command], Option[Command]), Command.Perspective] |
|
38151 | 37 |
|
44182 | 38 |
type Node_Header = Exn.Result[Thy_Header] |
39 |
||
38151 | 40 |
object Node |
41 |
{ |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
42 |
object Name |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
43 |
{ |
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
44 |
val empty = Name("", "", "") |
44959 | 45 |
def apply(path: Path): Name = |
46 |
{ |
|
47 |
val node = path.implode |
|
48 |
val dir = path.dir.implode |
|
49 |
val theory = Thy_Header.thy_name(node) getOrElse error("Bad theory file name: " + path) |
|
50 |
Name(node, dir, theory) |
|
51 |
} |
|
44957
098dd95349e7
more elaborate Node_Renderer, which paints node_name.theory only;
wenzelm
parents:
44676
diff
changeset
|
52 |
} |
44616 | 53 |
sealed case class Name(node: String, dir: String, theory: String) |
44615 | 54 |
{ |
55 |
override def hashCode: Int = node.hashCode |
|
56 |
override def equals(that: Any): Boolean = |
|
57 |
that match { |
|
58 |
case other: Name => node == other.node |
|
59 |
case _ => false |
|
60 |
} |
|
44642 | 61 |
override def toString: String = theory |
44615 | 62 |
} |
63 |
||
44384 | 64 |
sealed abstract class Edit[A, B] |
44156 | 65 |
{ |
44383 | 66 |
def foreach(f: A => Unit) |
67 |
{ |
|
44156 | 68 |
this match { |
44383 | 69 |
case Edits(es) => es.foreach(f) |
70 |
case _ => |
|
44156 | 71 |
} |
44383 | 72 |
} |
44156 | 73 |
} |
44384 | 74 |
case class Clear[A, B]() extends Edit[A, B] |
75 |
case class Edits[A, B](edits: List[A]) extends Edit[A, B] |
|
76 |
case class Header[A, B](header: Node_Header) extends Edit[A, B] |
|
77 |
case class Perspective[A, B](perspective: B) extends Edit[A, B] |
|
44156 | 78 |
|
44442
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
79 |
def norm_header(f: String => String, g: String => String, header: Node_Header): Node_Header = |
44182 | 80 |
header match { |
44442
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
81 |
case Exn.Res(h) => Exn.capture { h.norm_deps(f, g) } |
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
82 |
case exn => exn |
44182 | 83 |
} |
43697
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43662
diff
changeset
|
84 |
|
44474 | 85 |
val empty: Node = |
86 |
Node(Exn.Exn(ERROR("Bad theory header")), Command.Perspective.empty, Map(), Linear_Set()) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
87 |
|
38426 | 88 |
def command_starts(commands: Iterator[Command], offset: Text.Offset = 0) |
89 |
: Iterator[(Command, Text.Offset)] = |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
90 |
{ |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
91 |
var i = offset |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
92 |
for (command <- commands) yield { |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
93 |
val start = i |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
94 |
i += command.length |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
95 |
(command, start) |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
96 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
97 |
} |
38151 | 98 |
} |
99 |
||
38880
5b4efe90c120
simplified/clarified Document_View.text_area_extension;
wenzelm
parents:
38879
diff
changeset
|
100 |
private val block_size = 1024 |
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
101 |
|
43715
518e44a0ee15
some support for blobs (arbitrary text files) within document nodes;
wenzelm
parents:
43697
diff
changeset
|
102 |
sealed case class Node( |
44182 | 103 |
val header: Node_Header, |
44385
e7fdb008aa7d
propagate editor perspective through document model;
wenzelm
parents:
44384
diff
changeset
|
104 |
val perspective: Command.Perspective, |
43715
518e44a0ee15
some support for blobs (arbitrary text files) within document nodes;
wenzelm
parents:
43697
diff
changeset
|
105 |
val blobs: Map[String, Blob], |
518e44a0ee15
some support for blobs (arbitrary text files) within document nodes;
wenzelm
parents:
43697
diff
changeset
|
106 |
val commands: Linear_Set[Command]) |
38151 | 107 |
{ |
44443
35d67b2056cc
clarified Document.Node.clear -- retain header (cf. ML version);
wenzelm
parents:
44442
diff
changeset
|
108 |
def clear: Node = Node.empty.copy(header = header) |
35d67b2056cc
clarified Document.Node.clear -- retain header (cf. ML version);
wenzelm
parents:
44442
diff
changeset
|
109 |
|
35d67b2056cc
clarified Document.Node.clear -- retain header (cf. ML version);
wenzelm
parents:
44442
diff
changeset
|
110 |
|
43697
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43662
diff
changeset
|
111 |
/* commands */ |
77ce24aa1770
explicit Document.Node.Header, with master_dir and thy_name;
wenzelm
parents:
43662
diff
changeset
|
112 |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
113 |
private lazy val full_index: (Array[(Command, Text.Offset)], Text.Range) = |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
114 |
{ |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
115 |
val blocks = new mutable.ListBuffer[(Command, Text.Offset)] |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
116 |
var next_block = 0 |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
117 |
var last_stop = 0 |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
118 |
for ((command, start) <- Node.command_starts(commands.iterator)) { |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
119 |
last_stop = start + command.length |
38885
06582837872b
Node.full_index: allow command spans larger than block_size;
wenzelm
parents:
38882
diff
changeset
|
120 |
while (last_stop + 1 > next_block) { |
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
121 |
blocks += (command -> start) |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
122 |
next_block += block_size |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
123 |
} |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
124 |
} |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
125 |
(blocks.toArray, Text.Range(0, last_stop)) |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
126 |
} |
38151 | 127 |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
128 |
def full_range: Text.Range = full_index._2 |
38151 | 129 |
|
38569 | 130 |
def command_range(i: Text.Offset = 0): Iterator[(Command, Text.Offset)] = |
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
131 |
{ |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
132 |
if (!commands.isEmpty && full_range.contains(i)) { |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
133 |
val (cmd0, start0) = full_index._1(i / block_size) |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
134 |
Node.command_starts(commands.iterator(cmd0), start0) dropWhile { |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
135 |
case (cmd, start) => start + cmd.length <= i } |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
136 |
} |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
137 |
else Iterator.empty |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
138 |
} |
38151 | 139 |
|
38569 | 140 |
def command_range(range: Text.Range): Iterator[(Command, Text.Offset)] = |
141 |
command_range(range.start) takeWhile { case (_, start) => start < range.stop } |
|
38151 | 142 |
|
38426 | 143 |
def command_at(i: Text.Offset): Option[(Command, Text.Offset)] = |
38151 | 144 |
{ |
145 |
val range = command_range(i) |
|
146 |
if (range.hasNext) Some(range.next) else None |
|
147 |
} |
|
148 |
||
38426 | 149 |
def proper_command_at(i: Text.Offset): Option[Command] = |
38151 | 150 |
command_at(i) match { |
151 |
case Some((command, _)) => |
|
152 |
commands.reverse_iterator(command).find(cmd => !cmd.is_ignored) |
|
153 |
case None => None |
|
154 |
} |
|
38879
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
155 |
|
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
156 |
def command_start(cmd: Command): Option[Text.Offset] = |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
157 |
command_starts.find(_._1 == cmd).map(_._2) |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
158 |
|
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
159 |
def command_starts: Iterator[(Command, Text.Offset)] = |
dde403450419
Document.Node: significant speedup of command_range etc. via lazy full_index;
wenzelm
parents:
38872
diff
changeset
|
160 |
Node.command_starts(commands.iterator) |
38151 | 161 |
} |
162 |
||
163 |
||
38424 | 164 |
|
165 |
/** versioning **/ |
|
166 |
||
167 |
/* particular document versions */ |
|
34485 | 168 |
|
38417 | 169 |
object Version |
170 |
{ |
|
43722 | 171 |
val init: Version = Version(no_id, Map().withDefaultValue(Node.empty)) |
38417 | 172 |
} |
173 |
||
44615 | 174 |
type Nodes = Map[Node.Name, Node] |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
175 |
sealed case class Version(val id: Version_ID, val nodes: Nodes) |
44960 | 176 |
{ |
177 |
def topological_order: List[Node.Name] = |
|
178 |
{ |
|
179 |
val names = nodes.map({ case (name, node) => (name.node -> name) }) |
|
180 |
def next(x: Node.Name): List[Node.Name] = |
|
181 |
nodes(x).header match { |
|
182 |
case Exn.Res(header) => |
|
183 |
for (imp <- header.imports; name <- names.get(imp)) yield(name) |
|
184 |
case Exn.Exn(_) => Nil |
|
185 |
} |
|
45900 | 186 |
Library.topological_order(next, nodes.keys.toList.sortBy(_.node)) |
44960 | 187 |
} |
188 |
} |
|
34660 | 189 |
|
34859 | 190 |
|
38424 | 191 |
/* changes of plain text, eventually resulting in document edits */ |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
192 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
193 |
object Change |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
194 |
{ |
44672 | 195 |
val init: Change = Change(Some(Future.value(Version.init)), Nil, Future.value(Version.init)) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
196 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
197 |
|
43722 | 198 |
sealed case class Change( |
44672 | 199 |
val previous: Option[Future[Version]], |
40479 | 200 |
val edits: List[Edit_Text], |
43722 | 201 |
val version: Future[Version]) |
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
202 |
{ |
44672 | 203 |
def is_finished: Boolean = |
204 |
(previous match { case None => true case Some(future) => future.is_finished }) && |
|
205 |
version.is_finished |
|
206 |
||
207 |
def truncate: Change = copy(previous = None, edits = Nil) |
|
38227
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
208 |
} |
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
209 |
|
6bbb42843b6e
concentrate structural document notions in document.scala;
wenzelm
parents:
38220
diff
changeset
|
210 |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
211 |
/* history navigation */ |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
212 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
213 |
object History |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
214 |
{ |
44672 | 215 |
val init: History = History(List(Change.init)) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
216 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
217 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
218 |
// FIXME pruning, purging of state |
44672 | 219 |
sealed case class History(val undo_list: List[Change]) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
220 |
{ |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
221 |
require(!undo_list.isEmpty) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
222 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
223 |
def tip: Change = undo_list.head |
44672 | 224 |
def +(change: Change): History = copy(undo_list = change :: undo_list) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
225 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
226 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
227 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
228 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
229 |
/** global state -- document structure, execution process, editing history **/ |
38424 | 230 |
|
231 |
abstract class Snapshot |
|
232 |
{ |
|
44582 | 233 |
val state: State |
38424 | 234 |
val version: Version |
235 |
val node: Node |
|
236 |
val is_outdated: Boolean |
|
44582 | 237 |
def command_state(command: Command): Command.State |
38427 | 238 |
def convert(i: Text.Offset): Text.Offset |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
239 |
def convert(range: Text.Range): Text.Range |
38427 | 240 |
def revert(i: Text.Offset): Text.Offset |
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
241 |
def revert(range: Text.Range): Text.Range |
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
242 |
def cumulate_markup[A](range: Text.Range, info: A, elements: Option[Set[String]], |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
243 |
result: PartialFunction[(A, Text.Markup), A]): Stream[Text.Info[A]] |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
244 |
def select_markup[A](range: Text.Range, elements: Option[Set[String]], |
46198
cd040c5772de
improved select_markup: include filtering of defined results;
wenzelm
parents:
46178
diff
changeset
|
245 |
result: PartialFunction[Text.Markup, A]): Stream[Text.Info[A]] |
38424 | 246 |
} |
247 |
||
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
248 |
type Assign = |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
249 |
(List[(Document.Command_ID, Option[Document.Exec_ID])], // exec state assignment |
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
250 |
List[(String, Option[Document.Command_ID])]) // last exec |
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
251 |
|
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
252 |
val no_assign: Assign = (Nil, Nil) |
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
253 |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
254 |
object State |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
255 |
{ |
38373 | 256 |
class Fail(state: State) extends Exception |
257 |
||
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
258 |
val init: State = |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
259 |
State().define_version(Version.init, Assignment.init).assign(Version.init.id, no_assign)._2 |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
260 |
|
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
261 |
object Assignment |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
262 |
{ |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
263 |
val init: Assignment = Assignment(Map.empty, Map.empty, false) |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
264 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
265 |
|
38976
a4a465dc89d9
Document.State.Assignment: eliminated promise in favour of plain values -- signalling is done via event bus in Session;
wenzelm
parents:
38885
diff
changeset
|
266 |
case class Assignment( |
44477 | 267 |
val command_execs: Map[Command_ID, Exec_ID], |
268 |
val last_execs: Map[String, Option[Command_ID]], |
|
269 |
val is_finished: Boolean) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
270 |
{ |
44477 | 271 |
def check_finished: Assignment = { require(is_finished); this } |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
272 |
def unfinished: Assignment = copy(is_finished = false) |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
273 |
|
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
274 |
def assign(add_command_execs: List[(Command_ID, Option[Exec_ID])], |
44477 | 275 |
add_last_execs: List[(String, Option[Command_ID])]): Assignment = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
276 |
{ |
38976
a4a465dc89d9
Document.State.Assignment: eliminated promise in favour of plain values -- signalling is done via event bus in Session;
wenzelm
parents:
38885
diff
changeset
|
277 |
require(!is_finished) |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
278 |
val command_execs1 = |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
279 |
(command_execs /: add_command_execs) { |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
280 |
case (res, (command_id, None)) => res - command_id |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
281 |
case (res, (command_id, Some(exec_id))) => res + (command_id -> exec_id) |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
282 |
} |
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
283 |
Assignment(command_execs1, last_execs ++ add_last_execs, true) |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
284 |
} |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
285 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
286 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
287 |
|
43715
518e44a0ee15
some support for blobs (arbitrary text files) within document nodes;
wenzelm
parents:
43697
diff
changeset
|
288 |
sealed case class State( |
38417 | 289 |
val versions: Map[Version_ID, Version] = Map(), |
44446 | 290 |
val commands: Map[Command_ID, Command.State] = Map(), // static markup from define_command |
291 |
val execs: Map[Exec_ID, Command.State] = Map(), // dynamic markup from execution |
|
43722 | 292 |
val assignments: Map[Version_ID, State.Assignment] = Map(), |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
293 |
val history: History = History.init) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
294 |
{ |
38373 | 295 |
private def fail[A]: A = throw new State.Fail(this) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
296 |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
297 |
def define_version(version: Version, assignment: State.Assignment): State = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
298 |
{ |
38417 | 299 |
val id = version.id |
300 |
copy(versions = versions + (id -> version), |
|
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
301 |
assignments = assignments + (id -> assignment.unfinished)) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
302 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
303 |
|
38373 | 304 |
def define_command(command: Command): State = |
305 |
{ |
|
306 |
val id = command.id |
|
307 |
copy(commands = commands + (id -> command.empty_state)) |
|
308 |
} |
|
309 |
||
44582 | 310 |
def defined_command(id: Command_ID): Boolean = commands.isDefinedAt(id) |
311 |
||
44607
274eff0ea12e
maintain name of *the* enclosing node as part of command -- avoid full document traversal;
wenzelm
parents:
44582
diff
changeset
|
312 |
def find_command(version: Version, id: ID): Option[(Node, Command)] = |
44582 | 313 |
commands.get(id) orElse execs.get(id) match { |
314 |
case None => None |
|
315 |
case Some(st) => |
|
316 |
val command = st.command |
|
44607
274eff0ea12e
maintain name of *the* enclosing node as part of command -- avoid full document traversal;
wenzelm
parents:
44582
diff
changeset
|
317 |
version.nodes.get(command.node_name).map((_, command)) |
44582 | 318 |
} |
38373 | 319 |
|
38417 | 320 |
def the_version(id: Version_ID): Version = versions.getOrElse(id, fail) |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
321 |
def the_command(id: Command_ID): Command.State = commands.getOrElse(id, fail) // FIXME rename |
44446 | 322 |
def the_exec(id: Exec_ID): Command.State = execs.getOrElse(id, fail) |
43722 | 323 |
def the_assignment(version: Version): State.Assignment = |
324 |
assignments.getOrElse(version.id, fail) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
325 |
|
38872 | 326 |
def accumulate(id: ID, message: XML.Elem): (Command.State, State) = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
327 |
execs.get(id) match { |
44446 | 328 |
case Some(st) => |
46152
793cecd4ffc0
accumulate status as regular markup for command range;
wenzelm
parents:
45900
diff
changeset
|
329 |
val new_st = st + message |
44446 | 330 |
(new_st, copy(execs = execs + (id -> new_st))) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
331 |
case None => |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
332 |
commands.get(id) match { |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
333 |
case Some(st) => |
46152
793cecd4ffc0
accumulate status as regular markup for command range;
wenzelm
parents:
45900
diff
changeset
|
334 |
val new_st = st + message |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
335 |
(new_st, copy(commands = commands + (id -> new_st))) |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
336 |
case None => fail |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
337 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
338 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
339 |
|
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
340 |
def assign(id: Version_ID, arg: Assign): (List[Command], State) = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
341 |
{ |
38417 | 342 |
val version = the_version(id) |
44477 | 343 |
val (command_execs, last_execs) = arg |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
344 |
|
44543 | 345 |
val (changed_commands, new_execs) = |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
346 |
((Nil: List[Command], execs) /: command_execs) { |
44543 | 347 |
case ((commands1, execs1), (cmd_id, exec)) => |
44479
9a04e7502e22
refined document state assignment: observe perspective, more explicit assignment message;
wenzelm
parents:
44477
diff
changeset
|
348 |
val st = the_command(cmd_id) |
44543 | 349 |
val commands2 = st.command :: commands1 |
350 |
val execs2 = |
|
351 |
exec match { |
|
352 |
case None => execs1 |
|
353 |
case Some(exec_id) => execs1 + (exec_id -> st) |
|
354 |
} |
|
355 |
(commands2, execs2) |
|
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
356 |
} |
44477 | 357 |
val new_assignment = the_assignment(version).assign(command_execs, last_execs) |
43722 | 358 |
val new_state = copy(assignments = assignments + (id -> new_assignment), execs = new_execs) |
44476
e8a87398f35d
propagate information about last command with exec state assignment through document model;
wenzelm
parents:
44475
diff
changeset
|
359 |
|
44543 | 360 |
(changed_commands, new_state) |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
361 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
362 |
|
38417 | 363 |
def is_assigned(version: Version): Boolean = |
43722 | 364 |
assignments.get(version.id) match { |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
365 |
case Some(assgn) => assgn.is_finished |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
366 |
case None => false |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
367 |
} |
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
368 |
|
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
369 |
def is_stable(change: Change): Boolean = |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
370 |
change.is_finished && is_assigned(change.version.get_finished) |
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
371 |
|
44672 | 372 |
def recent_stable: Change = history.undo_list.find(is_stable) getOrElse fail |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
373 |
def tip_stable: Boolean = is_stable(history.tip) |
44475 | 374 |
def tip_version: Version = history.tip.version.get_finished |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
375 |
|
44615 | 376 |
def last_exec_offset(name: Node.Name): Text.Offset = |
44484
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
377 |
{ |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
378 |
val version = tip_version |
44615 | 379 |
the_assignment(version).last_execs.get(name.node) match { |
44484
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
380 |
case Some(Some(id)) => |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
381 |
val node = version.nodes(name) |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
382 |
val cmd = the_command(id).command |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
383 |
node.command_start(cmd) match { |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
384 |
case None => 0 |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
385 |
case Some(start) => start + cmd.length |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
386 |
} |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
387 |
case _ => 0 |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
388 |
} |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
389 |
} |
470f2ee5950e
tuned Session.edit_node: update_perspective based on last_exec_offset;
wenzelm
parents:
44479
diff
changeset
|
390 |
|
44446 | 391 |
def continue_history( |
392 |
previous: Future[Version], |
|
40479 | 393 |
edits: List[Edit_Text], |
43722 | 394 |
version: Future[Version]): (Change, State) = |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
395 |
{ |
44672 | 396 |
val change = Change(Some(previous), edits, version) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
397 |
(change, copy(history = history + change)) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
398 |
} |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
399 |
|
44672 | 400 |
def prune_history(retain: Int = 0): (List[Version], State) = |
401 |
{ |
|
402 |
val undo_list = history.undo_list |
|
403 |
val n = undo_list.iterator.zipWithIndex.find(p => is_stable(p._1)).get._2 + 1 |
|
404 |
val (retained, dropped) = undo_list.splitAt(n max retain) |
|
405 |
||
406 |
retained.splitAt(retained.length - 1) match { |
|
407 |
case (prefix, List(last)) => |
|
408 |
val dropped_versions = dropped.map(change => change.version.get_finished) |
|
409 |
val state1 = copy(history = History(prefix ::: List(last.truncate))) |
|
410 |
(dropped_versions, state1) |
|
411 |
case _ => fail |
|
412 |
} |
|
413 |
} |
|
414 |
||
44676 | 415 |
def removed_versions(removed: List[Version_ID]): State = |
416 |
{ |
|
417 |
val versions1 = versions -- removed |
|
418 |
val assignments1 = assignments -- removed |
|
419 |
var commands1 = Map.empty[Command_ID, Command.State] |
|
420 |
var execs1 = Map.empty[Exec_ID, Command.State] |
|
421 |
for { |
|
422 |
(version_id, version) <- versions1.iterator |
|
423 |
val command_execs = assignments1(version_id).command_execs |
|
424 |
(_, node) <- version.nodes.iterator |
|
425 |
command <- node.commands.iterator |
|
426 |
} { |
|
427 |
val id = command.id |
|
428 |
if (!commands1.isDefinedAt(id) && commands.isDefinedAt(id)) |
|
429 |
commands1 += (id -> commands(id)) |
|
430 |
if (command_execs.isDefinedAt(id)) { |
|
431 |
val exec_id = command_execs(id) |
|
432 |
if (!execs1.isDefinedAt(exec_id) && execs.isDefinedAt(exec_id)) |
|
433 |
execs1 += (exec_id -> execs(exec_id)) |
|
434 |
} |
|
435 |
} |
|
436 |
copy(versions = versions1, commands = commands1, execs = execs1, assignments = assignments1) |
|
437 |
} |
|
438 |
||
44613 | 439 |
def command_state(version: Version, command: Command): Command.State = |
440 |
{ |
|
441 |
require(is_assigned(version)) |
|
442 |
try { |
|
443 |
the_exec(the_assignment(version).check_finished.command_execs |
|
444 |
.getOrElse(command.id, fail)) |
|
445 |
} |
|
446 |
catch { case _: State.Fail => command.empty_state } |
|
447 |
} |
|
448 |
||
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
449 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
450 |
// persistent user-view |
44615 | 451 |
def snapshot(name: Node.Name, pending_edits: List[Text.Edit]): Snapshot = |
38370
8b15d0f98962
explicit Document.State value, instead of individual state variables in Session, Command, Document;
wenzelm
parents:
38367
diff
changeset
|
452 |
{ |
44672 | 453 |
val stable = recent_stable |
44436
546adfa8a6fc
update_perspective without actual edits, bypassing the full state assignment protocol;
wenzelm
parents:
44385
diff
changeset
|
454 |
val latest = history.tip |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
455 |
|
44156 | 456 |
// FIXME proper treatment of removed nodes |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
457 |
val edits = |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
458 |
(pending_edits /: history.undo_list.takeWhile(_ != stable))((edits, change) => |
44156 | 459 |
(for ((a, Node.Edits(es)) <- change.edits if a == name) yield es).flatten ::: edits) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
460 |
lazy val reverse_edits = edits.reverse |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
461 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
462 |
new Snapshot |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
463 |
{ |
44582 | 464 |
val state = State.this |
39698 | 465 |
val version = stable.version.get_finished |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
466 |
val node = version.nodes(name) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
467 |
val is_outdated = !(pending_edits.isEmpty && latest == stable) |
44613 | 468 |
def command_state(command: Command): Command.State = state.command_state(version, command) |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
469 |
|
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
470 |
def convert(offset: Text.Offset) = (offset /: edits)((i, edit) => edit.convert(i)) |
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
471 |
def revert(offset: Text.Offset) = (offset /: reverse_edits)((i, edit) => edit.revert(i)) |
43425 | 472 |
def convert(range: Text.Range) = (range /: edits)((r, edit) => edit.convert(r)) |
473 |
def revert(range: Text.Range) = (range /: reverse_edits)((r, edit) => edit.revert(r)) |
|
39177
0468964aec11
simplified Markup_Tree.select: Stream instead of Iterator (again), explicit Option instead of default;
wenzelm
parents:
38976
diff
changeset
|
474 |
|
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
475 |
def cumulate_markup[A](range: Text.Range, info: A, elements: Option[Set[String]], |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
476 |
result: PartialFunction[(A, Text.Markup), A]): Stream[Text.Info[A]] = |
45459 | 477 |
{ |
45467 | 478 |
val former_range = revert(range) |
45459 | 479 |
for { |
480 |
(command, command_start) <- node.command_range(former_range).toStream |
|
481 |
Text.Info(r0, a) <- command_state(command).markup. |
|
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
482 |
cumulate[A]((former_range - command_start).restrict(command.range), info, elements, |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
483 |
{ |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
484 |
case (a, Text.Info(r0, b)) |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
485 |
if result.isDefinedAt((a, Text.Info(convert(r0 + command_start), b))) => |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
486 |
result((a, Text.Info(convert(r0 + command_start), b))) |
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
487 |
}) |
45459 | 488 |
} yield Text.Info(convert(r0 + command_start), a) |
489 |
} |
|
490 |
||
46178
1c5c88f6feb5
clarified Isabelle_Rendering vs. physical painting;
wenzelm
parents:
46152
diff
changeset
|
491 |
def select_markup[A](range: Text.Range, elements: Option[Set[String]], |
46198
cd040c5772de
improved select_markup: include filtering of defined results;
wenzelm
parents:
46178
diff
changeset
|
492 |
result: PartialFunction[Text.Markup, A]): Stream[Text.Info[A]] = |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
493 |
{ |
45468 | 494 |
val result1 = |
495 |
new PartialFunction[(Option[A], Text.Markup), Option[A]] { |
|
496 |
def isDefinedAt(arg: (Option[A], Text.Markup)): Boolean = result.isDefinedAt(arg._2) |
|
497 |
def apply(arg: (Option[A], Text.Markup)): Option[A] = Some(result(arg._2)) |
|
498 |
} |
|
46198
cd040c5772de
improved select_markup: include filtering of defined results;
wenzelm
parents:
46178
diff
changeset
|
499 |
for (Text.Info(r, Some(x)) <- cumulate_markup(range, None, elements, result1)) |
cd040c5772de
improved select_markup: include filtering of defined results;
wenzelm
parents:
46178
diff
changeset
|
500 |
yield Text.Info(r, x) |
38845
a9e37daf5bd0
added Document.Snapshot.select_markup, which includes command iteration, range conversion etc.;
wenzelm
parents:
38841
diff
changeset
|
501 |
} |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38569
diff
changeset
|
502 |
} |
38150
67fc24df3721
simplified/refined document model: collection of named nodes, without proper dependencies yet;
wenzelm
parents:
37849
diff
changeset
|
503 |
} |
34485 | 504 |
} |
34840
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
505 |
} |
6c5560d48561
more precise treatment of document/state assigment;
wenzelm
parents:
34838
diff
changeset
|
506 |