author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sun, 29 Jan 2012 15:33:37 +0000 | |
branch | jv |
changeset 12125 | 0c49a3b13e43 |
parent 12123 | 4bde08cebd48 |
child 12128 | a7ff7d66ee85 |
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 |
||
69 |
(anArray size == 3 and: [anArray second == #root:]) ifFalse: |
|
70 |
[self breakPoint: #jv. ^super decodeFromLiteralArray:anArray]. |
|
71 |
||
72 |
^self new root: anArray third decodeAsLiteralArray |
|
73 |
||
74 |
"Created: / 23-05-2011 / 14:28:47 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
75 |
! |
|
76 |
||
77 |
new |
|
78 |
"return an initialized instance" |
|
79 |
||
80 |
^ super new initialize. |
|
81 |
||
82 |
"Modified: / 23-05-2011 / 13:57:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
83 |
! |
|
84 |
||
85 |
readFrom: aStream onError: aBlock |
|
86 |
||
87 |
| litArray | |
|
88 |
^[ |
|
89 |
litArray := Compiler evaluate: aStream contents asString. |
|
90 |
litArray decodeAsLiteralArray. |
|
91 |
] on: Error do: [ |
|
92 |
aBlock value. |
|
93 |
nil |
|
94 |
] |
|
95 |
||
96 |
"Created: / 23-05-2011 / 15:58:13 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
97 |
! |
|
98 |
||
99 |
readFromFile: aStringOrFilename |
|
100 |
||
101 |
| bookmarks file | |
|
102 |
file := aStringOrFilename asFilename. |
|
103 |
file exists ifFalse: |
|
104 |
[self error: ('File does %1 not exists' bindWith: file pathName)]. |
|
105 |
bookmarks := self readFrom: file readStream onError: |
|
106 |
[self error: ('Cannot parse %1 not exists' bindWith: file pathName)]. |
|
107 |
bookmarks fileName: file pathName. |
|
108 |
^bookmarks |
|
109 |
||
110 |
"Created: / 23-05-2011 / 16:10:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
111 |
! |
|
112 |
||
113 |
readFromFile: aStringOrFilename onError: aBlock |
|
12125 | 114 |
| bookmarks file | |
12123
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10911
diff
changeset
|
115 |
|
9972 | 116 |
file := aStringOrFilename asFilename. |
12125 | 117 |
file exists ifFalse: [^aBlock value]. |
118 |
bookmarks := self readFrom: file readStream onError: [^aBlock value]. |
|
119 |
bookmarks isNil ifTrue: [^aBlock value]. |
|
9972 | 120 |
bookmarks fileName: file pathName. |
121 |
^bookmarks |
|
122 |
||
123 |
"Created: / 23-05-2011 / 16:32:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
124 |
"Modified: / 02-06-2011 / 19:43:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
12125 | 125 |
"Modified: / 18-11-2011 / 14:32:24 / cg" |
9972 | 126 |
! ! |
127 |
||
128 |
!BookmarkList class methodsFor:'accessing'! |
|
129 |
||
130 |
forSystemBrowser |
|
131 |
||
132 |
BrowserBookmarks isNil ifTrue: |
|
133 |
[self initializeBrowserBookmarks]. |
|
134 |
^BrowserBookmarks |
|
135 |
||
136 |
"Created: / 23-05-2011 / 10:10:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
137 |
! |
|
138 |
||
139 |
forWebBrowser |
|
140 |
||
141 |
WebBookmarks isNil ifTrue: |
|
142 |
[self initializeWebBookmarks]. |
|
143 |
^WebBookmarks |
|
144 |
||
145 |
"Created: / 08-06-2011 / 12:15:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
146 |
! |
|
147 |
||
148 |
forWorkspace |
|
149 |
||
150 |
WorkspaceBookmarks isNil ifTrue: |
|
151 |
[self initializeWorkspaceBookmarks]. |
|
152 |
^WorkspaceBookmarks |
|
153 |
||
154 |
"Created: / 20-06-2011 / 22:11:03 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
155 |
! ! |
|
156 |
||
157 |
!BookmarkList class methodsFor:'accessing - defaults'! |
|
158 |
||
159 |
defaultLabelForMyWorkspaces |
|
160 |
||
161 |
^'My Workspaces' |
|
162 |
||
163 |
"Created: / 21-06-2011 / 08:35:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
164 |
! |
|
165 |
||
166 |
defaultLabelForRecent |
|
167 |
||
168 |
^'Recent' |
|
169 |
||
170 |
"Created: / 21-06-2011 / 08:35:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
171 |
! ! |
|
172 |
||
173 |
!BookmarkList class methodsFor:'class initialization'! |
|
174 |
||
175 |
initializeBrowserBookmarks |
|
176 |
||
177 |
| file | |
|
178 |
file := Filename defaultDirectory / 'browser-bookmarks.rc'. |
|
179 |
BrowserBookmarks := self readFromFile: file onError:[nil]. |
|
12125 | 180 |
BrowserBookmarks notNil ifTrue:[^self]. |
9972 | 181 |
|
182 |
file := Filename homeDirectory / '.smalltalk' / 'browser-bookmarks.rc'. |
|
183 |
BrowserBookmarks := self readFromFile: file onError:[nil]. |
|
12125 | 184 |
BrowserBookmarks notNil ifTrue:[^self]. |
9972 | 185 |
|
186 |
BrowserBookmarks := self new fileName: file pathName. |
|
187 |
||
188 |
"Created: / 23-05-2011 / 10:06:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
189 |
"Modified: / 23-05-2011 / 16:35:08 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
12125 | 190 |
"Modified: / 29-11-2011 / 11:21:06 / cg" |
9972 | 191 |
! |
192 |
||
193 |
initializeWebBookmarks |
|
194 |
||
195 |
| file | |
|
196 |
file := Filename defaultDirectory / 'web-bookmarks.rc'. |
|
197 |
WebBookmarks := self readFromFile: file onError:[nil]. |
|
12125 | 198 |
WebBookmarks notNil ifTrue:[^self]. |
9972 | 199 |
|
200 |
file := Filename homeDirectory / '.smalltalk' / 'web-bookmarks.rc'. |
|
201 |
WebBookmarks := self readFromFile: file onError:[nil]. |
|
12125 | 202 |
WebBookmarks notNil ifTrue:[^self]. |
9972 | 203 |
|
204 |
WebBookmarks := self new fileName: file pathName. |
|
205 |
||
206 |
"Created: / 08-06-2011 / 12:15:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
12125 | 207 |
"Modified: / 29-11-2011 / 11:21:10 / cg" |
9972 | 208 |
! |
209 |
||
210 |
initializeWorkspaceBookmarks |
|
211 |
||
212 |
| file | |
|
213 |
file := Filename defaultDirectory / 'workspace-bookmarks.rc'. |
|
214 |
WorkspaceBookmarks := self readFromFile: file onError:[nil]. |
|
12125 | 215 |
WorkspaceBookmarks notNil ifTrue:[^self]. |
9972 | 216 |
|
217 |
file := Filename homeDirectory / '.smalltalk' / 'workspace-bookmarks.rc'. |
|
218 |
WorkspaceBookmarks := self readFromFile: file onError:[nil]. |
|
12125 | 219 |
WorkspaceBookmarks notNil ifTrue:[^self]. |
9972 | 220 |
|
221 |
WorkspaceBookmarks := self new fileName: file pathName. |
|
222 |
WorkspaceBookmarks root add: |
|
223 |
((Bookmark forFolderNamed: self defaultLabelForMyWorkspaces) |
|
224 |
add: (Bookmark forFile: WorkspaceApplication defaultMyWorkspaceDotWspFile pathName); |
|
225 |
yourself). |
|
226 |
||
227 |
" |
|
228 |
WorkspaceBookmarks := nil. |
|
229 |
BookmarkList initializeWorkspaceBookmarks. |
|
230 |
" |
|
231 |
||
232 |
" |
|
233 |
WorkspaceBookmarks := nil. |
|
234 |
" |
|
235 |
||
236 |
"Created: / 20-06-2011 / 22:10:34 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
237 |
"Modified: / 21-06-2011 / 08:46:56 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
12125 | 238 |
"Modified: / 29-11-2011 / 11:21:16 / cg" |
9972 | 239 |
! ! |
240 |
||
241 |
!BookmarkList methodsFor:'accessing'! |
|
242 |
||
243 |
/ label |
|
244 |
||
245 |
^ self root / label |
|
246 |
||
247 |
"Created: / 21-06-2011 / 08:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
248 |
! |
|
249 |
||
250 |
fileName |
|
251 |
^ fileName |
|
252 |
! |
|
253 |
||
254 |
fileName:aString |
|
255 |
fileName := aString. |
|
256 |
! ! |
|
257 |
||
258 |
!BookmarkList methodsFor:'accessing - special folders'! |
|
259 |
||
260 |
myWorkspaces |
|
261 |
||
262 |
^self / self class defaultLabelForMyWorkspaces |
|
263 |
||
264 |
" |
|
265 |
BookmarkList forWorkspace myWorkspaces |
|
266 |
" |
|
267 |
||
268 |
"Created: / 21-06-2011 / 08:53:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
269 |
! ! |
|
270 |
||
271 |
!BookmarkList methodsFor:'change & update'! |
|
272 |
||
273 |
changed:aParameter with:anArgument |
|
274 |
||
275 |
super changed:aParameter with:anArgument. |
|
276 |
"/self save. |
|
277 |
||
278 |
"Created: / 23-05-2011 / 16:13:31 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
279 |
"Modified: / 02-06-2011 / 13:35:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
280 |
! ! |
|
281 |
||
282 |
!BookmarkList methodsFor:'collection protocol'! |
|
283 |
||
284 |
add: item |
|
285 |
||
286 |
^root add: item |
|
287 |
||
288 |
"Created: / 23-05-2011 / 10:49:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
289 |
"Modified: / 23-05-2011 / 13:45:58 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
290 |
! |
|
291 |
||
292 |
contains: anObject |
|
293 |
||
294 |
^root contains: anObject |
|
295 |
||
296 |
"Created: / 23-05-2011 / 10:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
297 |
"Modified: / 23-05-2011 / 13:46:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
298 |
! |
|
299 |
||
300 |
remove: item ifAbsent: block |
|
301 |
||
302 |
^root remove: item |
|
303 |
||
304 |
"Created: / 23-05-2011 / 10:47:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
305 |
"Modified: / 23-05-2011 / 13:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
306 |
! ! |
|
307 |
||
308 |
!BookmarkList methodsFor:'converting'! |
|
309 |
||
310 |
asMenu |
|
311 |
||
312 |
^root asMenu |
|
313 |
||
314 |
"Created: / 23-05-2011 / 10:31:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
315 |
! |
|
316 |
||
317 |
asMenuUsingBuilder: builderClass |
|
318 |
||
319 |
^self root asMenuUsingBuilder: builderClass |
|
320 |
||
321 |
"Created: / 21-06-2011 / 08:05:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
322 |
! |
|
323 |
||
324 |
literalArrayEncoding |
|
325 |
||
326 |
^Array |
|
327 |
with: self className |
|
328 |
with: #root: |
|
329 |
with: root literalArrayEncoding |
|
330 |
||
331 |
"Created: / 23-05-2011 / 14:23:37 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
332 |
! ! |
|
333 |
||
334 |
!BookmarkList methodsFor:'initialization'! |
|
335 |
||
336 |
initialize |
|
337 |
"Invoked when a new instance is created." |
|
338 |
||
339 |
"/ please change as required (and remove this comment) |
|
340 |
super initialize. |
|
341 |
||
342 |
showRoot := false. |
|
343 |
self root: (Bookmark forFolderNamed: '<bookmarks>'). |
|
344 |
||
345 |
"Modified: / 23-05-2011 / 13:56:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
346 |
! ! |
|
347 |
||
348 |
!BookmarkList methodsFor:'loading / saving'! |
|
349 |
||
350 |
save |
|
351 |
||
352 |
| f | |
|
353 |
||
354 |
(fileName notNil and: |
|
355 |
[(f := fileName asFilename) exists not or: |
|
356 |
[f isWritable]]) |
|
357 |
ifTrue:[self saveOn: fileName]. |
|
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 |
|
12125 | 384 |
^ '§Header: /cvs/stx/stx/libtool/BookmarkList.st,v 1.4 2011/11/29 10:21:52 cg Exp §' |
9972 | 385 |
! |
386 |
||
387 |
version_SVN |
|
12123
4bde08cebd48
trunk branched into /branches/jv
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
10911
diff
changeset
|
388 |
^ '$Id$' |
12125 | 389 |
! ! |