Buffer is now responsible for window creation

This commit is contained in:
Maxime Coste 2011-09-08 14:30:36 +00:00
parent 60e673acba
commit 76b7c60afb
5 changed files with 16 additions and 16 deletions

View File

@ -316,14 +316,12 @@ void Buffer::append_modification(Modification&& modification)
m_current_undo_group.push_back(modification);
}
struct window_already_registered {};
void Buffer::register_window(Window* window)
Window* Buffer::get_or_create_window()
{
if (std::find(m_windows.begin(), m_windows.end(), window) != m_windows.end())
throw window_already_registered();
if (m_windows.empty())
m_windows.push_front(std::unique_ptr<Window>(new Window(*this)));
m_windows.push_front(std::unique_ptr<Window>(window));
return m_windows.front().get();
}
void Buffer::delete_window(Window* window)

View File

@ -100,7 +100,7 @@ public:
const BufferString& content() const { return m_content; }
void register_window(Window* window);
Window* get_or_create_window();
void delete_window(Window* window);
private:

View File

@ -4,6 +4,7 @@
#include "file.hh"
#include "regex_selector.hh"
#include "command_manager.hh"
#include "buffer_manager.hh"
#include <unordered_map>
#include <cassert>
@ -160,17 +161,17 @@ void edit(const CommandParameters& params)
throw wrong_argument_count();
std::string filename = params[0];
Buffer* buffer = NULL;
try
{
Buffer* buffer = create_buffer_from_file(filename);
if (buffer)
current_window = new Window(*buffer);
buffer = create_buffer_from_file(filename);
}
catch (file_not_found& what)
{
print_status("new file " + filename);
current_window = new Window(*new Buffer(filename));
buffer = new Buffer(filename);
}
current_window = buffer->get_or_create_window();
}
void write_buffer(const CommandParameters& params)
@ -293,7 +294,7 @@ int main()
try
{
auto buffer = new Buffer("<scratch>");
current_window = new Window(*buffer);
current_window = buffer->get_or_create_window();
draw_window(*current_window);
int count = 0;

View File

@ -11,7 +11,6 @@ Window::Window(Buffer& buffer)
m_cursor(0, 0),
m_dimensions(0, 0)
{
m_buffer.register_window(this);
}
void Window::erase()

View File

@ -34,9 +34,6 @@ public:
typedef BufferString String;
typedef std::function<Selection (const BufferIterator&)> Selector;
Window(Buffer& buffer);
Window(const Window&) = delete;
void erase();
void insert(const String& string);
void append(const String& string);
@ -69,6 +66,11 @@ public:
bool redo();
private:
friend class Buffer;
Window(Buffer& buffer);
Window(const Window&) = delete;
void scroll_to_keep_cursor_visible_ifn();
Buffer& m_buffer;