diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index b8d6102ac..3de90e468 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -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) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index eb9757f60..531c732ea 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -14,6 +14,7 @@ #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) { @@ -87,6 +88,20 @@ CSVWorld::ScriptEdit::ScriptEdit( <associateAction(comment); + mContextMenu->addAction(comment); + + QAction* uncomment = new QAction (tr ("Uncomment Selection"), this); + connect(uncomment, SIGNAL (triggered()), this, SLOT (uncommentSelection())); + CSMPrefs::Shortcut* uncommentShortcut = new CSMPrefs::Shortcut("script-editor-uncomment", this); + uncommentShortcut->associateAction(uncomment); + mContextMenu->addAction(uncomment); + mHighlighter = new ScriptHighlighter (document.getData(), mode, ScriptEdit::document()); connect (&document.getData(), SIGNAL (idListChanged()), this, SLOT (idListChanged())); @@ -295,7 +310,7 @@ void CSVWorld::ScriptEdit::commentSelection() end.setPosition(end.selectionEnd()); end.movePosition(QTextCursor::EndOfLine); - for (; begin < end; begin.movePosition(QTextCursor::StartOfLine), begin.movePosition(QTextCursor::Down)) + for (; begin < end; begin.movePosition(QTextCursor::EndOfLine), begin.movePosition(QTextCursor::Right)) { begin.insertText(";"); } @@ -311,7 +326,7 @@ void CSVWorld::ScriptEdit::uncommentSelection() end.setPosition(end.selectionEnd()); end.movePosition(QTextCursor::EndOfLine); - for (; begin < end; begin.movePosition(QTextCursor::StartOfLine), begin.movePosition(QTextCursor::Down)) { + for (; begin < end; begin.movePosition(QTextCursor::EndOfLine), begin.movePosition(QTextCursor::Right)) { begin.select(QTextCursor::LineUnderCursor); QString line = begin.selectedText(); @@ -346,12 +361,7 @@ void CSVWorld::ScriptEdit::resizeEvent(QResizeEvent *e) void CSVWorld::ScriptEdit::contextMenuEvent(QContextMenuEvent *event) { - QMenu *menu = createStandardContextMenu(); - menu->addAction("Comment Selection", this, SLOT(commentSelection())); - menu->addAction("Uncomment Selection", this, SLOT(uncommentSelection())); - - menu->exec(event->globalPos()); - delete menu; + mContextMenu->exec(event->globalPos()); } void CSVWorld::ScriptEdit::lineNumberAreaPaintEvent(QPaintEvent *event) diff --git a/apps/opencs/view/world/scriptedit.hpp b/apps/opencs/view/world/scriptedit.hpp index 27e2cd17e..1ae93b62e 100644 --- a/apps/opencs/view/world/scriptedit.hpp +++ b/apps/opencs/view/world/scriptedit.hpp @@ -54,6 +54,7 @@ namespace CSVWorld QFont mDefaultFont; QFont mMonoFont; int mTabCharCount; + QMenu *mContextMenu; protected: