author | wenzelm |
Tue, 27 Jan 2009 16:16:55 +0100 | |
changeset 34497 | 184fda8cce04 |
parent 34487 | b88ee385308d |
child 34502 | 7d1d13750890 |
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} |
34487
b88ee385308d
use Symbol.Interpretation from IsabelleSystem instance;
wenzelm
parents:
34475
diff
changeset
|
18 |
import isabelle.IsabelleSystem |
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 |
|
34440 | 26 |
object Isabelle { |
34433 | 27 |
// name |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
28 |
val NAME = "Isabelle" |
34337
5d5b69f2956b
renamed VFS protocol prefix from "isa:" to "isabelle:";
wenzelm
parents:
34318
diff
changeset
|
29 |
val VFS_PREFIX = "isabelle:" |
34433 | 30 |
|
31 |
// properties |
|
34468
9d4b4f290676
maintain Isabelle properties via object Isabelle.Property with apply/update methods;
wenzelm
parents:
34463
diff
changeset
|
32 |
object Property { |
9d4b4f290676
maintain Isabelle properties via object Isabelle.Property with apply/update methods;
wenzelm
parents:
34463
diff
changeset
|
33 |
private val OPTION_PREFIX = "options.isabelle." |
9d4b4f290676
maintain Isabelle properties via object Isabelle.Property with apply/update methods;
wenzelm
parents:
34463
diff
changeset
|
34 |
def apply(name: String) = jEdit.getProperty(OPTION_PREFIX + name) |
9d4b4f290676
maintain Isabelle properties via object Isabelle.Property with apply/update methods;
wenzelm
parents:
34463
diff
changeset
|
35 |
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
|
36 |
} |
34433 | 37 |
|
34487
b88ee385308d
use Symbol.Interpretation from IsabelleSystem instance;
wenzelm
parents:
34475
diff
changeset
|
38 |
// Isabelle system instance |
34441
ff3b7ae2b12a
replaced static IsabelleSystem by Isabelle.system;
wenzelm
parents:
34440
diff
changeset
|
39 |
var system: IsabelleSystem = null |
34487
b88ee385308d
use Symbol.Interpretation from IsabelleSystem instance;
wenzelm
parents:
34475
diff
changeset
|
40 |
def symbols = system.symbols |
34440 | 41 |
|
42 |
// plugin instance |
|
43 |
var plugin: Plugin = null |
|
34433 | 44 |
|
34487
b88ee385308d
use Symbol.Interpretation from IsabelleSystem instance;
wenzelm
parents:
34475
diff
changeset
|
45 |
// running provers |
34475
f963335dbc6b
implemented IsabelleSideKickParser.complete
immler@in.tum.de
parents:
34468
diff
changeset
|
46 |
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
|
47 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
48 |
|
34429 | 49 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
50 |
class Plugin extends EBPlugin { |
34433 | 51 |
|
52 |
// Isabelle font |
|
53 |
||
54 |
var font: Font = null |
|
34456 | 55 |
val font_changed = new EventBus[Font] |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
56 |
|
34433 | 57 |
def set_font(path: String, size: Float) { |
34456 | 58 |
font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(path)). |
59 |
deriveFont(Font.PLAIN, size) |
|
60 |
font_changed.event(font) |
|
34433 | 61 |
} |
62 |
||
63 |
||
34449 | 64 |
/* unique ids */ // FIXME specific to "session" (!??) |
65 |
||
66 |
private var id_count: BigInt = 0 |
|
67 |
def id() : String = synchronized { id_count += 1; "editor:" + id_count } |
|
68 |
||
69 |
||
34433 | 70 |
// mapping buffer <-> prover |
71 |
||
34497 | 72 |
private val mapping = new mutable.HashMap[JEditBuffer, ProverSetup] |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
73 |
|
34463
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
74 |
private def install(view: View) { |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
75 |
val buffer = view.getBuffer |
34463
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
76 |
val prover_setup = new ProverSetup(buffer) |
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
77 |
mapping.update(buffer, prover_setup) |
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
78 |
prover_setup.activate(view) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
79 |
} |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
80 |
|
34463
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
81 |
private def uninstall(view: View) = |
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
82 |
mapping.removeKey(view.getBuffer).get.deactivate |
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
83 |
|
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
84 |
def switch_active (view : View) = |
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
85 |
if (mapping.isDefinedAt(view.getBuffer)) uninstall(view) |
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
86 |
else install(view) |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
87 |
|
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
88 |
def prover_setup (buffer : JEditBuffer) : Option[ProverSetup] = mapping.get(buffer) |
34462 | 89 |
def is_active (buffer : JEditBuffer) = mapping.isDefinedAt(buffer) |
34463
b510b7d88de2
changed install/uninstall prover on view to private
immler@in.tum.de
parents:
34462
diff
changeset
|
90 |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
91 |
|
34433 | 92 |
// main plugin plumbing |
93 |
||
34429 | 94 |
override def handleMessage(msg: EBMessage) = msg match { |
34433 | 95 |
case epu: EditPaneUpdate => epu.getWhat match { |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
96 |
case EditPaneUpdate.BUFFER_CHANGED => |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
97 |
mapping get epu.getEditPane.getBuffer match { |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
98 |
//only activate 'isabelle'-buffers! |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
99 |
case None => |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
100 |
case Some(prover_setup) => |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
101 |
prover_setup.theory_view.activate |
34422 | 102 |
val dockable = epu.getEditPane.getView.getDockableWindowManager.getDockable("isabelle-output") |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
103 |
if(dockable != null) { |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
104 |
val output_dockable = dockable.asInstanceOf[OutputDockable] |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
105 |
if(output_dockable.getComponent(0) != prover_setup.output_text_view ) { |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
106 |
output_dockable.asInstanceOf[OutputDockable].removeAll |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
107 |
output_dockable.asInstanceOf[OutputDockable].add(new JScrollPane(prover_setup.output_text_view)) |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
108 |
output_dockable.revalidate |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
109 |
} |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
110 |
} |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
111 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
112 |
case EditPaneUpdate.BUFFER_CHANGING => |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
113 |
val buffer = epu.getEditPane.getBuffer |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
114 |
if(buffer != null) mapping get buffer match { |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
115 |
//only deactivate 'isabelle'-buffers! |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
116 |
case None => |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
117 |
case Some(prover_setup) => prover_setup.theory_view.deactivate |
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
118 |
} |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
119 |
case _ => |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
120 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
121 |
case _ => |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
122 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
123 |
|
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
124 |
override def start() { |
34441
ff3b7ae2b12a
replaced static IsabelleSystem by Isabelle.system;
wenzelm
parents:
34440
diff
changeset
|
125 |
Isabelle.system = new IsabelleSystem |
34440 | 126 |
Isabelle.plugin = this |
34406
f81cd75ae331
restructured: independent provers in different buffers
immler@in.tum.de
parents:
34337
diff
changeset
|
127 |
|
34468
9d4b4f290676
maintain Isabelle properties via object Isabelle.Property with apply/update methods;
wenzelm
parents:
34463
diff
changeset
|
128 |
if (Isabelle.Property("font-path") != null && Isabelle.Property("font-size") != null) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
129 |
try { |
34468
9d4b4f290676
maintain Isabelle properties via object Isabelle.Property with apply/update methods;
wenzelm
parents:
34463
diff
changeset
|
130 |
set_font(Isabelle.Property("font-path"), Isabelle.Property("font-size").toFloat) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
131 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
132 |
catch { |
34429 | 133 |
case e: NumberFormatException => |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
134 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
135 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
136 |
|
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
137 |
override def stop() { |
34429 | 138 |
// TODO: proper cleanup |
34441
ff3b7ae2b12a
replaced static IsabelleSystem by Isabelle.system;
wenzelm
parents:
34440
diff
changeset
|
139 |
Isabelle.system = null |
34440 | 140 |
Isabelle.plugin = null |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
141 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
142 |
} |