Index: openacs-4/packages/xowiki/tcl/includelet-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/includelet-procs.tcl,v diff -u -r1.227 -r1.228 --- openacs-4/packages/xowiki/tcl/includelet-procs.tcl 27 Jun 2018 16:12:34 -0000 1.227 +++ openacs-4/packages/xowiki/tcl/includelet-procs.tcl 11 Jul 2018 13:46:16 -0000 1.228 @@ -124,7 +124,7 @@ } # replace unwanted characters - regsub -all {[^A-Za-z0-9_:.-]} $name _ name + regsub -all {[^A-Za-z0-9_.-]} $name _ name return $name } @@ -1861,6 +1861,7 @@ {__decoration plain} {parameter_declaration { {-style ""} + {-renderer ""} {-open_page ""} {-book_mode false} {-folder_mode false} @@ -1872,6 +1873,7 @@ {-source ""} {-range ""} {-allow_reorder ""} + {-include_in_foldertree "true"} }} id } @@ -2190,6 +2192,21 @@ return $HTML } + + toc instproc render_tree {{-full false} pages} { + :get_parameters + set tree [::xowiki::Tree new -destroy_on_cleanup -orderby pos -id [:id] -verbose 1] + $tree array set open_node [array get :open_node] + $tree add_pages -full $full -remove_levels $remove_levels \ + -book_mode $book_mode -open_page $open_page \ + -owner [self] \ + $pages + + set HTML [$tree render -style ${:renderer}] + #:log "render_tree HTML => $HTML" + return $HTML + } + toc instproc parent_id {} { ${:__including_page} parent_id } @@ -2234,7 +2251,9 @@ toc instproc include_head_entries {} { switch -- ${:renderer} { - yuitree {::xowiki::Tree include_head_entries -renderer yuitree -style ${:style}} + yuitree { + ::xowiki::Tree include_head_entries -renderer yuitree -style ${:style} + } list { :get_parameters set tree_renderer [expr {$allow_reorder eq "" ? "list" : "listdnd"}] @@ -2247,47 +2266,68 @@ toc instproc initialize {} { :get_parameters array set :navigation {count 0 position 0 current ""} - set list_mode 0 - switch -- $style { - "menu" {set s "menu/"; set renderer yuitree} - "folders" {set s "folders/"; set renderer yuitree} - "list" {set s ""; set list_mode 1; set renderer list} - "none" {set s ""; set renderer none} - "default" {set s ""; set renderer yuitree} + + # + # If there is no renderer specified, determine the renderer from + # the (provided) style. When the render is explicitly specified, + # use it for rendering. + # + if {$renderer eq ""} { + switch -- $style { + "menu" {set s "menu/"; set renderer yuitree} + "folders" {set s "folders/"; set renderer yuitree} + "list" {set s ""; set list_mode 1; set renderer list} + "none" {set s ""; set renderer none} + "default" {set s ""; set renderer yuitree} + } + set :use_tree_renderer 0 + } else { + set :use_tree_renderer 1 } + + set :include_in_foldertree $include_in_foldertree set :renderer $renderer - set :style $s + set :style $style set :list_mode $list_mode set :book_mode $book_mode } toc instproc render {} { :get_parameters - if {![info exists :id]} {set :id [::xowiki::Includelet html_id [self]]} - if {[info exists category_id]} {set :category_id $category_id} + if {![info exists :id]} { + set :id [::xowiki::Includelet html_id [self]] + } + if {[info exists category_id]} { + set :category_id $category_id + } # - # Collect the pages + # Collect the pages which are either children of the page, or + # children of the parent of the page depending on "folder_mode". # set pages [:build_toc $package_id $locale $source $range] + # # Build the general navigation structure using associative arrays # :build_navigation $pages # # Call a render on the created structure # - if {[info commands ::__xowiki__MenuBar] ne ""} { + if {[info commands ::__xowiki__MenuBar] ne "" && ${:include_in_foldertree}} { ::__xowiki__MenuBar additional_sub_menu -kind folder -pages $pages -owner [self] } # # TODO: We should call here the appropriate tree-renderer instead # of the toc-specific renderers, but first we have to check, if # these are fully feature-compatible. # + if {${:renderer} eq "none"} { + } elseif {${:use_tree_renderer}} { + return [:render_tree -full 1 $pages] } elseif {${:list_mode}} { return [:render_list $pages] } else { @@ -2355,7 +2395,7 @@ selection instproc render_children {pages menu_buttons} { set output "" foreach o [$pages children] { - $o instvar page_order title page_id name title + $o instvar page_order title page_id name set level [expr {[regsub {[.]} $page_order . page_order] + 1}] set edit_markup "" set p [::xo::db::CrClass get_instance_from_db -item_id 0 -revision_id $page_id] Index: openacs-4/packages/xowiki/tcl/tree-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/tree-procs.tcl,v diff -u -r1.22 -r1.23 --- openacs-4/packages/xowiki/tcl/tree-procs.tcl 20 May 2018 11:01:57 -0000 1.22 +++ openacs-4/packages/xowiki/tcl/tree-procs.tcl 11 Jul 2018 13:46:15 -0000 1.23 @@ -16,7 +16,8 @@ Class create Tree \ -superclass ::xo::OrderedComposite \ -parameter { - {name ""} + {name ""} + {verbose 0} id } @@ -95,12 +96,14 @@ set tree(-1) [self] set :open_node($tree(-1)) 1 set pos 0 + if {${:verbose}} {:log "add_pages want to add [llength [$pages children]] pages"} foreach o [$pages children] { $o instvar page_order title name if {![regexp {^(.*)[.]([^.]+)} $page_order _ parent]} {set parent ""} set page_number [$owner page_number $page_order $remove_levels] set level [regsub -all {[.]} [$o set page_order] _ page_order_js] + if {${:verbose}} {:log "... work on [$o set page_order] level $level full $full"} if {$full || [info exists :open_node($parent)] || [info exists :open_node($page_order)]} { set href [$owner href $book_mode $name] set is_current [expr {$open_page eq $name}] @@ -110,7 +113,8 @@ -label $title -prefix $page_number -href $href \ -highlight $is_current \ -expanded $is_open \ - -open_requests 1] + -open_requests 1 \ + -verbose ${:verbose}] set tree($level) $c for {set l [expr {$level - 1}]} {![info exists tree($l)]} {incr l -1} {} $tree($l) add $c @@ -130,9 +134,14 @@ # "add_item". # Class create TreeNode -superclass Tree -parameter { - level label pos {open_requests 0} count {href ""} + level label pos + {open_requests 0} + count + {href ""} object owner li_id ul_id ul_class - {prefix ""} {expanded false} {highlight false} + {prefix ""} + {expanded false} + {highlight false} } TreeNode instproc open_tree {} { @@ -163,6 +172,7 @@ append content [:render_node -open true $cat_content] } + if {${:verbose}} {:log "TreeNode items [:isobject [self]::items] render open_requests ${:open_requests} -> $content"} return $content } @@ -306,6 +316,78 @@ } #-------------------------------------------------------------------------------- + # List-specific renderer based for bootstrap3 horizontal menu + # + # This tree renderer does not support the fancy options like + # counting, or attached items etc, but could be certainly extended + # to do so, if there is some application need. Also highlighting + # should be possible via the "open" parameter as in "list", but + # depends on the generator of the tree. + # -------------------------------------------------------------------------------- + TreeRenderer create TreeRenderer=bootstrap3horizontal \ + -superclass TreeRenderer=list + + TreeRenderer=bootstrap3horizontal instproc render_node {{-open:boolean false} cat_content} { + set label [::xowiki::Includelet html_encode ${:label}] + + if {${:level} == 0} { + # + # Top level entry: build menu-button and wrapper for dropdown menu + # + append entry \ + "" \ + [ns_quotehtml $label] \ + "" + set o_atts "class='dropdown'" + set u_atts "class='dropdown-menu'" + + } else { + # + # Lower level entry: build dropdown menu entries + # + # Probably, entries on a deeper level than 1 should be ignored + # or differently handled. + # + append entry \ + "" \ + [ns_quotehtml $label] \ + + set o_atts "" + set u_atts "" + } + if {$cat_content ne ""} { + set content "\n