mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-07 21:40:11 +00:00
Merge remote-tracking branch 'plutonicoverkill/master'
This commit is contained in:
commit
7919c4d672
@ -326,6 +326,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)
|
||||
|
@ -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);
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <QVector>
|
||||
#include <QTimer>
|
||||
#include <QFont>
|
||||
#include <QAction>
|
||||
|
||||
#include "../../model/world/universalid.hpp"
|
||||
|
||||
@ -54,6 +55,8 @@ namespace CSVWorld
|
||||
QFont mDefaultFont;
|
||||
QFont mMonoFont;
|
||||
int mTabCharCount;
|
||||
QAction *mCommentAction;
|
||||
QAction *mUncommentAction;
|
||||
|
||||
protected:
|
||||
|
||||
@ -77,6 +80,8 @@ namespace CSVWorld
|
||||
|
||||
virtual void resizeEvent(QResizeEvent *e);
|
||||
|
||||
virtual void contextMenuEvent(QContextMenuEvent *event);
|
||||
|
||||
private:
|
||||
|
||||
QVector<CSMWorld::UniversalId::Type> mAllowedTypes;
|
||||
@ -111,6 +116,10 @@ namespace CSVWorld
|
||||
void updateLineNumberAreaWidth(int newBlockCount);
|
||||
|
||||
void updateLineNumberArea(const QRect &, int);
|
||||
|
||||
void commentSelection();
|
||||
|
||||
void uncommentSelection();
|
||||
};
|
||||
|
||||
class LineNumberArea : public QWidget
|
||||
|
Loading…
x
Reference in New Issue
Block a user