mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-25 21:48:57 -05:00
Print info message when hiding the UI that shows how to get it back
- Print the information message informing about the keybdining if it exists - Add new function `keyBindingsForAction` that returns the list of keys that are bound to a specific action - Change the parameter to the `keyBindings` function to be optional, causing it to return all actions bound to keys
This commit is contained in:
@@ -47,7 +47,20 @@ local ToggleRollFriction = {
|
||||
local ToggleMainGui = {
|
||||
Identifier = "os.ToggleMainGui",
|
||||
Name = "Toggle main GUI",
|
||||
Command = [[openspace.invertBooleanProperty("Modules.CefWebGui.Visible")]],
|
||||
Command = [[
|
||||
openspace.invertBooleanProperty("Modules.CefWebGui.Visible")
|
||||
|
||||
if not openspace.propertyValue("Modules.CefWebGui.Visible") then
|
||||
local action_id = "os.ToggleMainGui"
|
||||
local keys = openspace.keyBindingsForAction(action_id)
|
||||
if #keys > 0 then
|
||||
local key = keys[1]
|
||||
openspace.printInfo(
|
||||
"Hiding the user interface. You can restore it with the '" .. key .. "' key"
|
||||
)
|
||||
end
|
||||
end
|
||||
]],
|
||||
Documentation = "Toggles the main GUI",
|
||||
GuiPath = "/System/GUI",
|
||||
IsLocal = true
|
||||
|
||||
@@ -119,6 +119,7 @@ scripting::LuaLibrary KeybindingManager::luaLibrary() {
|
||||
{
|
||||
codegen::lua::BindKey,
|
||||
codegen::lua::KeyBindings,
|
||||
codegen::lua::KeyBindingsForAction,
|
||||
codegen::lua::ClearKey,
|
||||
codegen::lua::ClearKeys
|
||||
}
|
||||
|
||||
@@ -49,22 +49,60 @@ namespace {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the strings of the script that are bound to the passed key and whether they
|
||||
* were local or remote key binds.
|
||||
* Returns the identifiers of the action that are bound to the passed key and whether they
|
||||
* were local or remote key binds. If no key is provided, all bound keybindings are
|
||||
* returned instead.
|
||||
*
|
||||
* \param key The key for which to return the keybindings. If no key is provided, all
|
||||
* keybindings are returned
|
||||
*/
|
||||
[[codegen::luawrap]] std::vector<std::string> keyBindings(std::string key) {
|
||||
[[codegen::luawrap]] std::vector<std::string> keyBindings(std::optional<std::string> key)
|
||||
{
|
||||
using namespace openspace;
|
||||
|
||||
using K = KeyWithModifier;
|
||||
using V = std::string;
|
||||
const std::vector<std::pair<K, V>>& info = global::keybindingManager->keyBinding(
|
||||
stringToKey(key)
|
||||
);
|
||||
std::vector<std::string> res;
|
||||
if (key.has_value()) {
|
||||
using K = KeyWithModifier;
|
||||
using V = std::string;
|
||||
const std::vector<std::pair<K, V>>& info = global::keybindingManager->keyBinding(
|
||||
stringToKey(*key)
|
||||
);
|
||||
|
||||
res.reserve(info.size());
|
||||
for (const std::pair<K, V>& it : info) {
|
||||
res.push_back(it.second);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const std::multimap<KeyWithModifier, std::string>& keybinds =
|
||||
global::keybindingManager->keyBindings();
|
||||
|
||||
res.reserve(keybinds.size());
|
||||
for (const std::pair<const KeyWithModifier, std::string>& it : keybinds) {
|
||||
res.push_back(it.second);
|
||||
}
|
||||
|
||||
// Actions might be bound to different actions
|
||||
std::unique(res.begin(), res.end());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the keybinds to which the provided action is bound. As actions can be bound to
|
||||
* multiple keys, this function returns a list of all keys
|
||||
*/
|
||||
[[codegen::luawrap]] std::vector<std::string> keyBindingsForAction(std::string action) {
|
||||
using namespace openspace;
|
||||
|
||||
const std::multimap<KeyWithModifier, std::string>& keybinds =
|
||||
global::keybindingManager->keyBindings();
|
||||
|
||||
std::vector<std::string> res;
|
||||
res.reserve(info.size());
|
||||
for (const std::pair<K, V>& it : info) {
|
||||
res.push_back(it.second);
|
||||
for (const std::pair<const KeyWithModifier, std::string>& it : keybinds) {
|
||||
if (it.second == action) {
|
||||
res.push_back(keyToString(it.first));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user