author | wenzelm |
Sun, 22 Nov 2015 20:53:38 +0100 | |
changeset 61734 | 31633e503c17 |
parent 61601 | 15952a05133c |
child 62113 | 16de2a9b5b3d |
permissions | -rw-r--r-- |
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 |
|
53246
8d34caf5bf82
more elementary Popup via JLayeredPane -- avoid javax.swing.PopupFactory with its many problems and dangers of accidental HeavyWeightPopup (especially on Mac OS X);
wenzelm
parents:
53244
diff
changeset
|
4 |
Completion 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
|
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 |
|
53297 | 12 |
import java.awt.{Color, Font, Point, BorderLayout, Dimension} |
53784 | 13 |
import java.awt.event.{KeyEvent, MouseEvent, MouseAdapter, FocusAdapter, FocusEvent} |
56843
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
14 |
import java.io.{File => JFile} |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
15 |
import java.util.regex.Pattern |
53246
8d34caf5bf82
more elementary Popup via JLayeredPane -- avoid javax.swing.PopupFactory with its many problems and dangers of accidental HeavyWeightPopup (especially on Mac OS X);
wenzelm
parents:
53244
diff
changeset
|
16 |
import javax.swing.{JPanel, JComponent, JLayeredPane, SwingUtilities} |
53297 | 17 |
import javax.swing.border.LineBorder |
53848
8d7029eb0c31
disable standard behaviour of Mac OS X text field (i.e. select-all after focus gain) in order to make completion work more smoothly;
wenzelm
parents:
53784
diff
changeset
|
18 |
import javax.swing.text.DefaultCaret |
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
|
19 |
|
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
|
20 |
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
|
21 |
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
|
22 |
|
53784 | 23 |
import org.gjt.sp.jedit.View |
56325
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
24 |
import org.gjt.sp.jedit.textarea.{JEditTextArea, TextArea, Selection} |
53784 | 25 |
import org.gjt.sp.jedit.gui.{HistoryTextField, KeyEventWorkaround} |
56843
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
26 |
import org.gjt.sp.util.StandardUtilities |
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
|
27 |
|
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
|
28 |
|
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
|
29 |
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
|
30 |
{ |
55978 | 31 |
/** items with HTML rendering **/ |
32 |
||
33 |
private class Item(val item: Completion.Item) |
|
34 |
{ |
|
35 |
private val html = |
|
36 |
item.description match { |
|
37 |
case a :: bs => |
|
38 |
"<html><b>" + HTML.encode(a) + "</b>" + |
|
39 |
HTML.encode(bs.map(" " + _).mkString) + "</html>" |
|
40 |
case Nil => "" |
|
41 |
} |
|
42 |
override def toString: String = html |
|
43 |
} |
|
44 |
||
45 |
||
46 |
||
53784 | 47 |
/** jEdit text area **/ |
53235
1b6a44859549
register single instance within root, in order to get rid of old popup as user continues typing;
wenzelm
parents:
53234
diff
changeset
|
48 |
|
53242 | 49 |
object Text_Area |
53233 | 50 |
{ |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
51 |
private val key = new Object |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
52 |
|
55712 | 53 |
def apply(text_area: TextArea): Option[Completion_Popup.Text_Area] = |
54 |
{ |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57588
diff
changeset
|
55 |
GUI_Thread.require {} |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
56 |
text_area.getClientProperty(key) match { |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
57 |
case text_area_completion: Completion_Popup.Text_Area => Some(text_area_completion) |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
58 |
case _ => None |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
59 |
} |
55712 | 60 |
} |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
61 |
|
55712 | 62 |
def active_range(text_area: TextArea): Option[Text.Range] = |
63 |
apply(text_area) match { |
|
64 |
case Some(text_area_completion) => text_area_completion.active_range |
|
65 |
case None => None |
|
55711 | 66 |
} |
67 |
||
56586 | 68 |
def action(text_area: TextArea, word_only: Boolean): Boolean = |
56170
638b29331549
allow implicit semantic completion, notably after delay that exceeds usual round-trip time;
wenzelm
parents:
55978
diff
changeset
|
69 |
apply(text_area) match { |
638b29331549
allow implicit semantic completion, notably after delay that exceeds usual round-trip time;
wenzelm
parents:
55978
diff
changeset
|
70 |
case Some(text_area_completion) => |
638b29331549
allow implicit semantic completion, notably after delay that exceeds usual round-trip time;
wenzelm
parents:
55978
diff
changeset
|
71 |
if (text_area_completion.active_range.isDefined) |
56586 | 72 |
text_area_completion.action(word_only = word_only) |
56177
bfa9dfb722de
proper flags for main action (amending 638b29331549);
wenzelm
parents:
56175
diff
changeset
|
73 |
else |
56586 | 74 |
text_area_completion.action(immediate = true, explicit = true, word_only = word_only) |
56170
638b29331549
allow implicit semantic completion, notably after delay that exceeds usual round-trip time;
wenzelm
parents:
55978
diff
changeset
|
75 |
true |
638b29331549
allow implicit semantic completion, notably after delay that exceeds usual round-trip time;
wenzelm
parents:
55978
diff
changeset
|
76 |
case None => false |
638b29331549
allow implicit semantic completion, notably after delay that exceeds usual round-trip time;
wenzelm
parents:
55978
diff
changeset
|
77 |
} |
638b29331549
allow implicit semantic completion, notably after delay that exceeds usual round-trip time;
wenzelm
parents:
55978
diff
changeset
|
78 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
79 |
def exit(text_area: JEditTextArea) |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
80 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57588
diff
changeset
|
81 |
GUI_Thread.require {} |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
82 |
apply(text_area) match { |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
83 |
case None => |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
84 |
case Some(text_area_completion) => |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
85 |
text_area_completion.deactivate() |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
86 |
text_area.putClientProperty(key, null) |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
87 |
} |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
88 |
} |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
89 |
|
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
90 |
def init(text_area: JEditTextArea): Completion_Popup.Text_Area = |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
91 |
{ |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
92 |
exit(text_area) |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
93 |
val text_area_completion = new Text_Area(text_area) |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
94 |
text_area.putClientProperty(key, text_area_completion) |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
95 |
text_area_completion.activate() |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
96 |
text_area_completion |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
97 |
} |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
98 |
|
55712 | 99 |
def dismissed(text_area: TextArea): Boolean = |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
100 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57588
diff
changeset
|
101 |
GUI_Thread.require {} |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
102 |
apply(text_area) match { |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
103 |
case Some(text_area_completion) => text_area_completion.dismissed() |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
104 |
case None => false |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
105 |
} |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
106 |
} |
53272 | 107 |
} |
108 |
||
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
109 |
class Text_Area private(text_area: JEditTextArea) |
53272 | 110 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57588
diff
changeset
|
111 |
// owned by GUI thread |
53272 | 112 |
private var completion_popup: Option[Completion_Popup] = None |
113 |
||
55711 | 114 |
def active_range: Option[Text.Range] = |
115 |
completion_popup match { |
|
56605 | 116 |
case Some(completion) => completion.active_range |
55711 | 117 |
case None => None |
118 |
} |
|
119 |
||
53272 | 120 |
|
55747
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
121 |
/* rendering */ |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
122 |
|
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
123 |
def rendering(rendering: Rendering, line_range: Text.Range): Option[Text.Info[Color]] = |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
124 |
{ |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
125 |
active_range match { |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
126 |
case Some(range) => range.try_restrict(line_range) |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
127 |
case None => |
55767
96ddf9bf12ac
more precise before_caret_range (looking both in space and time);
wenzelm
parents:
55752
diff
changeset
|
128 |
if (line_range.contains(text_area.getCaretPosition)) { |
56593
0ea7c84110ac
back to unrestricted before_caret_range, which is important for quick editing at the end of line (amending 83777a91f5de);
wenzelm
parents:
56589
diff
changeset
|
129 |
JEdit_Lib.before_caret_range(text_area, rendering).try_restrict(line_range) match { |
55747
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
130 |
case Some(range) if !range.is_singularity => |
61601
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
131 |
val range0 = |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
132 |
Completion.Result.merge(Completion.History.empty, |
61734 | 133 |
syntax_completion(Completion.History.empty, true, Some(rendering)), |
61601
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
134 |
Completion.Result.merge(Completion.History.empty, |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
135 |
path_completion(rendering), |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
136 |
Bibtex_JEdit.completion(Completion.History.empty, text_area, rendering))) |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
137 |
.map(_.range) |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
138 |
rendering.semantic_completion(range0, range) match { |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
139 |
case None => range0 |
56175 | 140 |
case Some(Text.Info(_, Completion.No_Completion)) => None |
141 |
case Some(Text.Info(range1, _: Completion.Names)) => Some(range1) |
|
55747
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
142 |
} |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
143 |
case _ => None |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
144 |
} |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
145 |
} |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
146 |
else None |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
147 |
} |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
148 |
}.map(range => Text.Info(range, rendering.completion_color)) |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
149 |
|
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
150 |
|
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
151 |
/* syntax completion */ |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
152 |
|
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
153 |
def syntax_completion( |
56175 | 154 |
history: Completion.History, |
155 |
explicit: Boolean, |
|
156 |
opt_rendering: Option[Rendering]): Option[Completion.Result] = |
|
55747
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
157 |
{ |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
158 |
val buffer = text_area.getBuffer |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
159 |
val decode = Isabelle_Encoding.is_active(buffer) |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
160 |
|
59074 | 161 |
Isabelle.buffer_syntax(buffer) match { |
55747
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
162 |
case Some(syntax) => |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
163 |
val context = |
56587
83777a91f5de
clarified before_caret_range: prevent continuation on next line;
wenzelm
parents:
56586
diff
changeset
|
164 |
(for { |
83777a91f5de
clarified before_caret_range: prevent continuation on next line;
wenzelm
parents:
56586
diff
changeset
|
165 |
rendering <- opt_rendering |
56842
b6e266574b26
yet another completion option, to imitate old less ambitious behavior;
wenzelm
parents:
56841
diff
changeset
|
166 |
if PIDE.options.bool("jedit_completion_context") |
56593
0ea7c84110ac
back to unrestricted before_caret_range, which is important for quick editing at the end of line (amending 83777a91f5de);
wenzelm
parents:
56589
diff
changeset
|
167 |
range = JEdit_Lib.before_caret_range(text_area, rendering) |
56587
83777a91f5de
clarified before_caret_range: prevent continuation on next line;
wenzelm
parents:
56586
diff
changeset
|
168 |
context <- rendering.language_context(range) |
83777a91f5de
clarified before_caret_range: prevent continuation on next line;
wenzelm
parents:
56586
diff
changeset
|
169 |
} yield context) getOrElse syntax.language_context |
55747
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
170 |
|
56589
71c5d1f516c0
more robust JEdit_Lib.line_range, according to usual jEdit confusion at end of last line;
wenzelm
parents:
56587
diff
changeset
|
171 |
val caret = text_area.getCaretPosition |
71c5d1f516c0
more robust JEdit_Lib.line_range, according to usual jEdit confusion at end of last line;
wenzelm
parents:
56587
diff
changeset
|
172 |
val line_range = JEdit_Lib.line_range(buffer, text_area.getCaretLine) |
71c5d1f516c0
more robust JEdit_Lib.line_range, according to usual jEdit confusion at end of last line;
wenzelm
parents:
56587
diff
changeset
|
173 |
val line_start = line_range.start |
71c5d1f516c0
more robust JEdit_Lib.line_range, according to usual jEdit confusion at end of last line;
wenzelm
parents:
56587
diff
changeset
|
174 |
for { |
71c5d1f516c0
more robust JEdit_Lib.line_range, according to usual jEdit confusion at end of last line;
wenzelm
parents:
56587
diff
changeset
|
175 |
line_text <- JEdit_Lib.try_get_text(buffer, line_range) |
71c5d1f516c0
more robust JEdit_Lib.line_range, according to usual jEdit confusion at end of last line;
wenzelm
parents:
56587
diff
changeset
|
176 |
result <- |
71c5d1f516c0
more robust JEdit_Lib.line_range, according to usual jEdit confusion at end of last line;
wenzelm
parents:
56587
diff
changeset
|
177 |
syntax.completion.complete( |
57588
ff31aad27661
discontinued unfinished attempts at syntactic word context (see 2e1398b484aa, 08a1c860bc12, 7f229b0212fe) -- back to more basic completion of Isabelle2013-2;
wenzelm
parents:
57127
diff
changeset
|
178 |
history, decode, explicit, line_start, line_text, caret - line_start, context) |
56589
71c5d1f516c0
more robust JEdit_Lib.line_range, according to usual jEdit confusion at end of last line;
wenzelm
parents:
56587
diff
changeset
|
179 |
} yield result |
55747
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
180 |
|
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
181 |
case None => None |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
182 |
} |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
183 |
} |
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
184 |
|
bef19c929ba5
more completion rendering: active, semantic, syntactic;
wenzelm
parents:
55712
diff
changeset
|
185 |
|
56843
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
186 |
/* path completion */ |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
187 |
|
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
188 |
def path_completion(rendering: Rendering): Option[Completion.Result] = |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
189 |
{ |
56844 | 190 |
def complete(text: String): List[(String, List[String])] = |
56843
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
191 |
{ |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
192 |
try { |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
193 |
val path = Path.explode(text) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
194 |
val (dir, base_name) = |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
195 |
if (text == "" || text.endsWith("/")) (path, "") |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
196 |
else (path.dir, path.base.implode) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
197 |
|
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
198 |
val directory = |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
199 |
new JFile(PIDE.resources.append(rendering.snapshot.node_name.master_dir, dir)) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
200 |
val files = directory.listFiles |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
201 |
if (files == null) Nil |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
202 |
else { |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
203 |
val ignore = |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
204 |
Library.space_explode(':', PIDE.options.string("jedit_completion_path_ignore")). |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
205 |
map(s => Pattern.compile(StandardUtilities.globToRE(s))) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
206 |
(for { |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
207 |
file <- files.iterator |
56844 | 208 |
|
56843
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
209 |
name = file.getName |
56844 | 210 |
if name.startsWith(base_name) |
56843
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
211 |
if !ignore.exists(pat => pat.matcher(name).matches) |
56844 | 212 |
|
213 |
text1 = (dir + Path.basic(name)).implode_short |
|
214 |
if text != text1 |
|
215 |
||
216 |
is_dir = new JFile(directory, name).isDirectory |
|
217 |
replacement = text1 + (if (is_dir) "/" else "") |
|
218 |
descr = List(text1, if (is_dir) "(directory)" else "(file)") |
|
219 |
} yield (replacement, descr)).take(PIDE.options.int("completion_limit")).toList |
|
56843
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
220 |
} |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
221 |
} |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
222 |
catch { case ERROR(_) => Nil } |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
223 |
} |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
224 |
|
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
225 |
for { |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
226 |
r1 <- rendering.language_path(JEdit_Lib.before_caret_range(text_area, rendering)) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
227 |
s1 <- JEdit_Lib.try_get_text(text_area.getBuffer, r1) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
228 |
s2 <- Library.try_unquote(s1) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
229 |
r2 = Text.Range(r1.start + 1, r1.stop - 1) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
230 |
if Path.is_valid(s2) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
231 |
paths = complete(s2) |
59319 | 232 |
if paths.nonEmpty |
56844 | 233 |
items = paths.map(p => Completion.Item(r2, s2, "", p._2, p._1, 0, false)) |
56843
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
234 |
} yield Completion.Result(r2, s2, false, items) |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
235 |
} |
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
236 |
|
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
237 |
|
56170
638b29331549
allow implicit semantic completion, notably after delay that exceeds usual round-trip time;
wenzelm
parents:
55978
diff
changeset
|
238 |
/* completion action: text area */ |
53273 | 239 |
|
53275 | 240 |
private def insert(item: Completion.Item) |
53242 | 241 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57588
diff
changeset
|
242 |
GUI_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
|
243 |
|
53242 | 244 |
val buffer = text_area.getBuffer |
55692
19e8b00684f7
more explicit Completion.Item.range, independently of caret;
wenzelm
parents:
55690
diff
changeset
|
245 |
val range = item.range |
56863 | 246 |
if (buffer.isEditable) { |
53242 | 247 |
JEdit_Lib.buffer_edit(buffer) { |
55692
19e8b00684f7
more explicit Completion.Item.range, independently of caret;
wenzelm
parents:
55690
diff
changeset
|
248 |
JEdit_Lib.try_get_text(buffer, range) match { |
53242 | 249 |
case Some(text) if text == item.original => |
56325
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
250 |
text_area.getSelectionAtOffset(text_area.getCaretPosition) match { |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
251 |
|
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
252 |
/*rectangular selection as "tall caret"*/ |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
253 |
case selection : Selection.Rect |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
254 |
if selection.getStart(buffer, text_area.getCaretLine) == range.stop => |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
255 |
text_area.moveCaretPosition(range.stop) |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
256 |
(0 until Character.codePointCount(item.original, 0, item.original.length)) |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
257 |
.foreach(_ => text_area.backspace()) |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
258 |
text_area.setSelectedText(selection, item.replacement) |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
259 |
text_area.moveCaretPosition(text_area.getCaretPosition + item.move) |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
260 |
|
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
261 |
/*other selections: rectangular, multiple range, ...*/ |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
262 |
case selection |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
263 |
if selection != null && |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
264 |
selection.getStart(buffer, text_area.getCaretLine) == range.start && |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
265 |
selection.getEnd(buffer, text_area.getCaretLine) == range.stop => |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
266 |
text_area.moveCaretPosition(range.stop + item.move) |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
267 |
text_area.getSelection.foreach(text_area.setSelectedText(_, item.replacement)) |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
268 |
|
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
269 |
/*no selection*/ |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
270 |
case _ => |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
271 |
buffer.remove(range.start, range.length) |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
272 |
buffer.insert(range.start, item.replacement) |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
273 |
text_area.moveCaretPosition(range.start + item.replacement.length + item.move) |
ffbfc92e6508
special treatment for various kinds of selections: imitate normal flow of editing;
wenzelm
parents:
56197
diff
changeset
|
274 |
} |
53242 | 275 |
case _ => |
276 |
} |
|
53233 | 277 |
} |
278 |
} |
|
279 |
} |
|
53242 | 280 |
|
56586 | 281 |
def action( |
282 |
immediate: Boolean = false, |
|
283 |
explicit: Boolean = false, |
|
284 |
delayed: Boolean = false, |
|
285 |
word_only: Boolean = false): Boolean = |
|
53292
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
286 |
{ |
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
287 |
val view = text_area.getView |
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
288 |
val layered = view.getLayeredPane |
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
289 |
val buffer = text_area.getBuffer |
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
290 |
val painter = text_area.getPainter |
53273 | 291 |
|
55693
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
292 |
val history = PIDE.completion_history.value |
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
293 |
val decode = Isabelle_Encoding.is_active(buffer) |
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
294 |
|
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
295 |
def open_popup(result: Completion.Result) |
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
296 |
{ |
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
297 |
val font = |
55825 | 298 |
painter.getFont.deriveFont( |
299 |
Font_Info.main_size(PIDE.options.real("jedit_popup_font_scale"))) |
|
55693
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
300 |
|
55711 | 301 |
val range = result.range |
302 |
||
303 |
val loc1 = text_area.offsetToXY(range.start) |
|
55693
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
304 |
if (loc1 != null) { |
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
305 |
val loc2 = |
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
306 |
SwingUtilities.convertPoint(painter, |
58767
30766b5fd0e1
proper line height and text base line, like regular TextAreaPainter.PaintText;
wenzelm
parents:
58592
diff
changeset
|
307 |
loc1.x, loc1.y + painter.getLineHeight, layered) |
55693
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
308 |
|
55978 | 309 |
val items = result.items.map(new Item(_)) |
55693
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
310 |
val completion = |
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
311 |
new Completion_Popup(Some(range), layered, loc2, font, items) |
55978 | 312 |
{ |
55693
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
313 |
override def complete(item: Completion.Item) { |
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
314 |
PIDE.completion_history.update(item) |
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
315 |
insert(item) |
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
316 |
} |
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
317 |
override def propagate(evt: KeyEvent) { |
56840
879fe16bd27c
propagate more events, notably after hide_popup (e.g. LEFT, RIGHT);
wenzelm
parents:
56662
diff
changeset
|
318 |
if (view.getKeyEventInterceptor == null) |
879fe16bd27c
propagate more events, notably after hide_popup (e.g. LEFT, RIGHT);
wenzelm
parents:
56662
diff
changeset
|
319 |
JEdit_Lib.propagate_key(view, evt) |
879fe16bd27c
propagate more events, notably after hide_popup (e.g. LEFT, RIGHT);
wenzelm
parents:
56662
diff
changeset
|
320 |
else if (view.getKeyEventInterceptor == inner_key_listener) { |
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
321 |
try { |
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
322 |
view.setKeyEventInterceptor(null) |
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
323 |
JEdit_Lib.propagate_key(view, evt) |
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
324 |
} |
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
325 |
finally { |
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
326 |
if (isDisplayable) view.setKeyEventInterceptor(inner_key_listener) |
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
327 |
} |
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
328 |
} |
56171
15351577da10
clarified key event propagation, in accordance to outer_key_listener;
wenzelm
parents:
56170
diff
changeset
|
329 |
if (evt.getID == KeyEvent.KEY_TYPED) input(evt) |
55693
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
330 |
} |
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
331 |
override def shutdown(focus: Boolean) { |
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
332 |
if (view.getKeyEventInterceptor == inner_key_listener) |
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
333 |
view.setKeyEventInterceptor(null) |
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
334 |
if (focus) text_area.requestFocus |
56606
68b7a6db4a32
avoid ooddity: invoke intended function instead of java.awt.Container.invalidate();
wenzelm
parents:
56605
diff
changeset
|
335 |
JEdit_Lib.invalidate_range(text_area, range) |
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
336 |
} |
55693
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
337 |
} |
57127
a406e15c3cf7
make double-sure that old popup is dismissed, before replacing it;
wenzelm
parents:
57051
diff
changeset
|
338 |
dismissed() |
55693
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
339 |
completion_popup = Some(completion) |
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
340 |
view.setKeyEventInterceptor(completion.inner_key_listener) |
56606
68b7a6db4a32
avoid ooddity: invoke intended function instead of java.awt.Container.invalidate();
wenzelm
parents:
56605
diff
changeset
|
341 |
JEdit_Lib.invalidate_range(text_area, range) |
56841 | 342 |
Pretty_Tooltip.dismissed_all() |
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
343 |
completion.show_popup(false) |
55693
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
344 |
} |
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
345 |
} |
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
346 |
|
56175 | 347 |
if (buffer.isEditable) { |
61601
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
348 |
val opt_rendering = PIDE.document_view(text_area).map(_.get_rendering()) |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
349 |
val result0 = syntax_completion(history, explicit, opt_rendering) |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
350 |
val (no_completion, semantic_completion) = |
56175 | 351 |
{ |
61601
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
352 |
opt_rendering match { |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
353 |
case Some(rendering) => |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
354 |
val caret_range = JEdit_Lib.before_caret_range(text_area, rendering) |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
355 |
rendering.semantic_completion(result0.map(_.range), caret_range) match { |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
356 |
case Some(Text.Info(_, Completion.No_Completion)) => (true, None) |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
357 |
case Some(Text.Info(range, names: Completion.Names)) => |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
358 |
JEdit_Lib.try_get_text(buffer, range) match { |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
359 |
case Some(original) => (false, names.complete(range, history, decode, original)) |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
360 |
case None => (false, None) |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
361 |
} |
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
362 |
case None => (false, None) |
56593
0ea7c84110ac
back to unrestricted before_caret_range, which is important for quick editing at the end of line (amending 83777a91f5de);
wenzelm
parents:
56589
diff
changeset
|
363 |
} |
61601
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
364 |
case None => (false, None) |
56175 | 365 |
} |
55693
93ba0085e888
try explicit semantic completion before syntax completion;
wenzelm
parents:
55692
diff
changeset
|
366 |
} |
56326
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
367 |
if (no_completion) false |
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
368 |
else { |
56564
94c55cc73747
added spell-checker completion dialog, without counting frequency of items due to empty name;
wenzelm
parents:
56326
diff
changeset
|
369 |
val result = |
56586 | 370 |
{ |
61601
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
371 |
val result1 = |
56586 | 372 |
if (word_only) None |
61601
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
373 |
else Completion.Result.merge(history, semantic_completion, result0) |
56564
94c55cc73747
added spell-checker completion dialog, without counting frequency of items due to empty name;
wenzelm
parents:
56326
diff
changeset
|
374 |
opt_rendering match { |
61601
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
375 |
case None => result1 |
56564
94c55cc73747
added spell-checker completion dialog, without counting frequency of items due to empty name;
wenzelm
parents:
56326
diff
changeset
|
376 |
case Some(rendering) => |
61601
15952a05133c
syntactic completion may supersede semantic completion, e.g. relevant for "\undefined" vs. "undefined" in ML;
wenzelm
parents:
59319
diff
changeset
|
377 |
Completion.Result.merge(history, result1, |
56843
b2bfcd8cda80
support for path completion based on file-system content;
wenzelm
parents:
56842
diff
changeset
|
378 |
Completion.Result.merge(history, |
58549 | 379 |
Spell_Checker.completion(text_area, explicit, rendering), |
58592 | 380 |
Completion.Result.merge(history, |
381 |
path_completion(rendering), |
|
382 |
Bibtex_JEdit.completion(history, text_area, rendering)))) |
|
56564
94c55cc73747
added spell-checker completion dialog, without counting frequency of items due to empty name;
wenzelm
parents:
56326
diff
changeset
|
383 |
} |
56586 | 384 |
} |
56175 | 385 |
result match { |
386 |
case Some(result) => |
|
387 |
result.items match { |
|
388 |
case List(item) if result.unique && item.immediate && immediate => |
|
389 |
insert(item) |
|
56326
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
390 |
true |
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
391 |
case _ :: _ if !delayed => |
56175 | 392 |
open_popup(result) |
56326
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
393 |
false |
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
394 |
case _ => false |
56175 | 395 |
} |
56326
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
396 |
case None => false |
56175 | 397 |
} |
53292
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
398 |
} |
55752 | 399 |
} |
56326
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
400 |
else false |
53292
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
401 |
} |
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
402 |
|
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
403 |
|
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
404 |
/* input key events */ |
53273 | 405 |
|
53272 | 406 |
def input(evt: KeyEvent) |
53242 | 407 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57588
diff
changeset
|
408 |
GUI_Thread.require {} |
53233 | 409 |
|
53273 | 410 |
if (PIDE.options.bool("jedit_completion")) { |
411 |
if (!evt.isConsumed) { |
|
412 |
dismissed() |
|
53397
b179cdfa9d82
no completion on backspace -- too intrusive, e.g. when deleting keywords;
wenzelm
parents:
53337
diff
changeset
|
413 |
if (evt.getKeyChar != '\b') { |
53784 | 414 |
val special = JEdit_Lib.special_key(evt) |
56326
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
415 |
val immediate = PIDE.options.bool("jedit_completion_immediate") |
53397
b179cdfa9d82
no completion on backspace -- too intrusive, e.g. when deleting keywords;
wenzelm
parents:
53337
diff
changeset
|
416 |
if (PIDE.options.seconds("jedit_completion_delay").is_zero && !special) { |
b179cdfa9d82
no completion on backspace -- too intrusive, e.g. when deleting keywords;
wenzelm
parents:
53337
diff
changeset
|
417 |
input_delay.revoke() |
56326
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
418 |
action(immediate = immediate) |
53397
b179cdfa9d82
no completion on backspace -- too intrusive, e.g. when deleting keywords;
wenzelm
parents:
53337
diff
changeset
|
419 |
} |
56326
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
420 |
else { |
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
421 |
if (!special && action(immediate = immediate, delayed = true)) |
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
422 |
input_delay.revoke() |
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
423 |
else |
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
424 |
input_delay.invoke() |
c3d7b3bb2708
immediate completion even with delay, which is the default according to 638b29331549;
wenzelm
parents:
56325
diff
changeset
|
425 |
} |
53292
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
426 |
} |
53242 | 427 |
} |
53228
f6c6688961db
some key event handling in the manner of SideKickBindings, SideKickCompletionPopup;
wenzelm
parents:
53226
diff
changeset
|
428 |
} |
f6c6688961db
some key event handling in the manner of SideKickBindings, SideKickCompletionPopup;
wenzelm
parents:
53226
diff
changeset
|
429 |
} |
53273 | 430 |
|
431 |
private val input_delay = |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57588
diff
changeset
|
432 |
GUI_Thread.delay_last(PIDE.options.seconds("jedit_completion_delay")) { |
53322 | 433 |
action() |
53292
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
434 |
} |
53273 | 435 |
|
436 |
||
53292
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
437 |
/* dismiss popup */ |
53273 | 438 |
|
53292
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
439 |
def dismissed(): Boolean = |
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
440 |
{ |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57588
diff
changeset
|
441 |
GUI_Thread.require {} |
53273 | 442 |
|
53292
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
443 |
completion_popup match { |
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
444 |
case Some(completion) => |
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
445 |
completion.hide_popup() |
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
446 |
completion_popup = None |
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
447 |
true |
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
448 |
case None => |
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
449 |
false |
53273 | 450 |
} |
53292
f567c1c7b180
option to insert unique completion immediately into buffer;
wenzelm
parents:
53275
diff
changeset
|
451 |
} |
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
452 |
|
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
453 |
|
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
454 |
/* activation */ |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
455 |
|
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
456 |
private val outer_key_listener = |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
457 |
JEdit_Lib.key_listener(key_typed = input _) |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
458 |
|
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
459 |
private def activate() |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
460 |
{ |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
461 |
text_area.addKeyListener(outer_key_listener) |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
462 |
} |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
463 |
|
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
464 |
private def deactivate() |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
465 |
{ |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
466 |
dismissed() |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
467 |
text_area.removeKeyListener(outer_key_listener) |
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
468 |
} |
53228
f6c6688961db
some key event handling in the manner of SideKickBindings, SideKickCompletionPopup;
wenzelm
parents:
53226
diff
changeset
|
469 |
} |
53784 | 470 |
|
471 |
||
472 |
||
473 |
/** history text field **/ |
|
474 |
||
475 |
class History_Text_Field( |
|
476 |
name: String = null, |
|
477 |
instant_popups: Boolean = false, |
|
478 |
enter_adds_to_history: Boolean = true, |
|
479 |
syntax: Outer_Syntax = Outer_Syntax.init) extends |
|
480 |
HistoryTextField(name, instant_popups, enter_adds_to_history) |
|
481 |
{ |
|
482 |
text_field => |
|
483 |
||
53848
8d7029eb0c31
disable standard behaviour of Mac OS X text field (i.e. select-all after focus gain) in order to make completion work more smoothly;
wenzelm
parents:
53784
diff
changeset
|
484 |
// see https://forums.oracle.com/thread/1361677 |
8d7029eb0c31
disable standard behaviour of Mac OS X text field (i.e. select-all after focus gain) in order to make completion work more smoothly;
wenzelm
parents:
53784
diff
changeset
|
485 |
if (GUI.is_macos_laf) text_field.setCaret(new DefaultCaret) |
53784 | 486 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57588
diff
changeset
|
487 |
// owned by GUI thread |
53784 | 488 |
private var completion_popup: Option[Completion_Popup] = None |
489 |
||
490 |
||
491 |
/* dismiss */ |
|
492 |
||
493 |
private def dismissed(): Boolean = |
|
494 |
{ |
|
495 |
completion_popup match { |
|
496 |
case Some(completion) => |
|
497 |
completion.hide_popup() |
|
498 |
completion_popup = None |
|
499 |
true |
|
500 |
case None => |
|
501 |
false |
|
502 |
} |
|
503 |
} |
|
504 |
||
505 |
||
506 |
/* insert */ |
|
507 |
||
508 |
private def insert(item: Completion.Item) |
|
509 |
{ |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57588
diff
changeset
|
510 |
GUI_Thread.require {} |
53784 | 511 |
|
55692
19e8b00684f7
more explicit Completion.Item.range, independently of caret;
wenzelm
parents:
55690
diff
changeset
|
512 |
val range = item.range |
56863 | 513 |
if (text_field.isEditable) { |
53784 | 514 |
val content = text_field.getText |
55692
19e8b00684f7
more explicit Completion.Item.range, independently of caret;
wenzelm
parents:
55690
diff
changeset
|
515 |
JEdit_Lib.try_get_text(content, range) match { |
53784 | 516 |
case Some(text) if text == item.original => |
517 |
text_field.setText( |
|
55692
19e8b00684f7
more explicit Completion.Item.range, independently of caret;
wenzelm
parents:
55690
diff
changeset
|
518 |
content.substring(0, range.start) + |
53784 | 519 |
item.replacement + |
55692
19e8b00684f7
more explicit Completion.Item.range, independently of caret;
wenzelm
parents:
55690
diff
changeset
|
520 |
content.substring(range.stop)) |
19e8b00684f7
more explicit Completion.Item.range, independently of caret;
wenzelm
parents:
55690
diff
changeset
|
521 |
text_field.getCaret.setDot(range.start + item.replacement.length + item.move) |
53784 | 522 |
case _ => |
523 |
} |
|
524 |
} |
|
525 |
} |
|
526 |
||
527 |
||
56170
638b29331549
allow implicit semantic completion, notably after delay that exceeds usual round-trip time;
wenzelm
parents:
55978
diff
changeset
|
528 |
/* completion action: text field */ |
53784 | 529 |
|
530 |
def action() |
|
531 |
{ |
|
532 |
GUI.layered_pane(text_field) match { |
|
533 |
case Some(layered) if text_field.isEditable => |
|
534 |
val history = PIDE.completion_history.value |
|
535 |
||
536 |
val caret = text_field.getCaret.getDot |
|
55813
08a1c860bc12
allow completion within a word (or symbol), like semantic completion;
wenzelm
parents:
55767
diff
changeset
|
537 |
val text = text_field.getText |
55748 | 538 |
|
55749 | 539 |
val context = syntax.language_context |
55748 | 540 |
|
57588
ff31aad27661
discontinued unfinished attempts at syntactic word context (see 2e1398b484aa, 08a1c860bc12, 7f229b0212fe) -- back to more basic completion of Isabelle2013-2;
wenzelm
parents:
57127
diff
changeset
|
541 |
syntax.completion.complete(history, true, false, 0, text, caret, context) match { |
53784 | 542 |
case Some(result) => |
543 |
val fm = text_field.getFontMetrics(text_field.getFont) |
|
544 |
val loc = |
|
545 |
SwingUtilities.convertPoint(text_field, fm.stringWidth(text), fm.getHeight, layered) |
|
546 |
||
55978 | 547 |
val items = result.items.map(new Item(_)) |
55711 | 548 |
val completion = |
55978 | 549 |
new Completion_Popup(None, layered, loc, text_field.getFont, items) |
550 |
{ |
|
551 |
override def complete(item: Completion.Item) { |
|
552 |
PIDE.completion_history.update(item) |
|
553 |
insert(item) |
|
554 |
} |
|
555 |
override def propagate(evt: KeyEvent) { |
|
556 |
if (!evt.isConsumed) text_field.processKeyEvent(evt) |
|
557 |
} |
|
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
558 |
override def shutdown(focus: Boolean) { if (focus) text_field.requestFocus } |
53784 | 559 |
} |
57127
a406e15c3cf7
make double-sure that old popup is dismissed, before replacing it;
wenzelm
parents:
57051
diff
changeset
|
560 |
dismissed() |
53784 | 561 |
completion_popup = Some(completion) |
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
562 |
completion.show_popup(true) |
53784 | 563 |
|
564 |
case None => |
|
565 |
} |
|
566 |
case _ => |
|
567 |
} |
|
568 |
} |
|
569 |
||
570 |
||
571 |
/* process key event */ |
|
572 |
||
573 |
private def process(evt: KeyEvent) |
|
574 |
{ |
|
575 |
if (PIDE.options.bool("jedit_completion")) { |
|
576 |
dismissed() |
|
577 |
if (evt.getKeyChar != '\b') { |
|
578 |
val special = JEdit_Lib.special_key(evt) |
|
579 |
if (PIDE.options.seconds("jedit_completion_delay").is_zero && !special) { |
|
580 |
process_delay.revoke() |
|
581 |
action() |
|
582 |
} |
|
583 |
else process_delay.invoke() |
|
584 |
} |
|
585 |
} |
|
586 |
} |
|
587 |
||
588 |
private val process_delay = |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57588
diff
changeset
|
589 |
GUI_Thread.delay_last(PIDE.options.seconds("jedit_completion_delay")) { |
53784 | 590 |
action() |
591 |
} |
|
592 |
||
593 |
override def processKeyEvent(evt0: KeyEvent) |
|
594 |
{ |
|
595 |
val evt = KeyEventWorkaround.processKeyEvent(evt0) |
|
596 |
if (evt != null) { |
|
597 |
evt.getID match { |
|
598 |
case KeyEvent.KEY_PRESSED => |
|
599 |
val key_code = evt.getKeyCode |
|
600 |
if (key_code == KeyEvent.VK_ESCAPE) { |
|
601 |
if (dismissed()) evt.consume |
|
602 |
} |
|
603 |
case KeyEvent.KEY_TYPED => |
|
604 |
super.processKeyEvent(evt) |
|
605 |
process(evt) |
|
606 |
evt.consume |
|
607 |
case _ => |
|
608 |
} |
|
609 |
if (!evt.isConsumed) super.processKeyEvent(evt) |
|
610 |
} |
|
611 |
} |
|
612 |
} |
|
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
|
613 |
} |
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
|
614 |
|
53233 | 615 |
|
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
|
616 |
class Completion_Popup private( |
56605 | 617 |
opt_range: Option[Text.Range], |
53246
8d34caf5bf82
more elementary Popup via JLayeredPane -- avoid javax.swing.PopupFactory with its many problems and dangers of accidental HeavyWeightPopup (especially on Mac OS X);
wenzelm
parents:
53244
diff
changeset
|
618 |
layered: JLayeredPane, |
8d34caf5bf82
more elementary Popup via JLayeredPane -- avoid javax.swing.PopupFactory with its many problems and dangers of accidental HeavyWeightPopup (especially on Mac OS X);
wenzelm
parents:
53244
diff
changeset
|
619 |
location: Point, |
53272 | 620 |
font: Font, |
55978 | 621 |
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
|
622 |
{ |
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
|
623 |
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
|
624 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57588
diff
changeset
|
625 |
GUI_Thread.require {} |
53405 | 626 |
|
59319 | 627 |
require(items.nonEmpty) |
53405 | 628 |
val multi = items.length > 1 |
53232 | 629 |
|
630 |
||
631 |
/* actions */ |
|
632 |
||
53275 | 633 |
def complete(item: Completion.Item) { } |
53232 | 634 |
def propagate(evt: KeyEvent) { } |
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
635 |
def shutdown(focus: Boolean) { } |
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
|
636 |
|
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
|
637 |
|
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
|
638 |
/* 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
|
639 |
|
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
|
640 |
private val list_view = new ListView(items) |
53272 | 641 |
list_view.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
|
642 |
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
|
643 |
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
|
644 |
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
|
645 |
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
|
646 |
|
53398
f8b150e8778b
remove Swing input map, which might bind keys in unexpected ways (e.g. LEFT/RIGHT in singleton list);
wenzelm
parents:
53397
diff
changeset
|
647 |
for (cond <- |
f8b150e8778b
remove Swing input map, which might bind keys in unexpected ways (e.g. LEFT/RIGHT in singleton list);
wenzelm
parents:
53397
diff
changeset
|
648 |
List(JComponent.WHEN_FOCUSED, |
f8b150e8778b
remove Swing input map, which might bind keys in unexpected ways (e.g. LEFT/RIGHT in singleton list);
wenzelm
parents:
53397
diff
changeset
|
649 |
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, |
f8b150e8778b
remove Swing input map, which might bind keys in unexpected ways (e.g. LEFT/RIGHT in singleton list);
wenzelm
parents:
53397
diff
changeset
|
650 |
JComponent.WHEN_IN_FOCUSED_WINDOW)) list_view.peer.setInputMap(cond, null) |
f8b150e8778b
remove Swing input map, which might bind keys in unexpected ways (e.g. LEFT/RIGHT in singleton list);
wenzelm
parents:
53397
diff
changeset
|
651 |
|
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
|
652 |
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
|
653 |
{ |
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
|
654 |
list_view.selection.items.toList match { |
55978 | 655 |
case item :: _ => complete(item.item); true |
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
|
656 |
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
|
657 |
} |
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
|
658 |
} |
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
|
659 |
|
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
|
660 |
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
|
661 |
{ |
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
|
662 |
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
|
663 |
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
|
664 |
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
|
665 |
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
|
666 |
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
|
667 |
} |
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
|
668 |
} |
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
|
669 |
|
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
|
670 |
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
|
671 |
{ |
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
|
672 |
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
|
673 |
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
|
674 |
} |
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
|
675 |
|
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
|
676 |
|
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
|
677 |
/* 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
|
678 |
|
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
679 |
val inner_key_listener = |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
680 |
JEdit_Lib.key_listener( |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
681 |
key_pressed = (e: KeyEvent) => |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
682 |
{ |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
683 |
if (!e.isConsumed) { |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
684 |
e.getKeyCode match { |
57833
2c2bae3da1c2
completion popup supports both ENTER and TAB (default);
wenzelm
parents:
57612
diff
changeset
|
685 |
case KeyEvent.VK_ENTER if PIDE.options.bool("jedit_completion_select_enter") => |
2c2bae3da1c2
completion popup supports both ENTER and TAB (default);
wenzelm
parents:
57612
diff
changeset
|
686 |
if (complete_selected()) e.consume |
2c2bae3da1c2
completion popup supports both ENTER and TAB (default);
wenzelm
parents:
57612
diff
changeset
|
687 |
hide_popup() |
2c2bae3da1c2
completion popup supports both ENTER and TAB (default);
wenzelm
parents:
57612
diff
changeset
|
688 |
case KeyEvent.VK_TAB if PIDE.options.bool("jedit_completion_select_tab") => |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
689 |
if (complete_selected()) e.consume |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
690 |
hide_popup() |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
691 |
case KeyEvent.VK_ESCAPE => |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
692 |
hide_popup() |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
693 |
e.consume |
53405 | 694 |
case KeyEvent.VK_UP | KeyEvent.VK_KP_UP if multi => |
53407 | 695 |
move_items(-1) |
696 |
e.consume |
|
53405 | 697 |
case KeyEvent.VK_DOWN | KeyEvent.VK_KP_DOWN if multi => |
53407 | 698 |
move_items(1) |
699 |
e.consume |
|
53405 | 700 |
case KeyEvent.VK_PAGE_UP if multi => |
53407 | 701 |
move_pages(-1) |
702 |
e.consume |
|
53405 | 703 |
case KeyEvent.VK_PAGE_DOWN if multi => |
53407 | 704 |
move_pages(1) |
705 |
e.consume |
|
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
706 |
case _ => |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
707 |
if (e.isActionKey || e.isAltDown || e.isMetaDown || e.isControlDown) |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
708 |
hide_popup() |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
709 |
} |
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
710 |
} |
53232 | 711 |
propagate(e) |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
712 |
}, |
53232 | 713 |
key_typed = propagate _ |
53226
9cf8e2263ca7
more systematic JEdit_Lib.key_listener with optional KeyEventWorkaround;
wenzelm
parents:
53023
diff
changeset
|
714 |
) |
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
|
715 |
|
53274
1760c01f1c78
maintain Completion_Popup.Text_Area as client property like Document_View;
wenzelm
parents:
53273
diff
changeset
|
716 |
list_view.peer.addKeyListener(inner_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
|
717 |
|
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
|
718 |
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
|
719 |
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
|
720 |
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
|
721 |
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
|
722 |
} |
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
|
723 |
}) |
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
|
724 |
|
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
|
725 |
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
|
726 |
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
|
727 |
}) |
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
|
728 |
|
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
|
729 |
|
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
|
730 |
/* 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
|
731 |
|
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
|
732 |
override def getFocusTraversalKeysEnabled = false |
53297 | 733 |
completion.setBorder(new LineBorder(Color.BLACK)) |
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
|
734 |
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
|
735 |
|
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
|
736 |
|
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
|
737 |
/* 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
|
738 |
|
56605 | 739 |
def active_range: Option[Text.Range] = |
740 |
if (isDisplayable) opt_range else None |
|
741 |
||
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
|
742 |
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
|
743 |
{ |
53247
bd595338ca18
uniform use of isabelle.jEdit.Popup, based on generic screen location operations;
wenzelm
parents:
53246
diff
changeset
|
744 |
val screen = JEdit_Lib.screen_location(layered, location) |
bd595338ca18
uniform use of isabelle.jEdit.Popup, based on generic screen location operations;
wenzelm
parents:
53246
diff
changeset
|
745 |
val size = |
53230 | 746 |
{ |
747 |
val geometry = JEdit_Lib.window_geometry(completion, completion) |
|
748 |
val bounds = Rendering.popup_bounds |
|
53247
bd595338ca18
uniform use of isabelle.jEdit.Popup, based on generic screen location operations;
wenzelm
parents:
53246
diff
changeset
|
749 |
val w = geometry.width min (screen.bounds.width * bounds).toInt min layered.getWidth |
bd595338ca18
uniform use of isabelle.jEdit.Popup, based on generic screen location operations;
wenzelm
parents:
53246
diff
changeset
|
750 |
val h = geometry.height min (screen.bounds.height * bounds).toInt min layered.getHeight |
bd595338ca18
uniform use of isabelle.jEdit.Popup, based on generic screen location operations;
wenzelm
parents:
53246
diff
changeset
|
751 |
new Dimension(w, h) |
53230 | 752 |
} |
53247
bd595338ca18
uniform use of isabelle.jEdit.Popup, based on generic screen location operations;
wenzelm
parents:
53246
diff
changeset
|
753 |
new Popup(layered, completion, screen.relative(layered, size), size) |
53246
8d34caf5bf82
more elementary Popup via JLayeredPane -- avoid javax.swing.PopupFactory with its many problems and dangers of accidental HeavyWeightPopup (especially on Mac OS X);
wenzelm
parents:
53244
diff
changeset
|
754 |
} |
8d34caf5bf82
more elementary Popup via JLayeredPane -- avoid javax.swing.PopupFactory with its many problems and dangers of accidental HeavyWeightPopup (especially on Mac OS X);
wenzelm
parents:
53244
diff
changeset
|
755 |
|
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
756 |
private def show_popup(focus: Boolean) |
53246
8d34caf5bf82
more elementary Popup via JLayeredPane -- avoid javax.swing.PopupFactory with its many problems and dangers of accidental HeavyWeightPopup (especially on Mac OS X);
wenzelm
parents:
53244
diff
changeset
|
757 |
{ |
8d34caf5bf82
more elementary Popup via JLayeredPane -- avoid javax.swing.PopupFactory with its many problems and dangers of accidental HeavyWeightPopup (especially on Mac OS X);
wenzelm
parents:
53244
diff
changeset
|
758 |
popup.show |
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
759 |
if (focus) 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
|
760 |
} |
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
|
761 |
|
53232 | 762 |
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
|
763 |
{ |
56197
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
764 |
shutdown(list_view.peer.isFocusOwner) |
416f7a00e4cb
back to KeyEventInterceptor (see 423e29f1f304), but without focus change, which helps to avoid loosing key events due to quick opening and closing of popups;
wenzelm
parents:
56177
diff
changeset
|
765 |
popup.hide |
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
|
766 |
} |
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
|
767 |
} |