int LuaUnsyncedRead::GetKeyBindings(lua_State* L)
{
	const int args = lua_gettop(L); // number of arguments
	if ((args != 1) || !lua_isstring(L, 1)) {
		luaL_error(L, "Incorrect arguments to GetKeyBindings(\"keyset\")");
	}
	const string keysetStr = lua_tostring(L, 1);
	CKeySet ks;
	if (!ks.Parse(keysetStr)) {
		return 0;
	}
	const CKeyBindings::ActionList&	actions = keyBindings->GetActionList(ks);
	lua_newtable(L);
	for (int i = 0; i < (int)actions.size(); i++) {
		const Action& action = actions[i];
		lua_pushnumber(L, i + 1);
		lua_newtable(L);
		lua_pushstring(L, action.command.c_str());
		lua_pushstring(L, action.extra.c_str());
		lua_rawset(L, -3);
		lua_rawset(L, -3);
	}
	lua_pushstring(L, "n");
	lua_pushnumber(L, actions.size());
	lua_rawset(L, -3);
	return 1;
}
Exemplo n.º 2
0
bool CKeyBindings::AddKeySymbol(const string& keysym, const string& code)
{
	CKeySet ks;
	if (!ks.Parse(code)) {
		LOG_L(L_WARNING, "AddKeySymbol: could not parse key: %s", code.c_str());
		return false;
	}
	if (!keyCodes->AddKeySymbol(keysym, ks.Key())) {
		LOG_L(L_WARNING, "AddKeySymbol: could not add: %s", keysym.c_str());
		return false;
	}
	return true;
}
Exemplo n.º 3
0
bool CKeyBindings::AddKeySymbol(const string& keysym, const string& code)
{
	CKeySet ks;
	if (!ks.Parse(code)) {
		logOutput.Print("AddKeySymbol: could not parse key: %s\n", code.c_str());
		return false;
	}
	if (!keyCodes->AddKeySymbol(keysym, ks.Key())) {
		logOutput.Print("AddKeySymbol: could not add: %s\n", keysym.c_str());
		return false;
	}
	return true;
}
Exemplo n.º 4
0
bool CKeyBindings::AddNamedKeySet(const string& name, const string& keystr)
{
	CKeySet ks;
	if (!ks.Parse(keystr)) {
		printf("AddNamedKeySet: could not parse keyset: %s\n", keystr.c_str());
		return false;
	}
	if ((ks.Key() < 0) || !CKeyCodes::IsValidLabel(name)) {
		printf("AddNamedKeySet: bad custom keyset name: %s\n", name.c_str());
		return false;
	}
	namedKeySets[name] = ks;
}
Exemplo n.º 5
0
bool CKeyBindings::SetFakeMetaKey(const string& keystr)
{
	CKeySet ks;
	if (StringToLower(keystr) == "none") {
		fakeMetaKey = -1;
		return true;
	}
	if (!ks.Parse(keystr)) {
		LOG_L(L_WARNING, "SetFakeMetaKey: could not parse key: %s", keystr.c_str());
		return false;
	}
	fakeMetaKey = ks.Key();
	return true;
}
Exemplo n.º 6
0
bool CKeyBindings::SetFakeMetaKey(const string& keystr)
{
	CKeySet ks;
	if (StringToLower(keystr) == "none") {
		fakeMetaKey = -1;
		return true;
	}
	if (!ks.Parse(keystr)) {
		logOutput.Print("SetFakeMetaKey: could not parse key: %s\n", keystr.c_str());
		return false;
	}
	fakeMetaKey = ks.Key();
	return true;
}
Exemplo n.º 7
0
bool CKeyBindings::ParseKeySet(const string& keystr, CKeySet& ks) const
{
	if (keystr[0] != NamedKeySetChar) {
		return ks.Parse(keystr);
	}
	else {
		const string keysetName = keystr.substr(1);
		NamedKeySetMap::const_iterator it = namedKeySets.find(keysetName);
		if (it !=  namedKeySets.end()) {
			ks = it->second;
		} else {
			return false;
		}
	}
	return true;
}
Exemplo n.º 8
0
bool CKeyBindings::UnBindKeyset(const std::string& keystr)
{
    CKeySet ks;
    if (!ks.Parse(keystr)) {
        LOG_L(L_WARNING, "UnBindKeyset: could not parse key: %s", keystr.c_str());
        return false;
    }
    bool success = false;

    KeyMap::iterator it = bindings.find(ks);
    if (it != bindings.end()) {
        bindings.erase(it);
        success = true;
    }

    return success;
}
Exemplo n.º 9
0
bool CKeyBindings::UnBind(const std::string& keystr, const std::string& command)
{
    CKeySet ks;
    if (!ks.Parse(keystr)) {
        LOG_L(L_WARNING, "UnBind: could not parse key: %s", keystr.c_str());
        return false;
    }
    bool success = false;

    KeyMap::iterator it = bindings.find(ks);
    if (it != bindings.end()) {
        ActionList& al = it->second;
        success = RemoveCommandFromList(al, command);
        if (al.empty()) {
            bindings.erase(it);
        }
    }
    return success;
}
Exemplo n.º 10
0
static bool ParseSingleChain(const std::string& keystr, CKeyChain* kc)
{
    kc->clear();
    CKeySet ks;

    // note: this will fail if keystr contains spaces
    std::stringstream ss(keystr);

    while (ss.good()) {
        char kcstr[256];
        ss.getline(kcstr, 256, ',');
        std::string kstr(kcstr);

        if (!ks.Parse(kstr, false))
            return false;

        kc->emplace_back(ks);
    }

    return true;
}