src/Tools/jEdit/src/document_dockable.scala
author wenzelm
Tue, 31 Jan 2023 14:32:07 +0100
changeset 77145 de618831ffd9
parent 77144 42c3970e1ac1
child 77146 eb114301c4df
permissions -rw-r--r--
removed obsolete parameter (see 7c23db6b857b);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
     1
/*  Title:      Tools/jEdit/src/document_dockable.scala
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
     3
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
     4
Dockable window for document build support.
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
     5
*/
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
     6
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
     8
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
     9
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    10
import isabelle._
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    11
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    12
import java.awt.BorderLayout
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    13
import java.awt.event.{ComponentEvent, ComponentAdapter}
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    14
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    15
import scala.swing.{ScrollPane, TextArea, Label, TabbedPane, BorderPanel, Component}
76602
b5dfe1551637 more specific GUI for document nodes;
wenzelm
parents: 76580
diff changeset
    16
import scala.swing.event.SelectionChanged
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    17
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    18
import org.gjt.sp.jedit.{jEdit, View}
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    19
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    20
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    21
object Document_Dockable {
76491
2c37c10d6884 clarified GUI state;
wenzelm
parents: 76490
diff changeset
    22
  /* state */
2c37c10d6884 clarified GUI state;
wenzelm
parents: 76490
diff changeset
    23
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    24
  object Status extends Enumeration {
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    25
    val WAITING = Value("waiting")
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    26
    val RUNNING = Value("running")
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    27
    val FINISHED = Value("finished")
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    28
  }
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    29
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    30
  object State {
76681
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
    31
    def init(): State = State()
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    32
  }
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    33
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    34
  sealed case class State(
76606
3558388330f8 clarified modules;
wenzelm
parents: 76602
diff changeset
    35
    progress: Progress = new Progress,
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    36
    process: Future[Unit] = Future.value(()),
76681
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
    37
    status: Status.Value = Status.FINISHED,
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    38
    output_results: Command.Results = Command.Results.empty,
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    39
    output_main: XML.Body = Nil,
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    40
    output_more: XML.Body = Nil
76681
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
    41
  ) {
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
    42
    def run(progress: Progress, process: Future[Unit]): State =
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
    43
      copy(progress = progress, process = process, status = Status.RUNNING)
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
    44
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    45
    def running(results: Command.Results, body: XML.Body): State =
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    46
      copy(status = Status.RUNNING, output_results = results, output_main = body)
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    47
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    48
    def finish(output: XML.Body): State =
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    49
      copy(process = Future.value(()), status = Status.FINISHED, output_more = output)
76718
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
    50
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    51
    def output_body: XML.Body =
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    52
      output_main :::
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    53
      (if (output_main.nonEmpty && output_more.nonEmpty) Pretty.Separator else Nil) :::
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    54
      output_more
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    55
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    56
    def ok: Boolean = !output_body.exists(Protocol.is_error)
76681
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
    57
  }
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    58
}
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    59
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    60
class Document_Dockable(view: View, position: String) extends Dockable(view, position) {
76609
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
    61
  dockable =>
cc9ddf373bd2 maintain global state of document editor views, notably for is_active operation;
wenzelm
parents: 76606
diff changeset
    62
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    63
  GUI_Thread.require {}
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    64
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    65
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    66
  /* component state -- owned by GUI thread */
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    67
76681
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
    68
  private val current_state = Synchronized(Document_Dockable.State.init())
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    69
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    70
  private val process_indicator = new Process_Indicator
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    71
  private val pretty_text_area = new Pretty_Text_Area(view)
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    72
  private val message_pane = new TabbedPane
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    73
76034
dda3c117f13c clarified GUI behaviour;
wenzelm
parents: 76026
diff changeset
    74
  private def show_state(): Unit = GUI_Thread.later {
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    75
    val st = current_state.value
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    76
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
    77
    pretty_text_area.update(Document.Snapshot.init, st.output_results, st.output_body)
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    78
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    79
    st.status match {
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    80
      case Document_Dockable.Status.WAITING =>
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    81
        process_indicator.update("Waiting for PIDE document content ...", 5)
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    82
      case Document_Dockable.Status.RUNNING =>
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    83
        process_indicator.update("Running document build process ...", 15)
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    84
      case Document_Dockable.Status.FINISHED =>
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    85
        process_indicator.update(null, 0)
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    86
    }
76034
dda3c117f13c clarified GUI behaviour;
wenzelm
parents: 76026
diff changeset
    87
  }
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    88
76034
dda3c117f13c clarified GUI behaviour;
wenzelm
parents: 76026
diff changeset
    89
  private def show_page(page: TabbedPane.Page): Unit = GUI_Thread.later {
dda3c117f13c clarified GUI behaviour;
wenzelm
parents: 76026
diff changeset
    90
    message_pane.selection.page = page
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    91
  }
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    92
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    93
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
    94
  /* text area with zoom/resize */
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    95
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    96
  override def detach_operation: Option[() => Unit] = pretty_text_area.detach_operation
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
    97
76021
752425c69577 clarified component structure, concerning initialization order;
wenzelm
parents: 75853
diff changeset
    98
  private val zoom = new Font_Info.Zoom { override def changed(): Unit = handle_resize() }
752425c69577 clarified component structure, concerning initialization order;
wenzelm
parents: 75853
diff changeset
    99
  private def handle_resize(): Unit = GUI_Thread.require { pretty_text_area.zoom(zoom) }
752425c69577 clarified component structure, concerning initialization order;
wenzelm
parents: 75853
diff changeset
   100
752425c69577 clarified component structure, concerning initialization order;
wenzelm
parents: 75853
diff changeset
   101
  private val delay_resize: Delay =
76610
6e2383488a55 clarified signature: proper scopes and types;
wenzelm
parents: 76609
diff changeset
   102
    Delay.first(PIDE.session.update_delay, gui = true) { handle_resize() }
76021
752425c69577 clarified component structure, concerning initialization order;
wenzelm
parents: 75853
diff changeset
   103
752425c69577 clarified component structure, concerning initialization order;
wenzelm
parents: 75853
diff changeset
   104
  addComponentListener(new ComponentAdapter {
752425c69577 clarified component structure, concerning initialization order;
wenzelm
parents: 75853
diff changeset
   105
    override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke()
752425c69577 clarified component structure, concerning initialization order;
wenzelm
parents: 75853
diff changeset
   106
    override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke()
752425c69577 clarified component structure, concerning initialization order;
wenzelm
parents: 75853
diff changeset
   107
  })
752425c69577 clarified component structure, concerning initialization order;
wenzelm
parents: 75853
diff changeset
   108
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   109
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   110
  /* progress */
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   111
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   112
  class Log_Progress extends Program_Progress {
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   113
    progress =>
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   114
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   115
    override def detect_program(s: String): Option[String] =
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   116
      Document_Build.detect_running_script(s)
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   117
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   118
    private val delay: Delay =
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   119
      Delay.first(PIDE.session.output_delay) {
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   120
        if (!stopped) {
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   121
          running_process(progress)
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   122
          GUI_Thread.later { show_state() }
76491
2c37c10d6884 clarified GUI state;
wenzelm
parents: 76490
diff changeset
   123
        }
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   124
      }
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   125
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   126
    override def echo(msg: String): Unit = { super.echo(msg); delay.invoke() }
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   127
    override def stop_program(): Unit = { super.stop_program(); delay.invoke() }
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   128
  }
76021
752425c69577 clarified component structure, concerning initialization order;
wenzelm
parents: 75853
diff changeset
   129
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   130
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   131
  /* document build process */
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   132
76491
2c37c10d6884 clarified GUI state;
wenzelm
parents: 76490
diff changeset
   133
  private def init_state(): Unit =
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   134
    current_state.change { st =>
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   135
      st.progress.stop()
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   136
      Document_Dockable.State(progress = new Log_Progress)
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   137
    }
76491
2c37c10d6884 clarified GUI state;
wenzelm
parents: 76490
diff changeset
   138
76718
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   139
  private def cancel_process(): Unit =
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   140
    current_state.change { st => st.process.cancel(); st }
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   141
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   142
  private def await_process(): Unit =
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   143
    current_state.guarded_access(st => if (st.process.is_finished) None else Some((), st))
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   144
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   145
  private def running_process(progress: Log_Progress): Unit = {
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   146
    val (results, body) = progress.output()
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   147
    current_state.change(_.running(results, body))
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   148
  }
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   149
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   150
  private def finish_process(output: XML.Body): Unit =
76718
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   151
    current_state.change(_.finish(output))
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   152
77145
de618831ffd9 removed obsolete parameter (see 7c23db6b857b);
wenzelm
parents: 77144
diff changeset
   153
  private def run_process(body: Log_Progress => Unit): Boolean = {
76718
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   154
    val started =
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   155
      current_state.change_result { st =>
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   156
        if (st.process.is_finished) {
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   157
          st.progress.stop()
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   158
          val progress = new Log_Progress
76718
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   159
          val process =
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   160
            Future.thread[Unit](name = "Document_Dockable.process") {
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   161
              await_process()
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   162
              body(progress)
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   163
            }
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   164
          (true, st.run(progress, process))
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   165
        }
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   166
        else (false, st)
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   167
      }
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   168
    show_state()
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   169
    started
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   170
  }
76716
a7602257a825 clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents: 76711
diff changeset
   171
76681
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
   172
  private def load_document(session: String): Boolean = {
76718
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   173
    val options = PIDE.options.value
77145
de618831ffd9 removed obsolete parameter (see 7c23db6b857b);
wenzelm
parents: 77144
diff changeset
   174
    run_process { _ =>
76718
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   175
      try {
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   176
        val session_background =
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   177
          Document_Build.session_background(
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   178
            options, session, dirs = JEdit_Sessions.session_dirs)
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   179
        PIDE.editor.document_setup(Some(session_background))
76716
a7602257a825 clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents: 76711
diff changeset
   180
76718
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   181
        finish_process(Nil)
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   182
        GUI_Thread.later {
76725
c8d5cc19270a more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents: 76720
diff changeset
   183
          refresh_theories()
76718
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   184
          show_state()
76996
6d847e27cafc tuned GUI;
wenzelm
parents: 76994
diff changeset
   185
          show_page(input_page)
76718
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   186
        }
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   187
      }
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   188
      catch {
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   189
        case exn: Throwable if !Exn.is_interrupt(exn) =>
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   190
          finish_process(List(Protocol.error_message(Exn.print(exn))))
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   191
          GUI_Thread.later {
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   192
            show_state()
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   193
            show_page(output_page)
76681
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
   194
          }
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
   195
      }
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
   196
    }
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
   197
  }
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
   198
76732
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   199
  private def document_build(
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   200
    document_session: Document_Editor.Session,
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   201
    progress: Log_Progress
76732
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   202
  ): Unit = {
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   203
    val session_background = document_session.get_background
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   204
    val snapshot = document_session.get_snapshot
77022
ac5ebdf19861 clarified signature;
wenzelm
parents: 77008
diff changeset
   205
    val session_context = JEdit_Sessions.open_session_context(document_snapshot = Some(snapshot))
76732
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   206
    try {
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   207
      val context =
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   208
        Document_Build.context(session_context,
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   209
          document_session = Some(session_background.base),
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   210
          document_selection = document_session.selection,
76732
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   211
          progress = progress)
76994
7c23db6b857b more detailed Program_Progress / Log_Progress: each program gets its own log output, which is attached to the document via markup;
wenzelm
parents: 76769
diff changeset
   212
76732
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   213
      Isabelle_System.make_directory(Document_Editor.document_output_dir())
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   214
      val doc = context.build_document(document_session.get_variant, verbose = true)
76732
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   215
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   216
      File.write(Document_Editor.document_output().log, doc.log)
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   217
      Bytes.write(Document_Editor.document_output().pdf, doc.pdf)
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   218
      Document_Editor.view_document()
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   219
    }
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   220
    finally { session_context.close() }
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   221
  }
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   222
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   223
  private def document_build_attempt(): Boolean = {
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   224
    val document_session = PIDE.editor.document_session()
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   225
    if (document_session.is_vacuous) true
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   226
    else if (document_session.is_pending) false
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   227
    else {
77145
de618831ffd9 removed obsolete parameter (see 7c23db6b857b);
wenzelm
parents: 77144
diff changeset
   228
      run_process { progress =>
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   229
        show_page(output_page)
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   230
        val result = Exn.capture { document_build(document_session, progress) }
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   231
        val msgs =
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   232
          result match {
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   233
            case Exn.Res(_) =>
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   234
              List(Protocol.writeln_message("OK"))
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   235
            case Exn.Exn(exn: Document_Build.Build_Error) =>
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   236
              exn.log_errors.map(s => Protocol.error_message(YXML.parse_body(s)))
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   237
            case Exn.Exn(exn) =>
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   238
              List(Protocol.error_message(YXML.parse_body(Exn.print(exn))))
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   239
          }
76732
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   240
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   241
        progress.stop_program()
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   242
        running_process(progress)
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   243
        finish_process(Pretty.separate(msgs))
76732
0ba6f360d38a actually build document;
wenzelm
parents: 76727
diff changeset
   244
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   245
        show_state()
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   246
        show_page(if (Exn.is_interrupt_exn(result)) input_page else output_page)
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   247
      }
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   248
      true
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   249
    }
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   250
  }
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   251
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   252
  private lazy val delay_build: Delay =
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   253
    Delay.first(PIDE.session.output_delay, gui = true) {
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   254
      if (!document_build_attempt()) delay_build.invoke()
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   255
    }
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   256
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   257
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   258
  /* controls */
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   259
76681
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
   260
  private val document_session =
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
   261
    JEdit_Sessions.document_selector(PIDE.options, standalone = true)
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
   262
76602
b5dfe1551637 more specific GUI for document nodes;
wenzelm
parents: 76580
diff changeset
   263
  private lazy val delay_load: Delay =
76610
6e2383488a55 clarified signature: proper scopes and types;
wenzelm
parents: 76609
diff changeset
   264
    Delay.last(PIDE.session.load_delay, gui = true) {
76681
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
   265
      for (session <- document_session.selection_value) {
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
   266
        if (!load_document(session)) delay_load.invoke()
8ad17c4669da clarified state and process;
wenzelm
parents: 76680
diff changeset
   267
      }
76602
b5dfe1551637 more specific GUI for document nodes;
wenzelm
parents: 76580
diff changeset
   268
    }
b5dfe1551637 more specific GUI for document nodes;
wenzelm
parents: 76580
diff changeset
   269
b5dfe1551637 more specific GUI for document nodes;
wenzelm
parents: 76580
diff changeset
   270
  document_session.reactions += { case SelectionChanged(_) => delay_load.invoke() }
b5dfe1551637 more specific GUI for document nodes;
wenzelm
parents: 76580
diff changeset
   271
76726
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   272
  private val load_button =
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   273
    new GUI.Button("Load") {
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   274
      tooltip = "Load document theories"
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   275
      override def clicked(): Unit = PIDE.editor.document_select_all(set = true)
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   276
    }
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   277
75853
f981111768ec clarified signature;
wenzelm
parents: 75839
diff changeset
   278
  private val build_button =
f981111768ec clarified signature;
wenzelm
parents: 75839
diff changeset
   279
    new GUI.Button("<html><b>Build</b></html>") {
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   280
      tooltip = "Build document"
77144
42c3970e1ac1 clarified Document_Editor.Session: more explicit types, more robust operations;
wenzelm
parents: 77142
diff changeset
   281
      override def clicked(): Unit = delay_build.invoke()
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   282
    }
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   283
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   284
  private val cancel_button =
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   285
    new GUI.Button("Cancel") {
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   286
      tooltip = "Cancel build process"
76718
3f50b24909df clarified process management;
wenzelm
parents: 76716
diff changeset
   287
      override def clicked(): Unit = cancel_process()
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   288
    }
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   289
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   290
  private val view_button =
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   291
    new GUI.Button("View") {
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   292
      tooltip = "View document"
76606
3558388330f8 clarified modules;
wenzelm
parents: 76602
diff changeset
   293
      override def clicked(): Unit = Document_Editor.view_document()
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   294
    }
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   295
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   296
  private val controls =
76726
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   297
    Wrap_Panel(List(document_session, process_indicator.component, load_button,
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   298
      build_button, view_button, cancel_button))
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   299
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   300
  add(controls.peer, BorderLayout.NORTH)
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   301
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   302
  override def focusOnDefaultComponent(): Unit = build_button.requestFocus()
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   303
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   304
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   305
  /* message pane with pages */
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   306
76726
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   307
  private val reset_button =
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   308
    new GUI.Button("Reset") {
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   309
      tooltip = "Deselect document theories"
76720
37f7b2965e02 more GUI operations;
wenzelm
parents: 76719
diff changeset
   310
      override def clicked(): Unit = PIDE.editor.document_select_all(set = false)
37f7b2965e02 more GUI operations;
wenzelm
parents: 76719
diff changeset
   311
    }
37f7b2965e02 more GUI operations;
wenzelm
parents: 76719
diff changeset
   312
76726
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   313
  private val purge_button = new GUI.Button("Purge") {
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   314
    tooltip = "Remove theories that are no longer required"
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   315
    override def clicked(): Unit = PIDE.editor.purge()
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   316
  }
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   317
76720
37f7b2965e02 more GUI operations;
wenzelm
parents: 76719
diff changeset
   318
  private val theories_controls =
76726
c83dfd565283 clarified GUI;
wenzelm
parents: 76725
diff changeset
   319
    Wrap_Panel(List(reset_button, purge_button))
76720
37f7b2965e02 more GUI operations;
wenzelm
parents: 76719
diff changeset
   320
76602
b5dfe1551637 more specific GUI for document nodes;
wenzelm
parents: 76580
diff changeset
   321
  private val theories = new Theories_Status(view, document = true)
77008
60b465c4463c tuned GUI;
wenzelm
parents: 76996
diff changeset
   322
  private val theories_pane = new ScrollPane(theories.gui)
76567
aef247025f07 more GUI elements;
wenzelm
parents: 76565
diff changeset
   323
76725
c8d5cc19270a more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents: 76720
diff changeset
   324
  private def refresh_theories(): Unit = {
c8d5cc19270a more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents: 76720
diff changeset
   325
    val domain = PIDE.editor.document_theories().toSet
c8d5cc19270a more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents: 76720
diff changeset
   326
    theories.update(domain = Some(domain), trim = true, force = true)
c8d5cc19270a more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents: 76720
diff changeset
   327
    theories.refresh()
c8d5cc19270a more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents: 76720
diff changeset
   328
  }
c8d5cc19270a more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents: 76720
diff changeset
   329
76996
6d847e27cafc tuned GUI;
wenzelm
parents: 76994
diff changeset
   330
  private val input_page =
6d847e27cafc tuned GUI;
wenzelm
parents: 76994
diff changeset
   331
    new TabbedPane.Page("Input", new BorderPanel {
76720
37f7b2965e02 more GUI operations;
wenzelm
parents: 76719
diff changeset
   332
      layout(theories_controls) = BorderPanel.Position.North
77008
60b465c4463c tuned GUI;
wenzelm
parents: 76996
diff changeset
   333
      layout(theories_pane) = BorderPanel.Position.Center
76567
aef247025f07 more GUI elements;
wenzelm
parents: 76565
diff changeset
   334
    }, "Selection and status of document theories")
aef247025f07 more GUI elements;
wenzelm
parents: 76565
diff changeset
   335
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   336
  private val output_controls =
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   337
    Wrap_Panel(List(pretty_text_area.search_label, pretty_text_area.search_field, zoom))
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   338
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   339
  private val output_page =
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   340
    new TabbedPane.Page("Output", new BorderPanel {
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   341
      layout(output_controls) = BorderPanel.Position.North
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   342
      layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center
76996
6d847e27cafc tuned GUI;
wenzelm
parents: 76994
diff changeset
   343
    }, "Results from document build process")
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   344
76996
6d847e27cafc tuned GUI;
wenzelm
parents: 76994
diff changeset
   345
  message_pane.pages ++= List(input_page, output_page)
76023
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   346
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   347
  set_content(message_pane)
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   348
c7fed2fd52f5 more GUI functionality;
wenzelm
parents: 76021
diff changeset
   349
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   350
  /* main */
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   351
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   352
  private val main =
76567
aef247025f07 more GUI elements;
wenzelm
parents: 76565
diff changeset
   353
    Session.Consumer[Any](getClass.getName) {
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   354
      case _: Session.Global_Options =>
76567
aef247025f07 more GUI elements;
wenzelm
parents: 76565
diff changeset
   355
        GUI_Thread.later {
76578
06b001094ddb more uniform session selectors, with persistent options;
wenzelm
parents: 76577
diff changeset
   356
          document_session.load()
76567
aef247025f07 more GUI elements;
wenzelm
parents: 76565
diff changeset
   357
          handle_resize()
76725
c8d5cc19270a more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents: 76720
diff changeset
   358
          refresh_theories()
76567
aef247025f07 more GUI elements;
wenzelm
parents: 76565
diff changeset
   359
        }
aef247025f07 more GUI elements;
wenzelm
parents: 76565
diff changeset
   360
      case changed: Session.Commands_Changed =>
aef247025f07 more GUI elements;
wenzelm
parents: 76565
diff changeset
   361
        GUI_Thread.later {
76719
2c8632c746fe proper handling of state updates;
wenzelm
parents: 76718
diff changeset
   362
          val domain = PIDE.editor.document_theories().filter(changed.nodes).toSet
76716
a7602257a825 clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents: 76711
diff changeset
   363
          if (domain.nonEmpty) theories.update(domain = Some(domain))
76567
aef247025f07 more GUI elements;
wenzelm
parents: 76565
diff changeset
   364
        }
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   365
    }
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   366
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   367
  override def init(): Unit = {
76701
3543ecb4c97d tuned signature;
wenzelm
parents: 76681
diff changeset
   368
    PIDE.editor.document_init(dockable)
76491
2c37c10d6884 clarified GUI state;
wenzelm
parents: 76490
diff changeset
   369
    init_state()
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   370
    PIDE.session.global_options += main
76567
aef247025f07 more GUI elements;
wenzelm
parents: 76565
diff changeset
   371
    PIDE.session.commands_changed += main
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   372
    handle_resize()
76602
b5dfe1551637 more specific GUI for document nodes;
wenzelm
parents: 76580
diff changeset
   373
    delay_load.invoke()
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   374
  }
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   375
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   376
  override def exit(): Unit = {
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   377
    PIDE.session.global_options -= main
76567
aef247025f07 more GUI elements;
wenzelm
parents: 76565
diff changeset
   378
    PIDE.session.commands_changed -= main
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   379
    delay_resize.revoke()
76701
3543ecb4c97d tuned signature;
wenzelm
parents: 76681
diff changeset
   380
    PIDE.editor.document_exit(dockable)
75816
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   381
  }
91f02f224b80 basic setup for document build panel;
wenzelm
parents:
diff changeset
   382
}