From f7ee2801e9f74f4954c305a2dc75ee5d519c2ca0 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 14 Jun 2012 13:19:38 +0000 Subject: [PATCH] Windows call the WinSetOption hook when an option changes --- src/window.cc | 16 ++++++++++++++++ src/window.hh | 5 ++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/window.cc b/src/window.cc index 2f32167f..e6fffa28 100644 --- a/src/window.cc +++ b/src/window.cc @@ -21,9 +21,18 @@ Window::Window(Buffer& buffer) HighlighterRegistry& registry = HighlighterRegistry::instance(); m_hook_manager.run_hook("WinCreate", buffer.name(), Context(*this)); + m_option_manager.register_watcher(*this); registry.add_highlighter_to_group(*this, m_highlighters, "expand_tabs", HighlighterParameters()); registry.add_highlighter_to_group(*this, m_highlighters, "highlight_selections", HighlighterParameters()); + + for (auto& option : m_option_manager.flatten_options()) + on_option_changed(option.first, option.second); +} + +Window::~Window() +{ + m_option_manager.unregister_watcher(*this); } BufferIterator Window::iterator_at(const DisplayCoord& window_pos) const @@ -126,4 +135,11 @@ void Window::on_incremental_insertion_end() pop_selections(); } +void Window::on_option_changed(const String& name, const Option& option) +{ + String desc = name + "=" + option.as_string(); + m_hook_manager.run_hook("WinSetOption", desc, Context(*this)); +} + + } diff --git a/src/window.hh b/src/window.hh index 66264c89..a4b3abf5 100644 --- a/src/window.hh +++ b/src/window.hh @@ -21,9 +21,11 @@ class HighlighterGroup; // to the editing ones already provided by the Editor class. // Display can be customized through the use of highlighters handled by // the window's HighlighterGroup -class Window : public Editor +class Window : public Editor, public OptionManagerWatcher { public: + ~Window(); + const BufferCoord& position() const { return m_position; } BufferIterator iterator_at(const DisplayCoord& window_pos) const; @@ -49,6 +51,7 @@ private: Window(const Window&) = delete; void on_incremental_insertion_end(); + void on_option_changed(const String& name, const Option& option); void scroll_to_keep_cursor_visible_ifn();