From 1b4c124fe8a36ef3d62f320ee53f7bae5fb577ec Mon Sep 17 00:00:00 2001 From: Rob Cutmore Date: Fri, 25 Mar 2016 12:13:55 -0400 Subject: [PATCH] Create record on Return key press (Feature #3250) Updated to create record when Return key is pressed while input has focus. Record is only created if input has been validated (i.e. Create button is enabled). --- apps/opencs/view/world/genericcreator.cpp | 9 +++++++++ apps/opencs/view/world/genericcreator.hpp | 3 +++ apps/opencs/view/world/infocreator.cpp | 3 ++- apps/opencs/view/world/referencecreator.cpp | 1 + apps/opencs/view/world/startscriptcreator.cpp | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apps/opencs/view/world/genericcreator.cpp b/apps/opencs/view/world/genericcreator.cpp index df7739941..b80625f83 100644 --- a/apps/opencs/view/world/genericcreator.cpp +++ b/apps/opencs/view/world/genericcreator.cpp @@ -170,6 +170,7 @@ CSVWorld::GenericCreator::GenericCreator (CSMWorld::Data& data, QUndoStack& undo connect (mCreate, SIGNAL (clicked (bool)), this, SLOT (create())); connect (mId, SIGNAL (textChanged (const QString&)), this, SLOT (textChanged (const QString&))); + connect (mId, SIGNAL (returnPressed()), this, SLOT (inputReturnPressed())); connect (&mData, SIGNAL (idListChanged()), this, SLOT (dataIdListChanged())); } @@ -205,6 +206,14 @@ void CSVWorld::GenericCreator::textChanged (const QString& text) update(); } +void CSVWorld::GenericCreator::inputReturnPressed() +{ + if (mCreate->isEnabled()) + { + create(); + } +} + void CSVWorld::GenericCreator::create() { if (!mLocked) diff --git a/apps/opencs/view/world/genericcreator.hpp b/apps/opencs/view/world/genericcreator.hpp index f63c45109..f9f6624bb 100644 --- a/apps/opencs/view/world/genericcreator.hpp +++ b/apps/opencs/view/world/genericcreator.hpp @@ -112,6 +112,9 @@ namespace CSVWorld void textChanged (const QString& text); + /// \brief Create record if able to after Return key is pressed on input. + void inputReturnPressed(); + void create(); void scopeChanged (int index); diff --git a/apps/opencs/view/world/infocreator.cpp b/apps/opencs/view/world/infocreator.cpp index 1139afd69..243b7d879 100644 --- a/apps/opencs/view/world/infocreator.cpp +++ b/apps/opencs/view/world/infocreator.cpp @@ -60,6 +60,7 @@ CSVWorld::InfoCreator::InfoCreator (CSMWorld::Data& data, QUndoStack& undoStack, setManualEditing (false); connect (mTopic, SIGNAL (textChanged (const QString&)), this, SLOT (topicChanged())); + connect (mTopic, SIGNAL (returnPressed()), this, SLOT (inputReturnPressed())); } void CSVWorld::InfoCreator::cloneMode (const std::string& originId, @@ -110,7 +111,7 @@ void CSVWorld::InfoCreator::topicChanged() update(); } -CSVWorld::Creator *CSVWorld::InfoCreatorFactory::makeCreator(CSMDoc::Document& document, +CSVWorld::Creator *CSVWorld::InfoCreatorFactory::makeCreator(CSMDoc::Document& document, const CSMWorld::UniversalId& id) const { return new InfoCreator(document.getData(), diff --git a/apps/opencs/view/world/referencecreator.cpp b/apps/opencs/view/world/referencecreator.cpp index 5428f4e95..82169a1a5 100644 --- a/apps/opencs/view/world/referencecreator.cpp +++ b/apps/opencs/view/world/referencecreator.cpp @@ -87,6 +87,7 @@ CSVWorld::ReferenceCreator::ReferenceCreator (CSMWorld::Data& data, QUndoStack& setManualEditing (false); connect (mCell, SIGNAL (textChanged (const QString&)), this, SLOT (cellChanged())); + connect (mCell, SIGNAL (returnPressed()), this, SLOT (inputReturnPressed())); } void CSVWorld::ReferenceCreator::reset() diff --git a/apps/opencs/view/world/startscriptcreator.cpp b/apps/opencs/view/world/startscriptcreator.cpp index 7495da035..1ffcdf06a 100644 --- a/apps/opencs/view/world/startscriptcreator.cpp +++ b/apps/opencs/view/world/startscriptcreator.cpp @@ -53,6 +53,7 @@ CSVWorld::StartScriptCreator::StartScriptCreator( insertBeforeButtons(mScript, true); connect(mScript, SIGNAL (textChanged(const QString&)), this, SLOT (scriptChanged())); + connect(mScript, SIGNAL (returnPressed()), this, SLOT (inputReturnPressed())); } void CSVWorld::StartScriptCreator::cloneMode(