src/Tools/jEdit/src/isabelle.scala
author wenzelm
Tue, 18 Feb 2014 19:00:13 +0100
changeset 55557 aa1adeca714b
parent 55500 cdbbaa3074a8
child 55558 298274c970b6
permissions -rw-r--r--
standardized action and panel names;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50208
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
     1
/*  Title:      Tools/jEdit/src/isabelle.scala
50183
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
     3
53277
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
     4
Global configuration and convenience operations for Isabelle/jEdit.
50183
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
     5
*/
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
     6
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
     8
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
     9
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
    10
import isabelle._
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
    11
53715
68c664737d04 added option "jedit_auto_load";
wenzelm
parents: 53497
diff changeset
    12
import scala.swing.CheckBox
68c664737d04 added option "jedit_auto_load";
wenzelm
parents: 53497
diff changeset
    13
import scala.swing.event.ButtonClicked
68c664737d04 added option "jedit_auto_load";
wenzelm
parents: 53497
diff changeset
    14
50198
0c7b351a6871 added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents: 50187
diff changeset
    15
import org.gjt.sp.jedit.{jEdit, View, Buffer}
50183
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
    16
import org.gjt.sp.jedit.textarea.JEditTextArea
53293
fd27b8f5a479 added action isabelle.complete, using standard jEdit keyboard shortcut;
wenzelm
parents: 53281
diff changeset
    17
import org.gjt.sp.jedit.gui.{DockableWindowManager, CompleteWord}
50183
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
    18
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
    19
50208
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    20
object Isabelle
50183
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
    21
{
53274
1760c01f1c78 maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents: 53272
diff changeset
    22
  /* editor modes */
1760c01f1c78 maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents: 53272
diff changeset
    23
53277
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    24
  val modes =
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    25
    List(
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    26
      "isabelle",         // theory source
55500
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    27
      "isabelle-ml",      // ML source
53281
251e1a2aa792 clarified SideKick parser name, which serves as quasi "mode" here;
wenzelm
parents: 53280
diff changeset
    28
      "isabelle-markup",  // SideKick markup tree
53277
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    29
      "isabelle-news",    // NEWS
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    30
      "isabelle-options", // etc/options
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    31
      "isabelle-output",  // pretty text area output
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    32
      "isabelle-root")    // session ROOT
53274
1760c01f1c78 maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents: 53272
diff changeset
    33
55500
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    34
  private lazy val symbols_syntax = Outer_Syntax.init().no_tokens
53276
cbed0aa0b0db syntax for isabelle-news with symbol completion;
wenzelm
parents: 53274
diff changeset
    35
53274
1760c01f1c78 maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents: 53272
diff changeset
    36
  def mode_syntax(name: String): Option[Outer_Syntax] =
1760c01f1c78 maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents: 53272
diff changeset
    37
    name match {
53281
251e1a2aa792 clarified SideKick parser name, which serves as quasi "mode" here;
wenzelm
parents: 53280
diff changeset
    38
      case "isabelle" | "isabelle-markup" =>
53277
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    39
        val syntax = PIDE.session.recent_syntax
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    40
        if (syntax == Outer_Syntax.empty) None else Some(syntax)
53274
1760c01f1c78 maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents: 53272
diff changeset
    41
      case "isabelle-options" => Some(Options.options_syntax)
1760c01f1c78 maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents: 53272
diff changeset
    42
      case "isabelle-root" => Some(Build.root_syntax)
55500
cdbbaa3074a8 isabelle-ml mode with separate token marker;
wenzelm
parents: 55316
diff changeset
    43
      case "isabelle-ml" | "isabelle-news" => Some(symbols_syntax)
53277
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    44
      case "isabelle-output" => None
53274
1760c01f1c78 maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents: 53272
diff changeset
    45
      case _ => None
1760c01f1c78 maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents: 53272
diff changeset
    46
    }
1760c01f1c78 maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents: 53272
diff changeset
    47
1760c01f1c78 maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents: 53272
diff changeset
    48
53277
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    49
  /* token markers */
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    50
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    51
  private val markers =
53280
c63a016805b9 explicit indication of outer syntax with no tokens;
wenzelm
parents: 53277
diff changeset
    52
    Map(modes.map(name => (name, new Token_Markup.Marker(name))): _*)
53277
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    53
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    54
  def token_marker(name: String): Option[Token_Markup.Marker] = markers.get(name)
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    55
6aa348237973 more uniform configuration of editor modes and token markers;
wenzelm
parents: 53276
diff changeset
    56
50208
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    57
  /* dockable windows */
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    58
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    59
  private def wm(view: View): DockableWindowManager = view.getDockableWindowManager
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    60
50299
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50209
diff changeset
    61
  def docked_theories(view: View): Option[Theories_Dockable] =
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50209
diff changeset
    62
    wm(view).getDockableWindow("isabelle-theories") match {
f70b3712040f renamed dockable "Prover Session" to "Theories";
wenzelm
parents: 50209
diff changeset
    63
      case dockable: Theories_Dockable => Some(dockable)
50208
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    64
      case _ => None
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    65
    }
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    66
51533
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 50775
diff changeset
    67
  def docked_timing(view: View): Option[Timing_Dockable] =
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 50775
diff changeset
    68
    wm(view).getDockableWindow("isabelle-timing") match {
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 50775
diff changeset
    69
      case dockable: Timing_Dockable => Some(dockable)
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 50775
diff changeset
    70
      case _ => None
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 50775
diff changeset
    71
    }
3f6280aedbcc dockable window for timing information;
wenzelm
parents: 50775
diff changeset
    72
50208
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    73
  def docked_output(view: View): Option[Output_Dockable] =
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    74
    wm(view).getDockableWindow("isabelle-output") match {
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    75
      case dockable: Output_Dockable => Some(dockable)
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    76
      case _ => None
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    77
    }
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    78
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    79
  def docked_raw_output(view: View): Option[Raw_Output_Dockable] =
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    80
    wm(view).getDockableWindow("isabelle-raw-output") match {
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    81
      case dockable: Raw_Output_Dockable => Some(dockable)
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    82
      case _ => None
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    83
    }
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    84
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54640
diff changeset
    85
  def docked_simplifier_trace(view: View): Option[Simplifier_Trace_Dockable] =
55557
aa1adeca714b standardized action and panel names;
wenzelm
parents: 55500
diff changeset
    86
    wm(view).getDockableWindow("isabelle-simplifier-trace") match {
55316
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54640
diff changeset
    87
      case dockable: Simplifier_Trace_Dockable => Some(dockable)
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54640
diff changeset
    88
      case _ => None
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54640
diff changeset
    89
    }
885500f4aa6a interactive simplifier trace: new panel in Isabelle/jEdit to inspect and modify simplification state
Lars Hupel <lars.hupel@mytum.de>
parents: 54640
diff changeset
    90
50208
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    91
  def docked_protocol(view: View): Option[Protocol_Dockable] =
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    92
    wm(view).getDockableWindow("isabelle-protocol") match {
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    93
      case dockable: Protocol_Dockable => Some(dockable)
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    94
      case _ => None
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    95
    }
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
    96
50433
9131dadb2bf7 basic monitor panel, using the powerful jfreechart library;
wenzelm
parents: 50341
diff changeset
    97
  def docked_monitor(view: View): Option[Monitor_Dockable] =
9131dadb2bf7 basic monitor panel, using the powerful jfreechart library;
wenzelm
parents: 50341
diff changeset
    98
    wm(view).getDockableWindow("isabelle-monitor") match {
9131dadb2bf7 basic monitor panel, using the powerful jfreechart library;
wenzelm
parents: 50341
diff changeset
    99
      case dockable: Monitor_Dockable => Some(dockable)
9131dadb2bf7 basic monitor panel, using the powerful jfreechart library;
wenzelm
parents: 50341
diff changeset
   100
      case _ => None
9131dadb2bf7 basic monitor panel, using the powerful jfreechart library;
wenzelm
parents: 50341
diff changeset
   101
    }
9131dadb2bf7 basic monitor panel, using the powerful jfreechart library;
wenzelm
parents: 50341
diff changeset
   102
50208
1382ad6d4774 tuned signature;
wenzelm
parents: 50206
diff changeset
   103
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   104
  /* continuous checking */
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   105
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   106
  private val CONTINUOUS_CHECKING = "editor_continuous_checking"
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   107
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   108
  def continuous_checking: Boolean = PIDE.options.bool(CONTINUOUS_CHECKING)
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   109
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   110
  def continuous_checking_=(b: Boolean)
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   111
  {
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   112
    Swing_Thread.require()
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   113
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   114
    if (continuous_checking != b) {
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   115
      PIDE.options.bool(CONTINUOUS_CHECKING) = b
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   116
      PIDE.options_changed()
52974
908e8a36e975 tuned signature;
wenzelm
parents: 52816
diff changeset
   117
      PIDE.editor.flush()
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   118
    }
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   119
  }
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   120
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   121
  def set_continuous_checking() { continuous_checking = true }
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   122
  def reset_continuous_checking() { continuous_checking = false }
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   123
  def toggle_continuous_checking() { continuous_checking = !continuous_checking }
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   124
53715
68c664737d04 added option "jedit_auto_load";
wenzelm
parents: 53497
diff changeset
   125
  class Continuous_Checking extends CheckBox("Continuous checking")
68c664737d04 added option "jedit_auto_load";
wenzelm
parents: 53497
diff changeset
   126
  {
68c664737d04 added option "jedit_auto_load";
wenzelm
parents: 53497
diff changeset
   127
    tooltip = "Continuous checking of proof document (visible and required parts)"
68c664737d04 added option "jedit_auto_load";
wenzelm
parents: 53497
diff changeset
   128
    reactions += { case ButtonClicked(_) => continuous_checking = selected }
68c664737d04 added option "jedit_auto_load";
wenzelm
parents: 53497
diff changeset
   129
    def load() { selected = continuous_checking }
68c664737d04 added option "jedit_auto_load";
wenzelm
parents: 53497
diff changeset
   130
    load()
68c664737d04 added option "jedit_auto_load";
wenzelm
parents: 53497
diff changeset
   131
  }
68c664737d04 added option "jedit_auto_load";
wenzelm
parents: 53497
diff changeset
   132
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   133
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   134
  /* required document nodes */
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   135
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   136
  private def node_required_update(view: View, toggle: Boolean = false, set: Boolean = false)
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   137
  {
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   138
    Swing_Thread.require()
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   139
    PIDE.document_model(view.getBuffer) match {
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   140
      case Some(model) =>
52816
c608e0ade554 home-grown mouse handling to pretend that the painted checkbox is actually a Swing component;
wenzelm
parents: 52815
diff changeset
   141
        model.node_required = (if (toggle) !model.node_required else set)
52815
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   142
      case None =>
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   143
    }
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   144
  }
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   145
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   146
  def set_node_required(view: View) { node_required_update(view, set = true) }
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   147
  def reset_node_required(view: View) { node_required_update(view, set = false) }
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   148
  def toggle_node_required(view: View) { node_required_update(view, toggle = true) }
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   149
eaad5fe7bb1b actions and shortcuts to change node_required status, with painter that looks like CheckBox (non-clickable);
wenzelm
parents: 51533
diff changeset
   150
50198
0c7b351a6871 added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents: 50187
diff changeset
   151
  /* font size */
0c7b351a6871 added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents: 50187
diff changeset
   152
53272
0dfd78ff7696 more abstract Completion_Popup.Text_Area;
wenzelm
parents: 53161
diff changeset
   153
  def reset_font_size(view: View): Unit =
0dfd78ff7696 more abstract Completion_Popup.Text_Area;
wenzelm
parents: 53161
diff changeset
   154
    Rendering.font_size_change(view, _ => PIDE.options.int("jedit_reset_font_size"))
50198
0c7b351a6871 added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents: 50187
diff changeset
   155
53272
0dfd78ff7696 more abstract Completion_Popup.Text_Area;
wenzelm
parents: 53161
diff changeset
   156
  def increase_font_size(view: View): Unit =
0dfd78ff7696 more abstract Completion_Popup.Text_Area;
wenzelm
parents: 53161
diff changeset
   157
    Rendering.font_size_change(view, i => i + ((i / 10) max 1))
0dfd78ff7696 more abstract Completion_Popup.Text_Area;
wenzelm
parents: 53161
diff changeset
   158
0dfd78ff7696 more abstract Completion_Popup.Text_Area;
wenzelm
parents: 53161
diff changeset
   159
  def decrease_font_size(view: View): Unit =
0dfd78ff7696 more abstract Completion_Popup.Text_Area;
wenzelm
parents: 53161
diff changeset
   160
    Rendering.font_size_change(view, i => i - ((i / 10) max 1))
50198
0c7b351a6871 added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents: 50187
diff changeset
   161
0c7b351a6871 added convenience actions isabelle.increase-font-size and isabelle.decrease-font-size;
wenzelm
parents: 50187
diff changeset
   162
53497
07bb77881b8d tuned signature;
wenzelm
parents: 53322
diff changeset
   163
  /* structured edits */
50341
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   164
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   165
  def insert_line_padding(text_area: JEditTextArea, text: String)
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   166
  {
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   167
    val buffer = text_area.getBuffer
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   168
    JEdit_Lib.buffer_edit(buffer) {
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   169
      val text1 =
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   170
        if (text_area.getSelectionCount == 0) {
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   171
          def pad(range: Text.Range): String =
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   172
            if (JEdit_Lib.try_get_text(buffer, range) == Some("\n")) "" else "\n"
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   173
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   174
          val caret = JEdit_Lib.point_range(buffer, text_area.getCaretPosition)
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   175
          val before_caret = JEdit_Lib.point_range(buffer, caret.start - 1)
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   176
          pad(before_caret) + text + pad(caret)
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   177
        }
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   178
        else text
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   179
      text_area.setSelectedText(text1)
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   180
    }
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   181
  }
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   182
53497
07bb77881b8d tuned signature;
wenzelm
parents: 53322
diff changeset
   183
  def edit_command(
07bb77881b8d tuned signature;
wenzelm
parents: 53322
diff changeset
   184
    snapshot: Document.Snapshot,
07bb77881b8d tuned signature;
wenzelm
parents: 53322
diff changeset
   185
    buffer: Buffer,
07bb77881b8d tuned signature;
wenzelm
parents: 53322
diff changeset
   186
    padding: Boolean,
54640
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   187
    id: Document_ID.Generic,
53497
07bb77881b8d tuned signature;
wenzelm
parents: 53322
diff changeset
   188
    s: String)
07bb77881b8d tuned signature;
wenzelm
parents: 53322
diff changeset
   189
  {
54640
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   190
    if (!snapshot.is_outdated) {
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   191
      snapshot.state.find_command(snapshot.version, id) match {
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   192
        case Some((node, command)) =>
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   193
          node.command_start(command) match {
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   194
            case Some(start) =>
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   195
              JEdit_Lib.buffer_edit(buffer) {
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   196
                val range = command.proper_range + start
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   197
                if (padding) {
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   198
                  buffer.insert(start + range.length, "\n" + s)
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   199
                }
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   200
                else {
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   201
                  buffer.remove(start, range.length)
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   202
                  buffer.insert(start, s)
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   203
                }
53497
07bb77881b8d tuned signature;
wenzelm
parents: 53322
diff changeset
   204
              }
54640
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   205
            case None =>
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   206
          }
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   207
        case None =>
bbd2fa353809 back to Status.FINISHED and immediate remove_overlay (reverting 6e69f9ca8f1c), which is important to avoid restart of print function after edits + re-assignment of located command;
wenzelm
parents: 53843
diff changeset
   208
      }
53497
07bb77881b8d tuned signature;
wenzelm
parents: 53322
diff changeset
   209
    }
07bb77881b8d tuned signature;
wenzelm
parents: 53322
diff changeset
   210
  }
07bb77881b8d tuned signature;
wenzelm
parents: 53322
diff changeset
   211
50341
0c65a7cfc0f3 provide general insert_line_padding as convenience operation, e.g. for BeanShell macros;
wenzelm
parents: 50299
diff changeset
   212
53293
fd27b8f5a479 added action isabelle.complete, using standard jEdit keyboard shortcut;
wenzelm
parents: 53281
diff changeset
   213
  /* completion */
fd27b8f5a479 added action isabelle.complete, using standard jEdit keyboard shortcut;
wenzelm
parents: 53281
diff changeset
   214
fd27b8f5a479 added action isabelle.complete, using standard jEdit keyboard shortcut;
wenzelm
parents: 53281
diff changeset
   215
  def complete(view: View)
fd27b8f5a479 added action isabelle.complete, using standard jEdit keyboard shortcut;
wenzelm
parents: 53281
diff changeset
   216
  {
fd27b8f5a479 added action isabelle.complete, using standard jEdit keyboard shortcut;
wenzelm
parents: 53281
diff changeset
   217
    Completion_Popup.Text_Area(view.getTextArea) match {
53322
a4cd032172e0 allow short words for explicit completion;
wenzelm
parents: 53293
diff changeset
   218
      case Some(text_area_completion) =>
a4cd032172e0 allow short words for explicit completion;
wenzelm
parents: 53293
diff changeset
   219
        text_area_completion.action(immediate = true, explicit = true)
53293
fd27b8f5a479 added action isabelle.complete, using standard jEdit keyboard shortcut;
wenzelm
parents: 53281
diff changeset
   220
      case None => CompleteWord.completeWord(view)
fd27b8f5a479 added action isabelle.complete, using standard jEdit keyboard shortcut;
wenzelm
parents: 53281
diff changeset
   221
    }
fd27b8f5a479 added action isabelle.complete, using standard jEdit keyboard shortcut;
wenzelm
parents: 53281
diff changeset
   222
  }
fd27b8f5a479 added action isabelle.complete, using standard jEdit keyboard shortcut;
wenzelm
parents: 53281
diff changeset
   223
fd27b8f5a479 added action isabelle.complete, using standard jEdit keyboard shortcut;
wenzelm
parents: 53281
diff changeset
   224
50183
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   225
  /* control styles */
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   226
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   227
  def control_sub(text_area: JEditTextArea)
50187
b5a09812abc4 special handling of control symbols in Symbols dockable;
wenzelm
parents: 50183
diff changeset
   228
  { Token_Markup.edit_control_style(text_area, Symbol.sub_decoded) }
50183
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   229
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   230
  def control_sup(text_area: JEditTextArea)
50187
b5a09812abc4 special handling of control symbols in Symbols dockable;
wenzelm
parents: 50183
diff changeset
   231
  { Token_Markup.edit_control_style(text_area, Symbol.sup_decoded) }
50183
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   232
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   233
  def control_bold(text_area: JEditTextArea)
50187
b5a09812abc4 special handling of control symbols in Symbols dockable;
wenzelm
parents: 50183
diff changeset
   234
  { Token_Markup.edit_control_style(text_area, Symbol.bold_decoded) }
50183
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   235
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   236
  def control_reset(text_area: JEditTextArea)
50187
b5a09812abc4 special handling of control symbols in Symbols dockable;
wenzelm
parents: 50183
diff changeset
   237
  { Token_Markup.edit_control_style(text_area, "") }
50183
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   238
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   239
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   240
  /* block styles */
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   241
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   242
  private def enclose_input(text_area: JEditTextArea, s1: String, s2: String)
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   243
  {
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   244
    s1.foreach(text_area.userInput(_))
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   245
    s2.foreach(text_area.userInput(_))
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   246
    s2.foreach(_ => text_area.goToPrevCharacter(false))
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   247
  }
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   248
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   249
  def input_bsub(text_area: JEditTextArea)
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   250
  { enclose_input(text_area, Symbol.bsub_decoded, Symbol.esub_decoded) }
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   251
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   252
  def input_bsup(text_area: JEditTextArea)
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   253
  { enclose_input(text_area, Symbol.bsup_decoded, Symbol.esup_decoded) }
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   254
}
2b3e24e1c9e7 improved editing support for control styles;
wenzelm
parents:
diff changeset
   255