diff --git a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp index 3ecc73045..1114d339b 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -470,6 +470,19 @@ namespace GeorgesQt m_ui.treeView->setCurrentIndex( idx ); } + void CGeorgesTreeViewDialog::onAppendArray() + { + QModelIndex idx = m_ui.treeView->currentIndex(); + + m_model->appendArray( idx ); + + m_ui.treeView->reset(); + m_ui.treeView->expandAll(); + + m_ui.treeView->setCurrentIndex( idx ); + m_browserCtrl->clicked( idx ); + } + void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event) { Q_EMIT closing(); @@ -523,7 +536,8 @@ namespace GeorgesQt // } if(item->isArray()) { - contextMenu.addAction("Append array entry..."); + QAction *appendAction = contextMenu.addAction("Append array entry..."); + connect( appendAction, SIGNAL( triggered( bool ) ), this, SLOT( onAppendArray() ) ); } else if(item->isArrayMember()) { @@ -558,24 +572,10 @@ namespace GeorgesQt // else if(item->getFormElm()->isAtom() && item->valueFrom() == NLGEORGES::UFormElm::ValueForm) // contextMenu.addAction("Revert to parent/default..."); - QAction *selectedItem = contextMenu.exec(QCursor::pos()); + contextMenu.exec(QCursor::pos()); + /* if(selectedItem) { - if(selectedItem->text() == "Append array entry...") - { - - - } // Append an array entry... - else if(selectedItem->text() == "Delete array entry...") - { - - } - else if(selectedItem->text() == "Insert after array entry...") - { - - } - - // if(selectedItem->text() == "Add parent...") // { // // Get the file extension of the form so we can build a dialog pattern. @@ -624,6 +624,7 @@ namespace GeorgesQt // } } // if selected context menu item is valid. + */ } // if 'm' model valid. //if(structContext) diff --git a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h index 7b40fc3ef..739fa0e28 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -104,6 +104,7 @@ namespace GeorgesQt void headerClicked(int); void onArrayResized( const QString &name, int size ); + void onAppendArray(); private: Ui::CGeorgesTreeViewDialog m_ui; diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.cpp b/code/studio/src/plugins/georges_editor/georgesform_model.cpp index f533970fa..f0f70b642 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.cpp +++ b/code/studio/src/plugins/georges_editor/georgesform_model.cpp @@ -515,6 +515,60 @@ void CGeorgesFormModel::arrayResized( const QString &name, int size ) } } +void CGeorgesFormModel::appendArray( QModelIndex idx ) +{ + if( !idx.isValid() ) + return; + + CFormItem *item = reinterpret_cast< CFormItem* >( idx.internalPointer() ); + NLGEORGES::UFormElm *elm = NULL; + + item->form()->getRootNode().getNodeByName( &elm, item->formName().c_str() ); + + const NLGEORGES::CFormDfn *parentDfn; + const NLGEORGES::CFormDfn *nodeDfn; + uint indexDfn; + const NLGEORGES::CType *type; + NLGEORGES::UFormDfn::TEntryType entryType; + NLGEORGES::CFormElm *node; + bool created; + bool isArray; + + if( elm == NULL ) + { + NLGEORGES::UFormElm *uroot = &item->form()->getRootNode(); + NLGEORGES::CFormElm *croot = static_cast< NLGEORGES::CFormElm* >( uroot ); + + croot->createNodeByName( item->formName().c_str(), &parentDfn, indexDfn, &nodeDfn, &type, &node, entryType, isArray, created ); + + if( !created ) + return; + + elm = node; + } + + NLGEORGES::CFormElmArray *celm = dynamic_cast< NLGEORGES::CFormElmArray* >( elm ); + if( celm == NULL ) + return; + + unsigned long s = celm->Elements.size(); + std::string nodeIdx = "["; + nodeIdx += QString::number( s ).toUtf8().constData(); + nodeIdx += "]"; + + celm->createNodeByName( nodeIdx.c_str(), &parentDfn, indexDfn, &nodeDfn, &type, &node, entryType, isArray, created ); + if( !created ) + return; + + std::string name = "#"; + name += QString::number( s ).toUtf8().constData(); + + std::string formName; + node->getFormName( formName ); + + item->add( CFormItem::Form, name.c_str(), s, formName.c_str(), 0, item->form(), false ); +} + /******************************************************************************/ diff --git a/code/studio/src/plugins/georges_editor/georgesform_model.h b/code/studio/src/plugins/georges_editor/georgesform_model.h index 4ca91398b..03c4c592a 100644 --- a/code/studio/src/plugins/georges_editor/georgesform_model.h +++ b/code/studio/src/plugins/georges_editor/georgesform_model.h @@ -76,6 +76,7 @@ namespace GeorgesQt } void arrayResized( const QString &name, int size ); + void appendArray( QModelIndex idx ); private: void setupModelData();