author | wenzelm |
Sat, 18 Sep 2010 14:28:42 +0200 | |
changeset 39515 | 57ceabb0bb8e |
parent 39241 | e9a442606db3 |
child 39517 | e036c67448e6 |
permissions | -rw-r--r-- |
36760 | 1 |
/* Title: Tools/jEdit/src/jedit/plugin.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Main Isabelle/jEdit plugin setup. |
|
5 |
*/ |
|
34407 | 6 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle.jedit |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
8 |
|
34429 | 9 |
|
36015 | 10 |
import isabelle._ |
11 |
||
34429 | 12 |
import java.io.{FileInputStream, IOException} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
13 |
import java.awt.Font |
34822 | 14 |
import javax.swing.JTextArea |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
15 |
|
34497 | 16 |
import scala.collection.mutable |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
17 |
|
39241 | 18 |
import org.gjt.sp.jedit.{jEdit, GUIUtilities, EBMessage, EBPlugin, |
19 |
Buffer, EditPane, ServiceManager, View} |
|
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
20 |
import org.gjt.sp.jedit.buffer.JEditBuffer |
39043 | 21 |
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea} |
37557
1ae272fd4082
refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents:
37241
diff
changeset
|
22 |
import org.gjt.sp.jedit.msg.{BufferUpdate, EditPaneUpdate, PropertiesChanged} |
37068 | 23 |
import org.gjt.sp.jedit.gui.DockableWindowManager |
34429 | 24 |
|
39241 | 25 |
import org.gjt.sp.util.Log |
26 |
||
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
27 |
|
34618 | 28 |
object Isabelle |
29 |
{ |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
30 |
/* plugin instance */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
31 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
32 |
var system: Isabelle_System = null |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
33 |
var session: Session = null |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
34 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
35 |
|
34618 | 36 |
/* properties */ |
37 |
||
38 |
val OPTION_PREFIX = "options.isabelle." |
|
39 |
||
40 |
object Property |
|
41 |
{ |
|
36814
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
42 |
def apply(name: String): String = |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
43 |
jEdit.getProperty(OPTION_PREFIX + name) |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
44 |
def apply(name: String, default: String): String = |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
45 |
jEdit.getProperty(OPTION_PREFIX + name, default) |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
46 |
def update(name: String, value: String) = |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
47 |
jEdit.setProperty(OPTION_PREFIX + name, value) |
34468
9d4b4f290676
maintain Isabelle properties via object Isabelle.Property with apply/update methods;
wenzelm
parents:
34463
diff
changeset
|
48 |
} |
34433 | 49 |
|
34618 | 50 |
object Boolean_Property |
51 |
{ |
|
36814
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
52 |
def apply(name: String): Boolean = |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
53 |
jEdit.getBooleanProperty(OPTION_PREFIX + name) |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
54 |
def apply(name: String, default: Boolean): Boolean = |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
55 |
jEdit.getBooleanProperty(OPTION_PREFIX + name, default) |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
56 |
def update(name: String, value: Boolean) = |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
57 |
jEdit.setBooleanProperty(OPTION_PREFIX + name, value) |
34618 | 58 |
} |
59 |
||
60 |
object Int_Property |
|
61 |
{ |
|
36814
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
62 |
def apply(name: String): Int = |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
63 |
jEdit.getIntegerProperty(OPTION_PREFIX + name) |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
64 |
def apply(name: String, default: Int): Int = |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
65 |
jEdit.getIntegerProperty(OPTION_PREFIX + name, default) |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
66 |
def update(name: String, value: Int) = |
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
67 |
jEdit.setIntegerProperty(OPTION_PREFIX + name, value) |
34618 | 68 |
} |
69 |
||
37164 | 70 |
|
71 |
/* font */ |
|
72 |
||
73 |
def font_family(): String = jEdit.getProperty("view.font") |
|
74 |
||
37019 | 75 |
def font_size(): Float = |
76 |
(jEdit.getIntegerProperty("view.fontsize", 16) * |
|
77 |
Int_Property("relative-font-size", 100)).toFloat / 100 |
|
36814
dc85664dbf6d
support Isabelle plugin properties with defaults;
wenzelm
parents:
36760
diff
changeset
|
78 |
|
34618 | 79 |
|
39043 | 80 |
/* text area ranges */ |
81 |
||
82 |
case class Gfx_Range(val x: Int, val y: Int, val length: Int) |
|
83 |
||
84 |
def gfx_range(text_area: TextArea, range: Text.Range): Option[Gfx_Range] = |
|
85 |
{ |
|
86 |
val p = text_area.offsetToXY(range.start) |
|
87 |
val q = text_area.offsetToXY(range.stop) |
|
88 |
if (p != null && q != null && p.y == q.y) Some(new Gfx_Range(p.x, p.y, q.x - p.x)) |
|
89 |
else None |
|
90 |
} |
|
91 |
||
92 |
||
37201
8517a650cfdc
control tooltip font via Swing HTML, with tooltip-font-size property;
wenzelm
parents:
37177
diff
changeset
|
93 |
/* tooltip markup */ |
8517a650cfdc
control tooltip font via Swing HTML, with tooltip-font-size property;
wenzelm
parents:
37177
diff
changeset
|
94 |
|
8517a650cfdc
control tooltip font via Swing HTML, with tooltip-font-size property;
wenzelm
parents:
37177
diff
changeset
|
95 |
def tooltip(text: String): String = |
37203
c4261f3bbdd7
more flexibile font size via CSS <style> instead of old <font> element;
wenzelm
parents:
37201
diff
changeset
|
96 |
"<html><pre style=\"font-family: " + font_family() + "; font-size: " + |
c4261f3bbdd7
more flexibile font size via CSS <style> instead of old <font> element;
wenzelm
parents:
37201
diff
changeset
|
97 |
Int_Property("tooltip-font-size", 10).toString + "px; \">" + // FIXME proper scaling (!?) |
c4261f3bbdd7
more flexibile font size via CSS <style> instead of old <font> element;
wenzelm
parents:
37201
diff
changeset
|
98 |
HTML.encode(text) + "</pre></html>" |
37201
8517a650cfdc
control tooltip font via Swing HTML, with tooltip-font-size property;
wenzelm
parents:
37177
diff
changeset
|
99 |
|
38854
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
100 |
def tooltip_dismiss_delay(): Int = |
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
101 |
Int_Property("tooltip-dismiss-delay", 8000) max 500 |
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
102 |
|
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
103 |
def setup_tooltips() |
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
104 |
{ |
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
105 |
Swing_Thread.now { |
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
106 |
val manager = javax.swing.ToolTipManager.sharedInstance |
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
107 |
manager.setDismissDelay(tooltip_dismiss_delay()) |
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
108 |
} |
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
109 |
} |
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
110 |
|
37201
8517a650cfdc
control tooltip font via Swing HTML, with tooltip-font-size property;
wenzelm
parents:
37177
diff
changeset
|
111 |
|
39241 | 112 |
/* icons */ |
113 |
||
114 |
def load_icon(name: String): javax.swing.Icon = |
|
115 |
{ |
|
116 |
val icon = GUIUtilities.loadIcon(name) |
|
117 |
if (icon.getIconWidth < 0 || icon.getIconHeight < 0) |
|
118 |
Log.log(Log.ERROR, icon, "Bad icon: " + name); |
|
119 |
icon |
|
120 |
} |
|
121 |
||
122 |
||
34618 | 123 |
/* settings */ |
124 |
||
34782
fcd6a41326a6
refined treatment of default logic concerning property and GUI;
wenzelm
parents:
34781
diff
changeset
|
125 |
def default_logic(): String = |
fcd6a41326a6
refined treatment of default logic concerning property and GUI;
wenzelm
parents:
34781
diff
changeset
|
126 |
{ |
fcd6a41326a6
refined treatment of default logic concerning property and GUI;
wenzelm
parents:
34781
diff
changeset
|
127 |
val logic = system.getenv("JEDIT_LOGIC") |
fcd6a41326a6
refined treatment of default logic concerning property and GUI;
wenzelm
parents:
34781
diff
changeset
|
128 |
if (logic != "") logic |
fcd6a41326a6
refined treatment of default logic concerning property and GUI;
wenzelm
parents:
34781
diff
changeset
|
129 |
else system.getenv_strict("ISABELLE_LOGIC") |
fcd6a41326a6
refined treatment of default logic concerning property and GUI;
wenzelm
parents:
34781
diff
changeset
|
130 |
} |
fcd6a41326a6
refined treatment of default logic concerning property and GUI;
wenzelm
parents:
34781
diff
changeset
|
131 |
|
fcd6a41326a6
refined treatment of default logic concerning property and GUI;
wenzelm
parents:
34781
diff
changeset
|
132 |
def isabelle_args(): List[String] = |
34618 | 133 |
{ |
34780 | 134 |
val modes = system.getenv("JEDIT_PRINT_MODE").split(",").toList.map("-m" + _) |
135 |
val logic = { |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
136 |
val logic = Property("logic") |
34782
fcd6a41326a6
refined treatment of default logic concerning property and GUI;
wenzelm
parents:
34781
diff
changeset
|
137 |
if (logic != null && logic != "") logic |
fcd6a41326a6
refined treatment of default logic concerning property and GUI;
wenzelm
parents:
34781
diff
changeset
|
138 |
else default_logic() |
34780 | 139 |
} |
140 |
modes ++ List(logic) |
|
34502 | 141 |
} |
142 |
||
34618 | 143 |
|
38221 | 144 |
/* main jEdit components */ |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
145 |
|
37177 | 146 |
def jedit_buffers(): Iterator[Buffer] = jEdit.getBuffers().iterator |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
147 |
|
37177 | 148 |
def jedit_views(): Iterator[View] = jEdit.getViews().iterator |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
149 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
150 |
def jedit_text_areas(view: View): Iterator[JEditTextArea] = |
37177 | 151 |
view.getEditPanes().iterator.map(_.getTextArea) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
152 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
153 |
def jedit_text_areas(): Iterator[JEditTextArea] = |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
154 |
jedit_views().flatMap(jedit_text_areas(_)) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
155 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
156 |
def jedit_text_areas(buffer: JEditBuffer): Iterator[JEditTextArea] = |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
157 |
jedit_text_areas().filter(_.getBuffer == buffer) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
158 |
|
38843 | 159 |
def buffer_lock[A](buffer: JEditBuffer)(body: => A): A = |
38640 | 160 |
{ |
161 |
try { buffer.readLock(); body } |
|
162 |
finally { buffer.readUnlock() } |
|
163 |
} |
|
164 |
||
38843 | 165 |
def swing_buffer_lock[A](buffer: JEditBuffer)(body: => A): A = |
166 |
Swing_Thread.now { buffer_lock(buffer) { body } } |
|
167 |
||
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
168 |
|
37068 | 169 |
/* dockable windows */ |
170 |
||
171 |
private def wm(view: View): DockableWindowManager = view.getDockableWindowManager |
|
172 |
||
39515 | 173 |
def docked_session(view: View): Option[Session_Dockable] = |
174 |
wm(view).getDockableWindow("isabelle-session") match { |
|
175 |
case dockable: Session_Dockable => Some(dockable) |
|
176 |
case _ => None |
|
177 |
} |
|
178 |
||
37068 | 179 |
def docked_output(view: View): Option[Output_Dockable] = |
180 |
wm(view).getDockableWindow("isabelle-output") match { |
|
181 |
case dockable: Output_Dockable => Some(dockable) |
|
182 |
case _ => None |
|
183 |
} |
|
184 |
||
185 |
def docked_raw_output(view: View): Option[Raw_Output_Dockable] = |
|
186 |
wm(view).getDockableWindow("isabelle-raw-output") match { |
|
187 |
case dockable: Raw_Output_Dockable => Some(dockable) |
|
188 |
case _ => None |
|
189 |
} |
|
190 |
||
191 |
def docked_protocol(view: View): Option[Protocol_Dockable] = |
|
192 |
wm(view).getDockableWindow("isabelle-protocol") match { |
|
193 |
case dockable: Protocol_Dockable => Some(dockable) |
|
194 |
case _ => None |
|
195 |
} |
|
196 |
||
197 |
||
38221 | 198 |
/* manage prover */ // FIXME async!? |
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
199 |
|
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
200 |
private def prover_started(view: View): Boolean = |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
201 |
{ |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
202 |
val timeout = Int_Property("startup-timeout") max 1000 |
38221 | 203 |
session.started(timeout, Isabelle.isabelle_args()) match { |
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
204 |
case Some(err) => |
34822 | 205 |
val text = new JTextArea(err); text.setEditable(false) |
206 |
Library.error_dialog(view, null, "Failed to start Isabelle process", text) |
|
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
207 |
false |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
208 |
case None => true |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
209 |
} |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
210 |
} |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
211 |
|
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
212 |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
213 |
/* activation */ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
214 |
|
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
215 |
def activate_buffer(view: View, buffer: Buffer) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
216 |
{ |
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
217 |
if (prover_started(view)) { |
38222
dac5fa0ac971
replaced individual Document_Model history by all-inclusive one in Session;
wenzelm
parents:
38221
diff
changeset
|
218 |
// FIXME proper error handling |
dac5fa0ac971
replaced individual Document_Model history by all-inclusive one in Session;
wenzelm
parents:
38221
diff
changeset
|
219 |
val (_, thy_name) = Thy_Header.split_thy_path(Isabelle.system.posix_path(buffer.getPath)) |
dac5fa0ac971
replaced individual Document_Model history by all-inclusive one in Session;
wenzelm
parents:
38221
diff
changeset
|
220 |
|
dac5fa0ac971
replaced individual Document_Model history by all-inclusive one in Session;
wenzelm
parents:
38221
diff
changeset
|
221 |
val model = Document_Model.init(session, buffer, thy_name) |
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
222 |
for (text_area <- jedit_text_areas(buffer)) |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
223 |
Document_View.init(model, text_area) |
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
224 |
} |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
225 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
226 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
227 |
def deactivate_buffer(buffer: Buffer) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
228 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
229 |
session.stop() // FIXME not yet |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
230 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
231 |
for (text_area <- jedit_text_areas(buffer)) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
232 |
Document_View.exit(text_area) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
233 |
Document_Model.exit(buffer) |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
234 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
235 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
236 |
def switch_active(view: View) = |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
237 |
{ |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
238 |
val buffer = view.getBuffer |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34787
diff
changeset
|
239 |
if (Document_Model(buffer).isDefined) deactivate_buffer(buffer) |
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34808
diff
changeset
|
240 |
else activate_buffer(view, buffer) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
241 |
} |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
242 |
|
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
243 |
def is_active(view: View): Boolean = |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34787
diff
changeset
|
244 |
Document_Model(view.getBuffer).isDefined |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
245 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
246 |
|
34429 | 247 |
|
34618 | 248 |
class Plugin extends EBPlugin |
249 |
{ |
|
250 |
/* main plugin plumbing */ |
|
34433 | 251 |
|
34767 | 252 |
override def handleMessage(message: EBMessage) |
34618 | 253 |
{ |
34767 | 254 |
message match { |
37557
1ae272fd4082
refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents:
37241
diff
changeset
|
255 |
case msg: BufferUpdate |
1ae272fd4082
refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents:
37241
diff
changeset
|
256 |
if msg.getWhat == BufferUpdate.PROPERTIES_CHANGED => |
1ae272fd4082
refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents:
37241
diff
changeset
|
257 |
Document_Model(msg.getBuffer) match { |
1ae272fd4082
refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents:
37241
diff
changeset
|
258 |
case Some(model) => model.refresh() |
1ae272fd4082
refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents:
37241
diff
changeset
|
259 |
case _ => |
1ae272fd4082
refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents:
37241
diff
changeset
|
260 |
} |
1ae272fd4082
refresh Isabelle token marker after buffer properties changed, e.g. when fold mode is switched;
wenzelm
parents:
37241
diff
changeset
|
261 |
|
34767 | 262 |
case msg: EditPaneUpdate => |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
263 |
val edit_pane = msg.getEditPane |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
264 |
val buffer = edit_pane.getBuffer |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
265 |
val text_area = edit_pane.getTextArea |
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
266 |
|
34787
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
267 |
def init_view() |
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
268 |
{ |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34787
diff
changeset
|
269 |
Document_Model(buffer) match { |
34787
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
270 |
case Some(model) => Document_View.init(model, text_area) |
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
271 |
case None => |
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
272 |
} |
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
273 |
} |
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
274 |
def exit_view() |
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
275 |
{ |
34788
3779c54a2d21
direct apply for Document_Model and Document_View;
wenzelm
parents:
34787
diff
changeset
|
276 |
if (Document_View(text_area).isDefined) |
34787
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
277 |
Document_View.exit(text_area) |
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
278 |
} |
34767 | 279 |
msg.getWhat match { |
34787
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
280 |
case EditPaneUpdate.BUFFER_CHANGED => exit_view(); init_view() |
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
281 |
case EditPaneUpdate.CREATED => init_view() |
0feac35069c6
need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents:
34784
diff
changeset
|
282 |
case EditPaneUpdate.DESTROYED => exit_view() |
34671 | 283 |
case _ => |
284 |
} |
|
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
285 |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34774
diff
changeset
|
286 |
case msg: PropertiesChanged => |
37241
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37203
diff
changeset
|
287 |
Swing_Thread.now { |
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37203
diff
changeset
|
288 |
for (text_area <- Isabelle.jedit_text_areas if Document_View(text_area).isDefined) |
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37203
diff
changeset
|
289 |
Document_View(text_area).get.extend_styles() |
38854
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
290 |
|
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
291 |
Isabelle.setup_tooltips() |
37241
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37203
diff
changeset
|
292 |
} |
04d2521e79b0
basic support for sub/superscript token markup -- NB: need to maintain extended token types eagerly, since jEdit occasionally reinstalls a style array that is too short;
wenzelm
parents:
37203
diff
changeset
|
293 |
|
34791 | 294 |
Isabelle.session.global_settings.event(Session.Global_Settings) |
34784
02959dcea756
split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents:
34782
diff
changeset
|
295 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
296 |
case _ => |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
297 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
298 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
299 |
|
34618 | 300 |
override def start() |
301 |
{ |
|
34615 | 302 |
Isabelle.system = new Isabelle_System |
34774 | 303 |
Isabelle.system.install_fonts() |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34774
diff
changeset
|
304 |
Isabelle.session = new Session(Isabelle.system) // FIXME dialog!? |
38854
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
305 |
|
eb6a35be18ca
Isabelle/jEdit property for global tooltip dismiss delay;
wenzelm
parents:
38843
diff
changeset
|
306 |
Isabelle.setup_tooltips() |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
307 |
} |
34618 | 308 |
|
39167
803431dcc7fb
slightly more robust Plugin.stop -- components might refer to Isabelle.system even after shutdown;
wenzelm
parents:
39043
diff
changeset
|
309 |
override def stop() // FIXME fragile |
34618 | 310 |
{ |
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34774
diff
changeset
|
311 |
Isabelle.session.stop() // FIXME dialog!? |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34774
diff
changeset
|
312 |
Isabelle.session = null |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
313 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
314 |
} |