src/Tools/jEdit/src/find_dockable.scala
author wenzelm
Sat, 26 Apr 2014 13:07:20 +0200
changeset 56743 81370dfadb1d
parent 56715 52125652e82a
child 56751 2080e752ed40
permissions -rw-r--r--
tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
     1
/*  Title:      Tools/jEdit/src/find_dockable.scala
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
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
     4
Dockable window for "find" dialog.
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
53711
8ce7795256e1 improved FlowLayout for wrapping of components over multiple lines;
wenzelm
parents: 53177
diff changeset
    12
import scala.swing.{Button, Component, TextField, CheckBox, Label, ComboBox}
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    13
import scala.swing.event.ButtonClicked
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    14
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    15
import java.awt.BorderLayout
52886
1e22e8101f47 enabled key event to apply query;
wenzelm
parents: 52885
diff changeset
    16
import java.awt.event.{ComponentEvent, ComponentAdapter, KeyEvent}
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
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    21
class Find_Dockable(view: View, position: String) extends Dockable(view, position)
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    22
{
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    23
  val pretty_text_area = new Pretty_Text_Area(view)
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    24
  set_content(pretty_text_area)
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    25
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    26
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    27
  /* query operation */
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    28
52935
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    29
  private val process_indicator = new Process_Indicator
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    30
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    31
  private def consume_status(status: Query_Operation.Status.Value)
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    32
  {
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    33
    status match {
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    34
      case Query_Operation.Status.WAITING =>
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    35
        process_indicator.update("Waiting for evaluation of context ...", 5)
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    36
      case Query_Operation.Status.RUNNING =>
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    37
        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
    38
      case Query_Operation.Status.FINISHED =>
52935
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    39
        process_indicator.update(null, 0)
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    40
    }
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    41
  }
6fc13c31c775 more abstract consume_status operation;
wenzelm
parents: 52886
diff changeset
    42
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    43
  private val find_theorems =
52971
31926d2c04ee tuned signature -- more abstract PIDE editor operations;
wenzelm
parents: 52951
diff changeset
    44
    new Query_Operation(PIDE.editor, view, "find_theorems", consume_status _,
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    45
      (snapshot, results, body) =>
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    46
        pretty_text_area.update(snapshot, results, Pretty.separate(body)))
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    47
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    48
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    49
  /* resize */
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    50
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    51
  private var zoom_factor = 100
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    52
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    53
  private def handle_resize()
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    54
  {
56662
f373fb77e0a4 avoid "Adaptation of argument list by inserting ()" -- deprecated in scala-2.11.0;
wenzelm
parents: 56622
diff changeset
    55
    Swing_Thread.require {}
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    56
55825
694833e3e4a0 tuned signature -- separate module Font_Info;
wenzelm
parents: 55618
diff changeset
    57
    pretty_text_area.resize(
694833e3e4a0 tuned signature -- separate module Font_Info;
wenzelm
parents: 55618
diff changeset
    58
      Font_Info.main(PIDE.options.real("jedit_font_scale") * zoom_factor / 100))
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    59
  }
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    60
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    61
  private val delay_resize =
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    62
    Swing_Thread.delay_first(PIDE.options.seconds("editor_update_delay")) { handle_resize() }
52854
92932931bd82 more general Output.result: allow to update arbitrary properties;
wenzelm
parents: 52851
diff changeset
    63
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    64
  addComponentListener(new ComponentAdapter {
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    65
    override def componentResized(e: ComponentEvent) { delay_resize.invoke() }
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    66
  })
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    67
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    68
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
    69
  /* main */
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    70
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
    71
  private val main =
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
    72
    Session.Consumer[Session.Global_Options](getClass.getName) {
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
    73
      case _: Session.Global_Options => Swing_Thread.later { handle_resize() }
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    74
    }
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    75
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    76
  override def init()
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    77
  {
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
    78
    PIDE.session.global_options += main
52848
9489ca1d55dd some tracking of command location;
wenzelm
parents: 52846
diff changeset
    79
    handle_resize()
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    80
    find_theorems.activate()
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    81
  }
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    82
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    83
  override def exit()
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    84
  {
52865
02a7e7180ee5 slightly more general support for one-shot query operations via asynchronous print functions and temporary document overlay;
wenzelm
parents: 52864
diff changeset
    85
    find_theorems.deactivate()
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56662
diff changeset
    86
    PIDE.session.global_options -= main
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    87
    delay_resize.revoke()
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    88
  }
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    89
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    90
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    91
  /* controls */
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
    92
56621
798ba1c2da12 removed odd context argument: Thy_Info.get_theory does not fit into PIDE document model;
wenzelm
parents: 56208
diff changeset
    93
  private def clicked
798ba1c2da12 removed odd context argument: Thy_Info.get_theory does not fit into PIDE document model;
wenzelm
parents: 56208
diff changeset
    94
  {
798ba1c2da12 removed odd context argument: Thy_Info.get_theory does not fit into PIDE document model;
wenzelm
parents: 56208
diff changeset
    95
    find_theorems.apply_query(List(limit.text, allow_dups.selected.toString, query.getText))
52942
07093b66fc9d more GUI options;
wenzelm
parents: 52935
diff changeset
    96
  }
07093b66fc9d more GUI options;
wenzelm
parents: 52935
diff changeset
    97
52946
976bd071360c tuned GUI;
wenzelm
parents: 52944
diff changeset
    98
  private val query_label = new Label("Search criteria:") {
54367
e358b79b533a tuned tooltips;
wenzelm
parents: 53872
diff changeset
    99
    tooltip =
56622
891d1b8b64fb clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents: 56621
diff changeset
   100
      GUI.tooltip_lines(
891d1b8b64fb clarified tooltip_lines: HTML.encode already takes care of newline (but not space);
wenzelm
parents: 56621
diff changeset
   101
        "Search criteria for find operation, e.g.\n\"_ = _\" \"op +\" name: Group -name: monoid")
52946
976bd071360c tuned GUI;
wenzelm
parents: 52944
diff changeset
   102
  }
52886
1e22e8101f47 enabled key event to apply query;
wenzelm
parents: 52885
diff changeset
   103
53784
322a3ff42b33 completion popup for history text field;
wenzelm
parents: 53711
diff changeset
   104
  private val query = new Completion_Popup.History_Text_Field("isabelle-find-theorems") {
52886
1e22e8101f47 enabled key event to apply query;
wenzelm
parents: 52885
diff changeset
   105
    override def processKeyEvent(evt: KeyEvent)
1e22e8101f47 enabled key event to apply query;
wenzelm
parents: 52885
diff changeset
   106
    {
1e22e8101f47 enabled key event to apply query;
wenzelm
parents: 52885
diff changeset
   107
      if (evt.getID == KeyEvent.KEY_PRESSED && evt.getKeyCode == KeyEvent.VK_ENTER) clicked
1e22e8101f47 enabled key event to apply query;
wenzelm
parents: 52885
diff changeset
   108
      super.processKeyEvent(evt)
1e22e8101f47 enabled key event to apply query;
wenzelm
parents: 52885
diff changeset
   109
    }
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   110
    { val max = getPreferredSize; max.width = Integer.MAX_VALUE; setMaximumSize(max) }
52885
9e4bae21494d prefer single-line HistoryTextField;
wenzelm
parents: 52880
diff changeset
   111
    setColumns(40)
52946
976bd071360c tuned GUI;
wenzelm
parents: 52944
diff changeset
   112
    setToolTipText(query_label.tooltip)
55825
694833e3e4a0 tuned signature -- separate module Font_Info;
wenzelm
parents: 55618
diff changeset
   113
    setFont(GUI.imitate_font(Font_Info.main_family(), getFont, 1.2))
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   114
  }
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   115
52942
07093b66fc9d more GUI options;
wenzelm
parents: 52935
diff changeset
   116
  private val limit = new TextField(PIDE.options.int("find_theorems_limit").toString, 5) {
07093b66fc9d more GUI options;
wenzelm
parents: 52935
diff changeset
   117
    tooltip = "Limit of displayed results"
07093b66fc9d more GUI options;
wenzelm
parents: 52935
diff changeset
   118
    verifier = (s: String) =>
07093b66fc9d more GUI options;
wenzelm
parents: 52935
diff changeset
   119
      s match { case Properties.Value.Int(x) => x >= 0 case _ => false }
07093b66fc9d more GUI options;
wenzelm
parents: 52935
diff changeset
   120
  }
07093b66fc9d more GUI options;
wenzelm
parents: 52935
diff changeset
   121
07093b66fc9d more GUI options;
wenzelm
parents: 52935
diff changeset
   122
  private val allow_dups = new CheckBox("Duplicates") {
52951
de4bccddcdbd adjust tooltip for duplicates option
kleing
parents: 52946
diff changeset
   123
    tooltip = "Show all versions of matching theorems"
52942
07093b66fc9d more GUI options;
wenzelm
parents: 52935
diff changeset
   124
    selected = false
07093b66fc9d more GUI options;
wenzelm
parents: 52935
diff changeset
   125
  }
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   126
52880
91f7fcaa2147 more generic button;
wenzelm
parents: 52874
diff changeset
   127
  private val apply_query = new Button("Apply") {
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   128
    tooltip = "Find theorems meeting specified criteria"
52886
1e22e8101f47 enabled key event to apply query;
wenzelm
parents: 52885
diff changeset
   129
    reactions += { case ButtonClicked(_) => clicked }
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   130
  }
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   131
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   132
  private val zoom = new GUI.Zoom_Box(factor => { zoom_factor = factor; handle_resize() }) {
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   133
    tooltip = "Zoom factor for output font size"
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   134
  }
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   135
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   136
  private val controls =
53711
8ce7795256e1 improved FlowLayout for wrapping of components over multiple lines;
wenzelm
parents: 53177
diff changeset
   137
    new Wrap_Panel(Wrap_Panel.Alignment.Right)(
56621
798ba1c2da12 removed odd context argument: Thy_Info.get_theory does not fit into PIDE document model;
wenzelm
parents: 56208
diff changeset
   138
      query_label, Component.wrap(query), limit, allow_dups,
52944
4b053d8d0e7e removed "Locate" button, to avoid confusion about the slightly odd meaning of current_command with explicit theory context;
wenzelm
parents: 52943
diff changeset
   139
      process_indicator.component, apply_query, zoom)
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   140
  add(controls.peer, BorderLayout.NORTH)
53787
e64389fe2d2c focus on default component according to jEdit window management;
wenzelm
parents: 53785
diff changeset
   141
e64389fe2d2c focus on default component according to jEdit window management;
wenzelm
parents: 53785
diff changeset
   142
  override def focusOnDefaultComponent { query.requestFocus }
52846
82ac963c68cb dockable window for "find" dialog (GUI only);
wenzelm
parents:
diff changeset
   143
}