src/Tools/jEdit/src/state_dockable.scala
author wenzelm
Tue, 17 Dec 2024 12:36:37 +0100
changeset 81615 ebf954ceb4d1
parent 81493 07e79b80e96d
child 81617 5c1059702995
permissions -rw-r--r--
clarified split_pane layout: close on first display, open on first search;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
     1
/*  Title:      Tools/jEdit/src/state_dockable.scala
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
     3
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
     4
Dockable window for proof state output.
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
     5
*/
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
     6
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
     8
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
     9
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    10
import isabelle._
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    11
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    12
import java.awt.BorderLayout
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    13
import java.awt.event.{ComponentEvent, ComponentAdapter}
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    14
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    15
import org.gjt.sp.jedit.View
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    16
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    17
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    18
class State_Dockable(view: View, position: String) extends Dockable(view, position) {
81493
07e79b80e96d clarified signature: avoid implicit functionality;
wenzelm
parents: 81489
diff changeset
    19
  dockable =>
07e79b80e96d clarified signature: avoid implicit functionality;
wenzelm
parents: 81489
diff changeset
    20
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    21
  GUI_Thread.require {}
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    22
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    23
81489
7293d47a9a70 re-use Output_Area with search results;
wenzelm
parents: 81398
diff changeset
    24
  /* output text area */
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    25
81615
ebf954ceb4d1 clarified split_pane layout: close on first display, open on first search;
wenzelm
parents: 81493
diff changeset
    26
  private val output: Output_Area =
ebf954ceb4d1 clarified split_pane layout: close on first display, open on first search;
wenzelm
parents: 81493
diff changeset
    27
    new Output_Area(view) {
ebf954ceb4d1 clarified split_pane layout: close on first display, open on first search;
wenzelm
parents: 81493
diff changeset
    28
      override def handle_shown(): Unit = split_pane_layout()
ebf954ceb4d1 clarified split_pane layout: close on first display, open on first search;
wenzelm
parents: 81493
diff changeset
    29
    }
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    30
81489
7293d47a9a70 re-use Output_Area with search results;
wenzelm
parents: 81398
diff changeset
    31
  override def detach_operation: Option[() => Unit] = output.pretty_text_area.detach_operation
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    32
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    33
  private val print_state =
81489
7293d47a9a70 re-use Output_Area with search results;
wenzelm
parents: 81398
diff changeset
    34
    new Query_Operation(PIDE.editor, view, "print_state", _ => (), output.pretty_text_area.update)
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    35
81493
07e79b80e96d clarified signature: avoid implicit functionality;
wenzelm
parents: 81489
diff changeset
    36
  output.setup(dockable)
07e79b80e96d clarified signature: avoid implicit functionality;
wenzelm
parents: 81489
diff changeset
    37
  set_content(output.split_pane)
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    38
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    39
61211
8a5d5ca5d8bc added action "isabelle-update-state";
wenzelm
parents: 61210
diff changeset
    40
  /* update */
61210
a3a05d734858 support for auto update via caret focus;
wenzelm
parents: 61208
diff changeset
    41
61801
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
    42
  def update_request(): Unit =
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
    43
    GUI_Thread.require { print_state.apply_query(Nil) }
61720
a31730632e13 recovered auto update from f9aaca00be49;
wenzelm
parents: 61220
diff changeset
    44
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    45
  def update(): Unit = {
61210
a3a05d734858 support for auto update via caret focus;
wenzelm
parents: 61208
diff changeset
    46
    GUI_Thread.require {}
a3a05d734858 support for auto update via caret focus;
wenzelm
parents: 61208
diff changeset
    47
66091
wenzelm
parents: 66082
diff changeset
    48
    PIDE.editor.current_node_snapshot(view) match {
61211
8a5d5ca5d8bc added action "isabelle-update-state";
wenzelm
parents: 61210
diff changeset
    49
      case Some(snapshot) =>
66082
2d12a730a380 clarified modules;
wenzelm
parents: 65246
diff changeset
    50
        (PIDE.editor.current_command(view, snapshot), print_state.get_location) match {
61211
8a5d5ca5d8bc added action "isabelle-update-state";
wenzelm
parents: 61210
diff changeset
    51
          case (Some(command1), Some(command2)) if command1.id == command2.id =>
61801
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
    52
          case _ => update_request()
61211
8a5d5ca5d8bc added action "isabelle-update-state";
wenzelm
parents: 61210
diff changeset
    53
        }
8a5d5ca5d8bc added action "isabelle-update-state";
wenzelm
parents: 61210
diff changeset
    54
      case None =>
61210
a3a05d734858 support for auto update via caret focus;
wenzelm
parents: 61208
diff changeset
    55
    }
a3a05d734858 support for auto update via caret focus;
wenzelm
parents: 61208
diff changeset
    56
  }
a3a05d734858 support for auto update via caret focus;
wenzelm
parents: 61208
diff changeset
    57
a3a05d734858 support for auto update via caret focus;
wenzelm
parents: 61208
diff changeset
    58
61801
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
    59
  /* auto update */
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
    60
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
    61
  private var auto_update_enabled = true
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
    62
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
    63
  private def auto_update(): Unit =
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
    64
    GUI_Thread.require { if (auto_update_enabled) update() }
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
    65
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
    66
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    67
  /* controls */
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    68
75854
2163772eeaf2 tuned signature;
wenzelm
parents: 75853
diff changeset
    69
  private val auto_update_button = new GUI.Check("Auto update", init = auto_update_enabled) {
61720
a31730632e13 recovered auto update from f9aaca00be49;
wenzelm
parents: 61220
diff changeset
    70
    tooltip = "Indicate automatic update following cursor movement"
75852
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
    71
    override def clicked(state: Boolean): Unit = {
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
    72
      auto_update_enabled = state
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
    73
      auto_update()
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
    74
    }
61720
a31730632e13 recovered auto update from f9aaca00be49;
wenzelm
parents: 61220
diff changeset
    75
  }
a31730632e13 recovered auto update from f9aaca00be49;
wenzelm
parents: 61220
diff changeset
    76
75853
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
    77
  private val update_button = new GUI.Button("<html><b>Update</b></html>") {
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    78
    tooltip = "Update display according to the command at cursor position"
75853
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
    79
    override def clicked(): Unit = update_request()
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    80
  }
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    81
75853
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
    82
  private val locate_button = new GUI.Button("Locate") {
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    83
    tooltip = "Locate printed command within source text"
75853
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
    84
    override def clicked(): Unit = print_state.locate_query()
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    85
  }
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    86
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    87
  private val controls =
66205
e9fa94f43a15 tuned signature;
wenzelm
parents: 66091
diff changeset
    88
    Wrap_Panel(
81379
cbfc76aace10 tuned signature;
wenzelm
parents: 76610
diff changeset
    89
      List(auto_update_button, update_button, locate_button) :::
81489
7293d47a9a70 re-use Output_Area with search results;
wenzelm
parents: 81398
diff changeset
    90
      output.pretty_text_area.search_zoom_components)
66205
e9fa94f43a15 tuned signature;
wenzelm
parents: 66091
diff changeset
    91
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    92
  add(controls.peer, BorderLayout.NORTH)
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    93
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    94
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    95
  /* main */
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    96
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    97
  private val main =
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    98
    Session.Consumer[Any](getClass.getName) {
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
    99
      case _: Session.Global_Options =>
81489
7293d47a9a70 re-use Output_Area with search results;
wenzelm
parents: 81398
diff changeset
   100
        GUI_Thread.later { output.handle_resize() }
61720
a31730632e13 recovered auto update from f9aaca00be49;
wenzelm
parents: 61220
diff changeset
   101
a31730632e13 recovered auto update from f9aaca00be49;
wenzelm
parents: 61220
diff changeset
   102
      case changed: Session.Commands_Changed =>
61801
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
   103
        if (changed.assignment) GUI_Thread.later { auto_update() }
61720
a31730632e13 recovered auto update from f9aaca00be49;
wenzelm
parents: 61220
diff changeset
   104
a31730632e13 recovered auto update from f9aaca00be49;
wenzelm
parents: 61220
diff changeset
   105
      case Session.Caret_Focus =>
61801
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
   106
        GUI_Thread.later { auto_update() }
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
   107
    }
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
   108
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
   109
  override def init(): Unit = {
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
   110
    PIDE.session.global_options += main
61720
a31730632e13 recovered auto update from f9aaca00be49;
wenzelm
parents: 61220
diff changeset
   111
    PIDE.session.commands_changed += main
a31730632e13 recovered auto update from f9aaca00be49;
wenzelm
parents: 61220
diff changeset
   112
    PIDE.session.caret_focus += main
81489
7293d47a9a70 re-use Output_Area with search results;
wenzelm
parents: 81398
diff changeset
   113
    output.init()
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
   114
    print_state.activate()
61801
fa8d1cdf6518 tuned signature;
wenzelm
parents: 61726
diff changeset
   115
    auto_update()
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
   116
  }
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
   117
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
   118
  override def exit(): Unit = {
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
   119
    print_state.deactivate()
61720
a31730632e13 recovered auto update from f9aaca00be49;
wenzelm
parents: 61220
diff changeset
   120
    PIDE.session.caret_focus -= main
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
   121
    PIDE.session.global_options -= main
61720
a31730632e13 recovered auto update from f9aaca00be49;
wenzelm
parents: 61220
diff changeset
   122
    PIDE.session.commands_changed -= main
81489
7293d47a9a70 re-use Output_Area with search results;
wenzelm
parents: 81398
diff changeset
   123
    output.exit()
61208
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
   124
  }
19118f9b939d separate panel for proof state output;
wenzelm
parents:
diff changeset
   125
}