Transpiled version (68771L) is out of date.
1 | concept G22Text > ConceptWithChangeListeners { |
2 | settableWithVar S description; |
3 | |
4 | // the script (last "saved" version) |
5 | settableWithVar S text; |
6 | |
7 | // text currently being modified in an editor (or null) |
8 | // Note that "" doesn't count as null. |
9 | settableWithVar S editingText; |
10 | |
11 | // When imported from another project |
12 | settableWithVar S importNote; |
13 | |
14 | S myType() { ret dropPrefix("G22", shortClassName(this)); } |
15 | |
16 | toString { |
17 | ret colonCombine(myType() + id, description); |
18 | } |
19 | |
20 | void initEditingText { |
21 | editingText(unnull(or(editingText, text))); |
22 | } |
23 | |
24 | void receiveEditingText(S text) { |
25 | //printVars_shorten("receiveEditingText", +text); |
26 | editingText(text); |
27 | } |
28 | |
29 | S stableText() { ret text; } |
30 | S latestText() { ret or(editingText, text); } |
31 | |
32 | void completeEdit aka save() { |
33 | S t = editingText; |
34 | //printVars_shorten("completeEdit", +t); |
35 | if (t != null) { |
36 | setTextWithHistory(t); |
37 | //printVars_shorten("completeEdit", +editingText); |
38 | } |
39 | } |
40 | |
41 | void setTextWithHistory(S text) { |
42 | if (eq(this.text, text)) ret; |
43 | text(text); |
44 | saveTextToHistory(); |
45 | } |
46 | |
47 | void discardEdit { |
48 | S text = editedText(); |
49 | if (text == null) ret; |
50 | saveFieldToHistory("discardingEdit", text); |
51 | editingText(null); |
52 | } |
53 | |
54 | S textForEditing() { |
55 | initEditingText(); |
56 | ret editingText; |
57 | } |
58 | |
59 | File historyFile() { |
60 | ret fileInConceptsDir("History/" + shortDynName(this) + id + ".history"); |
61 | } |
62 | |
63 | void saveTextToHistory() { |
64 | saveFieldToHistory(+text); |
65 | } |
66 | |
67 | void saveFieldToHistory(S field, S value) { |
68 | File historyFile = historyFile(); |
69 | if (historyFile == null) ret; |
70 | S contents = value == null ? " empty" : " (" + nLines(value) + ", " + nChars(value) + "):\n" + |
71 | indentx(value) + "\n" + |
72 | "\n"; |
73 | appendToTextFile(historyFile, |
74 | "\n===\n" + |
75 | "Concept ID: " + id + "\n" + |
76 | "Date: " + dateWithMSUTC() + "\n" + |
77 | firstToUpper(field) + contents + |
78 | "===" + "\n"); |
79 | } |
80 | |
81 | bool isSaved() { ret text != null; } |
82 | bool isEditing() { ret editedText() != null; } |
83 | |
84 | S editedText() { ret eq(editingText, text) ? null : editingText; } |
85 | |
86 | G22Utils g22utils() { |
87 | ret assertNotNull(g22utils := main g22utils(_concepts())); |
88 | } |
89 | |
90 | Set<S> allTexts() { |
91 | ret asSet(llNonNulls(text(), editedText()); |
92 | } |
93 | } |
Began life as a copy of #1034255
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1036607 |
Snippet name: | G22Text (text concept, with editing state) |
Eternal ID of this version: | #1036607/4 |
Text MD5: | 61ff60c4d554f4e674996be06858c9fc |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2023-07-26 21:46:32 |
Source code size: | 2395 bytes / 93 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 200 / 268 |
Version history: | 3 change(s) |
Referenced in: | [show references] |