|
1 "{ Package: 'stx:libtool' }" |
|
2 |
|
3 SimpleDialog subclass:#BookmarksEditDialog |
|
4 instanceVariableNames:'selectedBookmarksHolder bookmarkListHolder defaultBookmark answer' |
|
5 classVariableNames:'' |
|
6 poolDictionaries:'' |
|
7 category:'Interface-Tools-File' |
|
8 ! |
|
9 |
|
10 |
|
11 !BookmarksEditDialog class methodsFor:'image specs'! |
|
12 |
|
13 fileIn22x22Icon |
|
14 "This resource specification was automatically generated |
|
15 by the ImageEditor of ST/X." |
|
16 |
|
17 "Do not manually edit this!! If it is corrupted, |
|
18 the ImageEditor may not be able to read the specification." |
|
19 |
|
20 " |
|
21 self fileIn22x22Icon inspect |
|
22 ImageEditor openOnClass:self andSelector:#fileIn22x22Icon |
|
23 Icon flushCachedIcons |
|
24 " |
|
25 |
|
26 <resource: #image> |
|
27 |
|
28 ^Icon |
|
29 constantNamed:'BookmarksDialog class fileIn22x22Icon' |
|
30 ifAbsentPut:[(Depth8Image new) width: 22; height: 22; photometric:(#palette); bitsPerSample:(#[8]); samplesPerPixel:(1); bits:(ByteArray fromPackedString:' |
|
31 @@@@@@@@GQ4]GQ4]GQ4]GQ4]GQ4]GP@@@@@@@A4]GQ4]GQ4]GQ4]GQ4]GQ4@@@@@@@@]GQ4]GQ4]GQ4]GQ4]GQ4]@ATUEQTUEQTUEA4]GQ4]GQ4]GQ4]GP@U |
|
32 GQ4]DPP''I!!TTGQ4]GQ4]GQ4]GQ4@EQ4]GP$K@"XUG!!P]GQ4]GQ4]GQ4]@AT]GQ4IDPX&EAPTEA4]GQ4]GQ4]GP@UGQ4]C1DEI!!<)HQP]@A4]GQ4]GQ4@EQ4] |
|
33 GQLIFQ,)JQ\TGP@@GQ4]GQ4]@AT]GQ4]BRH)JR$)JR$)JR$)GQ4]GP@UGQ4SDPP)JR$)JR$)JR$)JQ4]GQ4@EQ4SC1 )JR$)JR$)JR$)JR$@@A4]@AT]GQDZ |
|
34 F2$)JR$)JR$)JR$)GP@]GQ4UGP<LAPX&JR$)JR$)JR$)JP@@GQ4]EQ4@H TFI 8)JPDTGP@@GQ4]GQ4]GQT]ABHEF!!,NJB$AEA4@@A4]GQ4]GQ4UGRHYF XB |
|
35 C!!<J@QP]GQ4]GQ4]GQ4]EP$"H TFI 8(B DTGQ4]GQ4]GQ4]@APTEAPTEAPTEAPTEA4]GQ4]GQ4]GP@@@@@@@A4]GQ4]GQ4]GQ4]GQ4]GQ4@@@@@@@@]GQ4] |
|
36 GQ4]GQ4]GQ4]GQ4]@@@@@@@@@@@@@@@@@A4]GQ4]GQ4]GP@a') ; colorMapFromArray:#[250 250 255 225 225 237 236 236 244 213 213 228 245 245 252 241 241 248 239 239 246 216 216 230 210 210 224 252 252 255 229 229 239 248 248 254 244 244 250 219 219 232 234 234 243 253 253 255 232 232 241 249 249 254 224 224 236 254 254 255 156 156 182 208 208 223 206 206 221 204 204 219 246 246 253 242 242 249 240 240 247 238 238 245 215 215 229 255 255 255 211 211 225 230 230 240 228 228 238 201 201 218 243 243 249 222 222 235 220 220 233 218 218 231 235 235 244 233 233 242 231 231 240 248 0 0]; mask:((ImageMask new) width: 22; height: 22; photometric:(#blackIs0); bitsPerSample:(#[1]); samplesPerPixel:(1); bits:(ByteArray fromPackedString:'@@@@@@@@@@@@_<@@_>@@_?@@_? @_? @_? @_??@_??@_??@_??@_??@_? @_? @_? @_? @_? @@@@@@@@@@@@@') ; yourself); yourself] |
|
37 ! |
|
38 |
|
39 icon |
|
40 |
|
41 ^ ToolbarIconLibrary directoryBookmarksIcon |
|
42 ! ! |
|
43 |
|
44 !BookmarksEditDialog class methodsFor:'interface specs'! |
|
45 |
|
46 windowSpec |
|
47 "This resource specification was automatically generated |
|
48 by the UIPainter of ST/X." |
|
49 |
|
50 "Do not manually edit this!! If it is corrupted, |
|
51 the UIPainter may not be able to read the specification." |
|
52 |
|
53 " |
|
54 UIPainter new openOnClass:BookmarksDialog andSelector:#windowSpec |
|
55 BookmarksDialog new openInterface:#windowSpec |
|
56 BookmarksDialog open |
|
57 " |
|
58 |
|
59 <resource: #canvas> |
|
60 |
|
61 ^ |
|
62 #(FullSpec |
|
63 name: windowSpec |
|
64 window: |
|
65 (WindowSpec |
|
66 label: 'Edit Bookmarks' |
|
67 name: 'Edit Bookmarks' |
|
68 min: (Point 0 0) |
|
69 bounds: (Rectangle 0 0 450 296) |
|
70 ) |
|
71 component: |
|
72 (SpecCollection |
|
73 collection: ( |
|
74 (MenuPanelSpec |
|
75 name: 'ToolBar' |
|
76 layout: (LayoutFrame 0 0 0 0 0 1 30 0) |
|
77 menu: toolBarMenu |
|
78 textDefault: true |
|
79 ) |
|
80 (SequenceViewSpec |
|
81 name: 'BookmarkList' |
|
82 layout: (LayoutFrame 0 0 30 0 0 1 -30 1) |
|
83 model: selectedBookmarksHolder |
|
84 hasHorizontalScrollBar: true |
|
85 hasVerticalScrollBar: true |
|
86 isMultiSelect: true |
|
87 useIndex: false |
|
88 sequenceList: bookmarkListHolder |
|
89 ) |
|
90 (HorizontalPanelViewSpec |
|
91 name: 'HorizontalPanel1' |
|
92 layout: (LayoutFrame 0 0 -30 1 0 1 0 1) |
|
93 horizontalLayout: center |
|
94 verticalLayout: center |
|
95 horizontalSpace: 3 |
|
96 verticalSpace: 3 |
|
97 component: |
|
98 (SpecCollection |
|
99 collection: ( |
|
100 (ActionButtonSpec |
|
101 label: 'OK' |
|
102 name: 'Button1' |
|
103 translateLabel: true |
|
104 model: doAccept |
|
105 extent: (Point 125 22) |
|
106 ) |
|
107 (ActionButtonSpec |
|
108 label: 'Cancel' |
|
109 name: 'Button2' |
|
110 translateLabel: true |
|
111 model: doCancel |
|
112 extent: (Point 125 22) |
|
113 ) |
|
114 ) |
|
115 |
|
116 ) |
|
117 ) |
|
118 ) |
|
119 |
|
120 ) |
|
121 ) |
|
122 ! ! |
|
123 |
|
124 !BookmarksEditDialog class methodsFor:'menu specs'! |
|
125 |
|
126 toolBarMenu |
|
127 "This resource specification was automatically generated |
|
128 by the MenuEditor of ST/X." |
|
129 |
|
130 "Do not manually edit this!! If it is corrupted, |
|
131 the MenuEditor may not be able to read the specification." |
|
132 |
|
133 " |
|
134 MenuEditor new openOnClass:BookmarksEditDialog andSelector:#toolBarMenu |
|
135 (Menu new fromLiteralArrayEncoding:(BookmarksEditDialog toolBarMenu)) startUp |
|
136 " |
|
137 |
|
138 <resource: #menu> |
|
139 |
|
140 ^ |
|
141 #(Menu |
|
142 ( |
|
143 (MenuItem |
|
144 label: 'New' |
|
145 itemValue: new |
|
146 translateLabel: true |
|
147 labelImage: (ResourceRetriever XPToolbarIconLibrary newBookmark22x22Icon) |
|
148 ) |
|
149 (MenuItem |
|
150 enabled: removeButtonEnabledHolder |
|
151 label: 'Remove' |
|
152 itemValue: remove |
|
153 translateLabel: true |
|
154 labelImage: (ResourceRetriever XPToolbarIconLibrary close22x22Icon) |
|
155 ) |
|
156 (MenuItem |
|
157 label: '-' |
|
158 ) |
|
159 (MenuItem |
|
160 enabled: upButtonEnabledHolder |
|
161 label: 'Up' |
|
162 itemValue: up |
|
163 translateLabel: true |
|
164 labelImage: (ResourceRetriever XPToolbarIconLibrary up22x22Icon) |
|
165 ) |
|
166 (MenuItem |
|
167 enabled: downButtonEnabledHolder |
|
168 label: 'Down' |
|
169 itemValue: down |
|
170 translateLabel: true |
|
171 labelImage: (ResourceRetriever XPToolbarIconLibrary down22x22Icon) |
|
172 ) |
|
173 (MenuItem |
|
174 label: '-' |
|
175 ) |
|
176 (MenuItem |
|
177 label: 'Import' |
|
178 itemValue: import |
|
179 translateLabel: true |
|
180 labelImage: (ResourceRetriever BookmarksEditDialog fileIn22x22Icon) |
|
181 ) |
|
182 (MenuItem |
|
183 label: 'Export' |
|
184 itemValue: export |
|
185 translateLabel: true |
|
186 labelImage: (ResourceRetriever XPToolbarIconLibrary fileIn22x22Icon) |
|
187 ) |
|
188 ) |
|
189 nil |
|
190 nil |
|
191 ) |
|
192 ! ! |
|
193 |
|
194 !BookmarksEditDialog class methodsFor:'opening'! |
|
195 |
|
196 openWith: bookmarks |
|
197 |
|
198 ^ self openWith: bookmarks defaultBookmark: '' |
|
199 ! |
|
200 |
|
201 openWith: bookmarks defaultBookmark: aFilename |
|
202 |
|
203 | dialog bookmarkStrings | |
|
204 |
|
205 dialog := BookmarksEditDialog new. |
|
206 |
|
207 dialog allButOpenInterface:#windowSpec. |
|
208 Dialog aboutToOpenBoxNotificationSignal raiseRequestWith:dialog. |
|
209 |
|
210 aFilename notNil ifTrue:[dialog defaultBookmark: aFilename asString.]. |
|
211 bookmarkStrings := bookmarks collect:[:each | each asString]. |
|
212 dialog bookmarkList: bookmarkStrings. |
|
213 dialog openWindow. |
|
214 ^ dialog answer |
|
215 ! ! |
|
216 |
|
217 !BookmarksEditDialog methodsFor:'accessing'! |
|
218 |
|
219 answer |
|
220 ^ answer |
|
221 ! |
|
222 |
|
223 bookmarkList |
|
224 |
|
225 ^ self bookmarkListHolder. |
|
226 ! |
|
227 |
|
228 bookmarkList: bookmarkStrings |
|
229 |
|
230 self bookmarkList contents: bookmarkStrings. |
|
231 ! |
|
232 |
|
233 defaultBookmark |
|
234 ^ defaultBookmark |
|
235 ! |
|
236 |
|
237 defaultBookmark:something |
|
238 defaultBookmark := something. |
|
239 ! |
|
240 |
|
241 indexForNewBookmark |
|
242 |
|
243 | index | |
|
244 index := self selectedBookmarkIndex. |
|
245 index = 0 ifTrue:[^ self bookmarkList size]. |
|
246 ^ index |
|
247 ! |
|
248 |
|
249 indexOfBookmark: aString |
|
250 |
|
251 ^ self bookmarkList indexOf: aString |
|
252 ! |
|
253 |
|
254 selectBookmark: bookmark |
|
255 |
|
256 self selectedBookmarks: (Array with: bookmark). |
|
257 ! |
|
258 |
|
259 selectedBookmarkIndex |
|
260 |
|
261 | someBookmarks | |
|
262 |
|
263 someBookmarks := self selectedBookmarks. |
|
264 someBookmarks size = 1 ifTrue:[ |
|
265 ^ self indexOfBookmark: someBookmarks first |
|
266 ]. |
|
267 ^ 0 |
|
268 ! |
|
269 |
|
270 selectedBookmarks |
|
271 |
|
272 ^ self selectedBookmarksHolder value |
|
273 ! |
|
274 |
|
275 selectedBookmarks: aCollection |
|
276 |
|
277 ^ self selectedBookmarksHolder value: aCollection |
|
278 ! ! |
|
279 |
|
280 !BookmarksEditDialog methodsFor:'aspects'! |
|
281 |
|
282 bookmarkListHolder |
|
283 <resource: #uiAspect> |
|
284 |
|
285 bookmarkListHolder isNil ifTrue:[ |
|
286 bookmarkListHolder := List new. |
|
287 "/ if your app needs to be notified of changes, uncomment one of the lines below: |
|
288 "/ bookmarkListHolder addDependent:self. |
|
289 "/ bookmarkListHolder onChangeSend:#bookmarkListChanged to:self. |
|
290 ]. |
|
291 ^ bookmarkListHolder. |
|
292 ! |
|
293 |
|
294 downButtonEnabledHolder |
|
295 |
|
296 ^ builder valueAspectFor:#'downButtonEnabledHolder' initialValue:false |
|
297 ! |
|
298 |
|
299 removeButtonEnabledHolder |
|
300 |
|
301 ^ builder valueAspectFor:#'removeButtonEnabledHolder' initialValue:false |
|
302 ! |
|
303 |
|
304 selectedBookmarksHolder |
|
305 <resource: #uiAspect> |
|
306 |
|
307 selectedBookmarksHolder isNil ifTrue:[ |
|
308 selectedBookmarksHolder := #() asValue. |
|
309 "/ if your app needs to be notified of changes, uncomment one of the lines below: |
|
310 "/ selectedBookmarksHolder addDependent:self. |
|
311 selectedBookmarksHolder onChangeSend:#selectedBookmarksChanged to:self. |
|
312 ]. |
|
313 ^ selectedBookmarksHolder. |
|
314 ! |
|
315 |
|
316 upButtonEnabledHolder |
|
317 |
|
318 ^ builder valueAspectFor:#'upButtonEnabledHolder' initialValue:false |
|
319 ! ! |
|
320 |
|
321 !BookmarksEditDialog methodsFor:'initialize'! |
|
322 |
|
323 initialize |
|
324 |
|
325 defaultBookmark := ''. |
|
326 ^ super initialize. |
|
327 ! ! |
|
328 |
|
329 !BookmarksEditDialog methodsFor:'menu actions'! |
|
330 |
|
331 down |
|
332 |
|
333 | someBookmarks bookmarkToMove index | |
|
334 |
|
335 someBookmarks := self selectedBookmarks. |
|
336 someBookmarks size = 1 ifFalse:[^ self]. |
|
337 bookmarkToMove := someBookmarks first. |
|
338 index := self indexOfBookmark: bookmarkToMove. |
|
339 index = self bookmarkList size ifTrue:[^self]. |
|
340 self bookmarkList remove: bookmarkToMove. |
|
341 self bookmarkList add: bookmarkToMove afterIndex: index. |
|
342 self selectBookmark: bookmarkToMove. |
|
343 ! |
|
344 |
|
345 export |
|
346 |
|
347 | filename bookmarks | |
|
348 |
|
349 filename := Dialog |
|
350 requestFileName:'Select file to export bookmarks:' |
|
351 default:'.fileBrowserBookmarks' |
|
352 fromDirectory:Filename desktopDirectory. |
|
353 filename isEmptyOrNil ifTrue:[^ self]. |
|
354 |
|
355 bookmarks := self bookmarkList. |
|
356 AbstractFileBrowser saveBookmarks: bookmarks in:filename. |
|
357 ! |
|
358 |
|
359 import |
|
360 |
|
361 | answer filename bookmarksFromFile bookmarksToAdd bookmarks| |
|
362 |
|
363 answer := Dialog |
|
364 requestFileName:'Select file to import bookmarks:' |
|
365 default:'.fileBrowserBookmarks' |
|
366 fromDirectory:Filename desktopDirectory. |
|
367 |
|
368 answer isEmptyOrNil ifTrue:[^ self]. |
|
369 filename := answer asFilename. |
|
370 (filename isDirectory or:[filename exists not]) ifTrue:[^ self]. |
|
371 bookmarksFromFile := AbstractFileBrowser bookmarksFrom: filename. |
|
372 |
|
373 bookmarks := self bookmarkList. |
|
374 bookmarksToAdd := bookmarksFromFile reject:[:each | bookmarks includes: each]. |
|
375 bookmarks addAll: bookmarksToAdd. |
|
376 ! |
|
377 |
|
378 new |
|
379 |
|
380 | someBookmarks default index bookmark| |
|
381 |
|
382 someBookmarks := self selectedBookmarks. |
|
383 |
|
384 default := someBookmarks isEmpty |
|
385 ifTrue:[defaultBookmark] |
|
386 ifFalse:[someBookmarks first]. |
|
387 |
|
388 bookmark := Dialog request:'New Bookmark' title:'Enter a directory' initialAnswer:default. |
|
389 bookmark isEmptyOrNil ifTrue:[^ self]. |
|
390 (self bookmarkList includes: bookmark) ifTrue:[^ self]. |
|
391 |
|
392 index := self indexForNewBookmark. |
|
393 self bookmarkList add: bookmark afterIndex: index. |
|
394 self selectBookmark: bookmark. |
|
395 ! |
|
396 |
|
397 remove |
|
398 |
|
399 | someBookmarks message ans | |
|
400 |
|
401 someBookmarks := self selectedBookmarks. |
|
402 someBookmarks isEmpty ifTrue:[^ self]. |
|
403 |
|
404 message := 'Really remove bookmarks: ', String lf. |
|
405 someBookmarks do:[:each | message := message, String lf, (String new: 5) , each]. |
|
406 ans := Dialog confirm: message. |
|
407 ans ifFalse:[^ self]. |
|
408 |
|
409 self bookmarkList removeAll: someBookmarks. |
|
410 ! |
|
411 |
|
412 up |
|
413 |
|
414 | someBookmarks bookmarkToMove index | |
|
415 |
|
416 someBookmarks := self selectedBookmarks. |
|
417 someBookmarks size = 1 ifFalse:[^ self]. |
|
418 bookmarkToMove := someBookmarks first. |
|
419 index := self indexOfBookmark: bookmarkToMove. |
|
420 index = 1 ifTrue:[^self]. |
|
421 self bookmarkList remove: bookmarkToMove. |
|
422 self bookmarkList add: bookmarkToMove beforeIndex: index - 1. |
|
423 self selectBookmark: bookmarkToMove. |
|
424 ! ! |
|
425 |
|
426 !BookmarksEditDialog methodsFor:'queries'! |
|
427 |
|
428 hasChanges |
|
429 |
|
430 |oldDirectoryBookmarks| |
|
431 |
|
432 oldDirectoryBookmarks := AbstractFileBrowser directoryBookmarks collect:[:each | each asString]. |
|
433 ^ self bookmarkList ~= oldDirectoryBookmarks |
|
434 ! ! |
|
435 |
|
436 !BookmarksEditDialog methodsFor:'user actions'! |
|
437 |
|
438 doAccept |
|
439 |
|
440 | filenames | |
|
441 |
|
442 filenames := self bookmarkList collect:[:each | each asFilename]. |
|
443 answer := filenames. |
|
444 ^ super doAccept |
|
445 ! |
|
446 |
|
447 doCancel |
|
448 |
|
449 | ans | |
|
450 |
|
451 self hasChanges ifTrue:[ |
|
452 ans := Dialog confirm: 'Really cancel all changes?'. |
|
453 ans ifFalse:[^ self]. |
|
454 ]. |
|
455 ^ super doCancel |
|
456 ! |
|
457 |
|
458 selectedBookmarksChanged |
|
459 |
|
460 | someBookmarks selectedBookmarkIndex | |
|
461 |
|
462 someBookmarks := self selectedBookmarks. |
|
463 |
|
464 self upButtonEnabledHolder value: false. |
|
465 self downButtonEnabledHolder value: false. |
|
466 self removeButtonEnabledHolder value: false. |
|
467 |
|
468 someBookmarks isEmpty ifTrue:[^ self]. |
|
469 |
|
470 someBookmarks size = 1 ifTrue:[ |
|
471 selectedBookmarkIndex := self selectedBookmarkIndex. |
|
472 selectedBookmarkIndex = 1 ifFalse:[ |
|
473 self upButtonEnabledHolder value: true. |
|
474 ]. |
|
475 selectedBookmarkIndex = self bookmarkList size ifFalse:[ |
|
476 self downButtonEnabledHolder value: true. |
|
477 ]. |
|
478 ] ifFalse:[ |
|
479 self upButtonEnabledHolder value: false. |
|
480 self downButtonEnabledHolder value: false. |
|
481 ]. |
|
482 self removeButtonEnabledHolder value: true. |
|
483 ! ! |
|
484 |
|
485 !BookmarksEditDialog class methodsFor:'documentation'! |
|
486 |
|
487 version |
|
488 ^ '$Header: /cvs/stx/stx/libtool/BookmarksEditDialog.st,v 1.1 2008-03-12 16:38:30 fm Exp $' |
|
489 ! ! |