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