Minor formatting changes

This commit is contained in:
Maxime Coste 2014-04-01 18:54:46 +01:00
parent ac90839c3d
commit 84c30c4b8a
4 changed files with 47 additions and 19 deletions

View File

@ -40,8 +40,8 @@ void on_assert_failed(const char* message)
return;
}
#else
int res = system(("xmessage -buttons 'quit:0,ignore:1' '" + msg + "'").c_str());
switch (res)
auto cmd = "xmessage -buttons 'quit:0,ignore:1' '" + msg + "'";
switch (system(cmd.c_str()))
{
case -1:
case 0:

View File

@ -72,8 +72,10 @@ private:
class BufferChangeListener
{
public:
virtual void on_insert(const Buffer& buffer, BufferCoord begin, BufferCoord end) = 0;
virtual void on_erase(const Buffer& buffer, BufferCoord begin, BufferCoord end) = 0;
virtual void on_insert(const Buffer& buffer,
BufferCoord begin, BufferCoord end) = 0;
virtual void on_erase(const Buffer& buffer,
BufferCoord begin, BufferCoord end) = 0;
};
// A Buffer is a in-memory representation of a file
@ -107,8 +109,8 @@ public:
BufferIterator insert(const BufferIterator& pos, String content);
BufferIterator erase(BufferIterator begin, BufferIterator end);
size_t timestamp() const { return m_timestamp; }
size_t line_timestamp(LineCount line) const { return m_lines[line].timestamp; }
size_t timestamp() const;
size_t line_timestamp(LineCount line) const;
time_t fs_timestamp() const;
void set_fs_timestamp(time_t ts);
@ -128,8 +130,8 @@ public:
BufferCoord char_next(BufferCoord coord) const;
BufferCoord char_prev(BufferCoord coord) const;
BufferCoord back_coord() const { return { line_count() - 1, m_lines.back().length() - 1 }; }
BufferCoord end_coord() const { return { line_count() - 1, m_lines.back().length() }; }
BufferCoord back_coord() const;
BufferCoord end_coord() const;
bool is_valid(BufferCoord c) const;
bool is_end(BufferCoord c) const;

View File

@ -86,6 +86,26 @@ inline LineCount Buffer::line_count() const
return LineCount(m_lines.size());
}
inline size_t Buffer::timestamp() const
{
return m_timestamp;
}
inline size_t Buffer::line_timestamp(LineCount line) const
{
return m_lines[line].timestamp;
}
inline BufferCoord Buffer::back_coord() const
{
return { line_count() - 1, m_lines.back().length() - 1 };
}
inline BufferCoord Buffer::end_coord() const
{
return { line_count() - 1, m_lines.back().length() };
}
inline BufferIterator::BufferIterator(const Buffer& buffer, BufferCoord coord)
: m_buffer(&buffer), m_coord(coord)
{

View File

@ -16,7 +16,8 @@ Client::Client(std::unique_ptr<UserInterface>&& ui,
std::unique_ptr<Window>&& window,
SelectionList selections, String name)
: m_ui{std::move(ui)}, m_window{std::move(window)},
m_input_handler{m_window->buffer(), std::move(selections), std::move(name)}
m_input_handler{m_window->buffer(), std::move(selections),
std::move(name)}
{
context().set_client(*this);
context().set_window(*m_window);
@ -63,8 +64,10 @@ DisplayLine Client::generate_mode_line() const
void Client::change_buffer(Buffer& buffer)
{
ClientManager::instance().add_free_window(std::move(m_window), std::move(context().selections()));
WindowAndSelections ws = ClientManager::instance().get_free_window(buffer);
auto& client_manager = ClientManager::instance();
client_manager.add_free_window(std::move(m_window),
std::move(context().selections()));
WindowAndSelections ws = client_manager.get_free_window(buffer);
m_window = std::move(ws.window);
context().m_selections = std::move(ws.selections);
context().set_window(*m_window);
@ -116,12 +119,13 @@ void Client::check_buffer_fs_timestamp()
{
DisplayCoord pos = context().window().dimensions();
pos.column -= 1;
m_ui->info_show("reload '" + buffer.display_name() + "' ?",
m_ui->info_show(
"reload '" + buffer.display_name() + "' ?",
"'" + buffer.display_name() + "' was modified externally\n"
"press r or y to reload, k or n to keep",
pos, get_color("Information"), MenuStyle::Prompt);
m_input_handler.on_next_key([this, ts, filename](Key key, Context& context) {
m_input_handler.on_next_key([=, this](Key key, Context& context) {
Buffer* buf = BufferManager::instance().get_buffer_ifp(filename);
m_ui->info_hide();
// buffer got deleted while waiting for the key, do nothing
@ -132,11 +136,13 @@ void Client::check_buffer_fs_timestamp()
else if (key == 'k' or key == 'n')
{
buf->set_fs_timestamp(ts);
print_status({"'" + buf->display_name() + "' kept", get_color("Information") });
print_status({ "'" + buf->display_name() + "' kept",
get_color("Information") });
}
else
{
print_status({"'" + key_to_str(key) + "' is not a valid choice", get_color("Error")});
print_status({ "'" + key_to_str(key) + "' is not a valid choice",
get_color("Error") });
check_buffer_fs_timestamp();
}
});