diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index ecfaa3ba8..5d80d2904 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -1,6 +1,10 @@ #include "scriptedit.hpp" +#include + #include +#include +#include #include "../../model/world/universalid.hpp" #include "../../model/world/tablemimedata.hpp" @@ -64,8 +68,21 @@ void CSVWorld::ScriptEdit::dropEvent (QDropEvent* event) { if (mAllowedTypes.contains (it->getType())) { - QString::fromStdString ('"' + it->getId() + '"'); + if (stringNeedsQuote(it->getId())) + { + insertPlainText(QString::fromStdString ('"' + it->getId() + '"')); + } else { + insertPlainText(QString::fromStdString (it->getId())); + } } } } -} \ No newline at end of file +} + +bool CSVWorld::ScriptEdit::stringNeedsQuote (const std::string& id) +{ + QString string(QString::fromStdString(id)); // is only for c++11, so let's use qregexp for now. + //I'm not quite sure when do we need to put quotes. To be safe we will use quotes for anything other than… + QRegExp regexp("^[a-z]{1}[a-z|0-9]{0,}$", Qt::CaseInsensitive); + return !(string.contains(regexp)); +} diff --git a/apps/opencs/view/world/scriptedit.hpp b/apps/opencs/view/world/scriptedit.hpp index dc97382b3..afad12048 100644 --- a/apps/opencs/view/world/scriptedit.hpp +++ b/apps/opencs/view/world/scriptedit.hpp @@ -30,6 +30,8 @@ namespace CSVWorld void dropEvent (QDropEvent* event); void dragMoveEvent (QDragMoveEvent* event); + + bool stringNeedsQuote(const std::string& id); }; } #endif // SCRIPTEDIT_H \ No newline at end of file