summaryrefslogtreecommitdiff
path: root/src/client_manager.hh
blob: 2c2e01bc0a4da6f8fb9eb2338dbb956b9a144479 (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
48
49
50
51
52
53
54
55
56
57
#ifndef client_manager_hh_INCLUDED
#define client_manager_hh_INCLUDED

#include "client.hh"
#include "completion.hh"

namespace Kakoune
{

struct client_removed{};

struct WindowAndSelections
{
    std::unique_ptr<Window> window;
    SelectionList selections;
    size_t timestamp;
};

class ClientManager : public Singleton<ClientManager>
{
public:
    ClientManager();
    ~ClientManager();

    Client* create_client(std::unique_ptr<UserInterface>&& ui,
                          EnvVarMap env_vars, StringView init_cmd);

    bool   empty() const { return m_clients.empty(); }
    size_t count() const { return m_clients.size(); }

    void    ensure_no_client_uses_buffer(Buffer& buffer);

    WindowAndSelections get_free_window(Buffer& buffer);
    void add_free_window(std::unique_ptr<Window>&& window, SelectionList selections);

    void redraw_clients() const;
    void clear_mode_trashes() const;

    Client*  get_client_ifp(StringView name);
    Client&  get_client(StringView name);
    bool validate_client_name(StringView name) const;
    void remove_client(Client& client);

    CandidateList complete_client_name(StringView name,
                                       ByteCount cursor_pos = -1) const;

private:
    String generate_name() const;

    std::vector<std::unique_ptr<Client>> m_clients;
    std::vector<WindowAndSelections> m_free_windows;
};

}

#endif // client_manager_hh_INCLUDED