Do not fail to evaluate an expression if some input is missing

My keyboard layout does not have Alt_R but ISO_Level3_Shift. As a
consequence any control expression containing Alt_R fails to evaluate
completely and is unusable. This modification replace the missing term
of the expression by a dummy expression which always evaluate to
0. This way, the keybinding can work even if some keys are not
available.
This commit is contained in:
Gabriel Corona 2015-02-26 00:41:59 +01:00
parent b1fbf205ec
commit c626ce5809
1 changed files with 31 additions and 1 deletions

View File

@ -219,6 +219,33 @@ public:
virtual operator std::string() { return ""; }
};
class DummyExpression : public ExpressionNode
{
public:
std::string name;
DummyExpression(const std::string& name_) : name(name_) {}
ControlState GetValue() override
{
return 0.0;
}
void SetValue(ControlState value) override
{
}
int CountNumControls() override
{
return 0;
}
operator std::string() override
{
return "`" + name + "`";
}
};
class ControlExpression : public ExpressionNode
{
public:
@ -416,7 +443,10 @@ private:
{
Device::Control *control = finder.FindControl(tok.qualifier);
if (control == nullptr)
return EXPRESSION_PARSE_NO_DEVICE;
{
*expr_out = new DummyExpression(tok.qualifier);
return EXPRESSION_PARSE_SUCCESS;
}
*expr_out = new ControlExpression(tok.qualifier, control);
return EXPRESSION_PARSE_SUCCESS;