Merge branch 'master' into mark-variable

This commit is contained in:
PlutonicOverkill 2017-04-28 20:15:48 +12:00 committed by GitHub
commit 95f60d2bb3
5 changed files with 114 additions and 1 deletions

View file

@ -117,6 +117,7 @@ Programmers
Pi03k
Pieter van der Kloet (pvdk)
pkubik
PlutonicOverkill
Radu-Marius Popovici (rpopovici)
Rafael Moura (dhustkoder)
rdimesio

View file

@ -328,6 +328,10 @@ void CSMPrefs::State::declare()
declareShortcut ("orbit-roll-right", "Roll Right", QKeySequence(Qt::Key_E));
declareShortcut ("orbit-speed-mode", "Toggle Speed Mode", QKeySequence(Qt::Key_F));
declareShortcut ("orbit-center-selection", "Center On Selected", QKeySequence(Qt::Key_C));
declareSubcategory ("Script Editor");
declareShortcut ("script-editor-comment", "Comment Selection", QKeySequence());
declareShortcut ("script-editor-uncomment", "Uncomment Selection", QKeySequence());
}
void CSMPrefs::State::declareCategory (const std::string& key)

View file

@ -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)
{
@ -90,6 +92,16 @@ CSVWorld::ScriptEdit::ScriptEdit(
connect(this, SIGNAL(selectionChanged()), this, SLOT(markOccurrences()));
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()));
@ -317,6 +329,65 @@ void CSVWorld::ScriptEdit::markOccurrences()
mMarkOccurrencesRunning = false;
}
}
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)
{
@ -326,6 +397,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);

View file

@ -6,6 +6,7 @@
#include <QVector>
#include <QTimer>
#include <QFont>
#include <QAction>
#include "../../model/world/universalid.hpp"
@ -56,6 +57,8 @@ namespace CSVWorld
int mTabCharCount;
bool mMarkOccurrences;
bool mMarkOccurrencesRunning;
QAction *mCommentAction;
QAction *mUncommentAction;
protected:
@ -79,6 +82,8 @@ namespace CSVWorld
virtual void resizeEvent(QResizeEvent *e);
virtual void contextMenuEvent(QContextMenuEvent *event);
private:
QVector<CSMWorld::UniversalId::Type> mAllowedTypes;
@ -115,6 +120,11 @@ namespace CSVWorld
void updateLineNumberArea(const QRect &, int);
void markOccurrences();
void commentSelection();
void uncommentSelection();
};
class LineNumberArea : public QWidget

View file

@ -52,6 +52,13 @@ void CSVWorld::ScriptErrorTable::addMessage (const std::string& message,
columnItem->setFlags (columnItem->flags() ^ Qt::ItemIsEditable);
setItem (row, 3, columnItem);
}
else
{
QTableWidgetItem *lineItem = new QTableWidgetItem;
lineItem->setData (Qt::DisplayRole, "-");
lineItem->setFlags (lineItem->flags() ^ Qt::ItemIsEditable);
setItem (row, 1, lineItem);
}
QTableWidgetItem *messageItem = new QTableWidgetItem (QString::fromUtf8 (message.c_str()));
messageItem->setFlags (messageItem->flags() ^ Qt::ItemIsEditable);
@ -141,7 +148,7 @@ void CSVWorld::ScriptErrorTable::settingChanged (const CSMPrefs::Setting *settin
void CSVWorld::ScriptErrorTable::cellClicked (int row, int column)
{
if (item (row, 1))
if (item (row, 3))
{
int scriptLine = item (row, 1)->data (Qt::DisplayRole).toInt();
int scriptColumn = item (row, 3)->data (Qt::DisplayRole).toInt();