author | immler@in.tum.de |
Thu, 27 Aug 2009 10:51:09 +0200 | |
changeset 34671 | d179fcb04cbc |
parent 34670 | c99878d7bec7 |
child 34685 | 93f4978fe2a8 |
permissions | -rw-r--r-- |
34407 | 1 |
/* |
2 |
* Main Isabelle/jEdit plugin setup |
|
3 |
* |
|
4 |
* @author Johannes Hölzl, TU Munich |
|
5 |
* @author Fabian Immler, TU Munich |
|
6 |
*/ |
|
7 |
||
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
8 |
package isabelle.jedit |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
9 |
|
34429 | 10 |
|
11 |
import java.io.{FileInputStream, IOException} |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
12 |
import java.awt.Font |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
13 |
import javax.swing.JScrollPane |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
14 |
|
34497 | 15 |
import scala.collection.mutable |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
16 |
|
34429 | 17 |
import isabelle.prover.{Prover, Command} |
34615 | 18 |
import isabelle.Isabelle_System |
34429 | 19 |
|
20 |
import org.gjt.sp.jedit.{jEdit, EBMessage, EBPlugin, Buffer, EditPane, ServiceManager, View} |
|
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
21 |
import org.gjt.sp.jedit.buffer.JEditBuffer |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
22 |
import org.gjt.sp.jedit.textarea.JEditTextArea |
34429 | 23 |
import org.gjt.sp.jedit.msg.{EditPaneUpdate, PropertiesChanged} |
24 |
||
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
25 |
|
34618 | 26 |
object Isabelle |
27 |
{ |
|
28 |
/* name */ |
|
29 |
||
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
30 |
val NAME = "Isabelle" |
34623 | 31 |
|
34618 | 32 |
|
33 |
/* properties */ |
|
34 |
||
35 |
val OPTION_PREFIX = "options.isabelle." |
|
36 |
||
37 |
object Property |
|
38 |
{ |
|
39 |
def apply(name: String): String = jEdit.getProperty(OPTION_PREFIX + name) |
|
34468
9d4b4f290676
maintain Isabelle properties via object Isabelle.Property with apply/update methods;
wenzelm
parents:
34463
diff
changeset
|
40 |
def update(name: String, value: String) = jEdit.setProperty(OPTION_PREFIX + name, value) |
9d4b4f290676
maintain Isabelle properties via object Isabelle.Property with apply/update methods;
wenzelm
parents:
34463
diff
changeset
|
41 |
} |
34433 | 42 |
|
34618 | 43 |
object Boolean_Property |
44 |
{ |
|
45 |
def apply(name: String): Boolean = jEdit.getBooleanProperty(OPTION_PREFIX + name) |
|
46 |
def update(name: String, value: Boolean) = jEdit.setBooleanProperty(OPTION_PREFIX + name, value) |
|
47 |
} |
|
48 |
||
49 |
object Int_Property |
|
50 |
{ |
|
51 |
def apply(name: String): Int = jEdit.getIntegerProperty(OPTION_PREFIX + name) |
|
52 |
def update(name: String, value: Int) = jEdit.setIntegerProperty(OPTION_PREFIX + name, value) |
|
53 |
} |
|
54 |
||
55 |
||
56 |
/* Isabelle system instance */ |
|
57 |
||
34615 | 58 |
var system: Isabelle_System = null |
34487
b88ee385308d
use Symbol.Interpretation from IsabelleSystem instance;
wenzelm
parents:
34475
diff
changeset
|
59 |
def symbols = system.symbols |
34612
5a03dc7a19e1
fall back on Isabelle system completion (symbols only);
wenzelm
parents:
34503
diff
changeset
|
60 |
lazy val completion = new Completion + symbols |
34440 | 61 |
|
34618 | 62 |
|
63 |
/* settings */ |
|
64 |
||
65 |
def default_logic = |
|
66 |
{ |
|
34502 | 67 |
val logic = Isabelle.Property("logic") |
68 |
if (logic != null) logic else Isabelle.system.getenv_strict("ISABELLE_LOGIC") |
|
69 |
} |
|
70 |
||
34618 | 71 |
|
72 |
/* plugin instance */ |
|
73 |
||
34440 | 74 |
var plugin: Plugin = null |
34433 | 75 |
|
34618 | 76 |
|
77 |
/* running provers */ |
|
78 |
||
34475
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34468
diff
changeset
|
79 |
def prover_setup(buffer: JEditBuffer) = plugin.prover_setup(buffer) |
34318
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 |
|
34429 | 82 |
|
34618 | 83 |
class Plugin extends EBPlugin |
84 |
{ |
|
85 |
/* Isabelle font */ |
|
34433 | 86 |
|
87 |
var font: Font = null |
|
34456 | 88 |
val font_changed = new EventBus[Font] |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
89 |
|
34618 | 90 |
def set_font(size: Int) |
91 |
{ |
|
92 |
font = Font.createFont(Font.TRUETYPE_FONT, |
|
34627
313fcd844129
recovered Isabelle font -- deriveFont(Int) refers to style, not size!
wenzelm
parents:
34624
diff
changeset
|
93 |
Isabelle.system.platform_file("~~/lib/fonts/IsabelleMono.ttf")). |
313fcd844129
recovered Isabelle font -- deriveFont(Int) refers to style, not size!
wenzelm
parents:
34624
diff
changeset
|
94 |
deriveFont(Font.PLAIN, (size max 1).toFloat) |
34456 | 95 |
font_changed.event(font) |
34433 | 96 |
} |
97 |
||
98 |
||
34669 | 99 |
/* selected state */ |
100 |
||
101 |
val state_update = new EventBus[Command] |
|
102 |
||
103 |
private var _selected_state: Command = null |
|
104 |
def selected_state = _selected_state |
|
105 |
def selected_state_=(state: Command) { _selected_state = state; state_update.event(state) } |
|
106 |
||
107 |
||
34618 | 108 |
/* mapping buffer <-> prover */ |
34433 | 109 |
|
34497 | 110 |
private val mapping = new mutable.HashMap[JEditBuffer, ProverSetup] |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
111 |
|
34618 | 112 |
private def install(view: View) |
113 |
{ |
|
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
114 |
val buffer = view.getBuffer |
34463
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
115 |
val prover_setup = new ProverSetup(buffer) |
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
116 |
mapping.update(buffer, prover_setup) |
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
117 |
prover_setup.activate(view) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
118 |
} |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
119 |
|
34463
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
120 |
private def uninstall(view: View) = |
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
121 |
mapping.removeKey(view.getBuffer).get.deactivate |
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
122 |
|
34618 | 123 |
def switch_active (view: View) = |
34463
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
124 |
if (mapping.isDefinedAt(view.getBuffer)) uninstall(view) |
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
125 |
else install(view) |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
126 |
|
34618 | 127 |
def prover_setup(buffer: JEditBuffer): Option[ProverSetup] = mapping.get(buffer) |
128 |
def is_active (buffer: JEditBuffer) = mapping.isDefinedAt(buffer) |
|
129 |
||
130 |
||
131 |
/* main plugin plumbing */ |
|
34433 | 132 |
|
34618 | 133 |
override def handleMessage(msg: EBMessage) |
134 |
{ |
|
135 |
msg match { |
|
34671 | 136 |
case epu: EditPaneUpdate => |
137 |
val buffer = epu.getEditPane.getBuffer |
|
138 |
epu.getWhat match { |
|
139 |
case EditPaneUpdate.BUFFER_CHANGED => |
|
140 |
(mapping get buffer) map (_.theory_view.activate) |
|
141 |
case EditPaneUpdate.BUFFER_CHANGING => |
|
142 |
if (buffer != null) |
|
143 |
(mapping get buffer) map (_.theory_view.deactivate) |
|
144 |
case _ => |
|
145 |
} |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
146 |
case _ => |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
147 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
148 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
149 |
|
34618 | 150 |
override def start() |
151 |
{ |
|
34615 | 152 |
Isabelle.system = new Isabelle_System |
34440 | 153 |
Isabelle.plugin = this |
34618 | 154 |
set_font(Isabelle.Int_Property("font-size")) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
155 |
} |
34618 | 156 |
|
157 |
override def stop() |
|
158 |
{ |
|
34429 | 159 |
// TODO: proper cleanup |
34441
ff3b7ae2b12a
replaced static IsabelleSystem by Isabelle.system;
wenzelm
parents:
34440
diff
changeset
|
160 |
Isabelle.system = null |
34440 | 161 |
Isabelle.plugin = null |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
162 |
} |
34618 | 163 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
164 |
} |