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
|
|
114 |
|
|
115 |
| bookmarks file |
|
|
116 |
file := aStringOrFilename asFilename.
|
|
117 |
file exists ifFalse:
|
|
118 |
[^aBlock value].
|
|
119 |
bookmarks := self readFrom: file readStream onError:
|
|
120 |
[^aBlock value].
|
|
121 |
bookmarks ifNil:
|
|
122 |
[^aBlock value].
|
|
123 |
bookmarks fileName: file pathName.
|
|
124 |
^bookmarks
|
|
125 |
|
|
126 |
"Created: / 23-05-2011 / 16:32:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
127 |
"Modified: / 02-06-2011 / 19:43:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
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].
|
|
182 |
BrowserBookmarks ifNotNil:[^self].
|
|
183 |
|
|
184 |
file := Filename homeDirectory / '.smalltalk' / 'browser-bookmarks.rc'.
|
|
185 |
BrowserBookmarks := self readFromFile: file onError:[nil].
|
|
186 |
BrowserBookmarks ifNotNil:[^self].
|
|
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>"
|
|
192 |
!
|
|
193 |
|
|
194 |
initializeWebBookmarks
|
|
195 |
|
|
196 |
| file |
|
|
197 |
file := Filename defaultDirectory / 'web-bookmarks.rc'.
|
|
198 |
WebBookmarks := self readFromFile: file onError:[nil].
|
|
199 |
WebBookmarks ifNotNil:[^self].
|
|
200 |
|
|
201 |
file := Filename homeDirectory / '.smalltalk' / 'web-bookmarks.rc'.
|
|
202 |
WebBookmarks := self readFromFile: file onError:[nil].
|
|
203 |
WebBookmarks ifNotNil:[^self].
|
|
204 |
|
|
205 |
WebBookmarks := self new fileName: file pathName.
|
|
206 |
|
|
207 |
"Created: / 08-06-2011 / 12:15:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
208 |
!
|
|
209 |
|
|
210 |
initializeWorkspaceBookmarks
|
|
211 |
|
|
212 |
| file |
|
|
213 |
file := Filename defaultDirectory / 'workspace-bookmarks.rc'.
|
|
214 |
WorkspaceBookmarks := self readFromFile: file onError:[nil].
|
|
215 |
WorkspaceBookmarks ifNotNil:[^self].
|
|
216 |
|
|
217 |
file := Filename homeDirectory / '.smalltalk' / 'workspace-bookmarks.rc'.
|
|
218 |
WorkspaceBookmarks := self readFromFile: file onError:[nil].
|
|
219 |
WorkspaceBookmarks ifNotNil:[^self].
|
|
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>"
|
|
238 |
! !
|
|
239 |
|
|
240 |
!BookmarkList methodsFor:'accessing'!
|
|
241 |
|
|
242 |
/ label
|
|
243 |
|
|
244 |
^ self root / label
|
|
245 |
|
|
246 |
"Created: / 21-06-2011 / 08:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
247 |
!
|
|
248 |
|
|
249 |
fileName
|
|
250 |
^ fileName
|
|
251 |
!
|
|
252 |
|
|
253 |
fileName:aString
|
|
254 |
fileName := aString.
|
|
255 |
! !
|
|
256 |
|
|
257 |
!BookmarkList methodsFor:'accessing - special folders'!
|
|
258 |
|
|
259 |
myWorkspaces
|
|
260 |
|
|
261 |
^self / self class defaultLabelForMyWorkspaces
|
|
262 |
|
|
263 |
"
|
|
264 |
BookmarkList forWorkspace myWorkspaces
|
|
265 |
"
|
|
266 |
|
|
267 |
"Created: / 21-06-2011 / 08:53:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
268 |
! !
|
|
269 |
|
|
270 |
!BookmarkList methodsFor:'change & update'!
|
|
271 |
|
|
272 |
changed:aParameter with:anArgument
|
|
273 |
|
|
274 |
super changed:aParameter with:anArgument.
|
|
275 |
"/self save.
|
|
276 |
|
|
277 |
"Created: / 23-05-2011 / 16:13:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
278 |
"Modified: / 02-06-2011 / 13:35:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
279 |
! !
|
|
280 |
|
|
281 |
!BookmarkList methodsFor:'collection protocol'!
|
|
282 |
|
|
283 |
add: item
|
|
284 |
|
|
285 |
^root add: item
|
|
286 |
|
|
287 |
"Created: / 23-05-2011 / 10:49:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
288 |
"Modified: / 23-05-2011 / 13:45:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
289 |
!
|
|
290 |
|
|
291 |
contains: anObject
|
|
292 |
|
|
293 |
^root contains: anObject
|
|
294 |
|
|
295 |
"Created: / 23-05-2011 / 10:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
296 |
"Modified: / 23-05-2011 / 13:46:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
297 |
!
|
|
298 |
|
|
299 |
remove: item ifAbsent: block
|
|
300 |
|
|
301 |
^root remove: item
|
|
302 |
|
|
303 |
"Created: / 23-05-2011 / 10:47:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
304 |
"Modified: / 23-05-2011 / 13:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
305 |
! !
|
|
306 |
|
|
307 |
!BookmarkList methodsFor:'converting'!
|
|
308 |
|
|
309 |
asMenu
|
|
310 |
|
|
311 |
^root asMenu
|
|
312 |
|
|
313 |
"Created: / 23-05-2011 / 10:31:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
314 |
!
|
|
315 |
|
|
316 |
asMenuUsingBuilder: builderClass
|
|
317 |
|
|
318 |
^self root asMenuUsingBuilder: builderClass
|
|
319 |
|
|
320 |
"Created: / 21-06-2011 / 08:05:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
321 |
!
|
|
322 |
|
|
323 |
literalArrayEncoding
|
|
324 |
|
|
325 |
^Array
|
|
326 |
with: self className
|
|
327 |
with: #root:
|
|
328 |
with: root literalArrayEncoding
|
|
329 |
|
|
330 |
"Created: / 23-05-2011 / 14:23:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
331 |
! !
|
|
332 |
|
|
333 |
!BookmarkList methodsFor:'initialization'!
|
|
334 |
|
|
335 |
initialize
|
|
336 |
"Invoked when a new instance is created."
|
|
337 |
|
|
338 |
"/ please change as required (and remove this comment)
|
|
339 |
super initialize.
|
|
340 |
|
|
341 |
showRoot := false.
|
|
342 |
self root: (Bookmark forFolderNamed: '<bookmarks>').
|
|
343 |
|
|
344 |
"Modified: / 23-05-2011 / 13:56:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
345 |
! !
|
|
346 |
|
|
347 |
!BookmarkList methodsFor:'loading / saving'!
|
|
348 |
|
|
349 |
save
|
|
350 |
|
|
351 |
| f |
|
|
352 |
|
|
353 |
(fileName notNil and:
|
|
354 |
[(f := fileName asFilename) exists not or:
|
|
355 |
[f isWritable]])
|
|
356 |
ifTrue:[self saveOn: fileName].
|
|
357 |
|
|
358 |
"Created: / 23-05-2011 / 16:38:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
359 |
!
|
|
360 |
|
|
361 |
saveOn: aStringOrFilename
|
|
362 |
|
|
363 |
aStringOrFilename asFilename writingFileDo:
|
|
364 |
[:s|s nextPutAll: self literalArrayEncoding storeString].
|
|
365 |
|
|
366 |
"Created: / 23-05-2011 / 16:39:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
367 |
! !
|
|
368 |
|
|
369 |
!BookmarkList methodsFor:'visiting'!
|
|
370 |
|
|
371 |
acceptVisitor:aVisitor
|
|
372 |
"Double dispatch back to the visitor, passing my type encoded in
|
|
373 |
the selector (visitor pattern)"
|
|
374 |
|
|
375 |
"stub code automatically generated - please change if required"
|
|
376 |
|
|
377 |
^ aVisitor visitBookmarkList:self
|
|
378 |
! !
|
|
379 |
|
|
380 |
!BookmarkList class methodsFor:'documentation'!
|
|
381 |
|
|
382 |
version_CVS
|
10085
|
383 |
^ '$Header: /cvs/stx/stx/libtool/BookmarkList.st,v 1.2 2011-07-03 18:00:51 cg Exp $'
|
9972
|
384 |
!
|
|
385 |
|
|
386 |
version_SVN
|
|
387 |
^ '§Id§'
|
|
388 |
! !
|