home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 December / PCWorld_2000-12_cd.bin / Komunikace / Comanche / help / apacheDocGui.tcl next >
Text File  |  2000-11-02  |  6KB  |  178 lines

  1.  
  2.  
  3. package require BWidget
  4.  
  5.  
  6. namespace eval ::comanchehelp:: {
  7.     variable directivesLocation /tmp/output
  8.  
  9.     # Listbox containing directives in search section
  10.  
  11.     variable listbox 
  12.  
  13.     variable tree
  14.     variable currentHelpWindow {}
  15.     
  16. }
  17. set currentDir [file dirname [file join [pwd] [info script]]]  
  18. set ::comanchehelp::directivesLocation [file join $currentDir data/output]
  19.  
  20. # We make args the name of the window. If it is a dialog, which has a grab, we need
  21. # to make the help window a children of that dialog or we will not be able to use both
  22. # (help and dialog} at the same time
  23.  
  24. proc ::comanchehelp::getHelpWindow {{w {}}} {
  25.     variable tree
  26.     variable listBox
  27.     variable rightPaneContent
  28.     variable leftNoteBook
  29.     variable currentHelpWindow
  30.  
  31.     if [winfo exists $w.comancheHelp] {
  32.     # Its already there!
  33.     
  34.     return
  35.     } else {
  36.     destroy $currentHelpWindow
  37.     }
  38.     set currentHelpWindow $w.comancheHelp
  39.     toplevel $currentHelpWindow 
  40.     pack [label $currentHelpWindow.l -text "This online documentation is still \
  41.         alpha stage and some links may not work"] -fill x  -anchor n
  42.     set frame [frame $currentHelpWindow.frame]
  43.     set panedWindow [PanedWindow $frame.pw -side bottom]
  44.     set leftPaneFrame [$panedWindow add -minsize 100]
  45.     set rightPaneFrame [$panedWindow add]
  46.     
  47.     # We use a comanche tree that will give us three callbacks
  48.     # showMenu, populateNode (we ignore)
  49.     # nodeSelectedNotidy (we use to update right pane)
  50.     
  51.     set leftNoteBook [NoteBook $leftPaneFrame.nb]
  52.     set availableFrame [$leftNoteBook insert end available -text "Available" \
  53.         -image information]
  54.     $leftNoteBook raise available
  55.     
  56.     set tree [comancheTree ::#auto $availableFrame ::comanchehelp::processEvent]
  57.     
  58.     # This listbox will be used when being called from the outside, with several directives
  59.     
  60.     set listboxFrame [$leftNoteBook insert end search -text "Search" -image files] 
  61.     set contframe $listboxFrame
  62.     set scwin [ScrolledWindow $contframe.scwin]
  63.     set listBox [ ListBox [$scwin getframe].listbox  -multicolumn 0 \
  64.         -background white -height 8 -selectbackground DarkBlue \
  65.         -selectforeground white]
  66.     $listBox bindText <Button-1> "::comanchehelp::processEvent listBoxNodeSelected"
  67.     $listBox bindImage <Button-1> "::comanchehelp::processEvent listBoxNodeSelected"
  68.     $scwin setwidget $listBox
  69.     pack $scwin -fill both 
  70.     pack $listBox -fill both 
  71.     
  72.     # HTML. We use Comanche rightPane, we have an observer to process Signals 
  73.     # (clicking on URLs)
  74.     
  75.     $leftNoteBook compute_size
  76.     pack $leftNoteBook -expand true -fill both
  77.     set rightPaneContent [ rightPane ::#auto $rightPaneFrame ::comanchehelp::processEvent]
  78.  
  79.     pack $panedWindow -expand true -fill both
  80.     pack $frame -expand true -fill both
  81.     
  82.     ::comanchehelp::createDirectiveTree    
  83.  
  84. }
  85.  
  86. proc ::comanchehelp::processEvent {args} {
  87.     variable tree
  88.     variable nodeToModuleDirectiveMapping
  89.     variable moduleDirectiveToNodeMapping
  90.     variable listBox
  91.     set signal [lindex $args 0]
  92.     switch $signal {
  93.     nodeSelectedNotify {
  94.         set nodeSelected [lindex $args 1]
  95.         eval showDirective $nodeToModuleDirectiveMapping($nodeSelected)
  96.     } processSignal {
  97.         set type [lindex $args 1]
  98.         switch $type {
  99.         showHelp {
  100.             set module [lindex $args 2]
  101.             set directive [lindex $args 3]
  102.             $tree selectNode \
  103.                 $moduleDirectiveToNodeMapping([list $module $directive])
  104.         }
  105.         }
  106.     } listBoxNodeSelected {
  107.         set selectedNode [lindex $args 1]
  108.         $listBox selection set $selectedNode 
  109.         $tree selectNode \
  110.             $moduleDirectiveToNodeMapping([$listBox itemcget $selectedNode -data])
  111.     }
  112.     }
  113. }
  114.  
  115.  
  116.  
  117.  
  118. proc ::comanchehelp::createDirectiveTree {} {
  119.     variable nodeToModuleDirectiveMapping
  120.     variable moduleDirectiveToNodeMapping
  121.     variable directivesLocation
  122.     variable tree
  123.     foreach module [glob [file join $directivesLocation *]] {
  124.     set moduleName [file tail $module] 
  125.     if [string match $moduleName CVS] {
  126.         continue
  127.     }
  128.     set moduleNode [$tree addNode root -type container -text $moduleName \
  129.         -openImage information -closedImage information ]
  130.     set nodeToModuleDirectiveMapping($moduleNode) [list $moduleName {}]
  131.     foreach directive [glob [file join $module *]] {
  132.         if [file isfile $directive] {
  133.         set dirName [lindex [split [file tail $directive] . ] 0]
  134.         set dirNode [$tree addNode $moduleNode -type leaf -text $dirName \
  135.             -openImage files -closedImage files]
  136.         set nodeToModuleDirectiveMapping($dirNode) [list $moduleName $dirName]
  137.         set moduleDirectiveToNodeMapping([list $moduleName $dirName]) $dirNode
  138.         }
  139.     }
  140.     }
  141. }
  142.  
  143. proc ::comanchehelp::showDirective {module directive} {
  144.     variable directivesLocation
  145.     variable rightPaneContent
  146.     if [llength $directive] {
  147.     set htmlFile [file join $directivesLocation $module $directive.html]
  148.     set f [ open $htmlFile]
  149.     $rightPaneContent loadHTML [read $f]
  150.     close $f
  151.     } 
  152. }
  153.  
  154. proc ::comanchehelp::showDirectives {directiveList} {
  155.     variable listBox
  156.     variable leftNoteBook
  157.  
  158.     $listBox delete [$listBox items]
  159.     
  160.     # directive list: pairs of module/directive
  161.     
  162.     foreach dirPair $directiveList {
  163.     set module [lindex $dirPair 0]
  164.     if [string match $module coredirs] {set module core}
  165.     set directive [lindex $dirPair 1]
  166.     $listBox insert end $directive -image listicon -data [list $module $directive] \
  167.         -text $directive
  168.     #puts "ddd $module $directive"
  169.     }
  170.     $leftNoteBook raise search
  171.     $listBox selection set [lindex [$listBox items] 0 ]
  172.     processEvent listBoxNodeSelected [lindex [$listBox items] 0 ]  
  173.  
  174.  
  175.  
  176. }
  177.  
  178.