src/Tools/jEdit/src/query_dockable.scala
author wenzelm
Sat, 13 Aug 2022 23:04:53 +0200
changeset 75853 f981111768ec
parent 75852 fcc25bb49def
child 75854 2163772eeaf2
permissions -rw-r--r--
clarified signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56879
ee2b61f37ad9 renamed "Find" to "Query", with more general operations;
wenzelm
parents: 56872
diff changeset
     1
/*  Title:      Tools/jEdit/src/query_dockable.scala
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
     3
56879
ee2b61f37ad9 renamed "Find" to "Query", with more general operations;
wenzelm
parents: 56872
diff changeset
     4
Dockable window for query operations.
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
     5
*/
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
     6
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
     8
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
     9
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    10
import isabelle._
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    11
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    12
import java.awt.event.{ComponentEvent, ComponentAdapter, KeyEvent}
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    13
import javax.swing.{JComponent, JTextField}
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    14
75853
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
    15
import scala.swing.{Component, TextField, Label, ListView, TabbedPane, BorderPanel}
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
    16
import scala.swing.event.{SelectionChanged, Key, KeyPressed}
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    17
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    18
import org.gjt.sp.jedit.View
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    19
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    20
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    21
object Query_Dockable {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    22
  private abstract class Operation(view: View) {
56758
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
    23
    val pretty_text_area = new Pretty_Text_Area(view)
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    24
    def query_operation: Query_Operation[View]
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    25
    def query: JComponent
75809
1dd5d4f4b69e tuned signature;
wenzelm
parents: 75807
diff changeset
    26
    def select(): Unit
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    27
    def page: TabbedPane.Page
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    28
  }
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    29
}
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    30
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    31
class Query_Dockable(view: View, position: String) extends Dockable(view, position) {
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    32
  /* common GUI components */
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    33
75839
29441f2bfe81 clarified signature: more explicit types;
wenzelm
parents: 75836
diff changeset
    34
  private val zoom = new Font_Info.Zoom { override def changed(): Unit = handle_resize() }
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    35
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    36
  private def make_query(
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    37
    property: String,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    38
    tooltip: String,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    39
    apply_query: () => Unit
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    40
  ): Completion_Popup.History_Text_Field = {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    41
    new Completion_Popup.History_Text_Field(property) {
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    42
      override def processKeyEvent(evt: KeyEvent): Unit = {
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    43
        if (evt.getID == KeyEvent.KEY_PRESSED && evt.getKeyCode == KeyEvent.VK_ENTER) apply_query()
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    44
        super.processKeyEvent(evt)
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    45
      }
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    46
      { val max = getPreferredSize; max.width = Integer.MAX_VALUE; setMaximumSize(max) }
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    47
      setColumns(40)
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    48
      setToolTipText(tooltip)
69358
71ef6e6da3dc prefer Isabelle_Fonts.sans (not mono) as derived GUI font;
wenzelm
parents: 66591
diff changeset
    49
      setFont(GUI.imitate_font(getFont, scale = 1.2))
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    50
    }
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    51
  }
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    52
52935
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    53
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    54
  /* consume status */
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    55
73340
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 72215
diff changeset
    56
  def consume_status(
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    57
    process_indicator: Process_Indicator,
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    58
    status: Query_Operation.Status.Value
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    59
  ): Unit = {
52935
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    60
    status match {
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    61
      case Query_Operation.Status.WAITING =>
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    62
        process_indicator.update("Waiting for evaluation of context ...", 5)
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    63
      case Query_Operation.Status.RUNNING =>
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    64
        process_indicator.update("Running find operation ...", 15)
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: 54368
diff changeset
    65
      case Query_Operation.Status.FINISHED =>
52935
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    66
        process_indicator.update(null, 0)
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    67
    }
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    68
  }
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    69
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    70
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    71
  /* find theorems */
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    72
75810
51867c8ad109 tuned, following hints by IntelliJ IDEA;
wenzelm
parents: 75809
diff changeset
    73
  private val find_theorems: Query_Dockable.Operation = new Query_Dockable.Operation(view) {
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    74
    /* query */
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    75
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    76
    private val process_indicator = new Process_Indicator
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    77
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    78
    val query_operation =
66082
2d12a730a380 clarified modules;
wenzelm
parents: 65246
diff changeset
    79
      new Query_Operation(PIDE.editor, view, "find_theorems",
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    80
        consume_status(process_indicator, _),
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    81
        (snapshot, results, body) =>
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    82
          pretty_text_area.update(snapshot, results, Pretty.separate(body)))
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    83
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
    84
    private def apply_query(): Unit = {
60861
fa77faa87d5f maintain history more often;
wenzelm
parents: 60750
diff changeset
    85
      query.addCurrentToHistory()
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    86
      query_operation.apply_query(List(limit.text, allow_dups.selected.toString, query.getText))
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    87
    }
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    88
56909
a1557dc7f589 tuned GUI;
wenzelm
parents: 56907
diff changeset
    89
    private val query_label = new Label("Find:") {
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    90
      tooltip =
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    91
        GUI.tooltip_lines(
70278
94b332206700 proper message;
wenzelm
parents: 69358
diff changeset
    92
          "Search criteria for find operation, e.g.\n\"_ = _\" \"(+)\" name: Group -name: monoid")
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    93
    }
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    94
75404
a1363da718aa more robust types (for scala3);
wenzelm
parents: 75393
diff changeset
    95
    val query: Completion_Popup.History_Text_Field =
a1363da718aa more robust types (for scala3);
wenzelm
parents: 75393
diff changeset
    96
      make_query("isabelle-find-theorems", query_label.tooltip, apply_query _)
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    97
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
    98
56758
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
    99
    /* GUI page */
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   100
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   101
    private val limit = new TextField(PIDE.options.int("find_theorems_limit").toString, 5) {
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   102
      tooltip = "Limit of displayed results"
75810
51867c8ad109 tuned, following hints by IntelliJ IDEA;
wenzelm
parents: 75809
diff changeset
   103
      verifier = { case Value.Int(x) => x >= 0 case _ => false }
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   104
      listenTo(keys)
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   105
      reactions += { case KeyPressed(_, Key.Enter, 0, _) => apply_query() }
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   106
    }
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   107
75852
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
   108
    private val allow_dups = new GUI.Bool("Duplicates") {
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   109
      tooltip = "Show all versions of matching theorems"
75852
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
   110
      override def clicked(): Unit = apply_query()
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   111
    }
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   112
75853
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
   113
    private val apply_button = new GUI.Button("<html><b>Apply</b></html>") {
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   114
      tooltip = "Find theorems meeting specified criteria"
75853
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
   115
      override def clicked(): Unit = apply_query()
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   116
    }
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   117
56759
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   118
    private val control_panel =
66205
e9fa94f43a15 tuned signature;
wenzelm
parents: 66082
diff changeset
   119
      Wrap_Panel(
e9fa94f43a15 tuned signature;
wenzelm
parents: 66082
diff changeset
   120
        List(query_label, Component.wrap(query), limit, allow_dups,
e9fa94f43a15 tuned signature;
wenzelm
parents: 66082
diff changeset
   121
          process_indicator.component, apply_button,
66206
2d2082db735a clarified defaults;
wenzelm
parents: 66205
diff changeset
   122
          pretty_text_area.search_label, pretty_text_area.search_field))
56759
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   123
75809
1dd5d4f4b69e tuned signature;
wenzelm
parents: 75807
diff changeset
   124
    def select(): Unit = { control_panel.contents += zoom }
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   125
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   126
    val page =
56879
ee2b61f37ad9 renamed "Find" to "Query", with more general operations;
wenzelm
parents: 56872
diff changeset
   127
      new TabbedPane.Page("Find Theorems", new BorderPanel {
59391
wenzelm
parents: 59286
diff changeset
   128
        layout(control_panel) = BorderPanel.Position.North
wenzelm
parents: 59286
diff changeset
   129
        layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   130
      }, apply_button.tooltip)
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   131
  }
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   132
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   133
56758
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   134
  /* find consts */
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   135
75810
51867c8ad109 tuned, following hints by IntelliJ IDEA;
wenzelm
parents: 75809
diff changeset
   136
  private val find_consts: Query_Dockable.Operation = new Query_Dockable.Operation(view) {
56758
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   137
    /* query */
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   138
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   139
    private val process_indicator = new Process_Indicator
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   140
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   141
    val query_operation =
66082
2d12a730a380 clarified modules;
wenzelm
parents: 65246
diff changeset
   142
      new Query_Operation(PIDE.editor, view, "find_consts",
56758
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   143
        consume_status(process_indicator, _),
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   144
        (snapshot, results, body) =>
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   145
          pretty_text_area.update(snapshot, results, Pretty.separate(body)))
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   146
75404
a1363da718aa more robust types (for scala3);
wenzelm
parents: 75393
diff changeset
   147
    private val query_label = new Label("Find:") {
a1363da718aa more robust types (for scala3);
wenzelm
parents: 75393
diff changeset
   148
      tooltip = GUI.tooltip_lines("Name / type patterns for constants")
a1363da718aa more robust types (for scala3);
wenzelm
parents: 75393
diff changeset
   149
    }
a1363da718aa more robust types (for scala3);
wenzelm
parents: 75393
diff changeset
   150
a1363da718aa more robust types (for scala3);
wenzelm
parents: 75393
diff changeset
   151
    val query: Completion_Popup.History_Text_Field =
a1363da718aa more robust types (for scala3);
wenzelm
parents: 75393
diff changeset
   152
      make_query("isabelle-find-consts", query_label.tooltip, apply_query _)
a1363da718aa more robust types (for scala3);
wenzelm
parents: 75393
diff changeset
   153
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
   154
    private def apply_query(): Unit = {
60861
fa77faa87d5f maintain history more often;
wenzelm
parents: 60750
diff changeset
   155
      query.addCurrentToHistory()
56758
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   156
      query_operation.apply_query(List(query.getText))
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   157
    }
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   158
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   159
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   160
    /* GUI page */
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   161
75853
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
   162
    private val apply_button = new GUI.Button("<html><b>Apply</b></html>") {
56758
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   163
      tooltip = "Find constants by name / type patterns"
75853
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
   164
      override def clicked(): Unit = apply_query()
56758
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   165
    }
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   166
56759
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   167
    private val control_panel =
66205
e9fa94f43a15 tuned signature;
wenzelm
parents: 66082
diff changeset
   168
      Wrap_Panel(
e9fa94f43a15 tuned signature;
wenzelm
parents: 66082
diff changeset
   169
        List(
e9fa94f43a15 tuned signature;
wenzelm
parents: 66082
diff changeset
   170
          query_label, Component.wrap(query), process_indicator.component, apply_button,
66206
2d2082db735a clarified defaults;
wenzelm
parents: 66205
diff changeset
   171
          pretty_text_area.search_label, pretty_text_area.search_field))
56759
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   172
75809
1dd5d4f4b69e tuned signature;
wenzelm
parents: 75807
diff changeset
   173
    def select(): Unit = { control_panel.contents += zoom }
56758
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   174
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   175
    val page =
56879
ee2b61f37ad9 renamed "Find" to "Query", with more general operations;
wenzelm
parents: 56872
diff changeset
   176
      new TabbedPane.Page("Find Constants", new BorderPanel {
59391
wenzelm
parents: 59286
diff changeset
   177
        layout(control_panel) = BorderPanel.Position.North
wenzelm
parents: 59286
diff changeset
   178
        layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center
56758
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   179
      }, apply_button.tooltip)
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   180
  }
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   181
d203b9c400a2 PIDE support for find_consts;
wenzelm
parents: 56757
diff changeset
   182
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   183
  /* print operation */
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   184
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
   185
  private val print_operation = new Query_Dockable.Operation(view) {
57604
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   186
    /* items */
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   187
75852
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
   188
    private class Item(val name: String, description: String, selected: Boolean) {
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
   189
      val gui: GUI.Bool = new GUI.Bool(name, init = selected) {
57604
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   190
        tooltip = "Print " + description
75852
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
   191
        override def clicked(): Unit = apply_query()
57604
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   192
      }
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   193
    }
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   194
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   195
    private var _items: List[Item] = Nil
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   196
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   197
    private def selected_items(): List[String] =
75852
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
   198
      for (item <- _items if item.gui.selected) yield item.name
57604
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   199
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
   200
    private def update_items(): List[Item] = {
57604
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   201
      val old_items = _items
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   202
      def was_selected(name: String): Boolean =
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   203
        old_items.find(item => item.name == name) match {
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   204
          case None => false
75852
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
   205
          case Some(item) => item.gui.selected
57604
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   206
        }
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   207
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   208
      _items =
72215
8f9cffa78112 clarified signature;
wenzelm
parents: 71704
diff changeset
   209
        for ((name, description) <- Print_Operation.get(PIDE.session))
8f9cffa78112 clarified signature;
wenzelm
parents: 71704
diff changeset
   210
        yield new Item(name, description, was_selected(name))
57604
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   211
      _items
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   212
    }
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   213
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   214
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   215
    /* query */
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   216
56909
a1557dc7f589 tuned GUI;
wenzelm
parents: 56907
diff changeset
   217
    private val process_indicator = new Process_Indicator
a1557dc7f589 tuned GUI;
wenzelm
parents: 56907
diff changeset
   218
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   219
    val query_operation =
66082
2d12a730a380 clarified modules;
wenzelm
parents: 65246
diff changeset
   220
      new Query_Operation(PIDE.editor, view, "print_operation",
56909
a1557dc7f589 tuned GUI;
wenzelm
parents: 56907
diff changeset
   221
        consume_status(process_indicator, _),
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   222
        (snapshot, results, body) =>
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   223
          pretty_text_area.update(snapshot, results, Pretty.separate(body)))
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   224
73340
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 72215
diff changeset
   225
    private def apply_query(): Unit =
57604
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   226
      query_operation.apply_query(selected_items())
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   227
56866
c4512e94e15c tuned GUI;
wenzelm
parents: 56865
diff changeset
   228
    private val query_label = new Label("Print:")
56882
6d4b2f8f010c clarified GUI focus;
wenzelm
parents: 56881
diff changeset
   229
    def query: JComponent = apply_button.peer
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   230
57604
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   231
    update_items()
56872
1435f0c771dc some complication with ListView.Renderer to get tooltips;
wenzelm
parents: 56866
diff changeset
   232
1435f0c771dc some complication with ListView.Renderer to get tooltips;
wenzelm
parents: 56866
diff changeset
   233
1435f0c771dc some complication with ListView.Renderer to get tooltips;
wenzelm
parents: 56866
diff changeset
   234
    /* GUI page */
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   235
75853
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
   236
    private val apply_button = new GUI.Button("<html><b>Apply</b></html>") {
56865
168766e28f5e more decisive change of focus;
wenzelm
parents: 56864
diff changeset
   237
      tooltip = "Apply to current context"
75853
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
   238
      override def clicked(): Unit = apply_query()
f981111768ec clarified signature;
wenzelm
parents: 75852
diff changeset
   239
57000
c914618feef8 some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents: 56918
diff changeset
   240
      listenTo(keys)
c914618feef8 some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents: 56918
diff changeset
   241
      reactions += {
c914618feef8 some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents: 56918
diff changeset
   242
        case evt @ KeyPressed(_, Key.Enter, 0, _) =>
75807
b0394e7d43ea tuned signature, following hints by IntelliJ IDEA;
wenzelm
parents: 75404
diff changeset
   243
          evt.peer.consume()
57000
c914618feef8 some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents: 56918
diff changeset
   244
          apply_query()
c914618feef8 some adhoc event handling to unify L&F button focus behavior, e.g. Mac OS X vs. Nimbus;
wenzelm
parents: 56918
diff changeset
   245
      }
56865
168766e28f5e more decisive change of focus;
wenzelm
parents: 56864
diff changeset
   246
    }
168766e28f5e more decisive change of focus;
wenzelm
parents: 56864
diff changeset
   247
66206
2d2082db735a clarified defaults;
wenzelm
parents: 66205
diff changeset
   248
    private val control_panel = Wrap_Panel()
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   249
75809
1dd5d4f4b69e tuned signature;
wenzelm
parents: 75807
diff changeset
   250
    def select(): Unit = {
73367
77ef8bef0593 clarified signature --- fewer warnings;
wenzelm
parents: 73340
diff changeset
   251
      control_panel.contents.clear()
57604
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   252
      control_panel.contents += query_label
75852
fcc25bb49def clarified signature;
wenzelm
parents: 75839
diff changeset
   253
      update_items().foreach(item => control_panel.contents += item.gui)
56883
38c6b70e5e53 common support for search field, which is actually a light-weight Highlighter;
wenzelm
parents: 56882
diff changeset
   254
      control_panel.contents ++=
57604
30885e25c6de support multiple selected print operations instead of slightly odd "menu";
wenzelm
parents: 57044
diff changeset
   255
        List(process_indicator.component, apply_button,
57042
5576d22abf3c tuned signature;
wenzelm
parents: 57000
diff changeset
   256
          pretty_text_area.search_label, pretty_text_area.search_field, zoom)
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   257
    }
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   258
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   259
    val page =
56879
ee2b61f37ad9 renamed "Find" to "Query", with more general operations;
wenzelm
parents: 56872
diff changeset
   260
      new TabbedPane.Page("Print Context", new BorderPanel {
59391
wenzelm
parents: 59286
diff changeset
   261
        layout(control_panel) = BorderPanel.Position.North
wenzelm
parents: 59286
diff changeset
   262
        layout(Component.wrap(pretty_text_area)) = BorderPanel.Position.Center
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   263
      }, "Print information from context")
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   264
  }
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   265
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   266
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   267
  /* operations */
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   268
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents: 56759
diff changeset
   269
  private val operations = List(find_theorems, find_consts, print_operation)
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   270
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
   271
  private val operations_pane = new TabbedPane {
56759
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   272
    pages ++= operations.map(_.page)
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   273
    listenTo(selection)
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   274
    reactions += { case SelectionChanged(_) => select_operation() }
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   275
  }
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   276
56879
ee2b61f37ad9 renamed "Find" to "Query", with more general operations;
wenzelm
parents: 56872
diff changeset
   277
  private def get_operation(): Option[Query_Dockable.Operation] =
56759
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   278
    try { Some(operations(operations_pane.selection.index)) }
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   279
    catch { case _: IndexOutOfBoundsException => None }
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   280
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
   281
  private def select_operation(): Unit = {
75809
1dd5d4f4b69e tuned signature;
wenzelm
parents: 75807
diff changeset
   282
    for (op <- get_operation()) { op.select(); op.query.requestFocus() }
73367
77ef8bef0593 clarified signature --- fewer warnings;
wenzelm
parents: 73340
diff changeset
   283
    operations_pane.revalidate()
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   284
  }
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
   285
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
   286
  override def focusOnDefaultComponent(): Unit = {
73367
77ef8bef0593 clarified signature --- fewer warnings;
wenzelm
parents: 73340
diff changeset
   287
    for (op <- get_operation()) op.query.requestFocus()
73340
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 72215
diff changeset
   288
  }
56759
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   289
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   290
  select_operation()
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   291
  set_content(operations_pane)
790f7562cd0e proper handling of shared zoom component: update layout dynamically;
wenzelm
parents: 56758
diff changeset
   292
71601
97ccf48c2f0c misc tuning based on hints by IntelliJ IDEA;
wenzelm
parents: 71525
diff changeset
   293
  override def detach_operation: Option[() => Unit] =
56918
a442dc6d244d clarified detach_operation: ignore empty output;
wenzelm
parents: 56911
diff changeset
   294
    get_operation() match {
a442dc6d244d clarified detach_operation: ignore empty output;
wenzelm
parents: 56911
diff changeset
   295
      case None => None
a442dc6d244d clarified detach_operation: ignore empty output;
wenzelm
parents: 56911
diff changeset
   296
      case Some(op) => op.pretty_text_area.detach_operation
a442dc6d244d clarified detach_operation: ignore empty output;
wenzelm
parents: 56911
diff changeset
   297
    }
56906
408b526911f7 some odd tricks to provide "Detach" menu item, via "PIDE" docking framework;
wenzelm
parents: 56886
diff changeset
   298
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
   299
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
   300
  /* resize */
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
   301
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   302
  private def handle_resize(): Unit =
75839
29441f2bfe81 clarified signature: more explicit types;
wenzelm
parents: 75836
diff changeset
   303
    GUI_Thread.require { operations.foreach(_.pretty_text_area.zoom(zoom)) }
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   304
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
   305
  private val delay_resize =
71704
b9a5eb0f3b43 clarified modules;
wenzelm
parents: 71601
diff changeset
   306
    Delay.first(PIDE.options.seconds("editor_update_delay"), gui = true) { handle_resize() }
52854
92932931bd82 more general Output.result: allow to update arbitrary properties;
wenzelm
parents: 52851
diff changeset
   307
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
   308
  addComponentListener(new ComponentAdapter {
73340
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 72215
diff changeset
   309
    override def componentResized(e: ComponentEvent): Unit = delay_resize.invoke()
0ffcad1f6130 tuned --- fewer warnings;
wenzelm
parents: 72215
diff changeset
   310
    override def componentShown(e: ComponentEvent): Unit = delay_resize.invoke()
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
   311
  })
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   312
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   313
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   314
  /* main */
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   315
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   316
  private val main =
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   317
    Session.Consumer[Session.Global_Options](getClass.getName) {
57612
990ffb84489b clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents: 57604
diff changeset
   318
      case _: Session.Global_Options => GUI_Thread.later { handle_resize() }
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   319
    }
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   320
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
   321
  override def init(): Unit = {
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   322
    PIDE.session.global_options += main
52848
9489ca1d55dd some tracking of command location;
wenzelm
parents: 52846
diff changeset
   323
    handle_resize()
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   324
    operations.foreach(op => op.query_operation.activate())
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   325
  }
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   326
75393
87ebf5a50283 clarified formatting, for the sake of scala3;
wenzelm
parents: 73987
diff changeset
   327
  override def exit(): Unit = {
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   328
    operations.foreach(op => op.query_operation.deactivate())
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
   329
    PIDE.session.global_options -= main
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   330
    delay_resize.revoke()
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   331
  }
56757
d6fdf08282f3 some rearrangements to support multiple find operations;
wenzelm
parents: 56751
diff changeset
   332
}
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   333