From a47fb5a9cd62a08eba860a8b5b89002ac75e7fe9 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Thu, 27 Oct 2016 19:26:10 +1100 Subject: [PATCH] Tree View Node: implement recursive fold and unfold --- src/gui/widgets/tree_view_node.cpp | 16 ++++++++++++++-- src/gui/widgets/tree_view_node.hpp | 22 ++++++++++++---------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/gui/widgets/tree_view_node.cpp b/src/gui/widgets/tree_view_node.cpp index 55c2ef238aa9..0c1e044dde4e 100644 --- a/src/gui/widgets/tree_view_node.cpp +++ b/src/gui/widgets/tree_view_node.cpp @@ -229,7 +229,7 @@ bool ttree_view_node::is_folded() const return !unfolded_; } -void ttree_view_node::fold(/*const bool recursive*/) +void ttree_view_node::fold(const bool recursive) { if(!is_folded()) { fold_internal(); @@ -237,9 +237,15 @@ void ttree_view_node::fold(/*const bool recursive*/) toggle_->set_value(false); } } + + if(recursive) { + for(auto& child_node : children_) { + child_node.fold(true); + } + } } -void ttree_view_node::unfold(/*const texpand_mode mode*/) +void ttree_view_node::unfold(const bool recursive) { if(is_folded()) { unfold_internal(); @@ -247,6 +253,12 @@ void ttree_view_node::unfold(/*const texpand_mode mode*/) toggle_->set_value(true); } } + + if(recursive) { + for(auto& child_node : children_) { + child_node.unfold(true); + } + } } void ttree_view_node::fold_internal() diff --git a/src/gui/widgets/tree_view_node.hpp b/src/gui/widgets/tree_view_node.hpp index e9a9883ee257..58059828d649 100644 --- a/src/gui/widgets/tree_view_node.hpp +++ b/src/gui/widgets/tree_view_node.hpp @@ -117,19 +117,16 @@ class ttree_view_node : public twidget bool is_folded() const; #if 0 - enum texpand_mode - { - recursive_restore // recursively restores collapse mode - , recursive_expand // recursively expands the children - , not_recursive + // TODO: implement if different expand modes become necessary + enum texpand_mode { + recursive_restore, // recursively restores collapse mode + recursive_expand, // recursively expands the children + not_recursive }; #endif - // If recursive all children will be closed recursively causing - // restore expaning not to expand anything - // TODO: ^ implement - void fold(/*const bool recursive*/); - void unfold(/*const texpand_mode mode*/); + void fold(const bool recursive = false); + void unfold(const bool recursive = false); /** * See @ref twidget::create_walker. @@ -141,6 +138,11 @@ class ttree_view_node : public twidget return new gui2::iterator::ttree_node(*this, children_); } + boost::ptr_vector& children() + { + return children_; + } + /** See @ref twidget::find_at. */ virtual twidget* find_at(const tpoint& coordinate, const bool must_be_active) override;