author | wenzelm |
Thu, 07 Nov 2024 12:08:32 +0100 | |
changeset 81382 | 5e8287d34295 |
parent 76765 | c654103e9c9d |
permissions | -rw-r--r-- |
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50341
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/active.scala |
49492 | 2 |
Author: Makarius |
3 |
||
50450
358b6020f8b6
generalized notion of active area, where sendback is just one application;
wenzelm
parents:
50341
diff
changeset
|
4 |
Active areas within the document. |
49492 | 5 |
*/ |
6 |
||
7 |
package isabelle.jedit |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
71742
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
11 |
import org.gjt.sp.jedit.{ServiceManager, View} |
49492 | 12 |
|
13 |
||
75393 | 14 |
object Active { |
15 |
abstract class Handler { |
|
71742
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
16 |
def handle( |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
17 |
view: View, text: String, elem: XML.Elem, |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
18 |
doc_view: Document_View, snapshot: Document.Snapshot): Boolean |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
19 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
20 |
|
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
21 |
def handlers: List[Handler] = |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
22 |
ServiceManager.getServiceNames(classOf[Handler]).toList |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
23 |
.map(ServiceManager.getService(classOf[Handler], _)) |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
24 |
|
75393 | 25 |
def action(view: View, text: String, elem: XML.Elem): Unit = { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57594
diff
changeset
|
26 |
GUI_Thread.require {} |
49492 | 27 |
|
64882 | 28 |
Document_View.get(view.getTextArea) match { |
49492 | 29 |
case Some(doc_view) => |
71775 | 30 |
doc_view.rich_text_area.robust_body(()) { |
76765
c654103e9c9d
more robust Document.Pending_Edits: cover all nodes simulataneously, and thus support proper Snapshot.switch;
wenzelm
parents:
75393
diff
changeset
|
31 |
val snapshot = Document_Model.snapshot(doc_view.model) |
50164
77668b522ffe
some support for implicit senback, meaning that it uses the caret position instead of explicit command exec_id;
wenzelm
parents:
49493
diff
changeset
|
32 |
if (!snapshot.is_outdated) { |
71742
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
33 |
handlers.find(_.handle(view, text, elem, doc_view, snapshot)) |
49492 | 34 |
} |
35 |
} |
|
36 |
case None => |
|
37 |
} |
|
38 |
} |
|
71742
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
39 |
|
75393 | 40 |
class Misc_Handler extends Active.Handler { |
71742
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
41 |
override def handle( |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
42 |
view: View, text: String, elem: XML.Elem, |
75393 | 43 |
doc_view: Document_View, snapshot: Document.Snapshot |
44 |
): Boolean = { |
|
71742
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
45 |
val text_area = doc_view.text_area |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
46 |
val model = doc_view.model |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
47 |
val buffer = model.buffer |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
48 |
|
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
49 |
elem match { |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
50 |
case XML.Elem(Markup(Markup.BROWSER, _), body) => |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
51 |
Isabelle_Thread.fork(name = "browser") { |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
52 |
val graph_file = Isabelle_System.tmp_file("graph") |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
53 |
File.write(graph_file, XML.content(body)) |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
54 |
Isabelle_System.bash("isabelle browser -c " + File.bash_path(graph_file) + " &") |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
55 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
56 |
true |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
57 |
|
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
58 |
case XML.Elem(Markup(Markup.THEORY_EXPORTS, props), _) => |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
59 |
GUI_Thread.later { |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
60 |
val name = Markup.Name.unapply(props) getOrElse "" |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
61 |
PIDE.editor.hyperlink_file(true, Isabelle_Export.vfs_prefix + name).follow(view) |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
62 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
63 |
true |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
64 |
|
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
65 |
case XML.Elem(Markup(Markup.JEDIT_ACTION, _), body) => |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
66 |
GUI_Thread.later { |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
67 |
view.getInputHandler.invokeAction(XML.content(body)) |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
68 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
69 |
true |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
70 |
|
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
71 |
case XML.Elem(Markup(Markup.SIMP_TRACE_PANEL, props), _) => |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
72 |
val link = |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
73 |
props match { |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
74 |
case Position.Id(id) => PIDE.editor.hyperlink_command(true, snapshot, id) |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
75 |
case _ => None |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
76 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
77 |
GUI_Thread.later { |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
78 |
link.foreach(_.follow(view)) |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
79 |
view.getDockableWindowManager.showDockableWindow("isabelle-simplifier-trace") |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
80 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
81 |
true |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
82 |
|
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
83 |
case XML.Elem(Markup(Markup.SENDBACK, props), _) => |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
84 |
if (buffer.isEditable) { |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
85 |
props match { |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
86 |
case Position.Id(id) => |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
87 |
Isabelle.edit_command(snapshot, text_area, |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
88 |
props.contains(Markup.PADDING_COMMAND), id, text) |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
89 |
case _ => |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
90 |
if (props.contains(Markup.PADDING_LINE)) |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
91 |
Isabelle.insert_line_padding(text_area, text) |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
92 |
else text_area.setSelectedText(text) |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
93 |
} |
73367 | 94 |
text_area.requestFocus() |
71742
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
95 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
96 |
true |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
97 |
|
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
98 |
case Protocol.Dialog(id, serial, result) => |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
99 |
model.session.dialog_result(id, serial, result) |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
100 |
true |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
101 |
|
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
102 |
case _ => false |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
103 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
104 |
} |
de37910974da
avoid hard-wired stuff: configure via plugin services;
wenzelm
parents:
71692
diff
changeset
|
105 |
} |
49492 | 106 |
} |