author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 01 Apr 2015 10:38:01 +0100 | |
branch | jv |
changeset 15566 | 184cea584be5 |
parent 13289 | cc75e3cd0362 |
parent 14811 | 1105a50bafa5 |
child 16764 | ecd1c24daeeb |
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 |
|
14810 | 88 |
| litArray | |
9972 | 89 |
|
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 |
|
14810 | 102 |
^ self readFromFile: aStringOrFilename onError:[:reason | self error:reason] |
9972 | 103 |
! |
104 |
||
105 |
readFromFile: aStringOrFilename onError: aBlock |
|
14810 | 106 |
| bookmarks file pathName| |
9972 | 107 |
|
108 |
file := aStringOrFilename asFilename. |
|
14810 | 109 |
pathName := file pathName. |
110 |
file exists ifFalse: [^ aBlock valueWithOptionalArgument:('File does %1 not exist' bindWith: pathName)]. |
|
10864 | 111 |
bookmarks := self readFrom: file readStream onError: [^aBlock value]. |
14810 | 112 |
bookmarks isNil ifTrue: [^ aBlock valueWithOptionalArgument:('Cannot parse %1 not exist' bindWith: pathName)]. |
113 |
bookmarks fileName: pathName. |
|
9972 | 114 |
^bookmarks |
115 |
||
116 |
"Created: / 23-05-2011 / 16:32:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
117 |
"Modified: / 02-06-2011 / 19:43:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10864 | 118 |
"Modified: / 18-11-2011 / 14:32:24 / cg" |
9972 | 119 |
! ! |
120 |
||
121 |
!BookmarkList class methodsFor:'accessing'! |
|
122 |
||
13855 | 123 |
forFileBrowser |
124 |
FileBookmarks isNil ifTrue:[ |
|
125 |
self initializeFileBookmarks |
|
126 |
]. |
|
127 |
^ FileBookmarks |
|
128 |
||
129 |
"Created: / 04-04-2012 / 12:04:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
130 |
! |
|
131 |
||
9972 | 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 |
||
13855 | 195 |
initializeFileBookmarks |
196 |
||
197 |
| file | |
|
198 |
file := Filename defaultDirectory / 'file-bookmarks.rc'. |
|
199 |
FileBookmarks := self readFromFile: file onError:[nil]. |
|
200 |
FileBookmarks notNil ifTrue:[^self]. |
|
201 |
||
202 |
file := Filename homeDirectory / '.smalltalk' / 'file-bookmarks.rc'. |
|
203 |
FileBookmarks := self readFromFile: file onError:[nil]. |
|
204 |
FileBookmarks notNil ifTrue:[^self]. |
|
205 |
||
206 |
FileBookmarks := self new fileName: file pathName. |
|
207 |
||
208 |
"Created: / 04-04-2012 / 12:05:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
209 |
! |
|
210 |
||
9972 | 211 |
initializeWebBookmarks |
212 |
||
213 |
| file | |
|
214 |
file := Filename defaultDirectory / 'web-bookmarks.rc'. |
|
215 |
WebBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 216 |
WebBookmarks notNil ifTrue:[^self]. |
9972 | 217 |
|
218 |
file := Filename homeDirectory / '.smalltalk' / 'web-bookmarks.rc'. |
|
219 |
WebBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 220 |
WebBookmarks notNil ifTrue:[^self]. |
9972 | 221 |
|
222 |
WebBookmarks := self new fileName: file pathName. |
|
223 |
||
224 |
"Created: / 08-06-2011 / 12:15:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10911 | 225 |
"Modified: / 29-11-2011 / 11:21:10 / cg" |
9972 | 226 |
! |
227 |
||
228 |
initializeWorkspaceBookmarks |
|
229 |
||
230 |
| file | |
|
231 |
file := Filename defaultDirectory / 'workspace-bookmarks.rc'. |
|
232 |
WorkspaceBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 233 |
WorkspaceBookmarks notNil ifTrue:[^self]. |
9972 | 234 |
|
235 |
file := Filename homeDirectory / '.smalltalk' / 'workspace-bookmarks.rc'. |
|
236 |
WorkspaceBookmarks := self readFromFile: file onError:[nil]. |
|
10911 | 237 |
WorkspaceBookmarks notNil ifTrue:[^self]. |
9972 | 238 |
|
239 |
WorkspaceBookmarks := self new fileName: file pathName. |
|
240 |
WorkspaceBookmarks root add: |
|
241 |
((Bookmark forFolderNamed: self defaultLabelForMyWorkspaces) |
|
242 |
add: (Bookmark forFile: WorkspaceApplication defaultMyWorkspaceDotWspFile pathName); |
|
243 |
yourself). |
|
244 |
||
245 |
" |
|
246 |
WorkspaceBookmarks := nil. |
|
247 |
BookmarkList initializeWorkspaceBookmarks. |
|
248 |
" |
|
249 |
||
250 |
" |
|
251 |
WorkspaceBookmarks := nil. |
|
252 |
" |
|
253 |
||
254 |
"Created: / 20-06-2011 / 22:10:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
255 |
"Modified: / 21-06-2011 / 08:46:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
10911 | 256 |
"Modified: / 29-11-2011 / 11:21:16 / cg" |
9972 | 257 |
! ! |
258 |
||
259 |
!BookmarkList methodsFor:'accessing'! |
|
260 |
||
261 |
/ label |
|
262 |
||
263 |
^ self root / label |
|
264 |
||
265 |
"Created: / 21-06-2011 / 08:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
266 |
! |
|
267 |
||
268 |
fileName |
|
269 |
^ fileName |
|
270 |
! |
|
271 |
||
272 |
fileName:aString |
|
273 |
fileName := aString. |
|
274 |
! ! |
|
275 |
||
276 |
!BookmarkList methodsFor:'accessing - special folders'! |
|
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:'change & update'! |
|
290 |
||
291 |
changed:aParameter with:anArgument |
|
292 |
||
293 |
super changed:aParameter with:anArgument. |
|
294 |
"/self save. |
|
295 |
||
296 |
"Created: / 23-05-2011 / 16:13:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
297 |
"Modified: / 02-06-2011 / 13:35:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
298 |
! ! |
|
299 |
||
300 |
!BookmarkList methodsFor:'collection protocol'! |
|
301 |
||
302 |
add: item |
|
303 |
||
304 |
^root add: item |
|
305 |
||
306 |
"Created: / 23-05-2011 / 10:49:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
307 |
"Modified: / 23-05-2011 / 13:45:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
308 |
! |
|
309 |
||
310 |
contains: anObject |
|
311 |
||
312 |
^root contains: anObject |
|
313 |
||
314 |
"Created: / 23-05-2011 / 10:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
315 |
"Modified: / 23-05-2011 / 13:46:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
316 |
! |
|
317 |
||
318 |
remove: item ifAbsent: block |
|
319 |
||
320 |
^root remove: item |
|
321 |
||
322 |
"Created: / 23-05-2011 / 10:47:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
323 |
"Modified: / 23-05-2011 / 13:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
324 |
! ! |
|
325 |
||
326 |
!BookmarkList methodsFor:'converting'! |
|
327 |
||
328 |
asMenu |
|
329 |
||
330 |
^root asMenu |
|
331 |
||
332 |
"Created: / 23-05-2011 / 10:31:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
333 |
! |
|
334 |
||
335 |
asMenuUsingBuilder: builderClass |
|
336 |
||
337 |
^self root asMenuUsingBuilder: builderClass |
|
338 |
||
339 |
"Created: / 21-06-2011 / 08:05:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
340 |
! |
|
341 |
||
342 |
literalArrayEncoding |
|
343 |
||
344 |
^Array |
|
345 |
with: self className |
|
346 |
with: #root: |
|
347 |
with: root literalArrayEncoding |
|
348 |
||
349 |
"Created: / 23-05-2011 / 14:23:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
350 |
! ! |
|
351 |
||
352 |
!BookmarkList methodsFor:'initialization'! |
|
353 |
||
354 |
initialize |
|
355 |
"Invoked when a new instance is created." |
|
356 |
||
357 |
super initialize. |
|
358 |
||
359 |
showRoot := false. |
|
360 |
self root: (Bookmark forFolderNamed: '<bookmarks>'). |
|
361 |
||
362 |
"Modified: / 23-05-2011 / 13:56:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
363 |
! ! |
|
364 |
||
365 |
!BookmarkList methodsFor:'loading / saving'! |
|
366 |
||
367 |
save |
|
13240 | 368 |
|f| |
9972 | 369 |
|
13240 | 370 |
(fileName notNil |
371 |
and:[ (f := fileName asFilename) exists not or:[ f isWritable ] ]) |
|
372 |
ifTrue:[ self saveOn:fileName ]. |
|
9972 | 373 |
|
374 |
"Created: / 23-05-2011 / 16:38:17 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
375 |
! |
|
376 |
||
377 |
saveOn: aStringOrFilename |
|
378 |
||
379 |
aStringOrFilename asFilename writingFileDo: |
|
380 |
[:s|s nextPutAll: self literalArrayEncoding storeString]. |
|
381 |
||
382 |
"Created: / 23-05-2011 / 16:39:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
383 |
! ! |
|
384 |
||
385 |
!BookmarkList methodsFor:'visiting'! |
|
386 |
||
387 |
acceptVisitor:aVisitor |
|
388 |
"Double dispatch back to the visitor, passing my type encoded in |
|
389 |
the selector (visitor pattern)" |
|
390 |
||
391 |
"stub code automatically generated - please change if required" |
|
392 |
||
393 |
^ aVisitor visitBookmarkList:self |
|
394 |
! ! |
|
395 |
||
396 |
!BookmarkList class methodsFor:'documentation'! |
|
397 |
||
14811 | 398 |
version |
399 |
^ '$Header: /cvs/stx/stx/libtool/BookmarkList.st,v 1.9 2014-11-04 11:14:25 cg Exp $' |
|
400 |
! |
|
401 |
||
9972 | 402 |
version_CVS |
14811 | 403 |
^ '$Header: /cvs/stx/stx/libtool/BookmarkList.st,v 1.9 2014-11-04 11:14:25 cg Exp $' |
9972 | 404 |
! |
405 |
||
406 |
version_SVN |
|
14811 | 407 |
^ '$Id: BookmarkList.st,v 1.9 2014-11-04 11:14:25 cg Exp $' |
9972 | 408 |
! ! |
13240 | 409 |