author | wenzelm |
Tue, 20 Dec 2022 19:43:40 +0100 | |
changeset 76720 | 37f7b2965e02 |
parent 76716 | a7602257a825 |
child 76725 | c8d5cc19270a |
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) |
76715
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
30 |
(st.required != st1.required, st1) |
76705
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76701
diff
changeset
|
31 |
} |
76715
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
32 |
if (changed) document_state_changed() |
76705
ddf5764684dd
proper state change, e.g. on open/close of "Document" panel;
wenzelm
parents:
76701
diff
changeset
|
33 |
} |
76715
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
34 |
|
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
35 |
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
|
36 |
def document_required(): List[Document.Node.Name] = document_state().required |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
37 |
def document_node_required(name: Document.Node.Name): Boolean = document_state().is_required(name) |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
38 |
|
76716
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76715
diff
changeset
|
39 |
def document_theories(): List[Document.Node.Name] = document_state().active_document_theories |
a7602257a825
clarified state document nodes for Theories_Status / Document_Dockable;
wenzelm
parents:
76715
diff
changeset
|
40 |
|
76701 | 41 |
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
|
42 |
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
|
43 |
|
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
44 |
def document_select( |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
45 |
names: Iterable[Document.Node.Name], |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
46 |
set: Boolean = false, |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
47 |
toggle: Boolean = false |
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
48 |
): 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
|
49 |
|
76720 | 50 |
def document_select_all(set: Boolean = false): Unit = |
51 |
document_state_change(st => st.select(st.active_document_theories, set = set)) |
|
52 |
||
76715
bf5ff407f32f
clarified state of document model vs. document editor selection (again, see also a9d52d02bd83);
wenzelm
parents:
76705
diff
changeset
|
53 |
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
|
54 |
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
|
55 |
|
cc9ddf373bd2
maintain global state of document editor views, notably for is_active operation;
wenzelm
parents:
75393
diff
changeset
|
56 |
|
66101
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
57 |
/* current situation */ |
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
58 |
|
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
59 |
def current_node(context: Context): Option[Document.Node.Name] |
52978 | 60 |
def current_node_snapshot(context: Context): Option[Document.Snapshot] |
52974 | 61 |
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
|
62 |
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
|
63 |
|
66082 | 64 |
|
65 |
/* overlays */ |
|
66 |
||
66101
0f0f294e314f
maintain overlays within main state of document models;
wenzelm
parents:
66094
diff
changeset
|
67 |
def node_overlays(name: Document.Node.Name): Document.Node.Overlays |
73340 | 68 |
def insert_overlay(command: Command, fn: String, args: List[String]): Unit |
69 |
def remove_overlay(command: Command, fn: String, args: List[String]): Unit |
|
66082 | 70 |
|
71 |
||
72 |
/* hyperlinks */ |
|
52980 | 73 |
|
75393 | 74 |
abstract class Hyperlink { |
64663 | 75 |
def external: Boolean = false |
56494
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
55884
diff
changeset
|
76 |
def follow(context: Context): Unit |
1b74abf064e1
avoid confusion about pointless cursor movement with external links;
wenzelm
parents:
55884
diff
changeset
|
77 |
} |
66084 | 78 |
|
52980 | 79 |
def hyperlink_command( |
64664 | 80 |
focus: Boolean, snapshot: Document.Snapshot, id: Document_ID.Generic, offset: Symbol.Offset = 0) |
60893 | 81 |
: Option[Hyperlink] |
66094 | 82 |
|
83 |
||
84 |
/* dispatcher thread */ |
|
85 |
||
86 |
def assert_dispatcher[A](body: => A): A |
|
87 |
def require_dispatcher[A](body: => A): A |
|
88 |
def send_dispatcher(body: => Unit): Unit |
|
89 |
def send_wait_dispatcher(body: => Unit): Unit |
|
52971
31926d2c04ee
tuned signature -- more abstract PIDE editor operations;
wenzelm
parents:
diff
changeset
|
90 |
} |