From ee0d1e0d0ede0686e08bcc8676b19c87db5ba10f Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 27 Jan 2017 20:58:15 -0500 Subject: [PATCH] remove BufferPane::write_file() and handle writing from Window class --- src/gui/BufferPane.cc | 8 -------- src/gui/BufferPane.h | 2 +- src/gui/Window.cc | 12 ++++++++++-- src/gui/Window.h | 3 +++ 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/gui/BufferPane.cc b/src/gui/BufferPane.cc index 555b69e..0cb043f 100644 --- a/src/gui/BufferPane.cc +++ b/src/gui/BufferPane.cc @@ -519,14 +519,6 @@ void BufferPane::kill_character_at_cursor() } } -void BufferPane::write_file() -{ - if (m_buffer->filename()) - { - m_buffer->write_to_file(m_buffer->filename()->c_str()); - } -} - size_t BufferPane::display_column() const { if (!m_iterator->valid()) diff --git a/src/gui/BufferPane.h b/src/gui/BufferPane.h index e798b1c..d27fb21 100644 --- a/src/gui/BufferPane.h +++ b/src/gui/BufferPane.h @@ -19,7 +19,6 @@ public: void insert_code_point(uint32_t code_point); void exit_insert_mode(); void kill_character_at_cursor(); - void write_file(); bool insert_mode() const { return m_buffer->insert_mode(); } void scroll_window_up(Window::ScrollMode scroll_mode); void scroll_window_down(Window::ScrollMode scroll_mode); @@ -36,6 +35,7 @@ public: } void clear(); int calculate_rows_in_line(const Buffer::Iterator & start_of_line); + std::shared_ptr buffer() const { return m_buffer; } protected: int effective_scroll_offset() diff --git a/src/gui/Window.cc b/src/gui/Window.cc index 9cf2f67..2a93fc9 100644 --- a/src/gui/Window.cc +++ b/src/gui/Window.cc @@ -4,7 +4,6 @@ #include "BufferPane.h" #include #include "jes_icon-32x32.h" -#include "CommandParser.h" #define INITIAL_WIDTH 800 #define INITIAL_HEIGHT 800 @@ -575,7 +574,7 @@ void Window::handle_command(const EncodedString & command) { if (cp[0] == "w") { - m_focused_buffer_pane->write_file(); + command_write_file(cp); } } } @@ -584,3 +583,12 @@ void Window::handle_command(const EncodedString & command) /* TODO: handle command parsing failure */ } } + +void Window::command_write_file(const CommandParser & cp) +{ + std::shared_ptr buffer = m_focused_buffer_pane->buffer(); + if (buffer->filename()) + { + buffer->write_to_file(buffer->filename()->c_str()); + } +} diff --git a/src/gui/Window.h b/src/gui/Window.h index 260d02d..a8772bf 100644 --- a/src/gui/Window.h +++ b/src/gui/Window.h @@ -8,6 +8,7 @@ #include "Buffer.h" #include "GL.h" #include "EncodedString.h" +#include "CommandParser.h" class BufferPane; @@ -77,6 +78,8 @@ protected: void set_window_icon(); void handle_command(const EncodedString & command); + void command_write_file(const CommandParser & cp); + SDL_Window * m_window; bool m_exit_requested; bool m_redraw_requested;