From 7abf5b2aa1e724ef8b931b5d3304639809cccf78 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 18 Jul 2014 00:27:05 +0200 Subject: [PATCH] Apply table changes to the loaded data, and offer to save when closing the changed table. --- .../translation_manager/uxt_editor.cpp | 52 ++++++++++++++++++- .../plugins/translation_manager/uxt_editor.h | 4 ++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/code/studio/src/plugins/translation_manager/uxt_editor.cpp b/code/studio/src/plugins/translation_manager/uxt_editor.cpp index 3ac7cb066..69cd1a9b6 100644 --- a/code/studio/src/plugins/translation_manager/uxt_editor.cpp +++ b/code/studio/src/plugins/translation_manager/uxt_editor.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "nel/misc/diff_tool.h" @@ -17,9 +18,12 @@ public: UXTEditorPvt() { t = new QTableWidget(); + changed = false; } QTableWidget *t; + std::vector< STRING_MANAGER::TStringInfo > infos; + bool changed; }; @@ -30,6 +34,8 @@ CEditor( parent ) setAttribute( Qt::WA_DeleteOnClose ); d_ptr = new UXTEditorPvt(); + + blockTableSignals( false ); } UXTEditor::~UXTEditor() @@ -40,12 +46,16 @@ UXTEditor::~UXTEditor() void UXTEditor::open( QString filename ) { - std::vector< STRING_MANAGER::TStringInfo > infos; + std::vector< STRING_MANAGER::TStringInfo > &infos = d_ptr->infos; + + infos.clear(); STRING_MANAGER::loadStringFile( filename.toUtf8().constData(), infos, true ); - if( infos.size() == 0 ) + if( d_ptr->infos.size() == 0 ) return; + blockTableSignals( true ); + d_ptr->t->clear(); d_ptr->t->setColumnCount( 2 ); d_ptr->t->setRowCount( infos.size() ); @@ -71,6 +81,8 @@ void UXTEditor::open( QString filename ) d_ptr->t->resizeColumnsToContents(); + blockTableSignals( false ); + setWidget( d_ptr->t ); setCurrentFile( filename ); } @@ -91,10 +103,38 @@ void UXTEditor::activateWindow() void UXTEditor::closeEvent( QCloseEvent *e ) { + if( d_ptr->changed ) + { + int reply = QMessageBox::question( this, + tr( "Table changed" ), + tr( "The table has changed. Would you like to save your changes?" ), + QMessageBox::Yes, + QMessageBox::No + ); + + if( reply == QMessageBox::Yes ) + save(); + + } + e->accept(); close(); } +void UXTEditor::onCellChanged( int row, int column ) +{ + QTableWidgetItem *item = d_ptr->t->item( row, column ); + STRING_MANAGER::TStringInfo &info = d_ptr->infos[ row ]; + + if( column == 0 ) + info.Identifier = item->text().toUtf8().constData(); + else + if( column == 1 ) + info.Text = item->text().toUtf8().constData(); + + d_ptr->changed = true; +} + void UXTEditor::setHeaderText( const QString &id, const QString &text ) { QTableWidgetItem *h1 = new QTableWidgetItem( id ); @@ -105,4 +145,12 @@ void UXTEditor::setHeaderText( const QString &id, const QString &text ) d_ptr->t->setHorizontalHeaderItem( 1, h2 ); } +void UXTEditor::blockTableSignals( bool block ) +{ + if( block ) + disconnect( d_ptr->t, SIGNAL( cellChanged( int, int ) ), this, SLOT( onCellChanged( int, int ) ) ); + else + connect( d_ptr->t, SIGNAL( cellChanged( int, int ) ), this, SLOT( onCellChanged( int, int ) ) ); +} + } diff --git a/code/studio/src/plugins/translation_manager/uxt_editor.h b/code/studio/src/plugins/translation_manager/uxt_editor.h index 3f6d52b3a..5a96377a6 100644 --- a/code/studio/src/plugins/translation_manager/uxt_editor.h +++ b/code/studio/src/plugins/translation_manager/uxt_editor.h @@ -23,8 +23,12 @@ public: protected: void closeEvent( QCloseEvent *e ); +private Q_SLOTS: + void onCellChanged( int row, int column ); + private: void setHeaderText( const QString &id, const QString &text ); + void blockTableSignals( bool block = false ); UXTEditorPvt *d_ptr; };