summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2012-11-22 14:08:55 +0100
committerMaxime Coste <frrrwww@gmail.com>2012-11-22 14:08:55 +0100
commit08ad8e8a40ad189271ecea84ad31bd9ea4d9a5e6 (patch)
tree72765cbbb6e45262c1cae83a1c77d037b6055808 /src
parent3b5530ac09bc688f39cd4cd3c4845d8750664ce9 (diff)
move Window ownership to the ClientManager instead of the Buffer
Diffstat (limited to 'src')
-rw-r--r--src/buffer.cc15
-rw-r--r--src/buffer.hh13
-rw-r--r--src/client_manager.cc14
-rw-r--r--src/client_manager.hh3
-rw-r--r--src/window.hh4
5 files changed, 16 insertions, 33 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index 937cd6bc..0fc1709b 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -43,7 +43,6 @@ Buffer::~Buffer()
{
m_hooks.run_hook("BufClose", m_name, Context(Editor(*this)));
- m_windows.clear();
BufferManager::instance().unregister_buffer(*this);
assert(m_change_listeners.empty());
}
@@ -388,20 +387,6 @@ void Buffer::erase(BufferIterator begin, BufferIterator end)
do_erase(begin, end);
}
-Window& Buffer::new_window()
-{
- m_windows.emplace_back(new Window(*this));
- return *m_windows.back();
-}
-
-void Buffer::delete_window(Window& window)
-{
- assert(&window.buffer() == this);
- auto window_it = std::find(m_windows.begin(), m_windows.end(), &window);
- assert(window_it != m_windows.end());
- m_windows.erase(window_it);
-}
-
bool Buffer::is_modified() const
{
size_t history_cursor_index = m_history_cursor - m_history.begin();
diff --git a/src/buffer.hh b/src/buffer.hh
index db61d371..05776689 100644
--- a/src/buffer.hh
+++ b/src/buffer.hh
@@ -15,7 +15,6 @@ namespace Kakoune
{
class Buffer;
-class Window;
struct BufferCoord : LineAndColumn<BufferCoord, LineCount, ByteCount>
{
@@ -145,12 +144,6 @@ public:
const String& name() const { return m_name; }
- // Window handling
- using WindowList = std::vector<std::unique_ptr<Window>>;
- const WindowList& windows() const { return m_windows; }
- Window& new_window();
- void delete_window(Window& window);
-
// returns true if the buffer is in a different state than
// the last time it was saved
bool is_modified() const;
@@ -221,13 +214,11 @@ private:
void apply_modification(const Modification& modification);
void revert_modification(const Modification& modification);
- WindowList m_windows;
-
size_t m_last_save_undo_index;
size_t m_timestamp;
- // this mutable as adding or removing listeners is not muting the buffer
- // observable state.
+ // this is mutable as adding or removing listeners is not muting the
+ // buffer observable state.
mutable std::vector<BufferChangeListener*> m_change_listeners;
OptionManager m_options;
diff --git a/src/client_manager.cc b/src/client_manager.cc
index 3490ebcb..d6f0df73 100644
--- a/src/client_manager.cc
+++ b/src/client_manager.cc
@@ -49,10 +49,13 @@ void ClientManager::remove_client_by_context(Context& context)
assert(false);
}
-Window& ClientManager::get_unused_window_for_buffer(Buffer& buffer) const
+Window& ClientManager::get_unused_window_for_buffer(Buffer& buffer)
{
- for (auto& w : buffer.windows())
+ for (auto& w : m_windows)
{
+ if (&w->buffer() != &buffer)
+ continue;
+
auto it = std::find_if(m_clients.begin(), m_clients.end(),
[&](const Client& client) {
return &client.context->window() == w.get();
@@ -63,7 +66,8 @@ Window& ClientManager::get_unused_window_for_buffer(Buffer& buffer) const
return *w;
}
}
- return buffer.new_window();
+ m_windows.emplace_back(new Window(buffer));
+ return *m_windows.back();
}
void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer)
@@ -88,6 +92,10 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer)
}
}
}
+ auto end = std::remove_if(m_windows.begin(), m_windows.end(),
+ [&buffer](std::unique_ptr<Window>& w)
+ { return &w->buffer() == &buffer; });
+ m_windows.erase(end, m_windows.end());
}
void ClientManager::redraw_clients() const
diff --git a/src/client_manager.hh b/src/client_manager.hh
index d4b78480..49415ae2 100644
--- a/src/client_manager.hh
+++ b/src/client_manager.hh
@@ -18,7 +18,7 @@ public:
bool empty() const { return m_clients.empty(); }
size_t count() const { return m_clients.size(); }
- Window& get_unused_window_for_buffer(Buffer& buffer) const;
+ Window& get_unused_window_for_buffer(Buffer& buffer);
void ensure_no_client_uses_buffer(Buffer& buffer);
void redraw_clients() const;
@@ -50,6 +50,7 @@ private:
};
std::vector<Client> m_clients;
+ std::vector<std::unique_ptr<Window>> m_windows;
};
}
diff --git a/src/window.hh b/src/window.hh
index 396e0069..d4964111 100644
--- a/src/window.hh
+++ b/src/window.hh
@@ -22,6 +22,7 @@ class HighlighterGroup;
class Window : public Editor, public OptionManagerWatcher
{
public:
+ Window(Buffer& buffer);
~Window();
const DisplayCoord& position() const { return m_position; }
@@ -50,9 +51,6 @@ public:
void forget_timestamp() { m_timestamp = -1; }
private:
- friend class Buffer;
-
- Window(Buffer& buffer);
Window(const Window&) = delete;
void on_incremental_insertion_end() override;