src/Tools/jEdit/src/jedit/plugin.scala
author wenzelm
Tue, 15 Dec 2009 00:21:21 +0100
changeset 34782 fcd6a41326a6
parent 34781 6c2372c4aefb
child 34784 02959dcea756
permissions -rw-r--r--
refined treatment of default logic concerning property and GUI;
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
34782
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    58
  def default_logic(): String =
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    59
  {
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    60
    val logic = system.getenv("JEDIT_LOGIC")
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    61
    if (logic != "") logic
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    62
    else system.getenv_strict("ISABELLE_LOGIC")
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    63
  }
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    64
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    65
  def isabelle_args(): List[String] =
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    66
  {
34780
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34779
diff changeset
    67
    val modes = system.getenv("JEDIT_PRINT_MODE").split(",").toList.map("-m" + _)
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34779
diff changeset
    68
    val logic = {
34782
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    69
      val logic = Isabelle.Property("logic")
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    70
      if (logic != null && logic != "") logic
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    71
      else default_logic()
34780
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34779
diff changeset
    72
    }
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34779
diff changeset
    73
    modes ++ List(logic)
34502
7d1d13750890 added Isabelle.default_logic;
wenzelm
parents: 34497
diff changeset
    74
  }
7d1d13750890 added Isabelle.default_logic;
wenzelm
parents: 34497
diff changeset
    75
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    76
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    77
  /* plugin instance */
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    78
34440
561a6d19bd95 renamed object Plugin to Isabelle;
wenzelm
parents: 34433
diff changeset
    79
  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
    80
  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
    81
  var session: Session = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    82
}
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    83
34429
wenzelm
parents: 34422
diff changeset
    84
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    85
class Plugin extends EBPlugin
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    86
{
34777
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 */
34669
73727c7eec64 state_update global in Plugin
immler@in.tum.de
parents: 34627
diff changeset
    88
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    89
  private var mapping = Map[JEditBuffer, Theory_View]()
34406
f81cd75ae331 restructured: independent provers in different buffers
immler@in.tum.de
parents: 34337
diff changeset
    90
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    91
  private def install(view: View)
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    92
  {
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    93
    val text_area = view.getTextArea
34406
f81cd75ae331 restructured: independent provers in different buffers
immler@in.tum.de
parents: 34337
diff changeset
    94
    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
    95
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    96
 
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    97
    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
    98
    mapping += (buffer -> theory_view)
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
    99
34782
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
   100
    Isabelle.session.start(Isabelle.isabelle_args())
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   101
    theory_view.activate()
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   102
    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
   103
  }
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
  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
   106
  {
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   107
    val buffer = view.getBuffer
34779
d1040b77b189 proper uninstall;
wenzelm
parents: 34777
diff changeset
   108
    Isabelle.session.stop()
d1040b77b189 proper uninstall;
wenzelm
parents: 34777
diff changeset
   109
    mapping(buffer).deactivate()
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   110
    mapping -= buffer
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   111
  }
34463
b510b7d88de2 changed install/uninstall prover on view to private
immler@in.tum.de
parents: 34462
diff changeset
   112
34764
wenzelm
parents: 34762
diff changeset
   113
  def switch_active(view: View) =
34463
b510b7d88de2 changed install/uninstall prover on view to private
immler@in.tum.de
parents: 34462
diff changeset
   114
    if (mapping.isDefinedAt(view.getBuffer)) uninstall(view)
b510b7d88de2 changed install/uninstall prover on view to private
immler@in.tum.de
parents: 34462
diff changeset
   115
    else install(view)
34406
f81cd75ae331 restructured: independent provers in different buffers
immler@in.tum.de
parents: 34337
diff changeset
   116
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   117
  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
   118
  def is_active(buffer: JEditBuffer) = mapping.isDefinedAt(buffer)
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   119
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   120
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   121
  /* main plugin plumbing */
34433
3da749b53842 renamed Plugin.plugin to Plugin.self;
wenzelm
parents: 34429
diff changeset
   122
34767
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   123
  override def handleMessage(message: EBMessage)
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   124
  {
34767
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   125
    message match {
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   126
      case msg: EditPaneUpdate =>
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   127
        val buffer = msg.getEditPane.getBuffer
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   128
        msg.getWhat match {
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34670
diff changeset
   129
          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
   130
            theory_view(buffer)map(_.activate)
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34670
diff changeset
   131
          case EditPaneUpdate.BUFFER_CHANGING =>
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34670
diff changeset
   132
            if (buffer != null)
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   133
              theory_view(buffer).map(_.deactivate)
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34670
diff changeset
   134
          case _ =>
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34670
diff changeset
   135
        }
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   136
      case msg: PropertiesChanged =>
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   137
        Isabelle.session.global_settings.event(())
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   138
      case _ =>
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   139
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   140
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   141
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   142
  override def start()
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   143
  {
34751
6ed1b3701459 simplified treatment of Isabelle fonts, via Isabelle_System.register_fonts (requires Java 1.6);
wenzelm
parents: 34732
diff changeset
   144
    Isabelle.plugin = this
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   145
    Isabelle.system = new Isabelle_System
34774
1fa466333361 install_fonts;
wenzelm
parents: 34772
diff changeset
   146
    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
   147
    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
   148
  }
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   149
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   150
  override def stop()
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   151
  {
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   152
    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
   153
    Isabelle.session = null
34441
ff3b7ae2b12a replaced static IsabelleSystem by Isabelle.system;
wenzelm
parents: 34440
diff changeset
   154
    Isabelle.system = null
34440
561a6d19bd95 renamed object Plugin to Isabelle;
wenzelm
parents: 34433
diff changeset
   155
    Isabelle.plugin = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   156
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   157
}