author | Claus Gittinger <cg@exept.de> |
Tue, 03 Sep 2013 14:19:27 +0200 | |
changeset 13478 | 78279a57b313 |
parent 13240 | 37c7f875dae2 |
child 13289 | cc75e3cd0362 |
child 13855 | 98731325dba3 |
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' |
|
30 |
classVariableNames:'BrowserBookmarks WorkspaceBookmarks WebBookmarks' |
|
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 |
||
132 |
forSystemBrowser |
|
133 |
||
134 |
BrowserBookmarks isNil ifTrue: |
|
135 |
[self initializeBrowserBookmarks]. |
|
136 |
^BrowserBookmarks |
|
137 |
||
138 |
"Created: / 23-05-2011 / 10:10:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
139 |
! |
|
140 |
||
141 |
forWebBrowser |
|
142 |
||
143 |
WebBookmarks isNil ifTrue: |
|
144 |
[self initializeWebBookmarks]. |
|
145 |
^WebBookmarks |
|
146 |
||
147 |
"Created: / 08-06-2011 / 12:15:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
148 |
! |
|
149 |
||
150 |
forWorkspace |
|
151 |
||
152 |
WorkspaceBookmarks isNil ifTrue: |
|
153 |
[self initializeWorkspaceBookmarks]. |
|
154 |
^WorkspaceBookmarks |
|
155 |
||
156 |
"Created: / 20-06-2011 / 22:11:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
157 |
! ! |
|
158 |
||
159 |
!BookmarkList class methodsFor:'accessing - defaults'! |
|
160 |
||
161 |
defaultLabelForMyWorkspaces |
|
162 |
||
163 |
^'My Workspaces' |
|
164 |
||
165 |
"Created: / 21-06-2011 / 08:35:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
166 |
! |
|
167 |
||
168 |
defaultLabelForRecent |
|
169 |
||
170 |
^'Recent' |
|
171 |
||
172 |
"Created: / 21-06-2011 / 08:35:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
173 |
! ! |
|
174 |
||
175 |
!BookmarkList class methodsFor:'class initialization'! |
|
176 |
||
177 |
initializeBrowserBookmarks |
|
178 |
||
179 |
| file | |
|
180 |
file := Filename defaultDirectory / 'browser-bookmarks.rc'. |
|
181 |
BrowserBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 182 |
BrowserBookmarks notNil ifTrue:[^self]. |
9972 | 183 |
|
184 |
file := Filename homeDirectory / '.smalltalk' / 'browser-bookmarks.rc'. |
|
185 |
BrowserBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 186 |
BrowserBookmarks notNil ifTrue:[^self]. |
9972 | 187 |
|
188 |
BrowserBookmarks := self new fileName: file pathName. |
|
189 |
||
190 |
"Created: / 23-05-2011 / 10:06:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
191 |
"Modified: / 23-05-2011 / 16:35:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10911 | 192 |
"Modified: / 29-11-2011 / 11:21:06 / cg" |
9972 | 193 |
! |
194 |
||
195 |
initializeWebBookmarks |
|
196 |
||
197 |
| file | |
|
198 |
file := Filename defaultDirectory / 'web-bookmarks.rc'. |
|
199 |
WebBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 200 |
WebBookmarks notNil ifTrue:[^self]. |
9972 | 201 |
|
202 |
file := Filename homeDirectory / '.smalltalk' / 'web-bookmarks.rc'. |
|
203 |
WebBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 204 |
WebBookmarks notNil ifTrue:[^self]. |
9972 | 205 |
|
206 |
WebBookmarks := self new fileName: file pathName. |
|
207 |
||
208 |
"Created: / 08-06-2011 / 12:15:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10911 | 209 |
"Modified: / 29-11-2011 / 11:21:10 / cg" |
9972 | 210 |
! |
211 |
||
212 |
initializeWorkspaceBookmarks |
|
213 |
||
214 |
| file | |
|
215 |
file := Filename defaultDirectory / 'workspace-bookmarks.rc'. |
|
216 |
WorkspaceBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 217 |
WorkspaceBookmarks notNil ifTrue:[^self]. |
9972 | 218 |
|
219 |
file := Filename homeDirectory / '.smalltalk' / 'workspace-bookmarks.rc'. |
|
220 |
WorkspaceBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 221 |
WorkspaceBookmarks notNil ifTrue:[^self]. |
9972 | 222 |
|
223 |
WorkspaceBookmarks := self new fileName: file pathName. |
|
224 |
WorkspaceBookmarks root add: |
|
225 |
((Bookmark forFolderNamed: self defaultLabelForMyWorkspaces) |
|
226 |
add: (Bookmark forFile: WorkspaceApplication defaultMyWorkspaceDotWspFile pathName); |
|
227 |
yourself). |
|
228 |
||
229 |
" |
|
230 |
WorkspaceBookmarks := nil. |
|
231 |
BookmarkList initializeWorkspaceBookmarks. |
|
232 |
" |
|
233 |
||
234 |
" |
|
235 |
WorkspaceBookmarks := nil. |
|
236 |
" |
|
237 |
||
238 |
"Created: / 20-06-2011 / 22:10:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
239 |
"Modified: / 21-06-2011 / 08:46:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10911 | 240 |
"Modified: / 29-11-2011 / 11:21:16 / cg" |
9972 | 241 |
! ! |
242 |
||
243 |
!BookmarkList methodsFor:'accessing'! |
|
244 |
||
245 |
/ label |
|
246 |
||
247 |
^ self root / label |
|
248 |
||
249 |
"Created: / 21-06-2011 / 08:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
250 |
! |
|
251 |
||
252 |
fileName |
|
253 |
^ fileName |
|
254 |
! |
|
255 |
||
256 |
fileName:aString |
|
257 |
fileName := aString. |
|
258 |
! ! |
|
259 |
||
260 |
!BookmarkList methodsFor:'accessing - special folders'! |
|
261 |
||
262 |
myWorkspaces |
|
263 |
||
264 |
^self / self class defaultLabelForMyWorkspaces |
|
265 |
||
266 |
" |
|
267 |
BookmarkList forWorkspace myWorkspaces |
|
268 |
" |
|
269 |
||
270 |
"Created: / 21-06-2011 / 08:53:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
271 |
! ! |
|
272 |
||
273 |
!BookmarkList methodsFor:'change & update'! |
|
274 |
||
275 |
changed:aParameter with:anArgument |
|
276 |
||
277 |
super changed:aParameter with:anArgument. |
|
278 |
"/self save. |
|
279 |
||
280 |
"Created: / 23-05-2011 / 16:13:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
281 |
"Modified: / 02-06-2011 / 13:35:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
282 |
! ! |
|
283 |
||
284 |
!BookmarkList methodsFor:'collection protocol'! |
|
285 |
||
286 |
add: item |
|
287 |
||
288 |
^root add: item |
|
289 |
||
290 |
"Created: / 23-05-2011 / 10:49:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
291 |
"Modified: / 23-05-2011 / 13:45:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
292 |
! |
|
293 |
||
294 |
contains: anObject |
|
295 |
||
296 |
^root contains: anObject |
|
297 |
||
298 |
"Created: / 23-05-2011 / 10:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
299 |
"Modified: / 23-05-2011 / 13:46:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
300 |
! |
|
301 |
||
302 |
remove: item ifAbsent: block |
|
303 |
||
304 |
^root remove: item |
|
305 |
||
306 |
"Created: / 23-05-2011 / 10:47:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
307 |
"Modified: / 23-05-2011 / 13:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
308 |
! ! |
|
309 |
||
310 |
!BookmarkList methodsFor:'converting'! |
|
311 |
||
312 |
asMenu |
|
313 |
||
314 |
^root asMenu |
|
315 |
||
316 |
"Created: / 23-05-2011 / 10:31:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
317 |
! |
|
318 |
||
319 |
asMenuUsingBuilder: builderClass |
|
320 |
||
321 |
^self root asMenuUsingBuilder: builderClass |
|
322 |
||
323 |
"Created: / 21-06-2011 / 08:05:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
324 |
! |
|
325 |
||
326 |
literalArrayEncoding |
|
327 |
||
328 |
^Array |
|
329 |
with: self className |
|
330 |
with: #root: |
|
331 |
with: root literalArrayEncoding |
|
332 |
||
333 |
"Created: / 23-05-2011 / 14:23:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
334 |
! ! |
|
335 |
||
336 |
!BookmarkList methodsFor:'initialization'! |
|
337 |
||
338 |
initialize |
|
339 |
"Invoked when a new instance is created." |
|
340 |
||
341 |
"/ please change as required (and remove this comment) |
|
342 |
super initialize. |
|
343 |
||
344 |
showRoot := false. |
|
345 |
self root: (Bookmark forFolderNamed: '<bookmarks>'). |
|
346 |
||
347 |
"Modified: / 23-05-2011 / 13:56:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
348 |
! ! |
|
349 |
||
350 |
!BookmarkList methodsFor:'loading / saving'! |
|
351 |
||
352 |
save |
|
13240 | 353 |
|f| |
9972 | 354 |
|
13240 | 355 |
(fileName notNil |
356 |
and:[ (f := fileName asFilename) exists not or:[ f isWritable ] ]) |
|
357 |
ifTrue:[ self saveOn:fileName ]. |
|
9972 | 358 |
|
359 |
"Created: / 23-05-2011 / 16:38:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
360 |
! |
|
361 |
||
362 |
saveOn: aStringOrFilename |
|
363 |
||
364 |
aStringOrFilename asFilename writingFileDo: |
|
365 |
[:s|s nextPutAll: self literalArrayEncoding storeString]. |
|
366 |
||
367 |
"Created: / 23-05-2011 / 16:39:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
368 |
! ! |
|
369 |
||
370 |
!BookmarkList methodsFor:'visiting'! |
|
371 |
||
372 |
acceptVisitor:aVisitor |
|
373 |
"Double dispatch back to the visitor, passing my type encoded in |
|
374 |
the selector (visitor pattern)" |
|
375 |
||
376 |
"stub code automatically generated - please change if required" |
|
377 |
||
378 |
^ aVisitor visitBookmarkList:self |
|
379 |
! ! |
|
380 |
||
381 |
!BookmarkList class methodsFor:'documentation'! |
|
382 |
||
383 |
version_CVS |
|
13240 | 384 |
^ '$Header: /cvs/stx/stx/libtool/BookmarkList.st,v 1.6 2013-07-29 14:08:33 stefan Exp $' |
9972 | 385 |
! |
386 |
||
387 |
version_SVN |
|
13240 | 388 |
^ '$Id: BookmarkList.st,v 1.6 2013-07-29 14:08:33 stefan Exp $' |
9972 | 389 |
! ! |
13240 | 390 |