summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/Shortcut.cpp
blob: 73ce0db1073d21e68f5be5b374d5a360a9c8f7d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 * Copyright (c) 2022, Geordie Hall <me@geordiehall.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <LibGUI/Shortcut.h>

namespace GUI {

String Shortcut::to_string() const
{
    Vector<String, 8> parts;

    if (m_modifiers & Mod_Ctrl)
        parts.append("Ctrl");
    if (m_modifiers & Mod_Shift)
        parts.append("Shift");
    if (m_modifiers & Mod_Alt)
        parts.append("Alt");
    if (m_modifiers & Mod_AltGr)
        parts.append("AltGr");
    if (m_modifiers & Mod_Super)
        parts.append("Super");

    if (m_type == Type::Keyboard) {
        if (auto* key_name = key_code_to_string(m_keyboard_key))
            parts.append(key_name);
        else
            parts.append("(Invalid)");
    } else {
        if (m_mouse_button != MouseButton::None)
            parts.append(String::formatted("Mouse {}", mouse_button_to_string(m_mouse_button)));
        else
            parts.append("(Invalid)");
    }

    StringBuilder builder;
    builder.join('+', parts);
    return builder.to_string();
}

}