mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-31 01:15:34 +00:00
display script errors in script subview
This commit is contained in:
parent
ecbdd7d753
commit
c5eec822ae
5 changed files with 166 additions and 5 deletions
|
@ -64,7 +64,7 @@ opencs_units (view/world
|
|||
table tablesubview scriptsubview util regionmapsubview tablebottombox creator genericcreator
|
||||
cellcreator referenceablecreator referencecreator scenesubview
|
||||
infocreator scriptedit dialoguesubview previewsubview regionmap dragrecordtable nestedtable
|
||||
dialoguespinbox recordbuttonbar tableeditidaction
|
||||
dialoguespinbox recordbuttonbar tableeditidaction scripterrortable
|
||||
)
|
||||
|
||||
opencs_units_noqt (view/world
|
||||
|
|
87
apps/opencs/view/world/scripterrortable.cpp
Normal file
87
apps/opencs/view/world/scripterrortable.cpp
Normal file
|
@ -0,0 +1,87 @@
|
|||
|
||||
#include "scripterrortable.hpp"
|
||||
|
||||
#include <QHeaderView>
|
||||
|
||||
#include <components/compiler/tokenloc.hpp>
|
||||
#include <components/compiler/scanner.hpp>
|
||||
#include <components/compiler/fileparser.hpp>
|
||||
#include <components/compiler/exception.hpp>
|
||||
#include <components/compiler/extensions0.hpp>
|
||||
|
||||
#include "../../model/doc/document.hpp"
|
||||
|
||||
|
||||
void CSVWorld::ScriptErrorTable::report (const std::string& message, const Compiler::TokenLoc& loc, Type type)
|
||||
{
|
||||
addMessage (message, type==Compiler::ErrorHandler::WarningMessage ?
|
||||
CSMDoc::Message::Severity_Warning : CSMDoc::Message::Severity_Error, loc.mLine);
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptErrorTable::report (const std::string& message, Type type)
|
||||
{
|
||||
addMessage (message, type==Compiler::ErrorHandler::WarningMessage ?
|
||||
CSMDoc::Message::Severity_Warning : CSMDoc::Message::Severity_Error);
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptErrorTable::addMessage (const std::string& message,
|
||||
CSMDoc::Message::Severity severity, int line)
|
||||
{
|
||||
int row = rowCount();
|
||||
|
||||
setRowCount (row+1);
|
||||
|
||||
setItem (row, 0, new QTableWidgetItem (""));
|
||||
|
||||
if (line!=-1)
|
||||
{
|
||||
QTableWidgetItem *item = new QTableWidgetItem;
|
||||
item->setData (Qt::DisplayRole, line+1);
|
||||
setItem (row, 1, item);
|
||||
}
|
||||
|
||||
setItem (row, 2, new QTableWidgetItem (QString::fromUtf8 (message.c_str())));
|
||||
}
|
||||
|
||||
CSVWorld::ScriptErrorTable::ScriptErrorTable (const CSMDoc::Document& document, QWidget *parent)
|
||||
: QTableWidget (parent), mContext (document.getData())
|
||||
{
|
||||
setColumnCount (3);
|
||||
|
||||
QStringList headers;
|
||||
headers << "Severity" << "Line" << "Description";
|
||||
setHorizontalHeaderLabels (headers);
|
||||
horizontalHeader()->setStretchLastSection (true);
|
||||
|
||||
Compiler::registerExtensions (mExtensions);
|
||||
mContext.setExtensions (&mExtensions);
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptErrorTable::updateUserSetting (const QString& name, const QStringList& value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptErrorTable::update (const std::string& source)
|
||||
{
|
||||
setRowCount (0);
|
||||
|
||||
try
|
||||
{
|
||||
std::istringstream input (source);
|
||||
|
||||
Compiler::Scanner scanner (*this, input, mContext.getExtensions());
|
||||
|
||||
Compiler::FileParser parser (*this, mContext);
|
||||
|
||||
scanner.scan (parser);
|
||||
}
|
||||
catch (const Compiler::SourceException&)
|
||||
{
|
||||
// error has already been reported via error handler
|
||||
}
|
||||
catch (const std::exception& error)
|
||||
{
|
||||
addMessage (error.what(), CSMDoc::Message::Severity_SeriousError);
|
||||
}
|
||||
}
|
45
apps/opencs/view/world/scripterrortable.hpp
Normal file
45
apps/opencs/view/world/scripterrortable.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#ifndef CSV_WORLD_SCRIPTERRORTABLE_H
|
||||
#define CSV_WORLD_SCRIPTERRORTABLE_H
|
||||
|
||||
#include <QTableWidget>
|
||||
|
||||
#include <components/compiler/errorhandler.hpp>
|
||||
#include <components/compiler/extensions.hpp>
|
||||
|
||||
#include "../../model/world/scriptcontext.hpp"
|
||||
#include "../../model/doc/messages.hpp"
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
}
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class ScriptErrorTable : public QTableWidget, private Compiler::ErrorHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Compiler::Extensions mExtensions;
|
||||
CSMWorld::ScriptContext mContext;
|
||||
|
||||
virtual void report (const std::string& message, const Compiler::TokenLoc& loc, Type type);
|
||||
///< Report error to the user.
|
||||
|
||||
virtual void report (const std::string& message, Type type);
|
||||
///< Report a file related error
|
||||
|
||||
void addMessage (const std::string& message, CSMDoc::Message::Severity severity,
|
||||
int line = -1);
|
||||
|
||||
public:
|
||||
|
||||
ScriptErrorTable (const CSMDoc::Document& document, QWidget *parent = 0);
|
||||
|
||||
void updateUserSetting (const QString& name, const QStringList& value);
|
||||
|
||||
void update (const std::string& source);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <QStatusBar>
|
||||
#include <QStackedLayout>
|
||||
#include <QSplitter>
|
||||
|
||||
#include "../../model/doc/document.hpp"
|
||||
#include "../../model/world/universalid.hpp"
|
||||
|
@ -17,6 +18,7 @@
|
|||
#include "recordbuttonbar.hpp"
|
||||
#include "tablebottombox.hpp"
|
||||
#include "genericcreator.hpp"
|
||||
#include "scripterrortable.hpp"
|
||||
|
||||
void CSVWorld::ScriptSubView::addButtonBar()
|
||||
{
|
||||
|
@ -40,7 +42,16 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
|
|||
std::vector<std::string> selection (1, id.getId());
|
||||
mCommandDispatcher.setSelection (selection);
|
||||
|
||||
mLayout.addWidget (mEditor = new ScriptEdit (mDocument, ScriptHighlighter::Mode_General, this), 2);
|
||||
mMain = new QSplitter (this);
|
||||
mMain->setOrientation (Qt::Vertical);
|
||||
mLayout.addWidget (mMain, 2);
|
||||
|
||||
mEditor = new ScriptEdit (mDocument, ScriptHighlighter::Mode_General, this);
|
||||
mMain->addWidget (mEditor);
|
||||
mMain->setCollapsible (0, false);
|
||||
|
||||
mErrors = new ScriptErrorTable (document, this);
|
||||
mMain->addWidget (mErrors);
|
||||
|
||||
QWidget *widget = new QWidget (this);;
|
||||
widget->setLayout (&mLayout);
|
||||
|
@ -60,7 +71,9 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
|
|||
if (mColumn==-1)
|
||||
throw std::logic_error ("Can't find script column");
|
||||
|
||||
mEditor->setPlainText (mModel->data (mModel->getModelIndex (id.getId(), mColumn)).toString());
|
||||
QString source = mModel->data (mModel->getModelIndex (id.getId(), mColumn)).toString();
|
||||
|
||||
mEditor->setPlainText (source);
|
||||
// bottom box and buttons
|
||||
mBottom = new TableBottomBox (CreatorFactory<GenericCreator>(), document, id, this);
|
||||
|
||||
|
@ -83,6 +96,8 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
|
|||
|
||||
updateStatusBar();
|
||||
connect(mEditor, SIGNAL(cursorPositionChanged()), this, SLOT(updateStatusBar()));
|
||||
|
||||
mErrors->update (source.toUtf8().constData());
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptSubView::updateUserSetting (const QString& name, const QStringList& value)
|
||||
|
@ -116,6 +131,8 @@ void CSVWorld::ScriptSubView::updateUserSetting (const QString& name, const QStr
|
|||
|
||||
if (mButtons)
|
||||
mButtons->updateUserSetting (name, value);
|
||||
|
||||
mErrors->updateUserSetting (name, value);
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptSubView::setStatusBar (bool show)
|
||||
|
@ -173,8 +190,12 @@ void CSVWorld::ScriptSubView::textChanged()
|
|||
|
||||
ScriptEdit::ChangeLock lock (*mEditor);
|
||||
|
||||
QString source = mEditor->toPlainText();
|
||||
|
||||
mDocument.getUndoStack().push (new CSMWorld::ModifyCommand (*mModel,
|
||||
mModel->getModelIndex (getUniversalId().getId(), mColumn), mEditor->toPlainText()));
|
||||
mModel->getModelIndex (getUniversalId().getId(), mColumn), source));
|
||||
|
||||
mErrors->update (source.toUtf8().constData());
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptSubView::dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||
|
@ -189,9 +210,13 @@ void CSVWorld::ScriptSubView::dataChanged (const QModelIndex& topLeft, const QMo
|
|||
if (index.row()>=topLeft.row() && index.row()<=bottomRight.row() &&
|
||||
index.column()>=topLeft.column() && index.column()<=bottomRight.column())
|
||||
{
|
||||
QString source = mModel->data (index).toString();
|
||||
|
||||
QTextCursor cursor = mEditor->textCursor();
|
||||
mEditor->setPlainText (mModel->data (index).toString());
|
||||
mEditor->setPlainText (source);
|
||||
mEditor->setTextCursor (cursor);
|
||||
|
||||
mErrors->update (source.toUtf8().constData());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
class QModelIndex;
|
||||
class QLabel;
|
||||
class QVBoxLayout;
|
||||
class QSplitter;
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
|
@ -26,6 +27,7 @@ namespace CSVWorld
|
|||
class ScriptEdit;
|
||||
class RecordButtonBar;
|
||||
class TableBottomBox;
|
||||
class ScriptErrorTable;
|
||||
|
||||
class ScriptSubView : public CSVDoc::SubView
|
||||
{
|
||||
|
@ -39,6 +41,8 @@ namespace CSVWorld
|
|||
RecordButtonBar *mButtons;
|
||||
CSMWorld::CommandDispatcher mCommandDispatcher;
|
||||
QVBoxLayout mLayout;
|
||||
QSplitter *mMain;
|
||||
ScriptErrorTable *mErrors;
|
||||
|
||||
private:
|
||||
|
||||
|
|
Loading…
Reference in a new issue