Commit 8b37921b authored by hjk's avatar hjk Committed by hjk
Browse files

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



Task-number: QTCREATORBUG-7375
Change-Id: I947dd903a5e7d09e367afbc771582793e6c008f1
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
Reviewed-by: default avatarRobert Löhning <robert.loehning@nokia.com>
parent 4ea0cde8
......@@ -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;
......
......@@ -85,6 +85,7 @@ public:
Utils::SavedAction *item(int code);
Utils::SavedAction *item(const QString &name);
QString trySetValue(const QString &name, const QString &value);
void readSettings(QSettings *settings);
void writeSettings(QSettings *settings);
......
......@@ -3586,9 +3586,10 @@ bool FakeVimHandler::Private::handleExSetCommand(const ExCommand &cmd)
} else if (cmd.args.contains('=')) {
// Non-boolean config to set.
int p = cmd.args.indexOf('=');
act = theFakeVimSettings()->item(cmd.args.left(p));
if (act)
act->setValue(cmd.args.mid(p + 1));
QString error = theFakeVimSettings()
->trySetValue(cmd.args.left(p), cmd.args.mid(p + 1));
if (!error.isEmpty())
showRedMessage(error);
} else {
showRedMessage(FakeVimHandler::tr("Unknown option: ") + cmd.args);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment