Example #1
0
void NIBWriter::ExportController(const char *controllerId)
{
    char szFilename[255];

    XIBObject* controller = XIBObject::findReference(controllerId);
    UIViewController* uiViewController = dynamic_cast<UIViewController*>(controller);
    if (!uiViewController) {
        //object isn't really a controller
        printf("Object %s is not a controller\n", controller->stringValue());
        return;
    }

    const char* controllerIdentifier = uiViewController->_storyboardIdentifier;
    if (controllerIdentifier == NULL) {
        //not all viewcontrollers will have a storyboard identifier. If they don't use the controller Id for the key.
        controllerIdentifier = controllerId;
    }

    //  Check if we've already written out the controller
    if (_g_exportedControllers.find(controllerId) != _g_exportedControllers.end()) {
        return;
    }

    sprintf(szFilename, "%s.nib", controllerIdentifier);

    _g_exportedControllers[controllerIdentifier] = controllerIdentifier;

    XIBArray *objects = (XIBArray *) controller->_parent;

    printf("Writing %s\n", GetOutputFilename(szFilename).c_str());
    FILE *fpOut = fopen(GetOutputFilename(szFilename).c_str(), "wb");

    NIBWriter *writer = new NIBWriter(fpOut, NULL, NULL);

    XIBObject *firstResponderProxy = writer->AddProxy("IBFirstResponder");
    XIBObject *ownerProxy = writer->AddProxy("IBFilesOwner");
    XIBObject *storyboard = writer->AddProxy("UIStoryboardPlaceholder");

    XIBArray *arr = (XIBArray *) objects;
    for ( int i = 0; i < arr->count(); i ++ ) {
        XIBObject *curObj = arr->objectAtIndex(i);

        writer->ExportObject(curObj);
        if ( curObj->getAttrib("sceneMemberID") ) {
            if ( strcmp(curObj->getAttrib("sceneMemberID"), "viewController") == 0 ) {
                writer->AddOutletConnection(ownerProxy, curObj, "sceneViewController");
            }
        }
    }

    writer->WriteObjects();

    fclose(fpOut);
}
Example #2
0
void NIBWriter::ExportController(const char *controllerId)
{
    static std::vector<char *> _exportedControllers;

    for ( std::vector<char *>::iterator cur = _exportedControllers.begin(); cur != _exportedControllers.end(); cur ++ ) {
        if ( strcmp(*cur, controllerId) == 0 ) {
            return;
        }
    }
    _exportedControllers.push_back(strdup(controllerId));
    XIBObject *controller = XIBObject::findReference(controllerId);
    XIBArray *objects = (XIBArray *) controller->_parent;

    char szFilename[255];
    sprintf(szFilename, "UIViewController-%s.nib", controllerId);   
    printf("Writing %s\n", szFilename);
    FILE *fpOut = fopen(szFilename, "wb");

    NIBWriter *writer = new NIBWriter(fpOut, NULL, NULL);

    XIBObject *firstResponderProxy = writer->AddProxy("IBFirstResponder");
    XIBObject *ownerProxy = writer->AddProxy("IBFilesOwner");
    XIBObject *storyboard = writer->AddProxy("UIStoryboardPlaceholder");

    XIBArray *arr = (XIBArray *) objects;
    for ( int i = 0; i < arr->count(); i ++ ) {
        XIBObject *curObj = arr->objectAtIndex(i);

        writer->ExportObject(curObj);
        if ( curObj->getAttrib("sceneMemberID") ) {
            if ( strcmp(curObj->getAttrib("sceneMemberID"), "viewController") == 0 ) {
                writer->AddOutletConnection(ownerProxy, curObj, "sceneViewController");
            }
        }
    }

    writer->WriteObjects();

    fclose(fpOut);
}
Example #3
0
void UIViewController::ConvertStaticMappings(NIBWriter *writer, XIBObject *obj)
{
    Map(writer, obj, propertyMappings, numPropertyMappings);

    XIBArray *segueTemplates = new XIBArray();

    if ( _tabBarItem ) AddOutputMember(writer, "UITabBarItem", _tabBarItem);
    if ( _navigationItem ) AddOutputMember(writer, "UINavigationItem", _navigationItem);
    if ( !_resizesToFullSize ) AddBool(writer, "UIAutoresizesArchivedViewToFullSize", _resizesToFullSize);
    if ( _view ) {
        if ( !_isStory ) {
            AddOutputMember(writer, "UIView", _view);
        } else {
            ScanForSegues(segueTemplates, this);

            XIBDictionary *externalObjects = new XIBDictionary();

            char szNibName[255];

            sprintf(szNibName, "%s-view-%s", _id, _view->_id);
            AddString(writer, "UINibName", szNibName);

            char szOutputName[255];
            sprintf(szOutputName, "%s.nib", szNibName);
            printf("Writing %s\n", GetOutputFilename(szOutputName).c_str());
            FILE *fpOut = fopen(GetOutputFilename(szOutputName).c_str(), "wb");
    
            NIBWriter *viewWriter = new NIBWriter(fpOut, externalObjects, _view);
            viewWriter->ExportObject(_view);

            XIBObject *ownerProxy = viewWriter->AddProxy("IBFilesOwner");
            viewWriter->_topObjects->AddMember(NULL, ownerProxy);
            XIBObject *firstResponderProxy = viewWriter->AddProxy("IBFirstResponder");
            viewWriter->_topObjects->AddMember(NULL, firstResponderProxy);

            //  Add view connection
            viewWriter->AddOutletConnection(ownerProxy, _view, "view");

            viewWriter->WriteObjects();
            fclose(fpOut);

            if ( externalObjects->_members.size() > 1 ) AddOutputMember(writer, "UIExternalObjectsTableForViewLoading", externalObjects);
        }
    }
    if ( _parentViewController ) {
        AddOutputMember(writer, "UIParentViewController", _parentViewController);
    }
    if ( _isStory ) {
        XIBObject *storyboard = writer->AddProxy("UIStoryboardPlaceholder");
        writer->AddOutletConnection(this, storyboard, "storyboard");
        
        for ( int i = 0; i < segueTemplates->count(); i ++ ) {
            UIStoryboardSegue *curSegue = (UIStoryboardSegue *) segueTemplates->objectAtIndex(i);

            writer->AddOutletConnection(curSegue, this, "viewController");
        }
        if ( segueTemplates->count() > 0 ) {
            AddOutputMember(writer, "UIStoryboardSegueTemplates", segueTemplates);

            for ( int i = 0; i < segueTemplates->count(); i ++ ) {
                UIStoryboardSegue *curSegue = (UIStoryboardSegue *) segueTemplates->objectAtIndex(i);

                NIBWriter::ExportController(curSegue->getAttrib("destination"));
            }
        }
    }
    if ( _childViewControllers->count() > 0 ) {
        AddOutputMember(writer, "UIChildViewControllers", _childViewControllers);
    }
    if ( _viewControllers->count() > 0 ) {
        AddOutputMember(writer, "UIViewControllers", _viewControllers);
    }
    ObjectConverterSwapper::ConvertStaticMappings(writer, obj);
}