-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlers.aro
More file actions
executable file
·153 lines (128 loc) · 6.64 KB
/
handlers.aro
File metadata and controls
executable file
·153 lines (128 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
(* ============================================================
handlers.aro - Keyboard event handlers for ShowFiles
up/down → navigate file list, reset preview scroll
left/right → scroll preview panel independently
enter → navigate into selected directory
============================================================ *)
(Move Down: KeyPress Handler) where <key> = "down" {
Create the <state-key> with "main".
Retrieve the <state> from the <ui-state-repository> where <key> is <state-key>.
Extract the <cur-name> from the <state: selectedName>.
Compute the <raw-sel> from (<state: selection>) + 1.
Compute the <new-sel> from <raw-sel> % <state: totalFiles>.
Retrieve the <next-file> from the <file-list-repository> where <idx> = <new-sel>.
Update the <state: selection> with <new-sel>.
Update the <state: selectedName> with <next-file: name>.
Update the <state: prevName> with <cur-name>.
Update the <state: previewScroll> with 0.
Store the <state> into the <ui-state-repository>.
Return an <OK: status> for the <key-handled>.
}
(Move Up: KeyPress Handler) where <key> = "up" {
Create the <state-key> with "main".
Retrieve the <state> from the <ui-state-repository> where <key> is <state-key>.
Extract the <cur-name> from the <state: selectedName>.
Compute the <total-plus-prev> from (<state: totalFiles>) + <state: selection> - 1.
Compute the <new-sel> from <total-plus-prev> % <state: totalFiles>.
Retrieve the <prev-file> from the <file-list-repository> where <idx> = <new-sel>.
Update the <state: selection> with <new-sel>.
Update the <state: selectedName> with <prev-file: name>.
Update the <state: prevName> with <cur-name>.
Update the <state: previewScroll> with 0.
Store the <state> into the <ui-state-repository>.
Return an <OK: status> for the <key-handled>.
}
(Scroll Right: KeyPress Handler) where <key> = "right" {
(* Scroll preview panel forward by 1 line *)
Create the <state-key> with "main".
Retrieve the <state> from the <ui-state-repository> where <key> is <state-key>.
Compute the <new-ps> from (<state: previewScroll>) + 1.
Update the <state: previewScroll> with <new-ps>.
Store the <state> into the <ui-state-repository>.
Return an <OK: status> for the <key-handled>.
}
(Scroll Left: KeyPress Handler) where <key> = "left" {
(* Scroll preview panel back by 1 line, floor at 0 *)
Create the <state-key> with "main".
Retrieve the <state> from the <ui-state-repository> where <key> is <state-key>.
Compute the <raw-ps> from (<state: previewScroll>) - 1.
Compute the <can-scroll-up> from <raw-ps> >= 0.
match <can-scroll-up> {
case true {
Update the <state: previewScroll> with <raw-ps>.
}
case false {
Update the <state: previewScroll> with 0.
}
}
Store the <state> into the <ui-state-repository>.
Return an <OK: status> for the <key-handled>.
}
(Open Directory: KeyPress Handler) where <key> = "enter" {
Create the <state-key> with "main".
Retrieve the <state> from the <ui-state-repository> where <key> is <state-key>.
Extract the <cur-sel> from the <state: selection>.
Retrieve the <sel-entry> from the <file-list-repository> where <idx> = <cur-sel>.
Extract the <sel-name> from the <sel-entry: name>.
Extract the <entry-kind> from the <sel-entry: isFile>.
match <entry-kind> {
case false {
(* Navigate into directory or up to parent *)
Compute the <going-up> from <cur-sel> == 0.
match <going-up> {
case true {
Compute the <new-path> from (<state: currentPath>) ++ "/..".
}
case false {
Compute the <new-path> from (<state: currentPath>) ++ "/" ++ <sel-name>.
}
}
(* List new directory and rebuild file-list-repository *)
List the <new-entries> from the <directory: new-path>.
Compute the <new-raw-count: length> from <new-entries>.
Compute the <new-total> from <new-raw-count> + 1.
(* Store .. at idx 0 with fixed id so it updates in-place *)
Create the <parent-entry: FileItem> with { id: "fl-0", name: ".. (parent)", path: "..", isFile: false, marker: " ", idx: 0 }.
Store the <parent-entry> into the <file-list-repository>.
(* Store new entries at idx 1..N with fixed ids *)
Create the <nav-ctr-init> with { key: "navctr", val: 1 }.
Store the <nav-ctr-init> into the <nav-ctr-repository>.
for each <new-entry> in <new-entries> {
Create the <nav-ctr-key> with "navctr".
Retrieve the <nav-ctr> from the <nav-ctr-repository> where <key> is <nav-ctr-key>.
Extract the <nav-idx> from the <nav-ctr: val>.
Compute the <fl-nav-id> from "fl-" ++ <nav-idx>.
Create the <nav-item: FileItem> with { id: <fl-nav-id>, name: <new-entry: name>, path: <new-entry: path>, isFile: <new-entry: isFile>, marker: " ", idx: <nav-idx> }.
Store the <nav-item> into the <file-list-repository>.
Compute the <next-nav-idx> from <nav-idx> + 1.
Update the <nav-ctr: val> with <next-nav-idx>.
Store the <nav-ctr> into the <nav-ctr-repository>.
}
(* Select first actual file at idx 1, or .. if directory is empty *)
Compute the <has-files> from <new-raw-count> > 0.
match <has-files> {
case true {
Create the <first-new-idx> with 1.
Retrieve the <first-new-file> from the <file-list-repository> where <idx> = <first-new-idx>.
Extract the <first-new-name> from the <first-new-file: name>.
Update the <state: selection> with 1.
Update the <state: selectedName> with <first-new-name>.
}
case false {
Update the <state: selection> with 0.
Update the <state: selectedName> with ".. (parent)".
}
}
Update the <state: prevName> with <sel-name>.
Update the <state: currentPath> with <new-path>.
Update the <state: totalFiles> with <new-total>.
Update the <state: previewScroll> with 0.
Store the <state> into the <ui-state-repository>.
}
}
Return an <OK: status> for the <key-handled>.
}
(Quit: KeyPress Handler) where <key> = "q" or "escape" {
Stop the <keyboard> with <application>.
Return an <OK: status> for the <key-handled>.
}