Example #1
0
 void XMLNodeList::setElementAtPosition(double index, const XMLElement & elem)
 {
     if (size == 0)
     {
         insertAtEnd(elem);
         prevNode = parent->children;
         prev = 1;
     }
     else if (index < 1)
     {
         insertAtBeginning(elem);
     }
     else if (index > size)
     {
         insertAtEnd(elem);
     }
     else if ((int)index == index)
     {
         replaceAtIndex((int)index, elem);
     }
     else
     {
         insertAtIndex((int)index, elem);
     }
 }
void GenericMultiFieldEditor::handleListMouseClicked(MouseEventDetails* const details)
{
    if(details->getButton() == MouseEventDetails::BUTTON1 && 
       details->getClickCount() == 1 &&
       _FieldList->getIndexForDrawingSurfaceLocation(details->getLocation()) == -1)
    {
        insertAtIndex(getEditingFC(),
                      getEditingFieldId(),
                      //Size of list,
                      _FieldList->getModel()->getSize(),
                      getParentWindow()->getParentDrawingSurface(),
                      getCommandManager().get());
    }
}
void GenericMultiFieldEditor::handleInsertFCPtrDialogClosed(DialogWindowEventDetails* const details,
                                                            FieldContainer* const fc,
                                                            UInt32 fieldID,
                                                            UInt32 index,
                                                            CommandManager* cmdMgr)
{
    if(details->getOption() != DialogWindowEventDetails::DIALOG_OPTION_CANCEL)
    {
        const FieldContainerType* TheType(FieldContainerFactory::the()->findType(details->getInput().c_str()));

        if(TheType != NULL)
        {
            insertAtIndex(fc,fieldID,index,TheType,cmdMgr);
        }
    }
}
void GenericMultiFieldEditor::insertAtIndex(FieldContainer* const fc,
                                            UInt32 fieldID,
                                            UInt32 index,
                                            UIDrawingSurface* const drawingSurface,
                                            CommandManager* cmdMgr)
{
    //Is this a pointer field
    GetFieldHandlePtr TheFieldHandle(fc->getField(fieldID));
    if(TheFieldHandle->isPointerField())
    {
        //Create
        const FieldContainerType* ThePtrType(getFieldContainerTypeFromPtrType(fc->getFieldDescription(fieldID)->getFieldType().getContentType()));
        if(ThePtrType == NULL)
        {
            return;
        }

        //If the type is a node, then create a NodeCore instead
        //and then insert it as the core of a newly created node
        if(*ThePtrType == Node::getClassType())
        {
            ThePtrType = &NodeCore::getClassType();
        }

        std::vector<std::string> inputValues;
        UInt32 NumFieldContainersFound(0);
        const FieldContainerType* FoundType(NULL);
        for(UInt32 j(0) ; NumFieldContainersFound<FieldContainerFactory::the()->getNumTypes(); ++j)
        {
            FoundType = FieldContainerFactory::the()->findType(j);
            if(FoundType != NULL)
            {
                if(FoundType->isDerivedFrom(*ThePtrType)  && !FoundType->isAbstract())
                {
                    inputValues.push_back(FoundType->getName());
                }
                ++NumFieldContainersFound;
            }
        }

        if(inputValues.size() == 1)
        {
            insertAtIndex(fc,fieldID,index,FieldContainerFactory::the()->findType(inputValues[0].c_str()),cmdMgr);
        }
        else
        {
            DialogWindowRefPtr TheDialog = DialogWindow::createInputDialog("Create " + fc->getFieldDescription(fieldID)->getFieldType().getContentType().getName(),
                                                                           "Choose the type of object to create",
                                                                           DialogWindow::INPUT_COMBO,
                                                                           true,
                                                                           inputValues);
            TheDialog->connectDialogWindowClosed(boost::bind(&GenericMultiFieldEditor::handleInsertFCPtrDialogClosed,
                                                             _1,
                                                             fc,
                                                             fieldID,
                                                             index,
                                                             cmdMgr));

            Pnt2f CenteredPosition = calculateAlignment(Pnt2f(0.0f,0.0f), drawingSurface->getSize(), TheDialog->getPreferredSize(), 0.5f, 0.5f);
            TheDialog->setPosition(CenteredPosition);
            TheDialog->setAllwaysOnTop(true);
            TheDialog->setModal(true);
            TheDialog->setResizable(true);

            drawingSurface->openWindow(TheDialog);
        }
    }
    else
    {
        //Insert the default
        InsertFieldElementCommandPtr InsertIndexCommand = InsertFieldElementCommand::create(fc, fieldID, "", index);

        cmdMgr->executeCommand(InsertIndexCommand);
    }
}