From 6457ab90ebd4a93ec41581bb3ae36943accf52de Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 3 Sep 2014 19:55:46 +0200 Subject: [PATCH] Added support for creating new form documents --- .../georges_editor/georges_editor_form.cpp | 33 +++++++++ .../georges_treeview_dialog.cpp | 69 ++++++++++--------- .../georges_editor/georges_treeview_dialog.h | 1 + 3 files changed, 71 insertions(+), 32 deletions(-) diff --git a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp index cb4069818..54028b5a4 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -173,6 +173,39 @@ namespace GeorgesQt void GeorgesEditorForm::newForm() { + QString dfnFileName = QFileDialog::getOpenFileName( this, + tr( "New Form" ), + "", + "Definition files (*.dfn)" ); + if( dfnFileName.isEmpty() ) + return; + + QFileInfo dfnInfo( dfnFileName ); + QString baseName = dfnInfo.baseName(); + QString filter; + filter += baseName; + filter += " files (*."; + filter += baseName; + filter += ")"; + + QString fileName = QFileDialog::getSaveFileName( this, + tr( "New Form" ), + "", + filter ); + if( fileName.isEmpty() ) + return; + + CGeorgesTreeViewDialog *d = new CGeorgesTreeViewDialog(); + if( !d->newDocument( fileName, dfnFileName ) ) + { + QMessageBox::information( this, + tr( "Failed to create new form" ), + tr( "Failed to create new form!" ) ); + return; + } + + addGeorgesWidget( d ); + setModified(); } void GeorgesEditorForm::save() 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 86c0fb8af..c2aa78005 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp @@ -160,30 +160,25 @@ namespace GeorgesQt NLGEORGES::CForm* CGeorgesTreeViewDialog::getFormByDfnName(const QString dfnName) { - if(NLMISC::CPath::exists(dfnName.toAscii().data())) + // Create a new form object. + NLGEORGES::CForm *form = new NLGEORGES::CForm(); + m_form = form; + + // Retrieve a copy of the root definition. + NLGEORGES::CFormDfn *formDfn = dynamic_cast(m_georges->loadFormDfn(dfnName.toAscii().data())); + + // Next we'll use the root node to build a new form. + NLGEORGES::CFormElmStruct *fes = dynamic_cast(getRootNode(0)); + fes->build(formDfn); + + // And then initialize the held elements; + for(uint i = 0; i(m_georges->loadFormDfn(dfnName.toAscii().data())); - - // Next we'll use the root node to build a new form. - NLGEORGES::CFormElmStruct *fes = dynamic_cast(getRootNode(0)); + fes = dynamic_cast(getRootNode(i+1)); fes->build(formDfn); - - // And then initialize the held elements; - for(uint i = 0; i(getRootNode(i+1)); - fes->build(formDfn); - } - - return form; } - nlinfo("File '%s' does not exist!", dfnName.toAscii().data()); - return NULL; + + return form; } NLGEORGES::CFormElm *CGeorgesTreeViewDialog::getRootNode(uint slot) @@ -311,19 +306,9 @@ namespace GeorgesQt bool CGeorgesTreeViewDialog::load( const QString &fileName ) { - bool loadFromDFN = false; // Retrieve the form and load the form. - NLGEORGES::CForm *form; - if(loadFromDFN) - { - // Get the form by DFN name. - form = getFormByDfnName(fileName); - } - else - { - form = getFormByName(fileName); - } + NLGEORGES::CForm *form = getFormByName(fileName); if( form == NULL ) return false; @@ -421,6 +406,26 @@ namespace GeorgesQt } } + bool CGeorgesTreeViewDialog::newDocument( const QString &fileName, const QString &dfn ) + { + NLGEORGES::CForm *form = getFormByDfnName(dfn); + + if( form == NULL ) + return false; + + setForm(form); + loadFormIntoDialog(form); + QApplication::processEvents(); + + m_fileName = fileName; + + QFileInfo info( fileName ); + setWindowTitle( info.fileName() + "*" ); + setModified( true ); + + return true; + } + void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index ) { //CGeorgesFormModel *model = 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 0acb48941..459258c3f 100644 --- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.h @@ -71,6 +71,7 @@ namespace GeorgesQt bool load( const QString &fileName ); void write ( ); + bool newDocument( const QString &fileName, const QString &dfn ); QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; }