69 top := StandardSystemView new label:'select'; extent:300@500. |
69 top := StandardSystemView new label:'select'; extent:300@500. |
70 scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
70 scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
71 scr := scr scrolledView. |
71 scr := scr scrolledView. |
72 |
72 |
73 scr directory:Filename currentDirectory. |
73 scr directory:Filename currentDirectory. |
|
74 |
|
75 scr action:[:anIndex| Transcript showCR:anIndex. |
|
76 Transcript showCR:scr selectedPathname. |
|
77 ]. |
|
78 top open |
|
79 [exEnd] |
|
80 |
|
81 |
|
82 open a FileSelectionTree useing a model |
|
83 [exBegin] |
|
84 |top scr model| |
|
85 |
|
86 top := StandardSystemView new label:'select'; extent:300@500. |
|
87 scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
88 scr := scr scrolledView. |
|
89 model := (Filename currentDirectory asString) asValue. |
|
90 scr rootHolder:model. |
|
91 model inspect. |
|
92 |
|
93 scr action:[:anIndex| Transcript showCR:anIndex. |
|
94 Transcript showCR:scr selectedPathname. |
|
95 ]. |
|
96 top open |
|
97 [exEnd] |
|
98 |
|
99 |
|
100 [exBegin] |
|
101 |top scr| |
|
102 |
|
103 top := StandardSystemView new label:'select'; extent:300@500. |
|
104 scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
105 scr := scr scrolledView. |
|
106 |
|
107 scr directory:Filename currentDirectory. |
|
108 scr selectionHolder:nil asValue. |
|
109 scr selectionHolder inspect. |
|
110 scr multipleSelectOk:true. |
74 |
111 |
75 scr action:[:anIndex| Transcript showCR:anIndex. |
112 scr action:[:anIndex| Transcript showCR:anIndex. |
76 Transcript showCR:scr selectedPathname. |
113 Transcript showCR:scr selectedPathname. |
77 ]. |
114 ]. |
78 top open |
115 top open |
246 ]. |
283 ]. |
247 top open |
284 top open |
248 [exEnd] |
285 [exEnd] |
249 " |
286 " |
250 |
287 |
|
288 ! |
|
289 |
|
290 test |
|
291 |top scr| |
|
292 |
|
293 top := StandardSystemView new label:'select'; extent:300@500. |
|
294 scr := HVScrollableView for:FileSelectionTree origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
295 scr := scr scrolledView. |
|
296 |
|
297 scr directory:Filename currentDirectory. |
|
298 scr selectionHolder:nil asValue. |
|
299 scr selectionHolder inspect. |
|
300 scr multipleSelectOk:true. |
|
301 |
|
302 scr action:[:anIndex| Transcript showCR:anIndex. |
|
303 Transcript showCR:scr selectedPathname. |
|
304 ]. |
|
305 top open |
251 ! ! |
306 ! ! |
252 |
307 |
253 !FileSelectionTree methodsFor:'accessing'! |
308 !FileSelectionTree methodsFor:'accessing'! |
254 |
309 |
255 changeDirectory:aPathname |
310 changeDirectory:aPathname |
408 "setup my model and set the default path to the current directory; on default |
463 "setup my model and set the default path to the current directory; on default |
409 multiple selection is disabled. |
464 multiple selection is disabled. |
410 " |
465 " |
411 super initialize. |
466 super initialize. |
412 itemClass := FileSelectionItem. |
467 itemClass := FileSelectionItem. |
413 self model:(SelectionInTree new). |
468 |
414 |
469 ! ! |
|
470 |
|
471 !FileSelectionTree methodsFor:'model'! |
|
472 |
|
473 rootFromModel |
|
474 "update hierarchical list from root model |
|
475 " |
|
476 |oldPath newPath| |
|
477 |
|
478 (newPath := rootHolder value) notNil ifTrue:[ |
|
479 newPath := newPath asString. |
|
480 ]. |
|
481 |
|
482 self directory = newPath ifFalse:[ |
|
483 self changeDirectory:newPath |
|
484 ] |
|
485 ! |
|
486 |
|
487 selectionFromModel |
|
488 "set the selection derived from the selectionHolder |
|
489 " |
|
490 |selection value shown| |
|
491 |
|
492 selectionHolder isNil ifTrue:[ |
|
493 ^ self |
|
494 ]. |
|
495 |
|
496 value := selectionHolder value. |
|
497 |
|
498 multipleSelectOk ifFalse:[ |
|
499 value isNil ifTrue:[ |
|
500 self deselect |
|
501 ] ifFalse:[ |
|
502 value asFilename exists ifFalse:[ |
|
503 selectionHolder value:nil |
|
504 ] ifTrue:[ |
|
505 self selectPathname:value |
|
506 ] |
|
507 ]. |
|
508 ^ self |
|
509 ]. |
|
510 |
|
511 value size == 0 ifTrue:[ |
|
512 ^ self deselect |
|
513 ]. |
|
514 |
|
515 selection := value select:[:aPath| aPath asFilename exists ]. |
|
516 |
|
517 selection size ~~ value size ifTrue:[ |
|
518 selection size ~~ 0 ifTrue:[selectionHolder value:selection] |
|
519 ifFalse:[selectionHolder value:nil]. |
|
520 ^ self |
|
521 ]. |
|
522 |
|
523 selection size == 1 ifTrue:[ |
|
524 ^ self selectPathname:(selection first) |
|
525 ]. |
|
526 shown := true. |
|
527 |
|
528 selection do:[:el|(self showFile:el) ifFalse:[shown := false]]. |
|
529 |
|
530 shown ifFalse:[ |
|
531 model recomputeList. |
|
532 ]. |
|
533 |
|
534 selection := selection collect:[:el| |
|
535 listOfNodes findFirst:[:n| n pathName = el] |
|
536 ]. |
|
537 super selection:selection. |
|
538 |
|
539 ! |
|
540 |
|
541 selectionToModel |
|
542 "write selection to selection holder |
|
543 " |
|
544 |old new| |
|
545 |
|
546 old := selectionHolder value. |
|
547 |
|
548 multipleSelectOk ifFalse:[ |
|
549 (new := self pathnameAtIndex:selection) = old ifFalse:[ |
|
550 selectionHolder value:new |
|
551 ] |
|
552 ] ifTrue:[ |
|
553 self numberOfSelections == 0 ifTrue:[ |
|
554 old size ~~ 0 ifTrue:[ |
|
555 selectionHolder value:nil |
|
556 ] |
|
557 ] ifFalse:[ |
|
558 new := selection collect:[:i|(listOfNodes at:i) pathName]. |
|
559 |
|
560 new size ~~ old size ifTrue:[ |
|
561 selectionHolder value:new |
|
562 ] ifFalse:[ |
|
563 new do:[:pN| |
|
564 (old findFirst:[:pO| pO = pN]) == 0 ifTrue:[ |
|
565 ^ selectionHolder value:new |
|
566 ] |
|
567 ] |
|
568 ] |
|
569 ] |
|
570 ] |
|
571 |
|
572 ! ! |
|
573 |
|
574 !FileSelectionTree methodsFor:'private'! |
|
575 |
|
576 showFile:aPathname |
|
577 "show a file |
|
578 " |
|
579 |components path root node shown| |
|
580 |
|
581 path := aPathname asString. |
|
582 root := self directory. |
|
583 shown := true. |
|
584 |
|
585 (path startsWith:root) ifFalse:[ |
|
586 self error. |
|
587 ^ shown |
|
588 ]. |
|
589 |
|
590 path size <= (root size + 2) ifTrue:[^ shown]. |
|
591 path := path copyFrom:(root size + 2). |
|
592 |
|
593 components := Filename components:path. |
|
594 node := model root. |
|
595 |
|
596 components do:[:el||next| |
|
597 next := node detectChild:[:e|e name = el]. |
|
598 next isNil ifTrue:[ |
|
599 self error. |
|
600 ^ shown |
|
601 ]. |
|
602 node hidden ifTrue:[ |
|
603 node expand. |
|
604 shown := false. |
|
605 ]. |
|
606 node := next. |
|
607 ]. |
|
608 ^ shown |
415 ! ! |
609 ! ! |
416 |
610 |
417 !FileSelectionTree methodsFor:'selection'! |
611 !FileSelectionTree methodsFor:'selection'! |
418 |
612 |
419 selectPathname:aPath |
613 selectPathname:aPath |