src/Tools/jEdit/src/active.scala
author wenzelm
Wed, 12 Dec 2012 21:50:42 +0100
changeset 50498 6647ba2775c1
parent 50466 53d3930dae0c
child 50500 c94bba7906d2
permissions -rw-r--r--
support dialog via document content;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
     1
/*  Title:      Tools/jEdit/src/active.scala
49492
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
     3
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
     4
Active areas within the document.
49492
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
     5
*/
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
     6
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
     8
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
     9
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    10
import isabelle._
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    11
49493
db58490a68ac more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents: 49492
diff changeset
    12
import org.gjt.sp.jedit.View
49492
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    13
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    14
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
    15
object Active
49492
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    16
{
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
    17
  def action(view: View, text: String, elem: XML.Elem)
49492
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    18
  {
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    19
    Swing_Thread.require()
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    20
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    21
    Document_View(view.getTextArea) match {
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    22
      case Some(doc_view) =>
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    23
        doc_view.rich_text_area.robust_body() {
50215
97959912840a more general sendback properties;
wenzelm
parents: 50195
diff changeset
    24
          val text_area = doc_view.text_area
49492
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    25
          val model = doc_view.model
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    26
          val buffer = model.buffer
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    27
          val snapshot = model.snapshot()
49493
db58490a68ac more realistic sendback: pick exec_id from message position and text from buffer;
wenzelm
parents: 49492
diff changeset
    28
50452
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    29
          def try_replace_command(exec_id: Document.ID, s: String)
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    30
          {
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    31
            snapshot.state.execs.get(exec_id).map(_.command) match {
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    32
              case Some(command) =>
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    33
                snapshot.node.command_start(command) match {
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    34
                  case Some(start) =>
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    35
                    JEdit_Lib.buffer_edit(buffer) {
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    36
                      buffer.remove(start, command.proper_range.length)
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    37
                      buffer.insert(start, s)
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    38
                    }
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    39
                  case None =>
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    40
                }
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    41
              case None =>
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    42
            }
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    43
          }
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    44
50164
77668b522ffe some support for implicit senback, meaning that it uses the caret position instead of explicit command exec_id;
wenzelm
parents: 49493
diff changeset
    45
          if (!snapshot.is_outdated) {
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
    46
            elem match {
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
    47
              case XML.Elem(Markup(Markup.SENDBACK, props), _) =>
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
    48
                props match {
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
    49
                  case Position.Id(exec_id) =>
50452
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    50
                    try_replace_command(exec_id, text)
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
    51
                  case _ =>
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
    52
                    if (props.exists(_ == Markup.PADDING_LINE))
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
    53
                      Isabelle.insert_line_padding(text_area, text)
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
    54
                    else text_area.setSelectedText(text)
50164
77668b522ffe some support for implicit senback, meaning that it uses the caret position instead of explicit command exec_id;
wenzelm
parents: 49493
diff changeset
    55
                }
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
    56
50498
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50466
diff changeset
    57
              case XML.Elem(Markup(Markup.DIALOG, props), _) =>
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50466
diff changeset
    58
                (props, props, props) match {
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50466
diff changeset
    59
                  case (Position.Id(id), Markup.Name(name), Markup.Result(result)) =>
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50466
diff changeset
    60
                    model.session.dialog_result(id, name, result)
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50466
diff changeset
    61
                  case _ =>
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50466
diff changeset
    62
                }
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50466
diff changeset
    63
50452
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    64
              case XML.Elem(Markup(Markup.GRAPHVIEW, Position.Id(exec_id)), body) =>
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    65
                default_thread_pool.submit(() =>
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    66
                  {
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    67
                    val graph =
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    68
                      Exn.capture {
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    69
                        isabelle.graphview.Model.decode_graph(body)
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    70
                          .transitive_reduction_acyclic
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    71
                      }
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    72
                    Swing_Thread.later { Graphview_Dockable(view, snapshot, graph) }
bfb5964e3041 stateless dockable window for graphview, which is triggered by the active area of the corresponding diagnostic command;
wenzelm
parents: 50450
diff changeset
    73
                  })
50450
358b6020f8b6 generalized notion of active area, where sendback is just one application;
wenzelm
parents: 50341
diff changeset
    74
50215
97959912840a more general sendback properties;
wenzelm
parents: 50195
diff changeset
    75
              case _ =>
50164
77668b522ffe some support for implicit senback, meaning that it uses the caret position instead of explicit command exec_id;
wenzelm
parents: 49493
diff changeset
    76
            }
49492
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    77
          }
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    78
        }
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    79
      case None =>
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    80
    }
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    81
  }
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    82
}
2e3e7ea5ce8e some support for hovering and sendback area;
wenzelm
parents:
diff changeset
    83