src/Tools/jEdit/src/jedit/plugin.scala
author wenzelm
Thu, 10 Dec 2009 22:15:19 +0100
changeset 34777 91d6089cef88
parent 34774 1fa466333361
child 34779 d1040b77b189
permissions -rw-r--r--
class Session models full session, with or without prover process (cf. heaps, browser_info); replaced Prover by Session, with a singleton instance in Isabelle plugin (shared by all active buffers); misc cleanup of Session vs. Plugin instance; eliminated Prover_Setup -- maintain mapping of JEditBuffer <-> Theory_View directly; misc tuning and simplification;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     1
/*
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     2
 * Main Isabelle/jEdit plugin setup
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     3
 *
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     4
 * @author Johannes Hölzl, TU Munich
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     5
 * @author Fabian Immler, TU Munich
34760
dc7f5e0d9d27 misc modernization of names;
wenzelm
parents: 34759
diff changeset
     6
 * @author Makarius
34407
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     7
 */
aad6834ba380 added some headers and comments;
wenzelm
parents: 34406
diff changeset
     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
34429
wenzelm
parents: 34422
diff changeset
    11
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    12
import isabelle.proofdocument.{Session, Theory_View}
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    13
34429
wenzelm
parents: 34422
diff changeset
    14
import java.io.{FileInputStream, IOException}
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    15
import java.awt.Font
34406
f81cd75ae331 restructured: independent provers in different buffers
immler@in.tum.de
parents: 34337
diff changeset
    16
import javax.swing.JScrollPane
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    17
34497
184fda8cce04 more explicit indication of mutable collections;
wenzelm
parents: 34487
diff changeset
    18
import scala.collection.mutable
34406
f81cd75ae331 restructured: independent provers in different buffers
immler@in.tum.de
parents: 34337
diff changeset
    19
34429
wenzelm
parents: 34422
diff changeset
    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
wenzelm
parents: 34422
diff changeset
    23
import org.gjt.sp.jedit.msg.{EditPaneUpdate, PropertiesChanged}
wenzelm
parents: 34422
diff changeset
    24
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    25
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    26
object Isabelle
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    27
{
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    28
  /* name */
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    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
a356a8ee6f00 renamed UTF-8-isabelle to UTF-8-Isabelle;
wenzelm
parents: 34618
diff changeset
    31
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    32
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    33
  /* properties */
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    34
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    35
  val OPTION_PREFIX = "options.isabelle."
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    36
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    37
  object Property
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    38
  {
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    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
3da749b53842 renamed Plugin.plugin to Plugin.self;
wenzelm
parents: 34429
diff changeset
    42
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    43
  object Boolean_Property
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    44
  {
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    45
    def apply(name: String): Boolean = jEdit.getBooleanProperty(OPTION_PREFIX + name)
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    46
    def update(name: String, value: Boolean) = jEdit.setBooleanProperty(OPTION_PREFIX + name, value)
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    47
  }
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    48
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    49
  object Int_Property
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    50
  {
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    51
    def apply(name: String): Int = jEdit.getIntegerProperty(OPTION_PREFIX + name)
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    52
    def update(name: String, value: Int) = jEdit.setIntegerProperty(OPTION_PREFIX + name, value)
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    53
  }
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    54
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    55
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    56
  /* settings */
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    57
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    58
  def get_logic(): String =
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    59
  {
34502
7d1d13750890 added Isabelle.default_logic;
wenzelm
parents: 34497
diff changeset
    60
    val logic = Isabelle.Property("logic")
34703
ff037c17332a minor tuning;
wenzelm
parents: 34696
diff changeset
    61
    if (logic != null) logic
ff037c17332a minor tuning;
wenzelm
parents: 34696
diff changeset
    62
    else system.getenv_strict("ISABELLE_LOGIC")
34502
7d1d13750890 added Isabelle.default_logic;
wenzelm
parents: 34497
diff changeset
    63
  }
7d1d13750890 added Isabelle.default_logic;
wenzelm
parents: 34497
diff changeset
    64
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    65
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    66
  /* plugin instance */
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    67
34440
561a6d19bd95 renamed object Plugin to Isabelle;
wenzelm
parents: 34433
diff changeset
    68
  var plugin: Plugin = null
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    69
  var system: Isabelle_System = null
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    70
  var session: Session = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    71
}
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    72
34429
wenzelm
parents: 34422
diff changeset
    73
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    74
class Plugin extends EBPlugin
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    75
{
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    76
  /* mapping buffer <-> theory view */
34669
73727c7eec64 state_update global in Plugin
immler@in.tum.de
parents: 34627
diff changeset
    77
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    78
  private var mapping = Map[JEditBuffer, Theory_View]()
34406
f81cd75ae331 restructured: independent provers in different buffers
immler@in.tum.de
parents: 34337
diff changeset
    79
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    80
  private def install(view: View)
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    81
  {
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    82
    val text_area = view.getTextArea
34406
f81cd75ae331 restructured: independent provers in different buffers
immler@in.tum.de
parents: 34337
diff changeset
    83
    val buffer = view.getBuffer
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    84
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    85
 
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    86
    val theory_view = new Theory_View(Isabelle.session, text_area)   // FIXME multiple text areas!?
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    87
    mapping += (buffer -> theory_view)
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    88
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    89
    Isabelle.session.start(Isabelle.get_logic())
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    90
    theory_view.activate()
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    91
    Isabelle.session.begin_document(buffer.getName)
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    92
  }
34406
f81cd75ae331 restructured: independent provers in different buffers
immler@in.tum.de
parents: 34337
diff changeset
    93
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    94
  private def uninstall(view: View)
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    95
  {
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    96
    val buffer = view.getBuffer
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    97
    mapping(buffer).deactivate
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    98
    mapping -= buffer
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    99
  }
34463
b510b7d88de2 changed install/uninstall prover on view to private
immler@in.tum.de
parents: 34462
diff changeset
   100
34764
wenzelm
parents: 34762
diff changeset
   101
  def switch_active(view: View) =
34463
b510b7d88de2 changed install/uninstall prover on view to private
immler@in.tum.de
parents: 34462
diff changeset
   102
    if (mapping.isDefinedAt(view.getBuffer)) uninstall(view)
b510b7d88de2 changed install/uninstall prover on view to private
immler@in.tum.de
parents: 34462
diff changeset
   103
    else install(view)
34406
f81cd75ae331 restructured: independent provers in different buffers
immler@in.tum.de
parents: 34337
diff changeset
   104
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   105
  def theory_view(buffer: JEditBuffer): Option[Theory_View] = mapping.get(buffer)
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   106
  def is_active(buffer: JEditBuffer) = mapping.isDefinedAt(buffer)
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   107
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   108
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   109
  /* main plugin plumbing */
34433
3da749b53842 renamed Plugin.plugin to Plugin.self;
wenzelm
parents: 34429
diff changeset
   110
34767
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   111
  override def handleMessage(message: EBMessage)
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   112
  {
34767
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   113
    message match {
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   114
      case msg: EditPaneUpdate =>
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   115
        val buffer = msg.getEditPane.getBuffer
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   116
        msg.getWhat match {
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34670
diff changeset
   117
          case EditPaneUpdate.BUFFER_CHANGED =>
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   118
            theory_view(buffer)map(_.activate)
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34670
diff changeset
   119
          case EditPaneUpdate.BUFFER_CHANGING =>
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34670
diff changeset
   120
            if (buffer != null)
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   121
              theory_view(buffer).map(_.deactivate)
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34670
diff changeset
   122
          case _ =>
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34670
diff changeset
   123
        }
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   124
      case msg: PropertiesChanged =>
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   125
        Isabelle.session.global_settings.event(())
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   126
      case _ =>
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   127
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   128
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   129
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   130
  override def start()
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   131
  {
34751
6ed1b3701459 simplified treatment of Isabelle fonts, via Isabelle_System.register_fonts (requires Java 1.6);
wenzelm
parents: 34732
diff changeset
   132
    Isabelle.plugin = this
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   133
    Isabelle.system = new Isabelle_System
34774
1fa466333361 install_fonts;
wenzelm
parents: 34772
diff changeset
   134
    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
   135
    Isabelle.session = new Session(Isabelle.system)  // FIXME dialog!?
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   136
  }
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   137
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   138
  override def stop()
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   139
  {
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   140
    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
   141
    Isabelle.session = null
34441
ff3b7ae2b12a replaced static IsabelleSystem by Isabelle.system;
wenzelm
parents: 34440
diff changeset
   142
    Isabelle.system = null
34440
561a6d19bd95 renamed object Plugin to Isabelle;
wenzelm
parents: 34433
diff changeset
   143
    Isabelle.plugin = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   144
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   145
}