new clients always takes last used buffer, support multiple file on command line

This commit is contained in:
Maxime Coste 2012-12-28 13:51:14 +01:00
parent 8f5be9bf91
commit d4f155cae7
4 changed files with 21 additions and 24 deletions

View File

@ -8,9 +8,9 @@ namespace Kakoune
{
void ClientManager::create_client(std::unique_ptr<UserInterface>&& ui,
Buffer& buffer, int event_fd,
const String& init_commands)
int event_fd, const String& init_commands)
{
Buffer& buffer = **BufferManager::instance().begin();
m_clients.emplace_back(new Client{std::move(ui), get_unused_window_for_buffer(buffer)});
InputHandler* input_handler = &m_clients.back()->input_handler;

View File

@ -13,8 +13,7 @@ class ClientManager : public Singleton<ClientManager>
{
public:
void create_client(std::unique_ptr<UserInterface>&& ui,
Buffer& buffer, int event_fd,
const String& init_cmd);
int event_fd, const String& init_cmd);
bool empty() const { return m_clients.empty(); }
size_t count() const { return m_clients.size(); }

View File

@ -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
{
~LocalNCursesUI()
@ -649,20 +647,8 @@ void create_local_client(const String& file, const String& init_command)
};
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(
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)
@ -771,7 +757,21 @@ int main(int argc, char* argv[])
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())
event_manager.handle_next_events();

View File

@ -3,7 +3,6 @@
#include "display_buffer.hh"
#include "debug.hh"
#include "client_manager.hh"
#include "buffer_manager.hh"
#include "event_manager.hh"
#include <sys/types.h>
@ -370,11 +369,10 @@ void handle_remote(int socket)
{
String init_command = read<String>(socket);
auto& buffer = *BufferManager::instance().begin();
RemoteUI* ui = new RemoteUI{socket};
EventManager::instance().unwatch(socket);
ClientManager::instance().create_client(
std::unique_ptr<UserInterface>{ui}, *buffer, socket, init_command);
std::unique_ptr<UserInterface>{ui}, socket, init_command);
}
}