+2019-07-17 Tom Tromey <tom@tromey.com>
+
+ * tui/tui-source.c (tui_source_window): New constructor. Add
+ observer.
+ (~tui_source_window): New destructor.
+ (tui_source_window::style_changed): New method.
+ * tui/tui-hooks.c (tui_redisplay_source): Remove.
+ (tui_attach_detach_observers): Update.
+ * tui/tui-data.h (struct tui_source_window): Make constructor not
+ inline. Add destructor.
+ (struct tui_source_window) <style_changed>: New method.
+ <m_observable>: New member.
+
2019-07-17 Tom Tromey <tom@tromey.com>
* tui/tui-data.c (tui_clear_source_windows_detail): Fix typo.
#include "tui/tui.h" /* For enum tui_win_type. */
#include "gdb_curses.h" /* For WINDOW. */
+#include "observable.h"
/* This is a point definition. */
struct tui_point
struct tui_source_window : public tui_source_window_base
{
- tui_source_window ()
- : tui_source_window_base (SRC_WIN)
- {
- }
+ tui_source_window ();
+ ~tui_source_window ();
DISABLE_COPY_AND_ASSIGN (tui_source_window);
protected:
void do_scroll_vertical (int num_to_scroll) override;
+
+private:
+
+ void style_changed ();
+
+ /* A token used to register and unregister an observer. */
+ gdb::observers::token m_observable;
};
/* A TUI disassembly window. */
tui_refresh_frame_and_register_information (/*registers_too_p=*/1);
}
-/* Observer for source_cache_cleared. */
-
-static void
-tui_redisplay_source ()
-{
- if (tui_is_window_visible (SRC_WIN))
- {
- /* Force redisplay. */
- TUI_SRC_WIN->refill ();
- }
-}
-
/* Token associated with observers registered while TUI hooks are
installed. */
static const gdb::observers::token tui_observers_token {};
tui_normal_stop, attach);
attach_or_detach (gdb::observers::register_changed,
tui_register_changed, attach);
- attach_or_detach (gdb::observers::source_styling_changed,
- tui_redisplay_source, attach);
}
/* Install the TUI specific hooks. */
print_source_lines (s, l.u.line_no, l.u.line_no + 1, 0);
}
}
+
+tui_source_window::tui_source_window ()
+ : tui_source_window_base (SRC_WIN)
+{
+ gdb::observers::source_styling_changed.attach
+ (std::bind (&tui_source_window::style_changed, this),
+ m_observable);
+}
+
+tui_source_window::~tui_source_window ()
+{
+ gdb::observers::source_styling_changed.detach (m_observable);
+}
+
+void
+tui_source_window::style_changed ()
+{
+ if (tui_active && is_visible)
+ refill ();
+}