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