author | Claus Gittinger <cg@exept.de> |
Mon, 20 Jan 2020 21:02:47 +0100 | |
changeset 19422 | c6ca1c3e0fd7 |
parent 19160 | a1bb14d66f12 |
permissions | -rw-r--r-- |
19160 | 1 |
"{ Encoding: utf8 }" |
2 |
||
9972 | 3 |
" |
10085 | 4 |
Copyright (c) 2007-2010 Jan Vrany, SWING Research Group, Czech Technical University in Prague |
5 |
Copyright (c) 2009-2010 eXept Software AG |
|
9972 | 6 |
|
10085 | 7 |
Permission is hereby granted, free of charge, to any person |
8 |
obtaining a copy of this software and associated documentation |
|
9 |
files (the 'Software'), to deal in the Software without |
|
10 |
restriction, including without limitation the rights to use, |
|
11 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
12 |
copies of the Software, and to permit persons to whom the |
|
13 |
Software is furnished to do so, subject to the following |
|
14 |
conditions: |
|
15 |
||
16 |
The above copyright notice and this permission notice shall be |
|
17 |
included in all copies or substantial portions of the Software. |
|
18 |
||
19 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
20 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
21 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
22 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
23 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
24 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
25 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
26 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9972 | 27 |
" |
28 |
"{ Package: 'stx:libtool' }" |
|
29 |
||
16761 | 30 |
"{ NameSpace: Smalltalk }" |
31 |
||
9972 | 32 |
HierarchicalList subclass:#BookmarkList |
33 |
instanceVariableNames:'fileName' |
|
13855 | 34 |
classVariableNames:'BrowserBookmarks WorkspaceBookmarks WebBookmarks FileBookmarks' |
9972 | 35 |
poolDictionaries:'' |
36 |
category:'Interface-Bookmarks' |
|
37 |
! |
|
38 |
||
39 |
!BookmarkList class methodsFor:'documentation'! |
|
40 |
||
41 |
copyright |
|
42 |
" |
|
10085 | 43 |
Copyright (c) 2007-2010 Jan Vrany, SWING Research Group, Czech Technical University in Prague |
44 |
Copyright (c) 2009-2010 eXept Software AG |
|
45 |
||
46 |
Permission is hereby granted, free of charge, to any person |
|
47 |
obtaining a copy of this software and associated documentation |
|
48 |
files (the 'Software'), to deal in the Software without |
|
49 |
restriction, including without limitation the rights to use, |
|
50 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
51 |
copies of the Software, and to permit persons to whom the |
|
52 |
Software is furnished to do so, subject to the following |
|
53 |
conditions: |
|
9972 | 54 |
|
10085 | 55 |
The above copyright notice and this permission notice shall be |
56 |
included in all copies or substantial portions of the Software. |
|
57 |
||
58 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, |
|
59 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
60 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
61 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
62 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
63 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
64 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
65 |
OTHER DEALINGS IN THE SOFTWARE. |
|
9972 | 66 |
" |
67 |
! ! |
|
68 |
||
69 |
!BookmarkList class methodsFor:'instance creation'! |
|
70 |
||
71 |
decodeFromLiteralArray:anArray |
|
72 |
||
11886
0c039c26ad7b
comment/format in: #decodeFromLiteralArray:
Claus Gittinger <cg@exept.de>
parents:
10911
diff
changeset
|
73 |
(anArray size == 3 and: [anArray second == #root:]) ifFalse:[ |
0c039c26ad7b
comment/format in: #decodeFromLiteralArray:
Claus Gittinger <cg@exept.de>
parents:
10911
diff
changeset
|
74 |
self breakPoint: #jv. |
0c039c26ad7b
comment/format in: #decodeFromLiteralArray:
Claus Gittinger <cg@exept.de>
parents:
10911
diff
changeset
|
75 |
^ super decodeFromLiteralArray:anArray |
0c039c26ad7b
comment/format in: #decodeFromLiteralArray:
Claus Gittinger <cg@exept.de>
parents:
10911
diff
changeset
|
76 |
]. |
9972 | 77 |
|
78 |
^self new root: anArray third decodeAsLiteralArray |
|
79 |
||
80 |
"Created: / 23-05-2011 / 14:28:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
81 |
! |
|
82 |
||
83 |
new |
|
84 |
"return an initialized instance" |
|
85 |
||
86 |
^ super new initialize. |
|
87 |
||
88 |
"Modified: / 23-05-2011 / 13:57:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
89 |
! |
|
90 |
||
91 |
readFrom: aStream onError: aBlock |
|
14810 | 92 |
| litArray | |
9972 | 93 |
|
17248 | 94 |
^ [ |
9972 | 95 |
litArray := Compiler evaluate: aStream contents asString. |
96 |
litArray decodeAsLiteralArray. |
|
19160 | 97 |
] on:Error do:aBlock. |
9972 | 98 |
|
99 |
"Created: / 23-05-2011 / 15:58:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
19160 | 100 |
"Modified (format): / 11-09-2019 / 16:47:21 / Stefan Vogel" |
9972 | 101 |
! |
102 |
||
103 |
readFromFile: aStringOrFilename |
|
14810 | 104 |
^ self readFromFile: aStringOrFilename onError:[:reason | self error:reason] |
9972 | 105 |
! |
106 |
||
107 |
readFromFile: aStringOrFilename onError: aBlock |
|
14810 | 108 |
| bookmarks file pathName| |
9972 | 109 |
|
110 |
file := aStringOrFilename asFilename. |
|
14810 | 111 |
pathName := file pathName. |
112 |
file exists ifFalse: [^ aBlock valueWithOptionalArgument:('File does %1 not exist' bindWith: pathName)]. |
|
10864 | 113 |
bookmarks := self readFrom: file readStream onError: [^aBlock value]. |
14810 | 114 |
bookmarks isNil ifTrue: [^ aBlock valueWithOptionalArgument:('Cannot parse %1 not exist' bindWith: pathName)]. |
115 |
bookmarks fileName: pathName. |
|
9972 | 116 |
^bookmarks |
117 |
||
118 |
"Created: / 23-05-2011 / 16:32:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
119 |
"Modified: / 02-06-2011 / 19:43:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10864 | 120 |
"Modified: / 18-11-2011 / 14:32:24 / cg" |
9972 | 121 |
! ! |
122 |
||
123 |
!BookmarkList class methodsFor:'accessing'! |
|
124 |
||
13855 | 125 |
forFileBrowser |
126 |
FileBookmarks isNil ifTrue:[ |
|
127 |
self initializeFileBookmarks |
|
128 |
]. |
|
129 |
^ FileBookmarks |
|
130 |
||
131 |
"Created: / 04-04-2012 / 12:04:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
132 |
! |
|
133 |
||
9972 | 134 |
forSystemBrowser |
135 |
||
136 |
BrowserBookmarks isNil ifTrue: |
|
137 |
[self initializeBrowserBookmarks]. |
|
138 |
^BrowserBookmarks |
|
139 |
||
140 |
"Created: / 23-05-2011 / 10:10:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
141 |
! |
|
142 |
||
143 |
forWebBrowser |
|
144 |
||
145 |
WebBookmarks isNil ifTrue: |
|
146 |
[self initializeWebBookmarks]. |
|
147 |
^WebBookmarks |
|
148 |
||
149 |
"Created: / 08-06-2011 / 12:15:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
150 |
! |
|
151 |
||
152 |
forWorkspace |
|
153 |
||
154 |
WorkspaceBookmarks isNil ifTrue: |
|
155 |
[self initializeWorkspaceBookmarks]. |
|
156 |
^WorkspaceBookmarks |
|
157 |
||
158 |
"Created: / 20-06-2011 / 22:11:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
159 |
! ! |
|
160 |
||
161 |
!BookmarkList class methodsFor:'accessing - defaults'! |
|
162 |
||
163 |
defaultLabelForMyWorkspaces |
|
164 |
||
165 |
^'My Workspaces' |
|
166 |
||
167 |
"Created: / 21-06-2011 / 08:35:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
168 |
! |
|
169 |
||
170 |
defaultLabelForRecent |
|
171 |
||
172 |
^'Recent' |
|
173 |
||
174 |
"Created: / 21-06-2011 / 08:35:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
175 |
! ! |
|
176 |
||
177 |
!BookmarkList class methodsFor:'class initialization'! |
|
178 |
||
179 |
initializeBrowserBookmarks |
|
180 |
||
181 |
| file | |
|
182 |
file := Filename defaultDirectory / 'browser-bookmarks.rc'. |
|
183 |
BrowserBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 184 |
BrowserBookmarks notNil ifTrue:[^self]. |
9972 | 185 |
|
186 |
file := Filename homeDirectory / '.smalltalk' / 'browser-bookmarks.rc'. |
|
187 |
BrowserBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 188 |
BrowserBookmarks notNil ifTrue:[^self]. |
9972 | 189 |
|
190 |
BrowserBookmarks := self new fileName: file pathName. |
|
191 |
||
192 |
"Created: / 23-05-2011 / 10:06:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
193 |
"Modified: / 23-05-2011 / 16:35:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10911 | 194 |
"Modified: / 29-11-2011 / 11:21:06 / cg" |
9972 | 195 |
! |
196 |
||
13855 | 197 |
initializeFileBookmarks |
198 |
||
199 |
| file | |
|
200 |
file := Filename defaultDirectory / 'file-bookmarks.rc'. |
|
201 |
FileBookmarks := self readFromFile: file onError:[nil]. |
|
202 |
FileBookmarks notNil ifTrue:[^self]. |
|
203 |
||
204 |
file := Filename homeDirectory / '.smalltalk' / 'file-bookmarks.rc'. |
|
205 |
FileBookmarks := self readFromFile: file onError:[nil]. |
|
206 |
FileBookmarks notNil ifTrue:[^self]. |
|
207 |
||
208 |
FileBookmarks := self new fileName: file pathName. |
|
209 |
||
210 |
"Created: / 04-04-2012 / 12:05:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
211 |
! |
|
212 |
||
9972 | 213 |
initializeWebBookmarks |
214 |
||
215 |
| file | |
|
216 |
file := Filename defaultDirectory / 'web-bookmarks.rc'. |
|
217 |
WebBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 218 |
WebBookmarks notNil ifTrue:[^self]. |
9972 | 219 |
|
220 |
file := Filename homeDirectory / '.smalltalk' / 'web-bookmarks.rc'. |
|
221 |
WebBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 222 |
WebBookmarks notNil ifTrue:[^self]. |
9972 | 223 |
|
224 |
WebBookmarks := self new fileName: file pathName. |
|
225 |
||
226 |
"Created: / 08-06-2011 / 12:15:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10911 | 227 |
"Modified: / 29-11-2011 / 11:21:10 / cg" |
9972 | 228 |
! |
229 |
||
230 |
initializeWorkspaceBookmarks |
|
231 |
||
232 |
| file | |
|
233 |
file := Filename defaultDirectory / 'workspace-bookmarks.rc'. |
|
234 |
WorkspaceBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 235 |
WorkspaceBookmarks notNil ifTrue:[^self]. |
9972 | 236 |
|
237 |
file := Filename homeDirectory / '.smalltalk' / 'workspace-bookmarks.rc'. |
|
238 |
WorkspaceBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 239 |
WorkspaceBookmarks notNil ifTrue:[^self]. |
9972 | 240 |
|
241 |
WorkspaceBookmarks := self new fileName: file pathName. |
|
242 |
WorkspaceBookmarks root add: |
|
243 |
((Bookmark forFolderNamed: self defaultLabelForMyWorkspaces) |
|
244 |
add: (Bookmark forFile: WorkspaceApplication defaultMyWorkspaceDotWspFile pathName); |
|
245 |
yourself). |
|
246 |
||
247 |
" |
|
248 |
WorkspaceBookmarks := nil. |
|
249 |
BookmarkList initializeWorkspaceBookmarks. |
|
250 |
" |
|
251 |
||
252 |
" |
|
253 |
WorkspaceBookmarks := nil. |
|
254 |
" |
|
255 |
||
256 |
"Created: / 20-06-2011 / 22:10:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
257 |
"Modified: / 21-06-2011 / 08:46:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10911 | 258 |
"Modified: / 29-11-2011 / 11:21:16 / cg" |
9972 | 259 |
! ! |
260 |
||
261 |
!BookmarkList methodsFor:'accessing'! |
|
262 |
||
263 |
/ label |
|
264 |
||
265 |
^ self root / label |
|
266 |
||
267 |
"Created: / 21-06-2011 / 08:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
268 |
! |
|
269 |
||
270 |
fileName |
|
271 |
^ fileName |
|
272 |
! |
|
273 |
||
274 |
fileName:aString |
|
275 |
fileName := aString. |
|
17806 | 276 |
! |
9972 | 277 |
|
278 |
myWorkspaces |
|
279 |
||
280 |
^self / self class defaultLabelForMyWorkspaces |
|
281 |
||
282 |
" |
|
283 |
BookmarkList forWorkspace myWorkspaces |
|
284 |
" |
|
285 |
||
286 |
"Created: / 21-06-2011 / 08:53:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
287 |
! ! |
|
288 |
||
289 |
!BookmarkList methodsFor:'collection protocol'! |
|
290 |
||
291 |
add: item |
|
292 |
||
293 |
^root add: item |
|
294 |
||
295 |
"Created: / 23-05-2011 / 10:49:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
296 |
"Modified: / 23-05-2011 / 13:45:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
297 |
! |
|
298 |
||
299 |
contains: anObject |
|
300 |
||
301 |
^root contains: anObject |
|
302 |
||
303 |
"Created: / 23-05-2011 / 10:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
304 |
"Modified: / 23-05-2011 / 13:46:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
305 |
! |
|
306 |
||
307 |
remove: item ifAbsent: block |
|
308 |
||
309 |
^root remove: item |
|
310 |
||
311 |
"Created: / 23-05-2011 / 10:47:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
312 |
"Modified: / 23-05-2011 / 13:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
313 |
! ! |
|
314 |
||
315 |
!BookmarkList methodsFor:'converting'! |
|
316 |
||
317 |
asMenu |
|
318 |
||
319 |
^root asMenu |
|
320 |
||
321 |
"Created: / 23-05-2011 / 10:31:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
322 |
! |
|
323 |
||
324 |
asMenuUsingBuilder: builderClass |
|
325 |
||
326 |
^self root asMenuUsingBuilder: builderClass |
|
327 |
||
328 |
"Created: / 21-06-2011 / 08:05:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
329 |
! |
|
330 |
||
331 |
literalArrayEncoding |
|
332 |
||
333 |
^Array |
|
334 |
with: self className |
|
335 |
with: #root: |
|
336 |
with: root literalArrayEncoding |
|
337 |
||
338 |
"Created: / 23-05-2011 / 14:23:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
339 |
! ! |
|
340 |
||
341 |
!BookmarkList methodsFor:'initialization'! |
|
342 |
||
343 |
initialize |
|
344 |
"Invoked when a new instance is created." |
|
345 |
||
17370 | 346 |
<modifier: #super> "must be called if redefined" |
347 |
||
9972 | 348 |
super initialize. |
349 |
||
350 |
showRoot := false. |
|
351 |
self root: (Bookmark forFolderNamed: '<bookmarks>'). |
|
352 |
||
353 |
"Modified: / 23-05-2011 / 13:56:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
17370 | 354 |
"Modified: / 08-02-2017 / 00:33:41 / cg" |
9972 | 355 |
! ! |
356 |
||
16761 | 357 |
!BookmarkList methodsFor:'loading & saving'! |
9972 | 358 |
|
359 |
save |
|
13240 | 360 |
|f| |
9972 | 361 |
|
13240 | 362 |
(fileName notNil |
363 |
and:[ (f := fileName asFilename) exists not or:[ f isWritable ] ]) |
|
364 |
ifTrue:[ self saveOn:fileName ]. |
|
9972 | 365 |
|
366 |
"Created: / 23-05-2011 / 16:38:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
367 |
! |
|
368 |
||
369 |
saveOn: aStringOrFilename |
|
370 |
||
371 |
aStringOrFilename asFilename writingFileDo: |
|
372 |
[:s|s nextPutAll: self literalArrayEncoding storeString]. |
|
373 |
||
374 |
"Created: / 23-05-2011 / 16:39:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
375 |
! ! |
|
376 |
||
377 |
!BookmarkList methodsFor:'visiting'! |
|
378 |
||
379 |
acceptVisitor:aVisitor |
|
380 |
"Double dispatch back to the visitor, passing my type encoded in |
|
381 |
the selector (visitor pattern)" |
|
382 |
||
383 |
"stub code automatically generated - please change if required" |
|
384 |
||
385 |
^ aVisitor visitBookmarkList:self |
|
386 |
! ! |
|
387 |
||
388 |
!BookmarkList class methodsFor:'documentation'! |
|
389 |
||
14811 | 390 |
version |
16761 | 391 |
^ '$Header$' |
14811 | 392 |
! |
393 |
||
9972 | 394 |
version_CVS |
16761 | 395 |
^ '$Header$' |
9972 | 396 |
! |
397 |
||
398 |
version_SVN |
|
16761 | 399 |
^ '$Id$' |
9972 | 400 |
! ! |
13240 | 401 |