Make source windows be self-updating
authorTom Tromey <tom@tromey.com>
Fri, 28 Jun 2019 20:48:45 +0000 (14:48 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 17 Jul 2019 18:19:04 +0000 (12:19 -0600)
This changes the TUI source window to register itself on the
source_styling_changed observable, and removes a bit of code from
tui-hooks.c.  This reduces the number of uses of the TUI_SRC_WIN
global.

gdb/ChangeLog
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.

gdb/ChangeLog
gdb/tui/tui-data.h
gdb/tui/tui-hooks.c
gdb/tui/tui-source.c

index c7318267a1f24d0e8296655b97dea799cbf521cb..1235b1a382d62c3cf987bdf39aa92aa8e86da485 100644 (file)
@@ -1,3 +1,16 @@
+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.
index bd22f9eec6931f02c242ca59b9dcd1c3c70a9821..be951b4c840b0216fc532120bafb438af37d438c 100644 (file)
@@ -24,6 +24,7 @@
 
 #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
@@ -424,10 +425,8 @@ public:
 
 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);
 
@@ -439,6 +438,13 @@ struct tui_source_window : public tui_source_window_base
 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.  */
index 710105307499e59dc274abfb6153535da0051984..84acd3ac2e6bf6a582159ef33935727455995009 100644 (file)
@@ -204,18 +204,6 @@ tui_normal_stop (struct bpstats *bs, int print_frame)
   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 {};
@@ -251,8 +239,6 @@ tui_attach_detach_observers (bool attach)
                    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.  */
index e62ee4ea5f9dcffbaae4b9b67b48a3a7260fab84..34cb38b31afc25f1398dae89e4e3aa70d6e89982 100644 (file)
@@ -325,3 +325,23 @@ tui_source_window::do_scroll_vertical (int num_to_scroll)
       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 ();
+}
This page took 0.044289 seconds and 4 git commands to generate.