From 81febc27e10cf02aa010944d1abeec3e03b21903 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 3 Dec 2016 22:59:03 +0100 Subject: [PATCH] define the diff bindings for TimelineController - set the name field - manage a nested collection of markers All based on boilerplate code copied from my diff binding tests --- src/gui/timeline/clip-presenter.hpp | 6 +-- src/gui/timeline/marker-widget.hpp | 5 +-- src/gui/timeline/timeline-controller.cpp | 56 +++++++++--------------- src/gui/timeline/timeline-controller.hpp | 9 ++-- src/gui/timeline/track-presenter.hpp | 6 +-- 5 files changed, 33 insertions(+), 49 deletions(-) diff --git a/src/gui/timeline/clip-presenter.hpp b/src/gui/timeline/clip-presenter.hpp index 14cca339b..86876bce1 100644 --- a/src/gui/timeline/clip-presenter.hpp +++ b/src/gui/timeline/clip-presenter.hpp @@ -93,11 +93,11 @@ namespace timeline { ~ClipPresenter(); - private:/* ===== Internals ===== */ - /** set up a binding to respond to mutation messages via UiBus */ virtual void buildMutator (lib::diff::TreeMutator::Handle) override; - + + + private:/* ===== Internals ===== */ }; diff --git a/src/gui/timeline/marker-widget.hpp b/src/gui/timeline/marker-widget.hpp index 57908d9f7..1b8694197 100644 --- a/src/gui/timeline/marker-widget.hpp +++ b/src/gui/timeline/marker-widget.hpp @@ -69,11 +69,10 @@ namespace timeline { ~MarkerWidget(); - private:/* ===== Internals ===== */ - /** set up a binding to respond to mutation messages via UiBus */ virtual void buildMutator (lib::diff::TreeMutator::Handle) override; - + + private:/* ===== Internals ===== */ }; diff --git a/src/gui/timeline/timeline-controller.cpp b/src/gui/timeline/timeline-controller.cpp index 05407df91..b08b07962 100644 --- a/src/gui/timeline/timeline-controller.cpp +++ b/src/gui/timeline/timeline-controller.cpp @@ -56,6 +56,8 @@ //using util::_Fmt; using lib::diff::TreeMutator; +using lib::diff::collection; +using std::make_unique; //using std::shared_ptr; //using std::weak_ptr; //using util::contains; @@ -80,6 +82,7 @@ namespace timeline { : Controller{identity, nexus} , markers_{} , fork_{new TrackPresenter{trackID, nexus}} + , name_{identity.getSym()} // fallback initialise name from human-readable ID symbol { UNIMPLEMENTED ("how to make the controller operative..."); } @@ -93,57 +96,38 @@ namespace timeline { void TimelineController::buildMutator (TreeMutator::Handle buffer) { -#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1039 - using Attrib = std::pair; - using lib::diff::collection; + using PMarker = unique_ptr; buffer.create ( TreeMutator::build() - .attach (collection(scope) + .attach (collection(markers_) .isApplicableIf ([&](GenNode const& spec) -> bool { return spec.data.isNested(); // »Selector« : require object-like sub scope }) - .matchElement ([&](GenNode const& spec, PMockElm const& elm) -> bool + .matchElement ([&](GenNode const& spec, PMarker const& elm) -> bool { - return spec.idi == elm->getID(); + return spec.idi == ID(elm); }) - .constructFrom ([&](GenNode const& spec) -> PMockElm + .constructFrom ([&](GenNode const& spec) -> PMarker { - PMockElm child = std::make_unique(spec.idi, this->uiBus_); - return child; + return make_unique(spec.idi, this->uiBus_); }) - .buildChildMutator ([&](PMockElm& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool + .buildChildMutator ([&](PMarker& target, GenNode::ID const& subID, TreeMutator::Handle buff) -> bool { - if (target->getID() != subID) return false; //require match on already existing child object + if (ID(target) != subID) return false; //require match on already existing child object target->buildMutator (buff); // delegate to child to build nested TreeMutator return true; })) - .attach (collection(attrib) - .isApplicableIf ([&](GenNode const& spec) -> bool - { - return spec.isNamed() // »Selector« : accept attribute-like values - and not spec.data.isNested(); // but no nested objects - }) - .matchElement ([&](GenNode const& spec, Attrib const& elm) -> bool - { - return elm.first == spec.idi.getSym(); - }) - .constructFrom ([&](GenNode const& spec) -> Attrib - { - string key{spec.idi.getSym()}, - val{render(spec.data)}; - return {key, val}; - }) - .assignElement ([&](Attrib& target, GenNode const& spec) -> bool - { - string key{spec.idi.getSym()}, - newVal{render (spec.data)}; - target.second = newVal; - return true; - }))); -#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1039 - UNIMPLEMENTED ("diff mutation binding for the TimelineController"); + .change("name", [&](string val) + { + name_ = val; + }) + .mutateAttrib("fork", [&](TreeMutator::Handle buff) + { + REQUIRE (fork_); + fork_->buildMutator(buff); + })); } diff --git a/src/gui/timeline/timeline-controller.hpp b/src/gui/timeline/timeline-controller.hpp index 408279104..18db526c2 100644 --- a/src/gui/timeline/timeline-controller.hpp +++ b/src/gui/timeline/timeline-controller.hpp @@ -87,6 +87,8 @@ namespace timeline { vector> markers_; std::unique_ptr fork_; + string name_; + public: /** * @param identity used to refer to a corresponding timeline element in the Session @@ -98,6 +100,9 @@ namespace timeline { ~TimelineController(); + /** set up a binding to respond to mutation messages via UiBus */ + virtual void buildMutator (lib::diff::TreeMutator::Handle) override; + public: /* ===== Control interface ===== */ @@ -106,10 +111,6 @@ namespace timeline { private:/* ===== Events ===== */ private:/* ===== Internals ===== */ - - /** set up a binding to respond to mutation messages via UiBus */ - virtual void buildMutator (lib::diff::TreeMutator::Handle) override; - }; diff --git a/src/gui/timeline/track-presenter.hpp b/src/gui/timeline/track-presenter.hpp index b15c9ab79..41df348f5 100644 --- a/src/gui/timeline/track-presenter.hpp +++ b/src/gui/timeline/track-presenter.hpp @@ -91,11 +91,11 @@ namespace timeline { ~TrackPresenter(); - private:/* ===== Internals ===== */ - /** set up a binding to respond to mutation messages via UiBus */ virtual void buildMutator (lib::diff::TreeMutator::Handle) override; - + + + private:/* ===== Internals ===== */ };