From e685de0f8432358c5ec02afc42ae402005035489 Mon Sep 17 00:00:00 2001 From: PlutonicOverkill Date: Thu, 27 Apr 2017 19:48:01 +1200 Subject: [PATCH] Fix script editor undo/redo context menu actions --- apps/opencs/view/world/scriptedit.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 8804c960ad..bfd07035c9 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -306,10 +306,14 @@ void CSVWorld::ScriptEdit::commentSelection() 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() @@ -322,6 +326,8 @@ void CSVWorld::ScriptEdit::uncommentSelection() 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(); @@ -345,6 +351,8 @@ void CSVWorld::ScriptEdit::uncommentSelection() begin.insertText(line); } } + + begin.endEditBlock(); } void CSVWorld::ScriptEdit::resizeEvent(QResizeEvent *e) @@ -358,6 +366,16 @@ void CSVWorld::ScriptEdit::resizeEvent(QResizeEvent *e) void CSVWorld::ScriptEdit::contextMenuEvent(QContextMenuEvent *event) { QMenu *menu = createStandardContextMenu(); + + // remove redo/undo since they are disabled + QList menuActions = menu->actions(); + for (QList::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);