Revision: 44835
          http://brlcad.svn.sourceforge.net/brlcad/?rev=44835&view=rev
Author:   bhinesley
Date:     2011-06-08 22:29:12 +0000 (Wed, 08 Jun 2011)

Log Message:
-----------
ManBrowser is now ready to be used by Archer and MGED

Added -disabledPages and -enabledPages to give more control over which commands 
are displayed. 

Configured constructor to call configbody's with blank args if user didn't 
configure public variables, in order to trigger defaults.

Removed \"get\" method, as it doesn't appear to be necessary the way things are 
done now. 

Renamed cmd/commands etc. variable name components to page/pages, since they're 
not necessarily commands (ex: Introduction.html).

Changed regex uses to \[file\] commands.

The select method now returns boolean result to reflect failure

Modified Paths:
--------------
    brlcad/trunk/src/tclscripts/archer/Archer.tcl
    brlcad/trunk/src/tclscripts/man_browser.tcl

Modified: brlcad/trunk/src/tclscripts/archer/Archer.tcl
===================================================================
--- brlcad/trunk/src/tclscripts/archer/Archer.tcl       2011-06-08 21:51:19 UTC 
(rev 44834)
+++ brlcad/trunk/src/tclscripts/archer/Archer.tcl       2011-06-08 22:29:12 UTC 
(rev 44835)
@@ -3269,8 +3269,11 @@
 
 ::itcl::body Archer::buildarcherMan {} {
     # Testing ManBrowser mega-widget
-    #set asdf [ManBrowser $itk_interior.archerMan2 Archer]
-    #return "testing"
+    #set disabledPages [list journal oed rcc-blend rcc-cap rcc-tor rcc-tgc 
reset status ill sill rot orot rotobj qorot mrot vrot]
+    #set archerMan [ManBrowser $itk_interior.archerMan2 -parentName Archer \
+                   -disabledPages $disabledPages]
+    #$archerMan activate
+    #puts "selecing make: [$archerMan select make]"
 
 
 

Modified: brlcad/trunk/src/tclscripts/man_browser.tcl
===================================================================
--- brlcad/trunk/src/tclscripts/man_browser.tcl 2011-06-08 21:51:19 UTC (rev 
44834)
+++ brlcad/trunk/src/tclscripts/man_browser.tcl 2011-06-08 22:29:12 UTC (rev 
44835)
@@ -23,11 +23,8 @@
 #    Man page browser
 #
 # To do:
-#    -Get it working!
-#    -Add method for disabling a list of commands passed in
-#    -While we're at it, add method for enabling only commands passed in
+#    -Add ability to add >1 path (like {{mann/en/} {man/en/archer}}
 #    -Add method for retrieving the list of commands
-#    -Add ability to add >1 path (like {{mann/en/} {man/en/archer}}
 #    -Document the interface
 #    -Resizing window could be improved (i.e. limited).
 #    -It would be nice if clicking html text would bring you to
@@ -44,15 +41,16 @@
     public {   
        variable path
        variable parentName
+       variable disabledPages
+       variable enabledPages
 
-       method get              {option}        
-        method setCmdNames     {}
+        method setPageNames    {}
        method loadPage         {pageName}
-       method select           {cmdName}
+       method select           {pageName}
     }
  
     private {
-       common commands [list]
+       common pages [list]
        variable pageData
     }
 
@@ -72,30 +70,65 @@
     configure -title "[string trim $parentName] Manual Page Browser"
 }
 
-::itcl::body ManBrowser::get {option} {
-    switch -- $option {
-       #path {if {[info exists path]} {return $path}}
+::itcl::configbody ManBrowser::disabledPages {
+    # Page names added to this list are always disabled
+    set disabledByDefault [list Introduction]
+
+    if {![info exists disabledPages] || ![string is list $disabledPages]} {
+       set disabledPages $disabledByDefault
+    } else {
+       lappend disabledPages $disabledByDefault
     }
-    error "bad option \"$option\""
+    set disabledPages [lsort $disabledPages]
+
+    # Reset pages list
+    if {[info exists pages] && $pages != {}} {
+       setPageNames
+    }
 }
 
-::itcl::body ManBrowser::setCmdNames {} {
+::itcl::configbody ManBrowser::enabledPages {
+    if {![info exists enabledPages] || ![string is list $enabledPages]} {
+       set enabledPages [list]
+    }
+    set enabledPages [lsort $enabledPages]
+
+    # Reset pages list
+    if {[info exists pages] && $pages != {}} {
+       setPageNames
+    }
+}
+
+::itcl::body ManBrowser::setPageNames {} {
     set manFiles [glob -directory $path *.html ]
+
+    set pages [list]
     foreach manFile $manFiles {
-        # FIXME: should use [file rootname], etc rather than regexp
-        # FIXME: string comparison with Introduction should be removed in favor
-        #        of a mechanism for excluding a list of rootnames (commands)
-       regexp {(.+/)(.+)(.html)} $manFile -> url rootName htmlSuffix
-       if {[string compare $rootName Introduction]} {
-           set commands [concat $commands [list $rootName]]
+       set rootName [file rootname [file tail $manFile]]
+
+       # If the page exists in disabledPages, disable it 
+       set isDisabled [expr [lsearch -sorted -exact \
+                             $disabledPages $rootName] != -1]
+
+       # If enabledPages is defined and the page exists, enable it
+       if {$enabledPages != {}} {
+           set isEnabled [expr [lsearch -sorted -exact \
+                                $enabledPages $rootName] != -1]
+       } else {
+           set isEnabled 1
        }
+
+       # Obviously, if the page is both disabled/enabled, it will be disabled
+       if {!$isDisabled && $isEnabled} {
+           lappend pages $rootName
+       }
     }
-    set commands [lsort $commands]
+    set pages [lsort $pages]
 }
 
-::itcl::body ManBrowser::select {cmdName} {
+::itcl::body ManBrowser::select {pageName} {
     # Select the requested man page 
-    set idx [lsearch -sorted -exact $commands $cmdName]
+    set idx [lsearch -sorted -exact $pages $pageName]
 
     if {$idx != -1} {
         set result True
@@ -104,17 +137,17 @@
        # Deselect previous selection
        $toc selection clear 0 [$toc index end]
 
-        # Select cmdName in table of contents
+        # Select pageName in table of contents
        $toc selection set $idx
        $toc activate $idx
        $toc see $idx
 
-       loadPage $cmdName
+       loadPage $pageName
     } else {
        set result False
     }
     
-    return result
+    return $result
 }
 
 ::itcl::body ManBrowser::loadPage {pageName} {
@@ -132,10 +165,16 @@
 }
 
 ::itcl::body ManBrowser::constructor {args} {
-    # Set default path if user didn't pass one
-    set path [file join [bu_brlcad_data "html"] mann en]
-    #if {![info exists path]} {configure -path {}}
+    eval itk_initialize $args
 
+    # Trigger configbody defaults if user didn't pass them
+    set opts {{path} {parentName} {disabledPages} {enabledPages}}
+    foreach o $opts {
+       if {![info exists $o]} {eval itk_initialize {-$o {}}}
+    }
+
+    setPageNames
+    
     $this hide 1
     $this hide 2
     $this hide 3
@@ -167,9 +206,12 @@
         ::ttk::scrollbar $toc.toc_scrollbar
     } {}
 
-    setCmdNames
     itk_component add toc_listbox {
-        ::tk::listbox $toc.toc_listbox -bd 2 -width 16 -exportselection false 
-yscroll "$toc.toc_scrollbar set" -listvariable [scope commands]
+        ::tk::listbox $toc.toc_listbox -bd 2 \
+                                      -width 16 \
+                                       -exportselection false \
+                                      -yscroll "$toc.toc_scrollbar set" \
+                                      -listvariable [scope pages]
     } {}
 
     $toc.toc_scrollbar configure -command "$toc.toc_listbox yview"
@@ -199,11 +241,11 @@
 
     pack $itk_component(browser) -side left -expand yes -fill both
 
-    # Load Introduction.html if it's there, otherwise load first command
+    # Load Introduction.html if it's there, otherwise load first page
     if {[file exists [file join $path Introduction.html]]} {
         loadPage Introduction
     } else {
-        loadPage [lindex $commands 0]
+        loadPage [lindex $pages 0]
     }
 
     bind $toc.toc_listbox <<ListboxSelect>> {
@@ -211,10 +253,9 @@
        $mb loadPage [%W get [%W curselection]]
     }
 
-    center [namespace tail $this]
-    ::update
+    #center [namespace tail $this]
+    #::update
 
-    eval itk_initialize $args
     configure -height 600 -width 800
     return $this
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to