CInterfaceParser in editor mode should look for files in the working directory first.

This commit is contained in:
dfighter1985 2014-10-11 16:26:38 +02:00
parent 9a5d082583
commit c47188179a
6 changed files with 39 additions and 4 deletions

View file

@ -353,7 +353,15 @@ namespace NLGUI
std::map< std::string, std::string > pointerSettings;
std::map< std::string, std::map< std::string, std::string > > keySettings;
std::string _WorkDir;
public:
/// Sets the working directory, where files should be looked for
void setWorkDir( const std::string &workdir ){ _WorkDir = workdir; }
/// Looks up a file in either the working directory or using CPath::lookup
std::string lookup( const std::string &file );
void initLUA();
void uninitLUA();
bool isLuaInitialized() const{ return luaInitialized; }

View file

@ -88,6 +88,7 @@ namespace NLGUI
virtual bool serializePointerSettings( xmlNodePtr parentNode ) const = 0;
virtual bool serializeKeySettings( xmlNodePtr parentNode ) const = 0;
virtual CViewBase* createClass( const std::string &name ) = 0;
virtual void setWorkDir( const std::string &workdir ) = 0;
};
}

View file

@ -233,6 +233,22 @@ namespace NLGUI
destStream.seek(0, NLMISC::IStream::begin);
}
std::string CInterfaceParser::lookup( const std::string &file )
{
std::string filename;
if( editorMode && !_WorkDir.empty() )
{
std::string wdpath = CPath::standardizePath( _WorkDir ) + file;
if( CFile::fileExists( wdpath ) )
filename = wdpath;
}
if( filename.empty() )
filename = CPath::lookup( file );
return filename;
}
// ----------------------------------------------------------------------------
bool CInterfaceParser::parseInterface (const std::vector<std::string> & strings, bool reload, bool isFilename, bool checkInData)
{
@ -270,7 +286,7 @@ namespace NLGUI
{
//get the first file document pointer
firstFileName = *it;
string filename = CPath::lookup(firstFileName);
string filename = lookup( firstFileName );
bool isInData = false;
string::size_type pos = filename.find ("@");
if (pos != string::npos)
@ -283,7 +299,7 @@ namespace NLGUI
isInData = true;
}
if ((needCheck && !isInData) || !file.open (CPath::lookup(firstFileName)))
if ((needCheck && !isInData) || !file.open (lookup(firstFileName)))
{
// todo hulud interface syntax error
nlwarning ("could not open file %s, skipping xml parsing",firstFileName.c_str());
@ -331,7 +347,7 @@ namespace NLGUI
{
saveParseResult = true;
std::string archive = CPath::lookup(nextFileName + "_compressed", false, false);
std::string current = CPath::lookup(nextFileName, false, false);
std::string current = lookup(nextFileName);
if (!archive.empty() && !current.empty())
{
if (CFile::getFileModificationDate(current) <= CFile::getFileModificationDate(archive))
@ -351,7 +367,7 @@ namespace NLGUI
{
if (isFilename)
{
if (!file.open(CPath::lookup(nextFileName, false, false)))
if (!file.open(lookup(nextFileName)))
{
// todo hulud interface syntax error
nlwarning ("could not open file %s, skipping xml parsing",nextFileName.c_str());

View file

@ -181,6 +181,8 @@ namespace GUIEditor
currentProject = projectFiles.projectName.c_str();
currentProjectFile = fileName;
projectWindow->setupFiles( projectFiles );
GUICtrl->setWorkDir( _lastDir );
if( GUICtrl->parse( projectFiles ) )
{
hierarchyView->buildHierarchy( projectFiles.masterGroup );

View file

@ -187,6 +187,12 @@ namespace GUIEditor
}
}
void NelGUICtrl::setWorkDir( const QString &dir )
{
IParser *parser = CWidgetManager::getInstance()->getParser();
parser->setWorkDir( std::string( dir.toUtf8().constData() ) );
}
QWidget* NelGUICtrl::getViewPort()
{
return w;

View file

@ -52,6 +52,8 @@ namespace GUIEditor
void show();
void hide();
void setWorkDir( const QString &dir );
Q_SIGNALS:
void guiLoadComplete();