mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-13 02:39:34 +00:00
Some refactoring regarding saving.
This commit is contained in:
parent
bc3a6b83e5
commit
f27f391724
4 changed files with 40 additions and 43 deletions
|
@ -212,6 +212,7 @@ namespace GUIEditor
|
||||||
std::string wnd = d.getWindowName().toUtf8().constData();
|
std::string wnd = d.getWindowName().toUtf8().constData();
|
||||||
std::string mg = std::string( "ui:" ) + proj;
|
std::string mg = std::string( "ui:" ) + proj;
|
||||||
std::string dir = d.getProjectDirectory().toUtf8().constData();
|
std::string dir = d.getProjectDirectory().toUtf8().constData();
|
||||||
|
_lastDir = dir.c_str();
|
||||||
std::string uiFile = "ui_" + proj + ".xml";
|
std::string uiFile = "ui_" + proj + ".xml";
|
||||||
|
|
||||||
bool b = GUICtrl->createNewGUI( proj, wnd );
|
bool b = GUICtrl->createNewGUI( proj, wnd );
|
||||||
|
@ -228,7 +229,7 @@ namespace GUIEditor
|
||||||
projectFiles.projectName = proj;
|
projectFiles.projectName = proj;
|
||||||
projectFiles.masterGroup = mg;
|
projectFiles.masterGroup = mg;
|
||||||
projectFiles.activeGroup = std::string( "ui:" ) + proj + ":" + wnd;
|
projectFiles.activeGroup = std::string( "ui:" ) + proj + ":" + wnd;
|
||||||
projectFiles.version = NEW;
|
projectFiles.version = SProjectFiles::NEW;
|
||||||
projectFiles.guiFiles.push_back( uiFile );
|
projectFiles.guiFiles.push_back( uiFile );
|
||||||
projectWindow->setupFiles( projectFiles );
|
projectWindow->setupFiles( projectFiles );
|
||||||
|
|
||||||
|
@ -278,8 +279,23 @@ namespace GUIEditor
|
||||||
// Can't save old projects any further, since the widgets are in multiple files in them
|
// Can't save old projects any further, since the widgets are in multiple files in them
|
||||||
// using templates, styles and whatnot. There's no way to restore the original XML structure
|
// using templates, styles and whatnot. There's no way to restore the original XML structure
|
||||||
// after it's loaded
|
// after it's loaded
|
||||||
if( projectParser.getProjectVersion() == OLD )
|
if( projectFiles.version == SProjectFiles::OLD )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
std::string f = _lastDir.toUtf8().constData();
|
||||||
|
f += "/";
|
||||||
|
f += projectFiles.guiFiles[ 0 ];
|
||||||
|
|
||||||
|
WidgetSerializer widgetSerializer;
|
||||||
|
widgetSerializer.setFile( f );
|
||||||
|
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::saveAs()
|
void GUIEditorWindow::saveAs()
|
||||||
|
@ -292,42 +308,22 @@ namespace GUIEditor
|
||||||
|
|
||||||
if( dir.isEmpty() )
|
if( dir.isEmpty() )
|
||||||
return;
|
return;
|
||||||
|
_lastDir = dir;
|
||||||
|
|
||||||
|
if( projectFiles.version == SProjectFiles::OLD )
|
||||||
|
{
|
||||||
projectFiles.guiFiles.clear();
|
projectFiles.guiFiles.clear();
|
||||||
projectFiles.guiFiles.push_back( "ui_" + projectFiles.projectName + ".xml" );
|
projectFiles.guiFiles.push_back( "ui_" + projectFiles.projectName + ".xml" );
|
||||||
projectFiles.version = NEW;
|
projectFiles.version = SProjectFiles::NEW;
|
||||||
|
|
||||||
QString newFile =
|
|
||||||
dir + "/" + projectFiles.projectName.c_str() + ".xml";
|
|
||||||
|
|
||||||
CProjectFileSerializer serializer;
|
|
||||||
serializer.setFile( newFile.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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string guiFile =
|
currentProjectFile = _lastDir;
|
||||||
std::string( dir.toUtf8().constData() ) + "/" + "ui_" + projectFiles.projectName + ".xml";
|
currentProjectFile += "/";
|
||||||
|
currentProjectFile += projectFiles.projectName.c_str();
|
||||||
WidgetSerializer widgetSerializer;
|
currentProjectFile += ".xml";
|
||||||
widgetSerializer.setFile( guiFile );
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
QMessageBox::information( this,
|
|
||||||
tr( "Save successful" ),
|
|
||||||
tr( "Project saved successfully!" ) );
|
|
||||||
|
|
||||||
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIEditorWindow::reset()
|
void GUIEditorWindow::reset()
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace GUIEditor
|
||||||
unsigned long CProjectFileParser::getProjectVersion() const
|
unsigned long CProjectFileParser::getProjectVersion() const
|
||||||
{
|
{
|
||||||
if( !loaded )
|
if( !loaded )
|
||||||
return OLD;
|
return SProjectFiles::OLD;
|
||||||
|
|
||||||
return files.version;
|
return files.version;
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ namespace GUIEditor
|
||||||
void CProjectFileParser::clear()
|
void CProjectFileParser::clear()
|
||||||
{
|
{
|
||||||
files.projectName = "";
|
files.projectName = "";
|
||||||
files.version = OLD;
|
files.version = SProjectFiles::OLD;
|
||||||
files.activeGroup = "";
|
files.activeGroup = "";
|
||||||
files.guiFiles.clear();
|
files.guiFiles.clear();
|
||||||
files.mapFiles.clear();
|
files.mapFiles.clear();
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace GUIEditor
|
||||||
if( fileName.empty() )
|
if( fileName.empty() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if( project.version >= MAX_PROJECTFILE_VERSION )
|
if( project.version >= SProjectFiles::MAX_PROJECTFILE_VERSION )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
out.open( fileName.c_str() );
|
out.open( fileName.c_str() );
|
||||||
|
|
|
@ -23,6 +23,10 @@
|
||||||
|
|
||||||
namespace GUIEditor
|
namespace GUIEditor
|
||||||
{
|
{
|
||||||
|
struct SProjectFiles
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
enum ProjectVersion
|
enum ProjectVersion
|
||||||
{
|
{
|
||||||
OLD = 0,
|
OLD = 0,
|
||||||
|
@ -30,9 +34,6 @@ namespace GUIEditor
|
||||||
MAX_PROJECTFILE_VERSION
|
MAX_PROJECTFILE_VERSION
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SProjectFiles
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string projectName;
|
std::string projectName;
|
||||||
unsigned long version;
|
unsigned long version;
|
||||||
std::string masterGroup;
|
std::string masterGroup;
|
||||||
|
|
Loading…
Reference in a new issue