author | wenzelm |
Wed, 12 Feb 2025 00:40:57 +0100 | |
changeset 82142 | 508a673c87ac |
parent 81615 | ebf954ceb4d1 |
permissions | -rw-r--r-- |
49494
cbcccf2a0f6f
renamed Output to Output1 and Output2 to Output, and thus make the new version the default;
wenzelm
parents:
49473
diff
changeset
|
1 |
/* Title: Tools/jEdit/src/output_dockable.scala |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
3 |
|
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
4 |
Dockable window with result message output. |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
6 |
|
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle.jedit |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
8 |
|
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
9 |
|
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
10 |
import isabelle._ |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
11 |
|
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
12 |
import java.awt.BorderLayout |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
13 |
|
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
14 |
import org.gjt.sp.jedit.View |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
15 |
|
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
16 |
|
75393 | 17 |
class Output_Dockable(view: View, position: String) extends Dockable(view, position) { |
81476
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
18 |
dockable => |
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
19 |
|
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
20 |
|
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
21 |
/* component state -- owned by GUI thread */ |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
22 |
|
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
23 |
private var do_update = true |
81398
f92ea68473f2
clarified signature with subtle change of semantics: output consists of individual messages that are formatted (and separated) internally;
wenzelm
parents:
81387
diff
changeset
|
24 |
private var current_output: List[XML.Elem] = Nil |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
25 |
|
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
26 |
|
81486
ed5e75468db3
clarified signature: prefer defaults for Output_Dockable (and its variants);
wenzelm
parents:
81483
diff
changeset
|
27 |
/* output area */ |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
28 |
|
81615
ebf954ceb4d1
clarified split_pane layout: close on first display, open on first search;
wenzelm
parents:
81493
diff
changeset
|
29 |
val output: Output_Area = |
ebf954ceb4d1
clarified split_pane layout: close on first display, open on first search;
wenzelm
parents:
81493
diff
changeset
|
30 |
new Output_Area(view) { |
ebf954ceb4d1
clarified split_pane layout: close on first display, open on first search;
wenzelm
parents:
81493
diff
changeset
|
31 |
override def handle_update(): Unit = dockable.handle_update(true) |
ebf954ceb4d1
clarified split_pane layout: close on first display, open on first search;
wenzelm
parents:
81493
diff
changeset
|
32 |
override def handle_shown(): Unit = split_pane_layout() |
ebf954ceb4d1
clarified split_pane layout: close on first display, open on first search;
wenzelm
parents:
81493
diff
changeset
|
33 |
} |
56906
408b526911f7
some odd tricks to provide "Detach" menu item, via "PIDE" docking framework;
wenzelm
parents:
56886
diff
changeset
|
34 |
|
81476
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
35 |
override def detach_operation: Option[() => Unit] = |
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
36 |
output.pretty_text_area.detach_operation |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
37 |
|
81476
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
38 |
private def handle_update(follow: Boolean, restriction: Option[Set[Command]] = None): Unit = { |
57612
990ffb84489b
clarified module name: facilitate alternative GUI frameworks;
wenzelm
parents:
57044
diff
changeset
|
39 |
GUI_Thread.require {} |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
40 |
|
65194 | 41 |
for { |
66082 | 42 |
snapshot <- PIDE.editor.current_node_snapshot(view) |
65194 | 43 |
if follow && !snapshot.is_outdated |
44 |
} { |
|
45 |
val (command, results) = |
|
66082 | 46 |
PIDE.editor.current_command(view, snapshot) match { |
65195 | 47 |
case Some(command) => (command, snapshot.command_results(command)) |
65194 | 48 |
case None => (Command.empty, Command.Results.empty) |
49 |
} |
|
50 |
||
51 |
val new_output = |
|
71601 | 52 |
if (restriction.isEmpty || restriction.get.contains(command)) |
78468
33bc244eafdb
revert adhoc change ab9cc7cda0ec: lacks reasoning (and discussion);
wenzelm
parents:
78467
diff
changeset
|
53 |
Rendering.output_messages(results, JEdit_Options.output_state()) |
65194 | 54 |
else current_output |
55 |
||
56 |
if (current_output != new_output) { |
|
81476
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
57 |
output.pretty_text_area.update(snapshot, results, new_output) |
65194 | 58 |
current_output = new_output |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
59 |
} |
65194 | 60 |
} |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
61 |
} |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
62 |
|
81493
07e79b80e96d
clarified signature: avoid implicit functionality;
wenzelm
parents:
81486
diff
changeset
|
63 |
output.setup(dockable) |
07e79b80e96d
clarified signature: avoid implicit functionality;
wenzelm
parents:
81486
diff
changeset
|
64 |
dockable.set_content(output.split_pane) |
81476
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
65 |
|
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
66 |
|
61205 | 67 |
/* controls */ |
68 |
||
75849 | 69 |
private val output_state_button = new JEdit_Options.output_state.GUI |
61717
5922db0430f1
more direct access to option "editor_output_state";
wenzelm
parents:
61205
diff
changeset
|
70 |
|
81296
59994f7feace
GUI option "editor_auto_hovering" for Output panel;
wenzelm
parents:
78468
diff
changeset
|
71 |
private val auto_hovering_button = new JEdit_Options.auto_hovering.GUI |
59994f7feace
GUI option "editor_auto_hovering" for Output panel;
wenzelm
parents:
78468
diff
changeset
|
72 |
|
75854 | 73 |
private val auto_update_button = new GUI.Check("Auto update", init = do_update) { |
61205 | 74 |
tooltip = "Indicate automatic update following cursor movement" |
75852 | 75 |
override def clicked(state: Boolean): Unit = { |
76 |
do_update = state |
|
81476
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
77 |
handle_update(do_update) |
75833 | 78 |
} |
61205 | 79 |
} |
80 |
||
75853 | 81 |
private val update_button = new GUI.Button("Update") { |
61205 | 82 |
tooltip = "Update display according to the command at cursor position" |
81476
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
83 |
override def clicked(): Unit = handle_update(true) |
61205 | 84 |
} |
85 |
||
86 |
private val controls = |
|
66205 | 87 |
Wrap_Panel( |
81379 | 88 |
List(output_state_button, auto_hovering_button, auto_update_button, update_button) ::: |
81476
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
89 |
output.pretty_text_area.search_zoom_components) |
66205 | 90 |
|
61205 | 91 |
add(controls.peer, BorderLayout.NORTH) |
92 |
||
93 |
||
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
94 |
/* main */ |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
95 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
96 |
private val main = |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
97 |
Session.Consumer[Any](getClass.getName) { |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
98 |
case _: Session.Global_Options => |
61717
5922db0430f1
more direct access to option "editor_output_state";
wenzelm
parents:
61205
diff
changeset
|
99 |
GUI_Thread.later { |
81476
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
100 |
output.handle_resize() |
75847 | 101 |
output_state_button.load() |
81296
59994f7feace
GUI option "editor_auto_hovering" for Output panel;
wenzelm
parents:
78468
diff
changeset
|
102 |
auto_hovering_button.load() |
81476
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
103 |
handle_update(do_update) |
61717
5922db0430f1
more direct access to option "editor_output_state";
wenzelm
parents:
61205
diff
changeset
|
104 |
} |
53177
dcac8d837b9c
more uniform treatment of Swing_Thread context switch: prefer asynchronous Swing_Thread.later from actor;
wenzelm
parents:
52978
diff
changeset
|
105 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
106 |
case changed: Session.Commands_Changed => |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
107 |
val restriction = if (changed.assignment) None else Some(changed.commands) |
81476
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
108 |
GUI_Thread.later { handle_update(do_update, restriction = restriction) } |
53177
dcac8d837b9c
more uniform treatment of Swing_Thread context switch: prefer asynchronous Swing_Thread.later from actor;
wenzelm
parents:
52978
diff
changeset
|
109 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
110 |
case Session.Caret_Focus => |
81476
97a32b4d29e5
clarified signature and modules: without GUI change yet;
wenzelm
parents:
81398
diff
changeset
|
111 |
GUI_Thread.later { handle_update(do_update) } |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
112 |
} |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
113 |
|
75393 | 114 |
override def init(): Unit = { |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
115 |
PIDE.session.global_options += main |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
116 |
PIDE.session.commands_changed += main |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
117 |
PIDE.session.caret_focus += main |
81477 | 118 |
output.init() |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
119 |
} |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
120 |
|
75393 | 121 |
override def exit(): Unit = { |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
122 |
PIDE.session.global_options -= main |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
123 |
PIDE.session.commands_changed -= main |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56662
diff
changeset
|
124 |
PIDE.session.caret_focus -= main |
81477 | 125 |
output.exit() |
49398
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
126 |
} |
0fa4389c04f9
alternative output panel, based on Pretty_Text_Area, based on JEditEmbeddedTextArea;
wenzelm
parents:
diff
changeset
|
127 |
} |