From 5e2b448cbecc223f1840bc271d5dc90ec70456e7 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Sep 2014 23:54:42 +0200 Subject: [PATCH] Implemented saving. --- .../georges_editor/georges_editor_form.cpp | 2 + .../georges_editor/georges_typ_dialog.cpp | 38 +++++++++++++++++++ .../georges_editor/georges_typ_dialog.h | 6 +++ 3 files changed, 46 insertions(+) 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 47bd9de3d..c870ae668 100644 --- a/code/studio/src/plugins/georges_editor/georges_editor_form.cpp +++ b/code/studio/src/plugins/georges_editor/georges_editor_form.cpp @@ -324,6 +324,8 @@ namespace GeorgesQt return NULL; } + connect( d, SIGNAL( modified() ), this, SLOT( setModified() ) ); + return d; } diff --git a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp index b64368535..4b042d8e0 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.cpp @@ -4,6 +4,10 @@ #include #include +#include "nel/misc/file.h" +#include "nel/misc/o_xml.h" +#include "nel/misc/path.h" + class GeorgesTypDialogPvt { public: @@ -48,12 +52,31 @@ bool GeorgesTypDialog::load( const QString &fileName ) loadTyp(); + m_fileName = fileName; + setWindowTitle( fileName ); + return true; } void GeorgesTypDialog::write() { + std::string path = NLMISC::CPath::lookup( m_fileName.toUtf8().constData(), false ); + + NLMISC::COFile file; + if( !file.open( path.c_str(), false, true, false ) ) + return; + + NLMISC::COXml xml; + xml.init( &file ); + + m_pvt->typ->write( xml.getDocument() ); + + xml.flush(); + file.close(); + + setModified( false ); + setWindowTitle( windowTitle().remove( "*" ) ); } void GeorgesTypDialog::onAddClicked() @@ -84,6 +107,7 @@ void GeorgesTypDialog::onAddClicked() def.Value = ""; m_pvt->typ->Definitions.push_back( def ); + onModified(); } void GeorgesTypDialog::onRemoveClicked() @@ -105,6 +129,7 @@ void GeorgesTypDialog::onRemoveClicked() std::vector< NLGEORGES::CType::CDefinition >::iterator itr = m_pvt->typ->Definitions.begin() + i; m_pvt->typ->Definitions.erase( itr ); + onModified(); } void GeorgesTypDialog::onItemChanged( QTreeWidgetItem *item, int column ) @@ -122,6 +147,19 @@ void GeorgesTypDialog::onItemChanged( QTreeWidgetItem *item, int column ) def.Label = item->text( 0 ).toUtf8().constData(); else def.Value = item->text( 1 ).toUtf8().constData(); + + onModified(); +} + +void GeorgesTypDialog::onModified() +{ + if( isModified() ) + return; + + setModified( true ); + setWindowTitle( windowTitle() + "*" ); + + Q_EMIT modified(); } void GeorgesTypDialog::setupConnections() diff --git a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h index 8cca31fe6..ac203b8f6 100644 --- a/code/studio/src/plugins/georges_editor/georges_typ_dialog.h +++ b/code/studio/src/plugins/georges_editor/georges_typ_dialog.h @@ -16,11 +16,15 @@ public: bool load( const QString &fileName ); void write(); +Q_SIGNALS: + void modified(); + private Q_SLOTS: void onAddClicked(); void onRemoveClicked(); void onItemChanged( QTreeWidgetItem *item, int column ); + void onModified(); private: void setupConnections(); @@ -29,6 +33,8 @@ private: Ui::GeorgesTypDialog m_ui; GeorgesTypDialogPvt *m_pvt; + + QString m_fileName; };