From 2c5617cea7205510364137900ac649573ab4a957 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 12 Oct 2014 20:09:42 +0200 Subject: [PATCH] When creating a new project, save it right away. --HG-- branch : dfighter-tools --- .../plugins/gui_editor/gui_editor_window.cpp | 38 ++++++++++++++++++- .../src/plugins/gui_editor/new_gui_dlg.cpp | 26 +++++++++++++ .../src/plugins/gui_editor/new_gui_dlg.h | 2 + .../src/plugins/gui_editor/new_gui_dlg.ui | 23 +++++++++-- .../gui_editor/project_file_parser.cpp | 5 ++- 5 files changed, 89 insertions(+), 5 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/gui_editor_window.cpp b/code/studio/src/plugins/gui_editor/gui_editor_window.cpp index aedeea5d6..70f206b3b 100644 --- a/code/studio/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/studio/src/plugins/gui_editor/gui_editor_window.cpp @@ -210,6 +210,9 @@ namespace GUIEditor std::string proj = d.getProjectName().toUtf8().constData(); std::string wnd = d.getWindowName().toUtf8().constData(); + std::string mg = std::string( "ui:" ) + proj; + std::string dir = d.getProjectDirectory().toUtf8().constData(); + std::string uiFile = "ui_" + proj + ".xml"; bool b = GUICtrl->createNewGUI( proj, wnd ); if( !b ) @@ -220,8 +223,41 @@ namespace GUIEditor reset(); } - std::string mg = std::string( "ui:" ) + proj; hierarchyView->buildHierarchy( mg ); + + projectFiles.projectName = proj; + projectFiles.masterGroup = mg; + projectFiles.activeGroup = std::string( "ui:" ) + proj + ":" + wnd; + projectFiles.version = NEW; + projectFiles.guiFiles.push_back( uiFile ); + projectWindow->setupFiles( projectFiles ); + + currentProject = proj.c_str(); + currentProjectFile = std::string( dir + "/" + proj + ".xml" ).c_str(); + + + // Save the project file + CProjectFileSerializer serializer; + serializer.setFile( currentProjectFile.toUtf8().constData() ); + if( !serializer.serialize( projectFiles ) ) + { + QMessageBox::critical( this, + tr( "Failed to save project" ), + tr( "There was an error while trying to save the project." ) ); + return; + } + + // Save the GUI file + WidgetSerializer widgetSerializer; + widgetSerializer.setFile( dir + "/" + uiFile ); + widgetSerializer.setActiveGroup( projectFiles.activeGroup ); + if( !widgetSerializer.serialize( projectFiles.masterGroup ) ) + { + QMessageBox::critical( this, + tr( "Failed to save project" ), + tr( "There was an error while trying to save the project." ) ); + return; + } } void GUIEditorWindow::save() diff --git a/code/studio/src/plugins/gui_editor/new_gui_dlg.cpp b/code/studio/src/plugins/gui_editor/new_gui_dlg.cpp index 8dc7abb1e..88d4a19fd 100644 --- a/code/studio/src/plugins/gui_editor/new_gui_dlg.cpp +++ b/code/studio/src/plugins/gui_editor/new_gui_dlg.cpp @@ -18,6 +18,7 @@ #include "new_gui_dlg.h" #include +#include NewGUIDlg::NewGUIDlg( QWidget *parent ) : QDialog( parent ) @@ -26,6 +27,7 @@ QDialog( parent ) connect( m_ui.okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOKClicked() ) ); connect( m_ui.cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( onCancelClicked() ) ); + connect( m_ui.projectDirTB, SIGNAL( clicked( bool ) ), this, SLOT( onProjectDirTBClicked() ) ); } @@ -43,6 +45,11 @@ QString NewGUIDlg::getWindowName() const return m_ui.windowEdit->text(); } +QString NewGUIDlg::getProjectDirectory() const +{ + return m_ui.projectDirEdit->text(); +} + void NewGUIDlg::onOKClicked() { if( m_ui.projectEdit->text().isEmpty() ) @@ -61,6 +68,14 @@ void NewGUIDlg::onOKClicked() return; } + if( m_ui.projectDirEdit->text().isEmpty() ) + { + QMessageBox::information( this, + tr( "New project" ), + tr( "You must specify a project directory!" ) ); + return; + } + accept(); } @@ -69,4 +84,15 @@ void NewGUIDlg::onCancelClicked() reject(); } +void NewGUIDlg::onProjectDirTBClicked() +{ + QString dir = QFileDialog::getExistingDirectory( this, + tr( "Specify project directory" ), + "." ); + if( dir.isEmpty() ) + return; + + m_ui.projectDirEdit->setText( dir ); +} + diff --git a/code/studio/src/plugins/gui_editor/new_gui_dlg.h b/code/studio/src/plugins/gui_editor/new_gui_dlg.h index 3e290545c..f4bf474f7 100644 --- a/code/studio/src/plugins/gui_editor/new_gui_dlg.h +++ b/code/studio/src/plugins/gui_editor/new_gui_dlg.h @@ -31,10 +31,12 @@ public: QString getProjectName() const; QString getWindowName() const; + QString getProjectDirectory() const; private Q_SLOTS: void onOKClicked(); void onCancelClicked(); + void onProjectDirTBClicked(); private: Ui::NewGUIDialog m_ui; diff --git a/code/studio/src/plugins/gui_editor/new_gui_dlg.ui b/code/studio/src/plugins/gui_editor/new_gui_dlg.ui index a144c58e8..7dca6d2a3 100644 --- a/code/studio/src/plugins/gui_editor/new_gui_dlg.ui +++ b/code/studio/src/plugins/gui_editor/new_gui_dlg.ui @@ -6,8 +6,8 @@ 0 0 - 292 - 95 + 332 + 125 @@ -35,6 +35,23 @@ + + + Project directory + + + + + + + + + + ... + + + + Qt::Horizontal @@ -47,7 +64,7 @@ - + diff --git a/code/studio/src/plugins/gui_editor/project_file_parser.cpp b/code/studio/src/plugins/gui_editor/project_file_parser.cpp index 7213b332a..a5646c963 100644 --- a/code/studio/src/plugins/gui_editor/project_file_parser.cpp +++ b/code/studio/src/plugins/gui_editor/project_file_parser.cpp @@ -16,6 +16,7 @@ #include "project_file_parser.h" +#include "nel/misc/debug.h" namespace GUIEditor { @@ -208,7 +209,9 @@ namespace GUIEditor reader.readNext(); } if( files.mapFiles.empty() ) - return false; + { + nlinfo( "No map file(s) specified in project file." ); + } return true; }