src/Tools/jEdit/src/completion_popup.scala
author wenzelm
Wed, 28 Aug 2013 09:36:05 +0200
changeset 53244 ec6011bf2362
parent 53243 dabe46c68228
child 53246 8d34caf5bf82
permissions -rw-r--r--
dismiss popups more uniformly;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
     1
/*  Title:      Tools/jEdit/src/completion_popup.scala
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
     3
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
     4
Completion popup based on javax.swing.PopupFactory.
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
     5
*/
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
     6
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
     7
package isabelle.jedit
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
     8
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
     9
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
    10
import isabelle._
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
    11
53229
6ce8328d7912 explicit "hidden" operation with focus management;
wenzelm
parents: 53228
diff changeset
    12
import java.awt.{Font, Point, BorderLayout, Dimension}
53226
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
    13
import java.awt.event.{KeyEvent, MouseEvent, MouseAdapter, FocusAdapter, FocusEvent}
53228
f6c6688961db some key event handling in the manner of SideKickBindings, SideKickCompletionPopup;
wenzelm
parents: 53226
diff changeset
    14
import javax.swing.{JPanel, JComponent, PopupFactory, SwingUtilities}
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
    15
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
    16
import scala.swing.{ListView, ScrollPane}
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
    17
import scala.swing.event.MouseClicked
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
    18
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
    19
import org.gjt.sp.jedit.View
53228
f6c6688961db some key event handling in the manner of SideKickBindings, SideKickCompletionPopup;
wenzelm
parents: 53226
diff changeset
    20
import org.gjt.sp.jedit.textarea.JEditTextArea
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
    21
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
    22
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
    23
object Completion_Popup
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
    24
{
53235
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    25
  /* items */
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    26
53233
4b422e5d64fd some actual completion via outer syntax;
wenzelm
parents: 53232
diff changeset
    27
  private sealed case class Item(original: String, replacement: String, description: String)
4b422e5d64fd some actual completion via outer syntax;
wenzelm
parents: 53232
diff changeset
    28
  { override def toString: String = description }
4b422e5d64fd some actual completion via outer syntax;
wenzelm
parents: 53232
diff changeset
    29
53235
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    30
53244
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    31
  /* single instance within root */
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    32
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    33
  def dismissed_view(view: View): Boolean = dismissed(view.getRootPane)
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    34
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    35
  private def dismissed(root: JComponent): Boolean =
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    36
  {
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    37
    Swing_Thread.require()
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    38
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    39
    root.getClientProperty(Completion_Popup) match {
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    40
      case old_completion: Completion_Popup =>
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    41
        old_completion.hide_popup
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    42
        true
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    43
      case _ =>
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    44
        false
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    45
    }
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    46
  }
53235
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    47
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    48
  private def register(root: JComponent, completion: Completion_Popup)
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    49
  {
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    50
    Swing_Thread.require()
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    51
53244
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    52
    dismissed(root)
53235
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    53
    root.putClientProperty(Completion_Popup, completion)
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    54
  }
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    55
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    56
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    57
  /* jEdit text area operations */
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    58
53242
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    59
  object Text_Area
53233
4b422e5d64fd some actual completion via outer syntax;
wenzelm
parents: 53232
diff changeset
    60
  {
53242
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    61
    private def insert(text_area: JEditTextArea, item: Item)
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    62
    {
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    63
      Swing_Thread.require()
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
    64
53242
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    65
      val buffer = text_area.getBuffer
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    66
      val len = item.original.length
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    67
      if (buffer.isEditable && len > 0) {
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    68
        JEdit_Lib.buffer_edit(buffer) {
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    69
          val caret = text_area.getCaretPosition
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    70
          JEdit_Lib.try_get_text(buffer, Text.Range(caret - len, caret)) match {
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    71
            case Some(text) if text == item.original =>
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    72
              buffer.remove(caret - len, len)
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    73
              buffer.insert(caret - len, item.replacement)
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    74
            case _ =>
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    75
          }
53233
4b422e5d64fd some actual completion via outer syntax;
wenzelm
parents: 53232
diff changeset
    76
        }
4b422e5d64fd some actual completion via outer syntax;
wenzelm
parents: 53232
diff changeset
    77
      }
4b422e5d64fd some actual completion via outer syntax;
wenzelm
parents: 53232
diff changeset
    78
    }
53242
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    79
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    80
    def input(text_area: JEditTextArea, get_syntax: => Option[Outer_Syntax], evt: KeyEvent)
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    81
    {
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    82
      Swing_Thread.require()
53233
4b422e5d64fd some actual completion via outer syntax;
wenzelm
parents: 53232
diff changeset
    83
53244
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    84
      dismissed(text_area)
ec6011bf2362 dismiss popups more uniformly;
wenzelm
parents: 53243
diff changeset
    85
53242
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    86
      val view = text_area.getView
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    87
      val root = view.getRootPane
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    88
      val buffer = text_area.getBuffer
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    89
      val painter = text_area.getPainter
53235
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
    90
53243
dabe46c68228 more uniform check (see JEdit_Lib.propagate_key);
wenzelm
parents: 53242
diff changeset
    91
      if (buffer.isEditable && !evt.isConsumed) {
53242
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    92
        get_syntax match {
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    93
          case Some(syntax) =>
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    94
            val caret = text_area.getCaretPosition
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    95
            val result =
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    96
            {
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    97
              val line = buffer.getLineOfOffset(caret)
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    98
              val start = buffer.getLineStartOffset(line)
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
    99
              val text = buffer.getSegment(start, caret - start)
53228
f6c6688961db some key event handling in the manner of SideKickBindings, SideKickCompletionPopup;
wenzelm
parents: 53226
diff changeset
   100
53242
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   101
              syntax.completion.complete(text) match {
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   102
                case Some((word, cs)) =>
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   103
                  val ds =
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   104
                    (if (Isabelle_Encoding.is_active(buffer))
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   105
                      cs.map(Symbol.decode(_)).sorted
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   106
                     else cs).filter(_ != word)
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   107
                  if (ds.isEmpty) None
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   108
                  else Some((word, ds.map(s => Item(word, s, s))))
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   109
                case None => None
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   110
              }
53233
4b422e5d64fd some actual completion via outer syntax;
wenzelm
parents: 53232
diff changeset
   111
            }
53242
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   112
            result match {
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   113
              case Some((original, items)) =>
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   114
                val popup_font =
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   115
                  painter.getFont.deriveFont(
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   116
                    (painter.getFont.getSize2D * PIDE.options.real("jedit_popup_font_scale")).toFloat
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   117
                      max 10.0f)
53229
6ce8328d7912 explicit "hidden" operation with focus management;
wenzelm
parents: 53228
diff changeset
   118
53242
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   119
                val location = text_area.offsetToXY(caret - original.length)
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   120
                if (location != null) {
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   121
                  location.y = location.y + painter.getFontMetrics.getHeight
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   122
                  SwingUtilities.convertPointToScreen(location, painter)
53235
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
   123
53242
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   124
                  val completion =
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   125
                    new Completion_Popup(root, popup_font, location, items) {
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   126
                      override def complete(item: Item) { insert(text_area, item) }
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   127
                      override def propagate(e: KeyEvent) {
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   128
                        JEdit_Lib.propagate_key(view, e)
53243
dabe46c68228 more uniform check (see JEdit_Lib.propagate_key);
wenzelm
parents: 53242
diff changeset
   129
                        input(text_area, get_syntax, e)
53242
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   130
                      }
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   131
                      override def refocus() { text_area.requestFocus }
53235
1b6a44859549 register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents: 53234
diff changeset
   132
                    }
53242
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   133
                  register(root, completion)
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   134
                }
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   135
              case None =>
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   136
            }
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   137
          case None =>
142f4fff4e40 tuned signature;
wenzelm
parents: 53237
diff changeset
   138
        }
53228
f6c6688961db some key event handling in the manner of SideKickBindings, SideKickCompletionPopup;
wenzelm
parents: 53226
diff changeset
   139
      }
f6c6688961db some key event handling in the manner of SideKickBindings, SideKickCompletionPopup;
wenzelm
parents: 53226
diff changeset
   140
    }
f6c6688961db some key event handling in the manner of SideKickBindings, SideKickCompletionPopup;
wenzelm
parents: 53226
diff changeset
   141
  }
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   142
}
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   143
53233
4b422e5d64fd some actual completion via outer syntax;
wenzelm
parents: 53232
diff changeset
   144
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   145
class Completion_Popup private(
53229
6ce8328d7912 explicit "hidden" operation with focus management;
wenzelm
parents: 53228
diff changeset
   146
  root: JComponent,
6ce8328d7912 explicit "hidden" operation with focus management;
wenzelm
parents: 53228
diff changeset
   147
  popup_font: Font,
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   148
  screen_point: Point,
53232
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   149
  items: List[Completion_Popup.Item]) extends JPanel(new BorderLayout)
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   150
{
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   151
  completion =>
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   152
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   153
  Swing_Thread.require()
53232
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   154
  require(!items.isEmpty)
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   155
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   156
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   157
  /* actions */
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   158
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   159
  def complete(item: Completion_Popup.Item) { }
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   160
  def propagate(evt: KeyEvent) { }
53234
ea4abbbe1702 more careful refocus operation: do not reset focus if it was already lost (relevant when activating a different GUI component, for example);
wenzelm
parents: 53233
diff changeset
   161
  def refocus() { }
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   162
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   163
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   164
  /* list view */
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   165
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   166
  private val list_view = new ListView(items)
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   167
  {
53229
6ce8328d7912 explicit "hidden" operation with focus management;
wenzelm
parents: 53228
diff changeset
   168
    font = popup_font
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   169
  }
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   170
  list_view.selection.intervalMode = ListView.IntervalMode.Single
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   171
  list_view.peer.setFocusTraversalKeysEnabled(false)
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   172
  list_view.peer.setVisibleRowCount(items.length min 8)
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   173
  list_view.peer.setSelectedIndex(0)
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   174
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   175
  private def complete_selected(): Boolean =
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   176
  {
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   177
    list_view.selection.items.toList match {
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   178
      case item :: _ => complete(item); true
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   179
      case _ => false
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   180
    }
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   181
  }
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   182
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   183
  private def move_items(n: Int)
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   184
  {
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   185
    val i = list_view.peer.getSelectedIndex
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   186
    val j = ((i + n) min (items.length - 1)) max 0
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   187
    if (i != j) {
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   188
      list_view.peer.setSelectedIndex(j)
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   189
      list_view.peer.ensureIndexIsVisible(j)
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   190
    }
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   191
  }
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   192
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   193
  private def move_pages(n: Int)
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   194
  {
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   195
    val page_size = list_view.peer.getVisibleRowCount - 1
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   196
    move_items(page_size * n)
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   197
  }
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   198
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   199
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   200
  /* event handling */
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   201
53226
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   202
  private val key_listener =
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   203
    JEdit_Lib.key_listener(
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   204
      key_pressed = (e: KeyEvent) =>
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   205
        {
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   206
          if (!e.isConsumed) {
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   207
            e.getKeyCode match {
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   208
              case KeyEvent.VK_TAB =>
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   209
                if (complete_selected()) e.consume
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   210
                hide_popup()
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   211
              case KeyEvent.VK_ESCAPE =>
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   212
                hide_popup()
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   213
                e.consume
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   214
              case KeyEvent.VK_UP => move_items(-1); e.consume
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   215
              case KeyEvent.VK_DOWN => move_items(1); e.consume
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   216
              case KeyEvent.VK_PAGE_UP => move_pages(-1); e.consume
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   217
              case KeyEvent.VK_PAGE_DOWN => move_pages(1); e.consume
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   218
              case _ =>
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   219
                if (e.isActionKey || e.isAltDown || e.isMetaDown || e.isControlDown)
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   220
                  hide_popup()
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   221
            }
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   222
          }
53232
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   223
          propagate(e)
53226
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   224
        },
53232
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   225
      key_typed = propagate _
53226
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   226
    )
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   227
53226
9cf8e2263ca7 more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents: 53023
diff changeset
   228
  list_view.peer.addKeyListener(key_listener)
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   229
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   230
  list_view.peer.addMouseListener(new MouseAdapter {
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   231
    override def mouseClicked(e: MouseEvent) {
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   232
      if (complete_selected()) e.consume
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   233
      hide_popup()
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   234
    }
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   235
  })
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   236
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   237
  list_view.peer.addFocusListener(new FocusAdapter {
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   238
    override def focusLost(e: FocusEvent) { hide_popup() }
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   239
  })
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   240
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   241
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   242
  /* main content */
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   243
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   244
  override def getFocusTraversalKeysEnabled = false
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   245
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   246
  completion.add((new ScrollPane(list_view)).peer.asInstanceOf[JComponent])
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   247
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   248
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   249
  /* popup */
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   250
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   251
  private val popup =
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   252
  {
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   253
    val screen_bounds = JEdit_Lib.screen_bounds(screen_point)
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   254
53230
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   255
    val x0 = root.getLocationOnScreen.x
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   256
    val y0 = root.getLocationOnScreen.y
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   257
    val w0 = root.getWidth
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   258
    val h0 = root.getHeight
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   259
53230
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   260
    val (w, h) =
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   261
    {
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   262
      val geometry = JEdit_Lib.window_geometry(completion, completion)
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   263
      val bounds = Rendering.popup_bounds
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   264
      val w = geometry.width min (screen_bounds.width * bounds).toInt min w0
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   265
      val h = geometry.height min (screen_bounds.height * bounds).toInt min h0
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   266
      (w, h)
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   267
    }
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   268
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   269
    val (x, y) =
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   270
    {
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   271
      val x1 = x0 + w0 - w
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   272
      val y1 = y0 + h0 - h
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   273
      val x2 = screen_point.x min (screen_bounds.x + screen_bounds.width - w)
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   274
      val y2 = screen_point.y min (screen_bounds.y + screen_bounds.height - h)
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   275
      ((x2 min x1) max x0, (y2 min y1) max y0)
6589ff56cc3c determine completion geometry like tooltip;
wenzelm
parents: 53229
diff changeset
   276
    }
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   277
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   278
    completion.setSize(new Dimension(w, h))
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   279
    completion.setPreferredSize(new Dimension(w, h))
53229
6ce8328d7912 explicit "hidden" operation with focus management;
wenzelm
parents: 53228
diff changeset
   280
    PopupFactory.getSharedInstance.getPopup(root, completion, x, y)
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   281
  }
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   282
53232
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   283
  private def hide_popup()
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   284
  {
53234
ea4abbbe1702 more careful refocus operation: do not reset focus if it was already lost (relevant when activating a different GUI component, for example);
wenzelm
parents: 53233
diff changeset
   285
    val had_focus = list_view.peer.isFocusOwner
53229
6ce8328d7912 explicit "hidden" operation with focus management;
wenzelm
parents: 53228
diff changeset
   286
    popup.hide
53234
ea4abbbe1702 more careful refocus operation: do not reset focus if it was already lost (relevant when activating a different GUI component, for example);
wenzelm
parents: 53233
diff changeset
   287
    if (had_focus) refocus()
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   288
  }
53232
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   289
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   290
  popup.show
4a3762693452 tuned signature;
wenzelm
parents: 53231
diff changeset
   291
  list_view.requestFocus
53023
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   292
}
f127e949389f Completion popup based on javax.swing.PopupFactory, which has better cross-platform chances than JWindow (cf. org/gjt/jedit/gui/CompletionPopup.java);
wenzelm
parents:
diff changeset
   293