fakevim: don't allow non-positive numbers for tabstop and shiftwidth

Task-number: QTCREATORBUG-7375
Change-Id: I947dd903a5e7d09e367afbc771582793e6c008f1
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
Reviewed-by: Robert Löhning <robert.loehning@nokia.com>
This commit is contained in:
hjk
2012-05-03 10:43:04 +02:00
committed by hjk
parent 4ea0cde8bf
commit 8b37921bc5
3 changed files with 23 additions and 10 deletions

View File

@@ -31,6 +31,7 @@
**************************************************************************/
#include "fakevimactions.h"
#include "fakevimhandler.h"
// Please do not add any direct dependencies to other Qt Creator code here.
// Instead emit signals and let the FakeVimPlugin channel the information to
@@ -41,15 +42,8 @@
#include <utils/qtcassert.h>
#include <QDebug>
#include <QFile>
#include <QObject>
#include <QPointer>
#include <QProcess>
#include <QRegExp>
#include <QTextStream>
#include <QtAlgorithms>
#include <QCoreApplication>
#include <QStack>
using namespace Utils;
@@ -107,6 +101,23 @@ SavedAction *FakeVimSettings::item(const QString &name)
return m_items.value(m_nameToCode.value(name, -1), 0);
}
QString FakeVimSettings::trySetValue(const QString &name, const QString &value)
{
int code = m_nameToCode.value(name, -1);
if (code == -1)
return FakeVimHandler::tr("Unknown option: %1").arg(name);
if (code == ConfigTabStop || code == ConfigShiftWidth) {
if (value.toInt() <= 0)
return FakeVimHandler::tr("Argument must be positive: %1=%2")
.arg(name).arg(value);
}
SavedAction *act = item(code);
if (!act)
return FakeVimHandler::tr("Unknown option: %1").arg(name);
act->setValue(value);
return QString();
}
FakeVimSettings *theFakeVimSettings()
{
static FakeVimSettings *instance = 0;