|
|
|
@ -7,12 +7,14 @@
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QTextDocumentFragment>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
|
|
|
|
|
#include "../../model/doc/document.hpp"
|
|
|
|
|
|
|
|
|
|
#include "../../model/world/universalid.hpp"
|
|
|
|
|
#include "../../model/world/tablemimedata.hpp"
|
|
|
|
|
#include "../../model/prefs/state.hpp"
|
|
|
|
|
#include "../../model/prefs/shortcut.hpp"
|
|
|
|
|
|
|
|
|
|
CSVWorld::ScriptEdit::ChangeLock::ChangeLock (ScriptEdit& edit) : mEdit (edit)
|
|
|
|
|
{
|
|
|
|
@ -86,6 +88,16 @@ CSVWorld::ScriptEdit::ScriptEdit(
|
|
|
|
|
<<CSMWorld::UniversalId::Type_Script
|
|
|
|
|
<<CSMWorld::UniversalId::Type_Region;
|
|
|
|
|
|
|
|
|
|
mCommentAction = new QAction (tr ("Comment Selection"), this);
|
|
|
|
|
connect(mCommentAction, SIGNAL (triggered()), this, SLOT (commentSelection()));
|
|
|
|
|
CSMPrefs::Shortcut *commentShortcut = new CSMPrefs::Shortcut("script-editor-comment", this);
|
|
|
|
|
commentShortcut->associateAction(mCommentAction);
|
|
|
|
|
|
|
|
|
|
mUncommentAction = new QAction (tr ("Uncomment Selection"), this);
|
|
|
|
|
connect(mUncommentAction, SIGNAL (triggered()), this, SLOT (uncommentSelection()));
|
|
|
|
|
CSMPrefs::Shortcut *uncommentShortcut = new CSMPrefs::Shortcut("script-editor-uncomment", this);
|
|
|
|
|
uncommentShortcut->associateAction(mUncommentAction);
|
|
|
|
|
|
|
|
|
|
mHighlighter = new ScriptHighlighter (document.getData(), mode, ScriptEdit::document());
|
|
|
|
|
|
|
|
|
|
connect (&document.getData(), SIGNAL (idListChanged()), this, SLOT (idListChanged()));
|
|
|
|
@ -284,6 +296,65 @@ void CSVWorld::ScriptEdit::updateLineNumberArea(const QRect &rect, int dy)
|
|
|
|
|
updateLineNumberAreaWidth(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::ScriptEdit::commentSelection()
|
|
|
|
|
{
|
|
|
|
|
QTextCursor begin = textCursor();
|
|
|
|
|
QTextCursor end = begin;
|
|
|
|
|
begin.setPosition(begin.selectionStart());
|
|
|
|
|
begin.movePosition(QTextCursor::StartOfLine);
|
|
|
|
|
|
|
|
|
|
end.setPosition(end.selectionEnd());
|
|
|
|
|
end.movePosition(QTextCursor::EndOfLine);
|
|
|
|
|
|
|
|
|
|
begin.beginEditBlock();
|
|
|
|
|
|
|
|
|
|
for (; begin < end; begin.movePosition(QTextCursor::EndOfLine), begin.movePosition(QTextCursor::Right))
|
|
|
|
|
{
|
|
|
|
|
begin.insertText(";");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
begin.endEditBlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::ScriptEdit::uncommentSelection()
|
|
|
|
|
{
|
|
|
|
|
QTextCursor begin = textCursor();
|
|
|
|
|
QTextCursor end = begin;
|
|
|
|
|
begin.setPosition(begin.selectionStart());
|
|
|
|
|
begin.movePosition(QTextCursor::StartOfLine);
|
|
|
|
|
|
|
|
|
|
end.setPosition(end.selectionEnd());
|
|
|
|
|
end.movePosition(QTextCursor::EndOfLine);
|
|
|
|
|
|
|
|
|
|
begin.beginEditBlock();
|
|
|
|
|
|
|
|
|
|
for (; begin < end; begin.movePosition(QTextCursor::EndOfLine), begin.movePosition(QTextCursor::Right)) {
|
|
|
|
|
begin.select(QTextCursor::LineUnderCursor);
|
|
|
|
|
QString line = begin.selectedText();
|
|
|
|
|
|
|
|
|
|
if (line.size() == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// get first nonspace character in line
|
|
|
|
|
int index;
|
|
|
|
|
for (index = 0; index != line.size(); ++index)
|
|
|
|
|
{
|
|
|
|
|
if (!line[index].isSpace())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (index != line.size() && line[index] == ';')
|
|
|
|
|
{
|
|
|
|
|
// remove the semicolon
|
|
|
|
|
line.remove(index, 1);
|
|
|
|
|
// put the line back
|
|
|
|
|
begin.insertText(line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
begin.endEditBlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::ScriptEdit::resizeEvent(QResizeEvent *e)
|
|
|
|
|
{
|
|
|
|
|
QPlainTextEdit::resizeEvent(e);
|
|
|
|
@ -292,6 +363,26 @@ void CSVWorld::ScriptEdit::resizeEvent(QResizeEvent *e)
|
|
|
|
|
mLineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::ScriptEdit::contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QMenu *menu = createStandardContextMenu();
|
|
|
|
|
|
|
|
|
|
// remove redo/undo since they are disabled
|
|
|
|
|
QList<QAction*> menuActions = menu->actions();
|
|
|
|
|
for (QList<QAction*>::iterator i = menuActions.begin(); i < menuActions.end(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if ((*i)->text().contains("Undo") || (*i)->text().contains("Redo"))
|
|
|
|
|
{
|
|
|
|
|
(*i)->setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
menu->addAction(mCommentAction);
|
|
|
|
|
menu->addAction(mUncommentAction);
|
|
|
|
|
|
|
|
|
|
menu->exec(event->globalPos());
|
|
|
|
|
delete menu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSVWorld::ScriptEdit::lineNumberAreaPaintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QPainter painter(mLineNumberArea);
|
|
|
|
|