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
This commit is contained in:
Fischlurch 2016-12-03 22:59:03 +01:00
parent c5eff7f4c5
commit 81febc27e1
5 changed files with 33 additions and 49 deletions

View file

@ -93,11 +93,11 @@ namespace timeline {
~ClipPresenter(); ~ClipPresenter();
private:/* ===== Internals ===== */
/** set up a binding to respond to mutation messages via UiBus */ /** set up a binding to respond to mutation messages via UiBus */
virtual void buildMutator (lib::diff::TreeMutator::Handle) override; virtual void buildMutator (lib::diff::TreeMutator::Handle) override;
private:/* ===== Internals ===== */
}; };

View file

@ -69,11 +69,10 @@ namespace timeline {
~MarkerWidget(); ~MarkerWidget();
private:/* ===== Internals ===== */
/** set up a binding to respond to mutation messages via UiBus */ /** set up a binding to respond to mutation messages via UiBus */
virtual void buildMutator (lib::diff::TreeMutator::Handle) override; virtual void buildMutator (lib::diff::TreeMutator::Handle) override;
private:/* ===== Internals ===== */
}; };

View file

@ -56,6 +56,8 @@
//using util::_Fmt; //using util::_Fmt;
using lib::diff::TreeMutator; using lib::diff::TreeMutator;
using lib::diff::collection;
using std::make_unique;
//using std::shared_ptr; //using std::shared_ptr;
//using std::weak_ptr; //using std::weak_ptr;
//using util::contains; //using util::contains;
@ -80,6 +82,7 @@ namespace timeline {
: Controller{identity, nexus} : Controller{identity, nexus}
, markers_{} , markers_{}
, fork_{new TrackPresenter{trackID, nexus}} , fork_{new TrackPresenter{trackID, nexus}}
, name_{identity.getSym()} // fallback initialise name from human-readable ID symbol
{ {
UNIMPLEMENTED ("how to make the controller operative..."); UNIMPLEMENTED ("how to make the controller operative...");
} }
@ -93,57 +96,38 @@ namespace timeline {
void void
TimelineController::buildMutator (TreeMutator::Handle buffer) TimelineController::buildMutator (TreeMutator::Handle buffer)
{ {
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1039 using PMarker = unique_ptr<MarkerWidget>;
using Attrib = std::pair<const string,string>;
using lib::diff::collection;
buffer.create ( buffer.create (
TreeMutator::build() TreeMutator::build()
.attach (collection(scope) .attach (collection(markers_)
.isApplicableIf ([&](GenNode const& spec) -> bool .isApplicableIf ([&](GenNode const& spec) -> bool
{ {
return spec.data.isNested(); // »Selector« : require object-like sub scope 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<MockElm>(spec.idi, this->uiBus_); return make_unique<MarkerWidget>(spec.idi, this->uiBus_);
return child;
}) })
.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 target->buildMutator (buff); // delegate to child to build nested TreeMutator
return true; return true;
})) }))
.attach (collection(attrib) .change("name", [&](string val)
.isApplicableIf ([&](GenNode const& spec) -> bool {
{ name_ = val;
return spec.isNamed() // »Selector« : accept attribute-like values })
and not spec.data.isNested(); // but no nested objects .mutateAttrib("fork", [&](TreeMutator::Handle buff)
}) {
.matchElement ([&](GenNode const& spec, Attrib const& elm) -> bool REQUIRE (fork_);
{ fork_->buildMutator(buff);
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");
} }

View file

@ -87,6 +87,8 @@ namespace timeline {
vector<unique_ptr<MarkerWidget>> markers_; vector<unique_ptr<MarkerWidget>> markers_;
std::unique_ptr<TrackPresenter> fork_; std::unique_ptr<TrackPresenter> fork_;
string name_;
public: public:
/** /**
* @param identity used to refer to a corresponding timeline element in the Session * @param identity used to refer to a corresponding timeline element in the Session
@ -98,6 +100,9 @@ namespace timeline {
~TimelineController(); ~TimelineController();
/** set up a binding to respond to mutation messages via UiBus */
virtual void buildMutator (lib::diff::TreeMutator::Handle) override;
public: /* ===== Control interface ===== */ public: /* ===== Control interface ===== */
@ -106,10 +111,6 @@ namespace timeline {
private:/* ===== Events ===== */ private:/* ===== Events ===== */
private:/* ===== Internals ===== */ private:/* ===== Internals ===== */
/** set up a binding to respond to mutation messages via UiBus */
virtual void buildMutator (lib::diff::TreeMutator::Handle) override;
}; };

View file

@ -91,11 +91,11 @@ namespace timeline {
~TrackPresenter(); ~TrackPresenter();
private:/* ===== Internals ===== */
/** set up a binding to respond to mutation messages via UiBus */ /** set up a binding to respond to mutation messages via UiBus */
virtual void buildMutator (lib::diff::TreeMutator::Handle) override; virtual void buildMutator (lib::diff::TreeMutator::Handle) override;
private:/* ===== Internals ===== */
}; };