new clients always takes last used buffer, support multiple file on command line
This commit is contained in:
parent
8f5be9bf91
commit
d4f155cae7
|
@ -8,9 +8,9 @@ namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
void ClientManager::create_client(std::unique_ptr<UserInterface>&& ui,
|
void ClientManager::create_client(std::unique_ptr<UserInterface>&& ui,
|
||||||
Buffer& buffer, int event_fd,
|
int event_fd, const String& init_commands)
|
||||||
const String& init_commands)
|
|
||||||
{
|
{
|
||||||
|
Buffer& buffer = **BufferManager::instance().begin();
|
||||||
m_clients.emplace_back(new Client{std::move(ui), get_unused_window_for_buffer(buffer)});
|
m_clients.emplace_back(new Client{std::move(ui), get_unused_window_for_buffer(buffer)});
|
||||||
|
|
||||||
InputHandler* input_handler = &m_clients.back()->input_handler;
|
InputHandler* input_handler = &m_clients.back()->input_handler;
|
||||||
|
|
|
@ -13,8 +13,7 @@ class ClientManager : public Singleton<ClientManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void create_client(std::unique_ptr<UserInterface>&& ui,
|
void create_client(std::unique_ptr<UserInterface>&& ui,
|
||||||
Buffer& buffer, int event_fd,
|
int event_fd, const String& init_cmd);
|
||||||
const String& init_cmd);
|
|
||||||
|
|
||||||
bool empty() const { return m_clients.empty(); }
|
bool empty() const { return m_clients.empty(); }
|
||||||
size_t count() const { return m_clients.size(); }
|
size_t count() const { return m_clients.size(); }
|
||||||
|
|
34
src/main.cc
34
src/main.cc
|
@ -631,10 +631,8 @@ void register_registers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_local_client(const String& file, const String& init_command)
|
void create_local_client(const String& init_command)
|
||||||
{
|
{
|
||||||
Buffer* buffer = nullptr;
|
|
||||||
|
|
||||||
class LocalNCursesUI : public NCursesUI
|
class LocalNCursesUI : public NCursesUI
|
||||||
{
|
{
|
||||||
~LocalNCursesUI()
|
~LocalNCursesUI()
|
||||||
|
@ -649,20 +647,8 @@ void create_local_client(const String& file, const String& init_command)
|
||||||
};
|
};
|
||||||
|
|
||||||
UserInterface* ui = new LocalNCursesUI{};
|
UserInterface* ui = new LocalNCursesUI{};
|
||||||
if (not file.empty())
|
|
||||||
{
|
|
||||||
buffer = create_buffer_from_file(file);
|
|
||||||
if (not buffer)
|
|
||||||
{
|
|
||||||
ui->print_status("new file " + file, -1);
|
|
||||||
buffer = new Buffer(file, Buffer::Flags::New | Buffer::Flags::File);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
buffer = new Buffer("*scratch*", Buffer::Flags::None);
|
|
||||||
|
|
||||||
ClientManager::instance().create_client(
|
ClientManager::instance().create_client(
|
||||||
std::unique_ptr<UserInterface>{ui}, *buffer, 0, init_command);
|
std::unique_ptr<UserInterface>{ui}, 0, init_command);
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteClient* connect_to(const String& pid, const String& init_command)
|
RemoteClient* connect_to(const String& pid, const String& init_command)
|
||||||
|
@ -771,7 +757,21 @@ int main(int argc, char* argv[])
|
||||||
write_debug("error while parsing kakrc: " + error.description());
|
write_debug("error while parsing kakrc: " + error.description());
|
||||||
}
|
}
|
||||||
|
|
||||||
create_local_client(parser.positional_count() > 0 ? parser[0] : "", init_command);
|
if (parser.positional_count() != 0)
|
||||||
|
{
|
||||||
|
// create buffers in reverse order so that the first given buffer
|
||||||
|
// is the most recently created one.
|
||||||
|
for (int i = parser.positional_count() - 1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
const String& file = parser[i];
|
||||||
|
if (not create_buffer_from_file(file))
|
||||||
|
new Buffer(file, Buffer::Flags::New | Buffer::Flags::File);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
new Buffer("*scratch*", Buffer::Flags::None);
|
||||||
|
|
||||||
|
create_local_client(init_command);
|
||||||
|
|
||||||
while (not client_manager.empty())
|
while (not client_manager.empty())
|
||||||
event_manager.handle_next_events();
|
event_manager.handle_next_events();
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include "display_buffer.hh"
|
#include "display_buffer.hh"
|
||||||
#include "debug.hh"
|
#include "debug.hh"
|
||||||
#include "client_manager.hh"
|
#include "client_manager.hh"
|
||||||
#include "buffer_manager.hh"
|
|
||||||
#include "event_manager.hh"
|
#include "event_manager.hh"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -370,11 +369,10 @@ void handle_remote(int socket)
|
||||||
{
|
{
|
||||||
String init_command = read<String>(socket);
|
String init_command = read<String>(socket);
|
||||||
|
|
||||||
auto& buffer = *BufferManager::instance().begin();
|
|
||||||
RemoteUI* ui = new RemoteUI{socket};
|
RemoteUI* ui = new RemoteUI{socket};
|
||||||
EventManager::instance().unwatch(socket);
|
EventManager::instance().unwatch(socket);
|
||||||
ClientManager::instance().create_client(
|
ClientManager::instance().create_client(
|
||||||
std::unique_ptr<UserInterface>{ui}, *buffer, socket, init_command);
|
std::unique_ptr<UserInterface>{ui}, socket, init_command);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user