Flip BabyStep Tutorial

 

BabyStep 1: Binding Flip

This chapter will be our first modification of the code exposed in BabyStep 0: Starting Point . Here we will bind flip with our code, so that flip can be used in our application.

Adding a Document

BabystepGui.h

First, we are going to add a document to our application. The document is a flip class that will actually store, manage and own our data model. In the BabystepGui.h we will add the following lines :

ListingModifying BabystepGui.h

/*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
#include "ModelRoot.h"                                   // 1.
#include "ohm/flip/DocumentObserver.h"                   // 2.
#include "ohm/flip/DocumentLocal.h"                      // 3.
#include "ohm/opa/ApplicationWindowSimple.h"
class BabystepGui
:  public ohm::flip::DocumentObserver <ModelRoot>        // 4.
{
/*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
public:
                  BabystepGui (ohm::opa::ApplicationWindowSimple & window);
   virtual        ~BabystepGui ();
   // ohm::flip::DocumentObserver <ModelRoot>            // 5.
   virtual void   document_changed (ModelRoot & root);
   virtual void   signal (ohm::flip::Object * obj_ptr, ohm::archi::UInt32 type, const ohm::flip::DataMaster & signal_data);
/*\\\ PROTECTED \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
protected:
/*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
private:
   ohm::opa::ApplicationWindowSimple &
                  _window;
   ohm::flip::DocumentLocal
                  _document_local;                       // 6.
}; // class BabystepGui
  1. include the ModelRoot class...
  2. ... as well as the DocumentObserver : this will allow BabystepGui to act as a view of the model
  3. include the basic document
  4. enable the BabystepGui to be a view of the document model...
  5. ...by implementing the two functions document_changed and signal defined as pure virtual in DocumentObserver
  6. add the flip managed document itself

BabystepGui.cpp

Then we are going to change the definition file to reflect the changes we made in the header.

ListingModifying BabystepGui.cpp

/*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
#include "BabystepGui.h"
/*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
BabystepGui::BabystepGui (ohm::opa::ApplicationWindowSimple & window)
:  _window (window)
,  _document_local (*this)                                  // 1.
{
   _document_local.init (window.get ("--document_path"));   // 2.
   _window.bind_pre_post_ui <                               // 3.
      ohm::flip::DocumentLocal,
      &ohm::flip::DocumentLocal::notify_pre_user_inputs_tasks,
      &ohm::flip::DocumentLocal::notify_post_user_inputs_tasks
   > (_document_local);
}
BabystepGui::~BabystepGui ()
{
}
void  BabystepGui::document_changed (ModelRoot & root)
{
}
void  BabystepGui::signal (ohm::flip::Object * obj_ptr, ohm::archi::UInt32 type, const ohm::flip::DataMaster & signal_data)
{
}
  1. bind the document to our observer
  2. and tell the document where to read/write its file. window.get will fetch the launch arguments to retrieve the document path
  3. bind the window to the document to notify it when a potential user input will begins and ends

In this program, the executable will be launched like this :

babystep --document_path /Users/me/Documents/babystep.odf

The first time the program is launched it will automatically create the babystep.odf document on quit. The next time the program will be launched, it will read the babystep.odf document on launch, and will write it on quit.

Now that a flip document has been created for our application, we need to add it some objects for it to be useful.