From 5fa370463b4dffe2aefc71d4ed64c49bb8abe713 Mon Sep 17 00:00:00 2001
From: dfighter1985 <devnull@localhost>
Date: Tue, 2 Sep 2014 20:13:10 +0200
Subject: [PATCH] Logging DFN changes.

---
 .../georges_editor/georges_dfn_dialog.cpp     | 14 ++++++++++
 .../georges_editor/georges_dfn_dialog.h       |  1 +
 .../georges_editor/georges_dock_widget.cpp    | 28 +++++++++++++++++++
 .../georges_editor/georges_dock_widget.h      |  3 ++
 .../georges_treeview_dialog.cpp               | 25 +----------------
 5 files changed, 47 insertions(+), 24 deletions(-)

diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp
index 1dde9a693..56043b958 100644
--- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp
+++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.cpp
@@ -83,6 +83,8 @@ void GeorgesDFNDialog::write()
 	setModified( false );
 	setWindowTitle( windowTitle().remove( "*" ) );
 
+	m_pvt->dfn->Header.Log = m_ui.logEdit->toPlainText().toUtf8().constData();
+
 	std::string path = NLMISC::CPath::lookup( m_fileName.toUtf8().constData(), false );
 	if( path.empty() )
 		return;
@@ -117,6 +119,8 @@ void GeorgesDFNDialog::onAddClicked()
 
 	m_ui.list->addItem( name );
 	m_pvt->dfn->addEntry( name.toUtf8().constData() );
+
+	log( "Added " + name );
 }
 
 void GeorgesDFNDialog::onRemoveClicked()
@@ -125,6 +129,8 @@ void GeorgesDFNDialog::onRemoveClicked()
 	if( row < 0 )
 		return;
 
+	log( "Removed " + m_ui.list->currentItem()->text() );
+
 	QListWidgetItem *item = m_ui.list->takeItem( row );
 	delete item;
 
@@ -149,12 +155,20 @@ void GeorgesDFNDialog::onValueChanged( const QString &key, const QString &value
 		Q_EMIT modified();
 	}
 
+	log( m_ui.list->currentItem()->text() + "." + key + " = " + value );
+
 	if( key == "name" )
 	{
 		m_ui.list->currentItem()->setText( value );
 	}
 }
 
+void GeorgesDFNDialog::log( const QString &msg )
+{
+	QString logMsg = buildLogMsg( msg );
+	m_ui.logEdit->appendPlainText( logMsg );
+}
+
 void GeorgesDFNDialog::setupConnections()
 {
 	connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) );
diff --git a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h
index 2410c66df..6ce67c2d2 100644
--- a/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h
+++ b/code/studio/src/plugins/georges_editor/georges_dfn_dialog.h
@@ -27,6 +27,7 @@ private Q_SLOTS:
 	void onValueChanged( const QString& key, const QString &value );
 
 private:
+	void log( const QString &msg );
 	void setupConnections();
 
 	Ui::GeorgesDFNDialog m_ui;
diff --git a/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp b/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp
index 7fbc4906b..8736a604b 100644
--- a/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp
+++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.cpp
@@ -11,4 +11,32 @@ GeorgesDockWidget::~GeorgesDockWidget()
 {
 }
 
+QString GeorgesDockWidget::buildLogMsg( const QString &msg )
+{
+	QString user = getenv( "USER" );
+	if( user.isEmpty() )
+		user = getenv( "USERNAME" );
+	if( user.isEmpty() )
+		user = "anonymous";
+	
+	QTime time = QTime::currentTime();
+	QDate date = QDate::currentDate();
+	
+	QString dateString = date.toString( "ddd MMM dd" );
+	QString timeString = time.toString( "HH:mm:ss" );
+	
+	QString logMsg;
+	logMsg += dateString;
+	logMsg += ' ';
+	logMsg += timeString;
+	logMsg += ' ';
+	logMsg += QString::number( date.year() );
+	logMsg += ' ';
+	logMsg += "(";
+	logMsg += user;
+	logMsg += ")";
+	logMsg += ' ';
+	logMsg += msg;
 
+	return logMsg;
+}
diff --git a/code/studio/src/plugins/georges_editor/georges_dock_widget.h b/code/studio/src/plugins/georges_editor/georges_dock_widget.h
index 759986aa0..59aad9e8f 100644
--- a/code/studio/src/plugins/georges_editor/georges_dock_widget.h
+++ b/code/studio/src/plugins/georges_editor/georges_dock_widget.h
@@ -21,6 +21,9 @@ public:
 	virtual void write() = 0;
 
 protected:
+	QString buildLogMsg( const QString &msg );
+	virtual void log( const QString &msg ) = 0;
+
 	QString m_fileName;
 	bool m_modified;
 	QUndoStack *m_undoStack;
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 36efea208..184a8f845 100644
--- a/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp
+++ b/code/studio/src/plugins/georges_editor/georges_treeview_dialog.cpp
@@ -698,30 +698,7 @@ namespace GeorgesQt
 
 	void CGeorgesTreeViewDialog::log( const QString &msg )
 	{
-		QString user = getenv( "USER" );
-		if( user.isEmpty() )
-			user = getenv( "USERNAME" );
-		if( user.isEmpty() )
-			user = "anonymous";
-
-		QTime time = QTime::currentTime();
-		QDate date = QDate::currentDate();
-		
-		QString dateString = date.toString( "ddd MMM dd" );
-		QString timeString = time.toString( "HH:mm:ss" );
-
-		QString logMsg;
-		logMsg += dateString;
-		logMsg += ' ';
-		logMsg += timeString;
-		logMsg += ' ';
-		logMsg += QString::number( date.year() );
-		logMsg += ' ';
-		logMsg += "(";
-		logMsg += user;
-		logMsg += ")";
-		logMsg += ' ';
-		logMsg += msg;
+		QString logMsg = buildLogMsg( msg );
 
 		m_ui.logEdit->appendPlainText( logMsg );
 	}