author | immler@in.tum.de |
Mon, 13 Jul 2009 14:30:39 +0200 | |
changeset 34654 | 30f588245884 |
parent 34653 | 2e033aaf128e |
child 34660 | e0561943bfc9 |
permissions | -rw-r--r-- |
34407 | 1 |
/* |
34408 | 2 |
* jEdit text area as document text source |
34407 | 3 |
* |
4 |
* @author Fabian Immler, TU Munich |
|
5 |
* @author Johannes Hölzl, TU Munich |
|
34447 | 6 |
* @author Makarius |
34407 | 7 |
*/ |
8 |
||
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
9 |
package isabelle.jedit |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
10 |
|
34532 | 11 |
import scala.actors.Actor |
34582 | 12 |
import scala.actors.Actor._ |
34446 | 13 |
|
34653 | 14 |
import isabelle.proofdocument.{ProofDocument, Text} |
34649 | 15 |
import isabelle.prover.{Prover, ProverEvents, Command} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
16 |
|
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
17 |
import java.awt.Graphics2D |
34446 | 18 |
import java.awt.event.{ActionEvent, ActionListener} |
19 |
import java.awt.Color |
|
34447 | 20 |
import javax.swing.Timer |
21 |
import javax.swing.event.{CaretListener, CaretEvent} |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
22 |
|
34446 | 23 |
import org.gjt.sp.jedit.buffer.{BufferListener, JEditBuffer} |
24 |
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextAreaExtension, TextAreaPainter} |
|
34649 | 25 |
import org.gjt.sp.jedit.syntax.{ModeProvider, SyntaxStyle} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
26 |
|
34446 | 27 |
|
34588 | 28 |
object TheoryView |
29 |
{ |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
30 |
|
34574
d68352286c91
split large changes for faster responses of prover
immler@in.tum.de
parents:
34568
diff
changeset
|
31 |
val MAX_CHANGE_LENGTH = 1500 |
d68352286c91
split large changes for faster responses of prover
immler@in.tum.de
parents:
34568
diff
changeset
|
32 |
|
34653 | 33 |
def choose_color(cmd: Command, doc: ProofDocument): Color = { |
34 |
cmd.status(doc) match { |
|
35 |
case Command.Status.UNPROCESSED => new Color(255, 228, 225) |
|
36 |
case Command.Status.FINISHED => new Color(234, 248, 255) |
|
37 |
case Command.Status.FAILED => new Color(255, 192, 192) |
|
38 |
case _ => Color.red |
|
39 |
} |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
40 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
41 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
42 |
|
34446 | 43 |
|
34532 | 44 |
class TheoryView (text_area: JEditTextArea, document_actor: Actor) |
34588 | 45 |
extends TextAreaExtension with BufferListener |
46 |
{ |
|
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
47 |
|
34603
83a37e3b8c9c
produce ids via Isabelle.system (http://isabelle.in.tum.de/repos/isabelle/rev/c23663825e23);
wenzelm
parents:
34598
diff
changeset
|
48 |
def id() = Isabelle.system.id() |
34541 | 49 |
|
34446 | 50 |
private val buffer = text_area.getBuffer |
34475
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34458
diff
changeset
|
51 |
private val prover = Isabelle.prover_setup(buffer).get.prover |
34446 | 52 |
|
53 |
||
34526 | 54 |
private var col: Text.Change = null |
34446 | 55 |
private val col_timer = new Timer(300, new ActionListener() { |
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
56 |
override def actionPerformed(e: ActionEvent) = commit |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
57 |
}) |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
58 |
|
34446 | 59 |
col_timer.stop |
60 |
col_timer.setRepeats(true) |
|
61 |
||
62 |
||
34566 | 63 |
private val phase_overview = new PhaseOverviewPanel(prover, text_area, to_current) |
34446 | 64 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
65 |
|
34446 | 66 |
/* activation */ |
67 |
||
68 |
private val selected_state_controller = new CaretListener { |
|
69 |
override def caretUpdate(e: CaretEvent) = { |
|
34650 | 70 |
val doc = current_document() |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34549
diff
changeset
|
71 |
val cmd = doc.find_command_at(e.getDot) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34549
diff
changeset
|
72 |
if (cmd != null && doc.token_start(cmd.tokens.first) <= e.getDot && |
34475
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34458
diff
changeset
|
73 |
Isabelle.prover_setup(buffer).get.selected_state != cmd) |
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34458
diff
changeset
|
74 |
Isabelle.prover_setup(buffer).get.selected_state = cmd |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
75 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
76 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
77 |
|
34582 | 78 |
def activate() { |
34446 | 79 |
text_area.addCaretListener(selected_state_controller) |
80 |
text_area.addLeftOfScrollBar(phase_overview) |
|
81 |
text_area.getPainter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, this) |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
82 |
buffer.setTokenMarker(new DynamicTokenMarker(buffer, prover)) |
34649 | 83 |
buffer.addBufferListener(this) |
84 |
||
34654 | 85 |
col = Text.Change(Some(current_change), Isabelle.system.id(), 0, |
34650 | 86 |
buffer.getText(0, buffer.getLength), "") |
87 |
commit |
|
34446 | 88 |
} |
89 |
||
34582 | 90 |
def deactivate() { |
34649 | 91 |
buffer.setTokenMarker(buffer.getMode.getTokenMarker) |
92 |
buffer.removeBufferListener(this) |
|
34446 | 93 |
text_area.getPainter.removeExtension(this) |
94 |
text_area.removeLeftOfScrollBar(phase_overview) |
|
95 |
text_area.removeCaretListener(selected_state_controller) |
|
96 |
} |
|
97 |
||
98 |
||
99 |
/* painting */ |
|
100 |
||
34643
3896caeedf82
renamed Delay to clarified version Swing_Thread.delay;
wenzelm
parents:
34642
diff
changeset
|
101 |
val update_delay = Swing_Thread.delay(500){ buffer.propertiesChanged() } |
3896caeedf82
renamed Delay to clarified version Swing_Thread.delay;
wenzelm
parents:
34642
diff
changeset
|
102 |
val repaint_delay = Swing_Thread.delay(100){ repaint_all() } |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
103 |
|
34582 | 104 |
val change_receiver = actor { |
105 |
loop { |
|
106 |
react { |
|
34649 | 107 |
case ProverEvents.Activate => |
108 |
activate() |
|
109 |
case c: Command => |
|
34643
3896caeedf82
renamed Delay to clarified version Swing_Thread.delay;
wenzelm
parents:
34642
diff
changeset
|
110 |
update_delay() |
3896caeedf82
renamed Delay to clarified version Swing_Thread.delay;
wenzelm
parents:
34642
diff
changeset
|
111 |
repaint_delay() |
3896caeedf82
renamed Delay to clarified version Swing_Thread.delay;
wenzelm
parents:
34642
diff
changeset
|
112 |
phase_overview.repaint_delay() |
34649 | 113 |
case x => System.err.println("warning: change_receiver ignored " + x) |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
114 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
115 |
} |
34583
17c83413b7fe
change_receiver: start only once (already done in actor function);
wenzelm
parents:
34582
diff
changeset
|
116 |
} |
34446 | 117 |
|
118 |
||
34654 | 119 |
def transform_back(from: Text.Change, to: Text.Change, pos: Int): Int = |
120 |
if (from.id == to.id) pos |
|
121 |
else { |
|
122 |
val shifted = |
|
123 |
if (from.start <= pos) |
|
124 |
if (pos < from.start + from.added.length) from.start |
|
125 |
else pos - from.added.length + from.removed.length |
|
126 |
else pos |
|
127 |
transform_back(from.base.get, to, shifted) |
|
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
128 |
} |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
129 |
|
34654 | 130 |
def transform_forward(from: Text.Change, to: Text.Change, pos: Int): Int = |
131 |
if (from.id == to.id) pos |
|
132 |
else { |
|
133 |
val shifted = transform_forward(from, to.base.get, pos) |
|
134 |
if (to.start <= shifted) { |
|
135 |
if (shifted < to.start + to.removed.length) to.start |
|
136 |
else shifted + to.added.length - to.removed.length |
|
137 |
} else shifted |
|
138 |
} |
|
139 |
||
140 |
def from_current(doc: ProofDocument, pos: Int) = { |
|
141 |
val from = if (col == null) current_change else col |
|
142 |
val to = changes.find(_.id == doc.id).get |
|
143 |
transform_back(from, to, pos) |
|
144 |
} |
|
145 |
def to_current(doc: ProofDocument, pos: Int) = { |
|
146 |
val from = changes.find(_.id == doc.id).get |
|
147 |
val to = if (col == null) current_change else col |
|
148 |
transform_forward(from, to, pos) |
|
34651
23271beee68a
set current document version; forget "future" versions in list
immler@in.tum.de
parents:
34650
diff
changeset
|
149 |
} |
34446 | 150 |
|
151 |
def repaint(cmd: Command) = |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
152 |
{ |
34650 | 153 |
val document = current_document() |
34507 | 154 |
if (text_area != null) { |
34654 | 155 |
val start = text_area.getLineOfOffset(to_current(document, cmd.start(document))) |
156 |
val stop = text_area.getLineOfOffset(to_current(document, cmd.stop(document)) - 1) |
|
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
157 |
text_area.invalidateLineRange(start, stop) |
34446 | 158 |
|
34475
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34458
diff
changeset
|
159 |
if (Isabelle.prover_setup(buffer).get.selected_state == cmd) |
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34458
diff
changeset
|
160 |
Isabelle.prover_setup(buffer).get.selected_state = cmd // update State view |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
161 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
162 |
} |
34446 | 163 |
|
34588 | 164 |
def repaint_all() |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
165 |
{ |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
166 |
if (text_area != null) |
34446 | 167 |
text_area.invalidateLineRange(text_area.getFirstPhysicalLine, text_area.getLastPhysicalLine) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
168 |
} |
34391 | 169 |
|
34446 | 170 |
def encolor(gfx: Graphics2D, |
34588 | 171 |
y: Int, height: Int, begin: Int, finish: Int, color: Color, fill: Boolean) |
34446 | 172 |
{ |
173 |
val start = text_area.offsetToXY(begin) |
|
174 |
val stop = |
|
175 |
if (finish < buffer.getLength) text_area.offsetToXY(finish) |
|
176 |
else { |
|
177 |
val p = text_area.offsetToXY(finish - 1) |
|
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
178 |
val metrics = text_area.getPainter.getFontMetrics |
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
179 |
p.x = p.x + (metrics.charWidth(' ') max metrics.getMaxAdvance) |
34446 | 180 |
p |
34391 | 181 |
} |
34446 | 182 |
|
183 |
if (start != null && stop != null) { |
|
184 |
gfx.setColor(color) |
|
185 |
if (fill) gfx.fillRect(start.x, y, stop.x - start.x, height) |
|
186 |
else gfx.drawRect(start.x, y, stop.x - start.x, height) |
|
187 |
} |
|
34391 | 188 |
} |
189 |
||
34446 | 190 |
|
191 |
/* TextAreaExtension methods */ |
|
192 |
||
193 |
override def paintValidLine(gfx: Graphics2D, |
|
34588 | 194 |
screen_line: Int, physical_line: Int, start: Int, end: Int, y: Int) |
34446 | 195 |
{ |
34650 | 196 |
val document = current_document() |
34654 | 197 |
def from_current(pos: Int) = this.from_current(document, pos) |
198 |
def to_current(pos: Int) = this.to_current(document, pos) |
|
34446 | 199 |
val saved_color = gfx.getColor |
200 |
||
201 |
val metrics = text_area.getPainter.getFontMetrics |
|
34596 | 202 |
|
203 |
// encolor phase |
|
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
204 |
var e = document.find_command_at(from_current(start)) |
34596 | 205 |
while (e != null && e.start(document) < end) { |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34549
diff
changeset
|
206 |
val begin = start max to_current(e.start(document)) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34549
diff
changeset
|
207 |
val finish = end - 1 min to_current(e.stop(document)) |
34653 | 208 |
encolor(gfx, y, metrics.getHeight, begin, finish, |
209 |
TheoryView.choose_color(e, document), true) |
|
34596 | 210 |
e = document.commands.next(e).getOrElse(null) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
211 |
} |
34391 | 212 |
|
34446 | 213 |
gfx.setColor(saved_color) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
214 |
} |
34446 | 215 |
|
34562 | 216 |
override def getToolTipText(x: Int, y: Int) = { |
34650 | 217 |
val document = current_document() |
34654 | 218 |
val offset = from_current(document, text_area.xyToOffset(x, y)) |
34562 | 219 |
val cmd = document.find_command_at(offset) |
220 |
if (cmd != null) { |
|
221 |
document.token_start(cmd.tokens.first) |
|
34653 | 222 |
cmd.type_at(document, offset - cmd.start(document)) |
34562 | 223 |
} else null |
224 |
} |
|
225 |
||
34654 | 226 |
/* history of changes - TODO: seperate class?*/ |
227 |
||
228 |
val change_0 = Text.Change(None, prover.document_0.id, 0, "", "") |
|
229 |
private var changes = List(change_0) |
|
230 |
private var current_change = change_0 |
|
231 |
def get_changes = changes |
|
232 |
||
233 |
private def doc_or_pred(c: Text.Change): ProofDocument = |
|
234 |
prover.document(c.id).getOrElse(doc_or_pred(c.base.get)) |
|
235 |
def current_document() = doc_or_pred(current_change) |
|
236 |
||
237 |
/* update to desired version */ |
|
238 |
||
239 |
def set_version(goal: Text.Change) { |
|
240 |
// changes in buffer must be ignored |
|
241 |
buffer.removeBufferListener(this) |
|
242 |
||
243 |
def apply(c: Text.Change) = { |
|
244 |
buffer.remove(c.start, c.removed.length) |
|
245 |
buffer.insert(c.start, c.added)} |
|
246 |
def unapply(c: Text.Change) = { |
|
247 |
buffer.remove(c.start, c.added.length) |
|
248 |
buffer.insert(c.start, c.removed)} |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
249 |
|
34654 | 250 |
// undo/redo changes |
251 |
val ancs_current = current_change.ancestors |
|
252 |
val ancs_goal = goal.ancestors |
|
253 |
val paired = ancs_current.reverse zip ancs_goal.reverse |
|
254 |
def last_common[A](xs: List[(A, A)]): Option[A] = { |
|
255 |
xs match { |
|
256 |
case (x, y) :: xs => |
|
257 |
if (x == y) |
|
258 |
xs match { |
|
259 |
case (a, b) :: ys => |
|
260 |
if (a == b) last_common(xs) |
|
261 |
else Some(x) |
|
262 |
case _ => Some(x) |
|
263 |
} |
|
264 |
else None |
|
265 |
case _ => None |
|
266 |
} |
|
267 |
} |
|
268 |
val common_anc = last_common(paired).get |
|
269 |
||
270 |
ancs_current.takeWhile(_ != common_anc) map unapply |
|
271 |
ancs_goal.takeWhile(_ != common_anc).reverse map apply |
|
272 |
||
273 |
current_change = goal |
|
274 |
// invoke repaint |
|
275 |
update_delay() |
|
276 |
repaint_delay() |
|
277 |
phase_overview.repaint_delay() |
|
278 |
||
279 |
//track changes in buffer |
|
280 |
buffer.addBufferListener(this) |
|
281 |
} |
|
282 |
||
283 |
/* BufferListener methods */ |
|
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
284 |
|
34547 | 285 |
private def commit: Unit = synchronized { |
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
286 |
if (col != null) { |
34574
d68352286c91
split large changes for faster responses of prover
immler@in.tum.de
parents:
34568
diff
changeset
|
287 |
def split_changes(c: Text.Change): List[Text.Change] = { |
34582 | 288 |
val MAX = TheoryView.MAX_CHANGE_LENGTH |
289 |
if (c.added.length <= MAX) List(c) |
|
34654 | 290 |
else Text.Change(c.base, c.id, c.start, c.added.substring(0, MAX), c.removed) :: |
291 |
split_changes(Text.Change(Some(c), id(), c.start + MAX, c.added.substring(MAX), "")) |
|
34574
d68352286c91
split large changes for faster responses of prover
immler@in.tum.de
parents:
34568
diff
changeset
|
292 |
} |
d68352286c91
split large changes for faster responses of prover
immler@in.tum.de
parents:
34568
diff
changeset
|
293 |
val new_changes = split_changes(col) |
34654 | 294 |
changes ++= new_changes |
34574
d68352286c91
split large changes for faster responses of prover
immler@in.tum.de
parents:
34568
diff
changeset
|
295 |
new_changes map (document_actor ! _) |
34654 | 296 |
current_change = new_changes.last |
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
297 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
298 |
col = null |
34446 | 299 |
if (col_timer.isRunning()) |
300 |
col_timer.stop() |
|
301 |
} |
|
302 |
||
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
303 |
private def delay_commit { |
34446 | 304 |
if (col_timer.isRunning()) |
305 |
col_timer.restart() |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
306 |
else |
34446 | 307 |
col_timer.start() |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
308 |
} |
34446 | 309 |
|
310 |
||
311 |
override def contentInserted(buffer: JEditBuffer, |
|
312 |
start_line: Int, offset: Int, num_lines: Int, length: Int) { } |
|
313 |
||
314 |
override def contentRemoved(buffer: JEditBuffer, |
|
315 |
start_line: Int, offset: Int, num_lines: Int, length: Int) { } |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
316 |
|
34446 | 317 |
override def preContentInserted(buffer: JEditBuffer, |
34588 | 318 |
start_line: Int, offset: Int, num_lines: Int, length: Int) |
34446 | 319 |
{ |
34526 | 320 |
val text = buffer.getText(offset, length) |
34364 | 321 |
if (col == null) |
34654 | 322 |
col = new Text.Change(Some(current_change), id(), offset, text, "") |
34526 | 323 |
else if (col.start <= offset && offset <= col.start + col.added.length) |
34654 | 324 |
col = new Text.Change(Some(current_change), col.id, |
325 |
col.start, col.added + text, col.removed) |
|
34446 | 326 |
else { |
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
327 |
commit |
34654 | 328 |
col = new Text.Change(Some(current_change), id(), offset, text, "") |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
329 |
} |
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
330 |
delay_commit |
34446 | 331 |
} |
332 |
||
333 |
override def preContentRemoved(buffer: JEditBuffer, |
|
34648 | 334 |
start_line: Int, start: Int, num_lines: Int, removed_length: Int) |
34446 | 335 |
{ |
34648 | 336 |
val removed = buffer.getText(start, removed_length) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
337 |
if (col == null) |
34654 | 338 |
col = new Text.Change(Some(current_change), id(), start, "", removed) |
34648 | 339 |
else if (col.start > start + removed_length || start > col.start + col.added.length) { |
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
340 |
commit |
34654 | 341 |
col = new Text.Change(Some(current_change), id(), start, "", removed) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
342 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
343 |
else { |
34526 | 344 |
/* val offset = start - col.start |
345 |
val diff = col.added.length - removed |
|
34446 | 346 |
val (added, add_removed) = |
347 |
if (diff < offset) |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
348 |
(offset max 0, diff - (offset max 0)) |
34446 | 349 |
else |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
350 |
(diff - (offset min 0), offset min 0) |
34526 | 351 |
col = new Text.Changed(start min col.start, added, col.removed - add_removed)*/ |
352 |
commit |
|
34654 | 353 |
col = new Text.Change(Some(current_change), id(), start, "", removed) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
354 |
} |
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
355 |
delay_commit |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
356 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
357 |
|
34446 | 358 |
override def bufferLoaded(buffer: JEditBuffer) { } |
359 |
override def foldHandlerChanged(buffer: JEditBuffer) { } |
|
360 |
override def foldLevelChanged(buffer: JEditBuffer, start_line: Int, end_line: Int) { } |
|
361 |
override def transactionComplete(buffer: JEditBuffer) { } |
|
34588 | 362 |
|
34447 | 363 |
} |