author | wenzelm |
Thu, 22 Dec 2022 15:23:26 +0100 | |
changeset 76739 | cb72b5996520 |
parent 76732 | 0ba6f360d38a |
child 76794 | 941d4f527091 |
permissions | -rw-r--r-- |
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/PIDE/editor.scala |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
3 |
|
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
4 |
General editor operations. |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
6 |
|
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
8 |
|
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
9 |
|
75393 | 10 |
abstract class Editor[Context] { |
66082 | 11 |
/* session */ |
12 |
||
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
13 |
def session: Session |
66084 | 14 |
def flush(): Unit |
54461 | 15 |
def invoke(): Unit |
66101
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
16 |
|
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
17 |
|
76609
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
75393
diff
changeset
|
18 |
/* document editor */ |
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
75393
diff
changeset
|
19 |
|
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
75393
diff
changeset
|
20 |
protected val document_editor: Synchronized[Document_Editor.State] = |
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
75393
diff
changeset
|
21 |
Synchronized(Document_Editor.State()) |
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
75393
diff
changeset
|
22 |
|
76715
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
23 |
protected def document_state(): Document_Editor.State = document_editor.value |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
24 |
|
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
25 |
protected def document_state_changed(): Unit = {} |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
26 |
private def document_state_change(f: Document_Editor.State => Document_Editor.State): Unit = { |
76705
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76701
diff
changeset
|
27 |
val changed = |
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76701
diff
changeset
|
28 |
document_editor.change_result { st => |
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76701
diff
changeset
|
29 |
val st1 = f(st) |
76725
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
30 |
val changed = |
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
31 |
st.active_document_theories != st1.active_document_theories || |
76739
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
32 |
st.selection != st1.selection |
76725
c8d5cc19270a
more thorough GUI updates, notably for multiple Document dockables;
wenzelm
parents:
76720
diff
changeset
|
33 |
(changed, st1) |
76705
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76701
diff
changeset
|
34 |
} |
76715
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
35 |
if (changed) document_state_changed() |
76705
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76701
diff
changeset
|
36 |
} |
76715
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
37 |
|
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
38 |
def document_session(): Option[Sessions.Background] = document_state().session_background |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
39 |
|
76739
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
40 |
def document_required(): List[Document.Node.Name] = { |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
41 |
val st = document_state() |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
42 |
if (st.is_active) { |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
43 |
for { |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
44 |
a <- st.all_document_theories |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
45 |
b = session.resources.migrate_name(a) |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
46 |
if st.selection(b) |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
47 |
} yield b |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
48 |
} |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
49 |
else Nil |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
50 |
} |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
51 |
|
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
52 |
def document_node_required(name: Document.Node.Name): Boolean = { |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
53 |
val st = document_state() |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
54 |
st.is_active && |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
55 |
st.selection.contains(name) && |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
56 |
st.all_document_theories.exists(a => session.resources.migrate_name(a) == name) |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
57 |
} |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
58 |
|
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
59 |
def document_theories(): List[Document.Node.Name] = |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
60 |
document_state().active_document_theories.map(session.resources.migrate_name) |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
61 |
|
76732 | 62 |
def document_selection(): Set[Document.Node.Name] = document_state().selection |
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76715
diff
changeset
|
63 |
|
76701 | 64 |
def document_setup(background: Option[Sessions.Background]): Unit = |
76715
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
65 |
document_state_change(_.copy(session_background = background)) |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
66 |
|
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
67 |
def document_select( |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
68 |
names: Iterable[Document.Node.Name], |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
69 |
set: Boolean = false, |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
70 |
toggle: Boolean = false |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
71 |
): Unit = document_state_change(_.select(names, set = set, toggle = toggle)) |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
72 |
|
76720 | 73 |
def document_select_all(set: Boolean = false): Unit = |
76739
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
74 |
document_state_change { st => |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
75 |
val domain = st.active_document_theories.map(session.resources.migrate_name) |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
76 |
st.select(domain, set = set) |
cb72b5996520
proper migrate_name between different kinds of Resources, notably for Windows;
wenzelm
parents:
76732
diff
changeset
|
77 |
} |
76720 | 78 |
|
76715
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
79 |
def document_init(id: AnyRef): Unit = document_state_change(_.register_view(id)) |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
80 |
def document_exit(id: AnyRef): Unit = document_state_change(_.unregister_view(id)) |
76609
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
75393
diff
changeset
|
81 |
|
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
75393
diff
changeset
|
82 |
|
66101
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
83 |
/* current situation */ |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
84 |
|
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
85 |
def current_node(context: Context): Option[Document.Node.Name] |
52978 | 86 |
def current_node_snapshot(context: Context): Option[Document.Snapshot] |
52974 | 87 |
def node_snapshot(name: Document.Node.Name): Document.Snapshot |
53844
71f103629327
skip ignored commands, similar to former proper_command_at (see d68ea01d5084) -- relevant to Output, Query_Operation etc.;
wenzelm
parents:
52980
diff
changeset
|
88 |
def current_command(context: Context, snapshot: Document.Snapshot): Option[Command] |
52977
15254e32d299
central management of Document.Overlays, independent of Document_Model;
wenzelm
parents:
52974
diff
changeset
|
89 |
|
66082 | 90 |
|
91 |
/* overlays */ |
|
92 |
||
66101
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
93 |
def node_overlays(name: Document.Node.Name): Document.Node.Overlays |
73340 | 94 |
def insert_overlay(command: Command, fn: String, args: List[String]): Unit |
95 |
def remove_overlay(command: Command, fn: String, args: List[String]): Unit |
|
66082 | 96 |
|
97 |
||
98 |
/* hyperlinks */ |
|
52980 | 99 |
|
75393 | 100 |
abstract class Hyperlink { |
64663 | 101 |
def external: Boolean = false |
56494
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
55884
diff
changeset
|
102 |
def follow(context: Context): Unit |
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
55884
diff
changeset
|
103 |
} |
66084 | 104 |
|
52980 | 105 |
def hyperlink_command( |
64664 | 106 |
focus: Boolean, snapshot: Document.Snapshot, id: Document_ID.Generic, offset: Symbol.Offset = 0) |
60893 | 107 |
: Option[Hyperlink] |
66094 | 108 |
|
109 |
||
110 |
/* dispatcher thread */ |
|
111 |
||
112 |
def assert_dispatcher[A](body: => A): A |
|
113 |
def require_dispatcher[A](body: => A): A |
|
114 |
def send_dispatcher(body: => Unit): Unit |
|
115 |
def send_wait_dispatcher(body: => Unit): Unit |
|
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
116 |
} |