author | wenzelm |
Tue, 30 Jun 2009 21:22:50 +0200 | |
changeset 34634 | 4b797391859a |
parent 34603 | 83a37e3b8c9c |
child 34641 | 6fce475ba1c6 |
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 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
14 |
import isabelle.proofdocument.Text |
34452 | 15 |
import isabelle.prover.{Prover, 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} |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
25 |
import org.gjt.sp.jedit.syntax.SyntaxStyle |
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 |
|
34446 | 33 |
def choose_color(state: Command): Color = { |
34448 | 34 |
if (state == null) Color.red |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
35 |
else |
34458
e2aa32bb73c0
- renamed Command.Phase to Command.Status (cf. src/Pure/Isar/isar.ML);
wenzelm
parents:
34457
diff
changeset
|
36 |
state.status match { |
e2aa32bb73c0
- renamed Command.Phase to Command.Status (cf. src/Pure/Isar/isar.ML);
wenzelm
parents:
34457
diff
changeset
|
37 |
case Command.Status.UNPROCESSED => new Color(255, 228, 225) |
e2aa32bb73c0
- renamed Command.Phase to Command.Status (cf. src/Pure/Isar/isar.ML);
wenzelm
parents:
34457
diff
changeset
|
38 |
case Command.Status.FINISHED => new Color(234, 248, 255) |
e2aa32bb73c0
- renamed Command.Phase to Command.Status (cf. src/Pure/Isar/isar.ML);
wenzelm
parents:
34457
diff
changeset
|
39 |
case Command.Status.FAILED => new Color(255, 192, 192) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
40 |
case _ => Color.red |
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 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
43 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
44 |
|
34446 | 45 |
|
34532 | 46 |
class TheoryView (text_area: JEditTextArea, document_actor: Actor) |
34588 | 47 |
extends TextAreaExtension with BufferListener |
48 |
{ |
|
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
49 |
|
34603
83a37e3b8c9c
produce ids via Isabelle.system (http://isabelle.in.tum.de/repos/isabelle/rev/c23663825e23);
wenzelm
parents:
34598
diff
changeset
|
50 |
def id() = Isabelle.system.id() |
34541 | 51 |
|
34446 | 52 |
private val buffer = text_area.getBuffer |
34475
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34458
diff
changeset
|
53 |
private val prover = Isabelle.prover_setup(buffer).get.prover |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
54 |
buffer.addBufferListener(this) |
34446 | 55 |
|
56 |
||
34526 | 57 |
private var col: Text.Change = null |
34446 | 58 |
|
59 |
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
|
60 |
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
|
61 |
}) |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
62 |
|
34446 | 63 |
col_timer.stop |
64 |
col_timer.setRepeats(true) |
|
65 |
||
66 |
||
34566 | 67 |
private val phase_overview = new PhaseOverviewPanel(prover, text_area, to_current) |
34446 | 68 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
69 |
|
34446 | 70 |
/* activation */ |
71 |
||
72 |
private val selected_state_controller = new CaretListener { |
|
73 |
override def caretUpdate(e: CaretEvent) = { |
|
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34549
diff
changeset
|
74 |
val doc = prover.document |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34549
diff
changeset
|
75 |
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
|
76 |
if (cmd != null && doc.token_start(cmd.tokens.first) <= e.getDot && |
34475
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34458
diff
changeset
|
77 |
Isabelle.prover_setup(buffer).get.selected_state != cmd) |
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34458
diff
changeset
|
78 |
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
|
79 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
80 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
81 |
|
34582 | 82 |
def activate() { |
34446 | 83 |
text_area.addCaretListener(selected_state_controller) |
84 |
text_area.addLeftOfScrollBar(phase_overview) |
|
85 |
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
|
86 |
buffer.setTokenMarker(new DynamicTokenMarker(buffer, prover)) |
34446 | 87 |
} |
88 |
||
34582 | 89 |
def deactivate() { |
34446 | 90 |
text_area.getPainter.removeExtension(this) |
91 |
text_area.removeLeftOfScrollBar(phase_overview) |
|
92 |
text_area.removeCaretListener(selected_state_controller) |
|
93 |
} |
|
94 |
||
95 |
||
96 |
/* painting */ |
|
97 |
||
98 |
val repaint_delay = new isabelle.utils.Delay(100, () => repaint_all()) |
|
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
99 |
|
34582 | 100 |
val change_receiver = actor { |
101 |
loop { |
|
102 |
react { |
|
103 |
case _ => { // FIXME potentially blocking within loop/react!?!?!?! |
|
34634
4b797391859a
renamed Swing to Swing_Thread, to avoid overlap with scala.swing.Swing;
wenzelm
parents:
34603
diff
changeset
|
104 |
Swing_Thread.now { |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
105 |
repaint_delay.delay_or_ignore() |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
106 |
phase_overview.repaint_delay.delay_or_ignore() |
34541 | 107 |
} |
34538
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
108 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
109 |
} |
20bfcca24658
Prover as actor managing ProofDocument-versions (removed EventBus structural_changes);
immler@in.tum.de
parents:
34532
diff
changeset
|
110 |
} |
34583
17c83413b7fe
change_receiver: start only once (already done in actor function);
wenzelm
parents:
34582
diff
changeset
|
111 |
} |
34446 | 112 |
|
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
113 |
def _from_current(to_id: String, changes: List[Text.Change], pos: Int): Int = |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
114 |
changes match { |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
115 |
case Nil => pos |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
116 |
case Text.Change(id, start, added, removed) :: rest_changes => { |
34582 | 117 |
val shifted = |
118 |
if (start <= pos) |
|
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
119 |
if (pos < start + added.length) start |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
120 |
else pos - added.length + removed |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
121 |
else pos |
34547 | 122 |
if (id == to_id) pos |
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
123 |
else _from_current(to_id, rest_changes, shifted) |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
124 |
} |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
125 |
} |
34446 | 126 |
|
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
127 |
def _to_current(from_id: String, changes: List[Text.Change], pos: Int): Int = |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
128 |
changes match { |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
129 |
case Nil => pos |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
130 |
case Text.Change(id, start, added, removed) :: rest_changes => { |
34547 | 131 |
val shifted = _to_current(from_id, rest_changes, pos) |
132 |
if (id == from_id) pos |
|
133 |
else if (start <= shifted) { |
|
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
134 |
if (shifted < start + removed) start |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
135 |
else shifted + added.length - removed |
34547 | 136 |
} else shifted |
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
137 |
} |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
138 |
} |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
139 |
|
34588 | 140 |
def to_current(from_id: String, pos: Int) = |
34546 | 141 |
_to_current(from_id, if (col == null) changes else col :: changes, pos) |
34588 | 142 |
def from_current(to_id: String, pos: Int) = |
34546 | 143 |
_from_current(to_id, if (col == null) changes else col :: changes, pos) |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34566
diff
changeset
|
144 |
def to_current(document: isabelle.proofdocument.ProofDocument, pos: Int): Int = |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34566
diff
changeset
|
145 |
to_current(document.id, pos) |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34566
diff
changeset
|
146 |
def from_current(document: isabelle.proofdocument.ProofDocument, pos: Int): Int = |
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34566
diff
changeset
|
147 |
from_current(document.id, pos) |
34446 | 148 |
|
149 |
def repaint(cmd: Command) = |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
150 |
{ |
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
151 |
val document = prover.document |
34507 | 152 |
if (text_area != null) { |
34554
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34549
diff
changeset
|
153 |
val start = text_area.getLineOfOffset(to_current(document.id, cmd.start(document))) |
7dc6c231da40
abs. stops, markup nodes depend on doc-version;
immler@in.tum.de
parents:
34549
diff
changeset
|
154 |
val stop = text_area.getLineOfOffset(to_current(document.id, cmd.stop(document)) - 1) |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
155 |
text_area.invalidateLineRange(start, stop) |
34446 | 156 |
|
34475
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34458
diff
changeset
|
157 |
if (Isabelle.prover_setup(buffer).get.selected_state == cmd) |
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34458
diff
changeset
|
158 |
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
|
159 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
160 |
} |
34446 | 161 |
|
34588 | 162 |
def repaint_all() |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
163 |
{ |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
164 |
if (text_area != null) |
34446 | 165 |
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
|
166 |
} |
34391 | 167 |
|
34446 | 168 |
def encolor(gfx: Graphics2D, |
34588 | 169 |
y: Int, height: Int, begin: Int, finish: Int, color: Color, fill: Boolean) |
34446 | 170 |
{ |
171 |
val start = text_area.offsetToXY(begin) |
|
172 |
val stop = |
|
173 |
if (finish < buffer.getLength) text_area.offsetToXY(finish) |
|
174 |
else { |
|
175 |
val p = text_area.offsetToXY(finish - 1) |
|
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
176 |
val metrics = text_area.getPainter.getFontMetrics |
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
177 |
p.x = p.x + (metrics.charWidth(' ') max metrics.getMaxAdvance) |
34446 | 178 |
p |
34391 | 179 |
} |
34446 | 180 |
|
181 |
if (start != null && stop != null) { |
|
182 |
gfx.setColor(color) |
|
183 |
if (fill) gfx.fillRect(start.x, y, stop.x - start.x, height) |
|
184 |
else gfx.drawRect(start.x, y, stop.x - start.x, height) |
|
185 |
} |
|
34391 | 186 |
} |
187 |
||
34446 | 188 |
|
189 |
/* TextAreaExtension methods */ |
|
190 |
||
191 |
override def paintValidLine(gfx: Graphics2D, |
|
34588 | 192 |
screen_line: Int, physical_line: Int, start: Int, end: Int, y: Int) |
34446 | 193 |
{ |
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
194 |
val document = prover.document |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
195 |
def from_current(pos: Int) = this.from_current(document.id, pos) |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
196 |
def to_current(pos: Int) = this.to_current(document.id, pos) |
34446 | 197 |
val saved_color = gfx.getColor |
198 |
||
199 |
val metrics = text_area.getPainter.getFontMetrics |
|
34596 | 200 |
|
201 |
// encolor phase |
|
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
202 |
var e = document.find_command_at(from_current(start)) |
34596 | 203 |
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
|
204 |
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
|
205 |
val finish = end - 1 min to_current(e.stop(document)) |
34446 | 206 |
encolor(gfx, y, metrics.getHeight, begin, finish, TheoryView.choose_color(e), true) |
34596 | 207 |
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
|
208 |
} |
34391 | 209 |
|
34446 | 210 |
gfx.setColor(saved_color) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
211 |
} |
34446 | 212 |
|
34562 | 213 |
override def getToolTipText(x: Int, y: Int) = { |
214 |
val document = prover.document |
|
215 |
val offset = from_current(document.id, text_area.xyToOffset(x, y)) |
|
216 |
val cmd = document.find_command_at(offset) |
|
217 |
if (cmd != null) { |
|
218 |
document.token_start(cmd.tokens.first) |
|
219 |
cmd.type_at(offset - cmd.start(document)) |
|
220 |
} else null |
|
221 |
} |
|
222 |
||
34446 | 223 |
/* BufferListener methods */ |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
224 |
|
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
225 |
private var changes: List[Text.Change] = Nil |
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
226 |
|
34547 | 227 |
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
|
228 |
if (col != null) { |
34574
d68352286c91
split large changes for faster responses of prover
immler@in.tum.de
parents:
34568
diff
changeset
|
229 |
def split_changes(c: Text.Change): List[Text.Change] = { |
34582 | 230 |
val MAX = TheoryView.MAX_CHANGE_LENGTH |
231 |
if (c.added.length <= MAX) List(c) |
|
232 |
else Text.Change(c.id, c.start, c.added.substring(0, MAX), c.removed) :: |
|
233 |
split_changes(new Text.Change(id(), c.start + MAX, c.added.substring(MAX), c.removed)) |
|
34574
d68352286c91
split large changes for faster responses of prover
immler@in.tum.de
parents:
34568
diff
changeset
|
234 |
} |
d68352286c91
split large changes for faster responses of prover
immler@in.tum.de
parents:
34568
diff
changeset
|
235 |
val new_changes = split_changes(col) |
d68352286c91
split large changes for faster responses of prover
immler@in.tum.de
parents:
34568
diff
changeset
|
236 |
changes = new_changes.reverse ::: changes |
d68352286c91
split large changes for faster responses of prover
immler@in.tum.de
parents:
34568
diff
changeset
|
237 |
new_changes map (document_actor ! _) |
34545
b928628742ed
implemented to_current and from_current in dependancy of document-versions
immler@in.tum.de
parents:
34544
diff
changeset
|
238 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
239 |
col = null |
34446 | 240 |
if (col_timer.isRunning()) |
241 |
col_timer.stop() |
|
242 |
} |
|
243 |
||
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
244 |
private def delay_commit { |
34446 | 245 |
if (col_timer.isRunning()) |
246 |
col_timer.restart() |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
247 |
else |
34446 | 248 |
col_timer.start() |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
249 |
} |
34446 | 250 |
|
251 |
||
252 |
override def contentInserted(buffer: JEditBuffer, |
|
253 |
start_line: Int, offset: Int, num_lines: Int, length: Int) { } |
|
254 |
||
255 |
override def contentRemoved(buffer: JEditBuffer, |
|
256 |
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
|
257 |
|
34446 | 258 |
override def preContentInserted(buffer: JEditBuffer, |
34588 | 259 |
start_line: Int, offset: Int, num_lines: Int, length: Int) |
34446 | 260 |
{ |
34526 | 261 |
val text = buffer.getText(offset, length) |
34364 | 262 |
if (col == null) |
34541 | 263 |
col = new Text.Change(id(), offset, text, 0) |
34526 | 264 |
else if (col.start <= offset && offset <= col.start + col.added.length) |
34541 | 265 |
col = new Text.Change(col.id, col.start, col.added + text, col.removed) |
34446 | 266 |
else { |
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
267 |
commit |
34541 | 268 |
col = new Text.Change(id(), offset, text, 0) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
269 |
} |
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
270 |
delay_commit |
34446 | 271 |
} |
272 |
||
273 |
override def preContentRemoved(buffer: JEditBuffer, |
|
34588 | 274 |
start_line: Int, start: Int, num_lines: Int, removed: Int) |
34446 | 275 |
{ |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
276 |
if (col == null) |
34541 | 277 |
col = new Text.Change(id(), start, "", removed) |
34526 | 278 |
else if (col.start > start + removed || start > col.start + col.added.length) { |
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
279 |
commit |
34541 | 280 |
col = new Text.Change(id(), start, "", removed) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
281 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
282 |
else { |
34526 | 283 |
/* val offset = start - col.start |
284 |
val diff = col.added.length - removed |
|
34446 | 285 |
val (added, add_removed) = |
286 |
if (diff < offset) |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
287 |
(offset max 0, diff - (offset max 0)) |
34446 | 288 |
else |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
289 |
(diff - (offset min 0), offset min 0) |
34526 | 290 |
col = new Text.Changed(start min col.start, added, col.removed - add_removed)*/ |
291 |
commit |
|
34541 | 292 |
col = new Text.Change(id(), start, "", removed) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
293 |
} |
34515
3be515f1379d
use FontMetrics.getMaxAdvance if available; tuned
immler@in.tum.de
parents:
34514
diff
changeset
|
294 |
delay_commit |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
295 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
296 |
|
34446 | 297 |
override def bufferLoaded(buffer: JEditBuffer) { } |
298 |
override def foldHandlerChanged(buffer: JEditBuffer) { } |
|
299 |
override def foldLevelChanged(buffer: JEditBuffer, start_line: Int, end_line: Int) { } |
|
300 |
override def transactionComplete(buffer: JEditBuffer) { } |
|
34588 | 301 |
|
34447 | 302 |
} |