src/Tools/jEdit/src/jedit/plugin.scala
author wenzelm
Thu, 20 May 2010 23:20:01 +0200
changeset 37019 8f747cee4e27
parent 36814 dc85664dbf6d
child 37068 07936a4efe93
permissions -rw-r--r--
zoom font size;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36760
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     1
/*  Title:      Tools/jEdit/src/jedit/plugin.scala
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     2
    Author:     Johannes Hölzl, TU Munich
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     3
    Author:     Fabian Immler, TU Munich
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     4
    Author:     Makarius
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     5
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     6
Main Isabelle/jEdit plugin setup.
b82a698ef6c9 tuned headers;
wenzelm
parents: 36015
diff changeset
     7
*/
34407
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
36015
6111de7c916a adapted to Scala 2.8.0 Beta 1;
wenzelm
parents: 34871
diff changeset
    12
import isabelle._
6111de7c916a adapted to Scala 2.8.0 Beta 1;
wenzelm
parents: 34871
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
34822
8c31275868cc tuned dialog;
wenzelm
parents: 34821
diff changeset
    16
import javax.swing.JTextArea
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
{
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
    28
  /* plugin instance */
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
    29
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
    30
  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
    31
  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
    32
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
    33
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    34
  /* name */
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    35
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
    36
  val NAME = "Isabelle"
34623
a356a8ee6f00 renamed UTF-8-isabelle to UTF-8-Isabelle;
wenzelm
parents: 34618
diff changeset
    37
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    38
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    39
  /* properties */
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    40
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    41
  val OPTION_PREFIX = "options.isabelle."
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    42
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    43
  object Property
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    44
  {
36814
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    45
    def apply(name: String): String =
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    46
      jEdit.getProperty(OPTION_PREFIX + name)
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    47
    def apply(name: String, default: String): String =
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    48
      jEdit.getProperty(OPTION_PREFIX + name, default)
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    49
    def update(name: String, value: String) =
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    50
      jEdit.setProperty(OPTION_PREFIX + name, value)
34468
9d4b4f290676 maintain Isabelle properties via object Isabelle.Property with apply/update methods;
wenzelm
parents: 34463
diff changeset
    51
  }
34433
3da749b53842 renamed Plugin.plugin to Plugin.self;
wenzelm
parents: 34429
diff changeset
    52
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    53
  object Boolean_Property
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    54
  {
36814
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    55
    def apply(name: String): Boolean =
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    56
      jEdit.getBooleanProperty(OPTION_PREFIX + name)
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    57
    def apply(name: String, default: Boolean): Boolean =
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    58
      jEdit.getBooleanProperty(OPTION_PREFIX + name, default)
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    59
    def update(name: String, value: Boolean) =
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    60
      jEdit.setBooleanProperty(OPTION_PREFIX + name, value)
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    61
  }
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    62
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    63
  object Int_Property
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    64
  {
36814
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    65
    def apply(name: String): Int =
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    66
      jEdit.getIntegerProperty(OPTION_PREFIX + name)
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    67
    def apply(name: String, default: Int): Int =
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    68
      jEdit.getIntegerProperty(OPTION_PREFIX + name, default)
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    69
    def update(name: String, value: Int) =
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    70
      jEdit.setIntegerProperty(OPTION_PREFIX + name, value)
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    71
  }
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    72
37019
8f747cee4e27 zoom font size;
wenzelm
parents: 36814
diff changeset
    73
  def font_size(): Float =
8f747cee4e27 zoom font size;
wenzelm
parents: 36814
diff changeset
    74
    (jEdit.getIntegerProperty("view.fontsize", 16) *
8f747cee4e27 zoom font size;
wenzelm
parents: 36814
diff changeset
    75
      Int_Property("relative-font-size", 100)).toFloat / 100
36814
dc85664dbf6d support Isabelle plugin properties with defaults;
wenzelm
parents: 36760
diff changeset
    76
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    77
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    78
  /* settings */
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    79
34782
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    80
  def default_logic(): String =
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    81
  {
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    82
    val logic = system.getenv("JEDIT_LOGIC")
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    83
    if (logic != "") logic
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    84
    else system.getenv_strict("ISABELLE_LOGIC")
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    85
  }
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    86
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    87
  def isabelle_args(): List[String] =
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    88
  {
34780
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34779
diff changeset
    89
    val modes = system.getenv("JEDIT_PRINT_MODE").split(",").toList.map("-m" + _)
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34779
diff changeset
    90
    val logic = {
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
    91
      val logic = Property("logic")
34782
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    92
      if (logic != null && logic != "") logic
fcd6a41326a6 refined treatment of default logic concerning property and GUI;
wenzelm
parents: 34781
diff changeset
    93
      else default_logic()
34780
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34779
diff changeset
    94
    }
d0ff1c3a91ea more serious command line handling;
wenzelm
parents: 34779
diff changeset
    95
    modes ++ List(logic)
34502
7d1d13750890 added Isabelle.default_logic;
wenzelm
parents: 34497
diff changeset
    96
  }
7d1d13750890 added Isabelle.default_logic;
wenzelm
parents: 34497
diff changeset
    97
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
    98
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
    99
  /* main jEdit components */  // FIXME ownership!?
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   100
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   101
  def jedit_buffers(): Iterator[Buffer] = Iterator.fromArray(jEdit.getBuffers())
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   102
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   103
  def jedit_views(): Iterator[View] = Iterator.fromArray(jEdit.getViews())
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   104
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   105
  def jedit_text_areas(view: View): Iterator[JEditTextArea] =
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   106
    Iterator.fromArray(view.getEditPanes).map(_.getTextArea)
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   107
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   108
  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
   109
    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
   110
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   111
  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
   112
    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
   113
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   114
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   115
  /* manage prover */
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   116
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   117
  private def prover_started(view: View): Boolean =
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   118
  {
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   119
    val timeout = Int_Property("startup-timeout") max 1000
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   120
    session.start(timeout, Isabelle.isabelle_args()) match {
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   121
      case Some(err) =>
34822
8c31275868cc tuned dialog;
wenzelm
parents: 34821
diff changeset
   122
        val text = new JTextArea(err); text.setEditable(false)
8c31275868cc tuned dialog;
wenzelm
parents: 34821
diff changeset
   123
        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
   124
        false
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   125
      case None => true
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   126
    }
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   127
  }
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   128
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   129
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   130
  /* activation */
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   131
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   132
  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
   133
  {
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   134
    if (prover_started(view)) {
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   135
      val model = Document_Model.init(session, buffer)
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   136
      for (text_area <- jedit_text_areas(buffer))
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   137
        Document_View.init(model, text_area)
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   138
    }
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   139
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   140
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   141
  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
   142
  {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   143
    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
   144
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   145
    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
   146
      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
   147
    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
   148
  }
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 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
   151
  {
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   152
    val buffer = view.getBuffer
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34787
diff changeset
   153
    if (Document_Model(buffer).isDefined) deactivate_buffer(buffer)
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34808
diff changeset
   154
    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
   155
  }
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   156
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   157
  def is_active(view: View): Boolean =
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34787
diff changeset
   158
    Document_Model(view.getBuffer).isDefined
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   159
}
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   160
34429
wenzelm
parents: 34422
diff changeset
   161
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   162
class Plugin extends EBPlugin
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   163
{
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   164
  /* main plugin plumbing */
34433
3da749b53842 renamed Plugin.plugin to Plugin.self;
wenzelm
parents: 34429
diff changeset
   165
34767
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   166
  override def handleMessage(message: EBMessage)
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   167
  {
34767
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   168
    message match {
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   169
      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
   170
        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
   171
        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
   172
        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
   173
34787
0feac35069c6 need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents: 34784
diff changeset
   174
        def init_view()
0feac35069c6 need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents: 34784
diff changeset
   175
        {
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34787
diff changeset
   176
          Document_Model(buffer) match {
34787
0feac35069c6 need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents: 34784
diff changeset
   177
            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
   178
            case None =>
0feac35069c6 need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents: 34784
diff changeset
   179
          }
0feac35069c6 need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents: 34784
diff changeset
   180
        }
0feac35069c6 need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents: 34784
diff changeset
   181
        def exit_view()
0feac35069c6 need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents: 34784
diff changeset
   182
        {
34788
3779c54a2d21 direct apply for Document_Model and Document_View;
wenzelm
parents: 34787
diff changeset
   183
          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
   184
            Document_View.exit(text_area)
0feac35069c6 need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents: 34784
diff changeset
   185
        }
34767
8dd19c5f8c56 added properties_changed event bus;
wenzelm
parents: 34764
diff changeset
   186
        msg.getWhat match {
34787
0feac35069c6 need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents: 34784
diff changeset
   187
          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
   188
          case EditPaneUpdate.CREATED => init_view()
0feac35069c6 need to handle EditPaneUpdate.CREATED explicitly, not included in EditPaneUpdate.BUFFER_CHANGED;
wenzelm
parents: 34784
diff changeset
   189
          case EditPaneUpdate.DESTROYED => exit_view()
34671
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34670
diff changeset
   190
          case _ =>
d179fcb04cbc output_info specific to prover
immler@in.tum.de
parents: 34670
diff changeset
   191
        }
34784
02959dcea756 split Theory_View into Document_Model (connected to Buffer) and Document_View (connected to JEditTextArea);
wenzelm
parents: 34782
diff changeset
   192
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   193
      case msg: PropertiesChanged =>
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34788
diff changeset
   194
        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
   195
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   196
      case _ =>
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   197
    }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   198
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   199
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   200
  override def start()
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   201
  {
34615
5e61055bf35b renamed IsabelleProcess to Isabelle_Process;
wenzelm
parents: 34612
diff changeset
   202
    Isabelle.system = new Isabelle_System
34774
1fa466333361 install_fonts;
wenzelm
parents: 34772
diff changeset
   203
    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
   204
    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
   205
  }
34618
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   206
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   207
  override def stop()
e45052ff7233 added Boolean_Property, Int_Property;
wenzelm
parents: 34615
diff changeset
   208
  {
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents: 34774
diff changeset
   209
    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
   210
    Isabelle.session = null
34441
ff3b7ae2b12a replaced static IsabelleSystem by Isabelle.system;
wenzelm
parents: 34440
diff changeset
   211
    Isabelle.system = null
34318
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   212
  }
c13e168a8ae6 original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff changeset
   213
}