author | wenzelm |
Sun, 28 Dec 2008 19:37:51 +0100 | |
changeset 34448 | 39cb4ed5183b |
parent 34447 | dc8b486fde9f |
child 34450 | db45b50cd361 |
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 |
|
34446 | 11 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
12 |
import isabelle.utils.EventSource |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
13 |
import isabelle.proofdocument.Text |
34446 | 14 |
import isabelle.prover.{Prover, Command, CommandChangeInfo} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
15 |
import isabelle.prover.Command.Phase |
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 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
28 |
object TheoryView { |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
29 |
|
34446 | 30 |
def choose_color(state: Command): Color = { |
34448 | 31 |
if (state == null) Color.red |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
32 |
else |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
33 |
state.phase match { |
34448 | 34 |
case Phase.UNPROCESSED => new Color(255, 228, 225) |
35 |
case Phase.FINISHED => new Color(234, 248, 255) |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
36 |
case Phase.FAILED => new Color(255, 192, 192) |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
37 |
case _ => Color.red |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
38 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
39 |
} |
34391 | 40 |
|
34446 | 41 |
def choose_color(markup: String): Color = { |
42 |
// TODO: as properties |
|
43 |
markup match { |
|
34445
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
44 |
// logical entities |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
45 |
case Markup.TCLASS | Markup.TYCON | Markup.FIXED_DECL | Markup.FIXED | Markup.CONST_DECL |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
46 |
| Markup.CONST | Markup.FACT_DECL | Markup.FACT | Markup.DYNAMIC_FACT |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
47 |
| Markup.LOCAL_FACT_DECL | Markup.LOCAL_FACT => new Color(255, 0, 255) |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
48 |
// inner syntax |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
49 |
case Markup.TFREE | Markup.FREE => Color.blue |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
50 |
case Markup.TVAR | Markup.SKOLEM | Markup.BOUND | Markup.VAR => Color.green |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
51 |
case Markup.NUM | Markup.FLOAT | Markup.XNUM | Markup.XSTR | Markup.LITERAL |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
52 |
| Markup.INNER_COMMENT => new Color(255, 128, 128) |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
53 |
case Markup.SORT | Markup.TYP | Markup.TERM | Markup.PROP |
34446 | 54 |
| Markup.ATTRIBUTE | Markup.METHOD => Color.yellow |
34445
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
55 |
// embedded source text |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
56 |
case Markup.ML_SOURCE | Markup.DOC_SOURCE | Markup.ANTIQ | Markup.ML_ANTIQ |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
57 |
| Markup.DOC_ANTIQ => new Color(0, 192, 0) |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
58 |
// outer syntax |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
59 |
case Markup.IDENT | Markup.COMMAND | Markup.KEYWORD => Color.blue |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
60 |
case Markup.VERBATIM => Color.green |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
61 |
case Markup.COMMENT => Color.gray |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
62 |
case Markup.CONTROL => Color.white |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
63 |
case Markup.MALFORMED => Color.red |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
64 |
case Markup.STRING | Markup.ALTSTRING => Color.orange |
61ffe9a35f1d
use symbolic Markup elements instead of literal strings;
wenzelm
parents:
34440
diff
changeset
|
65 |
// other |
34399
5b8b89b7e597
interpretation of STATUS messages in one place, deleting inner syntax
immler@in.tum.de
parents:
34393
diff
changeset
|
66 |
case _ => Color.white |
34391 | 67 |
} |
68 |
} |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
69 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
70 |
|
34446 | 71 |
|
72 |
class TheoryView (text_area: JEditTextArea) |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
73 |
extends TextAreaExtension with Text with BufferListener { |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
74 |
|
34446 | 75 |
private val buffer = text_area.getBuffer |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
76 |
buffer.addBufferListener(this) |
34446 | 77 |
|
78 |
||
79 |
private var col: Text.Changed = null |
|
80 |
||
81 |
private val col_timer = new Timer(300, new ActionListener() { |
|
82 |
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
|
83 |
}) |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
84 |
|
34446 | 85 |
col_timer.stop |
86 |
col_timer.setRepeats(true) |
|
87 |
||
88 |
||
89 |
private val changes_source = new EventSource[Text.Changed] |
|
90 |
private val phase_overview = new PhaseOverviewPanel(Isabelle.prover(buffer)) |
|
91 |
||
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
92 |
|
34446 | 93 |
/* activation */ |
94 |
||
95 |
Isabelle.plugin.font_changed.add(font => update_font()) |
|
96 |
||
97 |
private def update_font() = { |
|
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34405
diff
changeset
|
98 |
if (text_area != null) { |
34440 | 99 |
if (Isabelle.plugin.font != null) { |
34446 | 100 |
val painter = text_area.getPainter |
34434 | 101 |
painter.setStyles(painter.getStyles.map(style => |
34446 | 102 |
new SyntaxStyle(style.getForegroundColor, style.getBackgroundColor, Isabelle.plugin.font) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
103 |
)) |
34440 | 104 |
painter.setFont(Isabelle.plugin.font) |
34446 | 105 |
repaint_all() |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
106 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
107 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
108 |
} |
34446 | 109 |
|
110 |
private val selected_state_controller = new CaretListener { |
|
111 |
override def caretUpdate(e: CaretEvent) = { |
|
112 |
val cmd = Isabelle.prover(buffer).document.getNextCommandContaining(e.getDot) |
|
113 |
if (cmd != null && cmd.start <= e.getDot && |
|
114 |
Isabelle.prover_setup(buffer).selectedState != cmd) |
|
34440 | 115 |
Isabelle.prover_setup(buffer).selectedState = cmd |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
116 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
117 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
118 |
|
34446 | 119 |
def activate() = { |
120 |
text_area.addCaretListener(selected_state_controller) |
|
121 |
phase_overview.textarea = text_area |
|
122 |
text_area.addLeftOfScrollBar(phase_overview) |
|
123 |
text_area.getPainter.addExtension(TextAreaPainter.LINE_BACKGROUND_LAYER + 1, this) |
|
124 |
update_font() |
|
125 |
} |
|
126 |
||
127 |
def deactivate() = { |
|
128 |
text_area.getPainter.removeExtension(this) |
|
129 |
text_area.removeLeftOfScrollBar(phase_overview) |
|
130 |
text_area.removeCaretListener(selected_state_controller) |
|
131 |
} |
|
132 |
||
133 |
||
134 |
/* painting */ |
|
135 |
||
136 |
val repaint_delay = new isabelle.utils.Delay(100, () => repaint_all()) |
|
137 |
Isabelle.prover(buffer).commandInfo.add(_ => repaint_delay.delay_or_ignore()) |
|
138 |
||
139 |
private def from_current(pos: Int) = |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
140 |
if (col != null && col.start <= pos) |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
141 |
if (pos < col.start + col.added) col.start |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
142 |
else pos - col.added + col.removed |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
143 |
else pos |
34446 | 144 |
|
145 |
private def to_current(pos : Int) = |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
146 |
if (col != null && col.start <= pos) |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
147 |
if (pos < col.start + col.removed) col.start |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
148 |
else pos + col.added - col.removed |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
149 |
else pos |
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 |
{ |
34446 | 153 |
val phase = cmd.phase |
154 |
if (text_area != null && phase != Phase.REMOVE && phase != Phase.REMOVED) { |
|
155 |
val start = text_area.getLineOfOffset(to_current(cmd.start)) |
|
156 |
val stop = text_area.getLineOfOffset(to_current(cmd.stop) - 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 |
|
34440 | 159 |
if (Isabelle.prover_setup(buffer).selectedState == cmd) |
34446 | 160 |
Isabelle.prover_setup(buffer).selectedState = 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 |
|
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, |
171 |
y: Int, height: Int, begin: Int, finish: Int, color: Color, fill: Boolean) = |
|
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) |
|
178 |
p.x = p.x + text_area.getPainter.getFontMetrics.charWidth(' ') |
|
179 |
p |
|
34391 | 180 |
} |
34446 | 181 |
|
182 |
if (start != null && stop != null) { |
|
183 |
gfx.setColor(color) |
|
184 |
if (fill) gfx.fillRect(start.x, y, stop.x - start.x, height) |
|
185 |
else gfx.drawRect(start.x, y, stop.x - start.x, height) |
|
186 |
} |
|
34391 | 187 |
} |
188 |
||
34446 | 189 |
|
190 |
/* TextAreaExtension methods */ |
|
191 |
||
192 |
override def paintValidLine(gfx: Graphics2D, |
|
193 |
screen_line: Int, pl: Int, start: Int, end: Int, y: Int) = |
|
194 |
{ |
|
195 |
val saved_color = gfx.getColor |
|
196 |
||
197 |
val metrics = text_area.getPainter.getFontMetrics |
|
198 |
var e = Isabelle.prover(buffer).document.getNextCommandContaining(from_current(start)) |
|
34391 | 199 |
|
34446 | 200 |
// encolor phase |
201 |
while (e != null && to_current(e.start) < end) { |
|
202 |
val begin = start max to_current(e.start) |
|
203 |
val finish = end - 1 min to_current(e.stop) |
|
204 |
encolor(gfx, y, metrics.getHeight, begin, finish, TheoryView.choose_color(e), true) |
|
205 |
||
34391 | 206 |
// paint details of command |
34446 | 207 |
for (node <- e.root_node.dfs) { |
208 |
val begin = to_current(node.start + e.start) |
|
209 |
val finish = to_current(node.end + e.start) |
|
210 |
if (finish > start && begin < end) { |
|
211 |
encolor(gfx, y + metrics.getHeight - 4, 2, begin max start, finish min end, |
|
212 |
TheoryView.choose_color(node.short), true) |
|
213 |
} |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
214 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
215 |
e = e.next |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
216 |
} |
34391 | 217 |
|
34446 | 218 |
gfx.setColor(saved_color) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
219 |
} |
34446 | 220 |
|
221 |
||
222 |
/* Text methods */ |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
223 |
|
34446 | 224 |
def content(start: Int, stop: Int) = buffer.getText(start, stop - start) |
225 |
def length = buffer.getLength |
|
226 |
def changes = changes_source |
|
227 |
||
228 |
||
229 |
||
230 |
/* BufferListener methods */ |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
231 |
|
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
232 |
private def commit() { |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
233 |
if (col != null) |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
234 |
changes.fire(col) |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
235 |
col = null |
34446 | 236 |
if (col_timer.isRunning()) |
237 |
col_timer.stop() |
|
238 |
} |
|
239 |
||
240 |
private def delay_commit() { |
|
241 |
if (col_timer.isRunning()) |
|
242 |
col_timer.restart() |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
243 |
else |
34446 | 244 |
col_timer.start() |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
245 |
} |
34446 | 246 |
|
247 |
||
248 |
override def contentInserted(buffer: JEditBuffer, |
|
249 |
start_line: Int, offset: Int, num_lines: Int, length: Int) { } |
|
250 |
||
251 |
override def contentRemoved(buffer: JEditBuffer, |
|
252 |
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
|
253 |
|
34446 | 254 |
override def preContentInserted(buffer: JEditBuffer, |
255 |
start_line: Int, offset: Int, num_lines: Int, length: Int) = |
|
256 |
{ |
|
34364 | 257 |
if (col == null) |
34446 | 258 |
col = new Text.Changed(offset, length, 0) |
259 |
else if (col.start <= offset && offset <= col.start + col.added) |
|
260 |
col = new Text.Changed(col.start, col.added + length, col.removed) |
|
261 |
else { |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
262 |
commit() |
34446 | 263 |
col = new Text.Changed(offset, length, 0) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
264 |
} |
34446 | 265 |
delay_commit() |
266 |
} |
|
267 |
||
268 |
override def preContentRemoved(buffer: JEditBuffer, |
|
269 |
start_line: Int, start: Int, num_lines: Int, removed: Int) = |
|
270 |
{ |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
271 |
if (col == null) |
34446 | 272 |
col = new Text.Changed(start, 0, removed) |
273 |
else if (col.start > start + removed || start > col.start + col.added) { |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
274 |
commit() |
34446 | 275 |
col = new Text.Changed(start, 0, removed) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
276 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
277 |
else { |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
278 |
val offset = start - col.start |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
279 |
val diff = col.added - removed |
34446 | 280 |
val (added, add_removed) = |
281 |
if (diff < offset) |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
282 |
(offset max 0, diff - (offset max 0)) |
34446 | 283 |
else |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
284 |
(diff - (offset min 0), offset min 0) |
34446 | 285 |
col = new Text.Changed(start min col.start, added, col.removed - add_removed) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
286 |
} |
34446 | 287 |
delay_commit() |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
288 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
289 |
|
34446 | 290 |
override def bufferLoaded(buffer: JEditBuffer) { } |
291 |
override def foldHandlerChanged(buffer: JEditBuffer) { } |
|
292 |
override def foldLevelChanged(buffer: JEditBuffer, start_line: Int, end_line: Int) { } |
|
293 |
override def transactionComplete(buffer: JEditBuffer) { } |
|
34447 | 294 |
} |