]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Reimplement TUI "C-x 1" binding
authorTom Tromey <tom@tromey.com>
Sat, 22 Feb 2020 18:48:26 +0000 (11:48 -0700)
committerTom Tromey <tom@tromey.com>
Sat, 22 Feb 2020 18:48:29 +0000 (11:48 -0700)
The TUI "C-x 1" key binding removes TUI windows, based on the current
layout.  With user-defined layouts, this is no longer easy to do.

This patch changes "C-x 1" to simply delete windows, leaving just the
focus window, the locator, and the command window.

gdb/ChangeLog
2020-02-22  Tom Tromey  <tom@tromey.com>

* tui/tui.c (tui_rl_delete_other_windows): Call
tui_remove_some_windows.
* tui/tui-layout.h (class tui_layout_base) <remove_windows>:
Declare method.
(class tui_layout_window) <remove_windows>: New method.
(class tui_layout_split) <remove_windows>: Declare.
(tui_remove_some_windows): Declare.
* tui/tui-layout.c (tui_remove_some_windows): New function.
(tui_layout_split::remove_windows): New method.

Change-Id: If186f9c3f263913e963b965204481d1b4385c6d4

gdb/ChangeLog
gdb/tui/tui-layout.c
gdb/tui/tui-layout.h
gdb/tui/tui.c

index 4ab0309dc2a08451235ac820789e120d1c8fa181..4579505c7d5c743f5f148f9bd1c55f02be34a531 100644 (file)
@@ -1,3 +1,15 @@
+2020-02-22  Tom Tromey  <tom@tromey.com>
+
+       * tui/tui.c (tui_rl_delete_other_windows): Call
+       tui_remove_some_windows.
+       * tui/tui-layout.h (class tui_layout_base) <remove_windows>:
+       Declare method.
+       (class tui_layout_window) <remove_windows>: New method.
+       (class tui_layout_split) <remove_windows>: Declare.
+       (tui_remove_some_windows): Declare.
+       * tui/tui-layout.c (tui_remove_some_windows): New function.
+       (tui_layout_split::remove_windows): New method.
+
 2020-02-22  Tom Tromey  <tom@tromey.com>
 
        * tui/tui.c (tui_rl_change_windows): Call tui_next_layout.
index 6a998e8b7d10bc03c4e251a27944fbe77e21bd3c..e9642584fdd25bd2c5c11ee247c51ca65fae32cf 100644 (file)
@@ -286,6 +286,28 @@ tui_next_layout ()
   tui_layout_command ("next", 0);
 }
 
+/* See tui-layout.h.  */
+
+void
+tui_remove_some_windows ()
+{
+  tui_win_info *focus = tui_win_with_focus ();
+
+  if (strcmp (focus->name (), "cmd") == 0)
+    {
+      /* Try leaving the source or disassembly window.  If neither
+        exists, just do nothing.  */
+      focus = TUI_SRC_WIN;
+      if (focus == nullptr)
+       focus = TUI_DISASM_WIN;
+      if (focus == nullptr)
+       return;
+    }
+
+  applied_layout->remove_windows (focus->name ());
+  tui_apply_current_layout ();
+}
+
 static void
 extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
 {
@@ -751,6 +773,29 @@ tui_layout_split::apply (int x_, int y_, int width_, int height_)
   m_applied = true;
 }
 
+/* See tui-layout.h.  */
+
+void
+tui_layout_split::remove_windows (const char *name)
+{
+  for (int i = 0; i < m_splits.size (); ++i)
+    {
+      const char *this_name = m_splits[i].layout->get_name ();
+      if (this_name == nullptr)
+       m_splits[i].layout->remove_windows (name);
+      else
+       {
+         if (strcmp (this_name, name) == 0
+             || strcmp (this_name, "cmd") == 0)
+           {
+             /* Keep.  */
+           }
+         m_splits.erase (m_splits.begin () + i);
+         --i;
+       }
+    }
+}
+
 static void
 initialize_layouts ()
 {
index 7e4b7b7a816771a6615f754f6ff34fd0ad6d185e..f711b004b840c71b310c07637223442a33f415ba 100644 (file)
@@ -64,6 +64,10 @@ public:
      the sizes of the other windows around it.  */
   virtual bool adjust_size (const char *name, int new_height) = 0;
 
+  /* Remove some windows from the layout, leaving the command window
+     and the window being passed in here.  */
+  virtual void remove_windows (const char *name) = 0;
+
   /* The most recent space allocation.  */
   int x = 0;
   int y = 0;
@@ -106,6 +110,10 @@ public:
 
   bool bottom_boxed_p () const override;
 
+  void remove_windows (const char *name) override
+  {
+  }
+
 protected:
 
   void get_sizes (int *min_height, int *max_height) override;
@@ -149,6 +157,8 @@ public:
 
   bool bottom_boxed_p () const override;
 
+  void remove_windows (const char *name) override;
+
 protected:
 
   void get_sizes (int *min_height, int *max_height) override;
@@ -184,6 +194,11 @@ extern void tui_set_layout (enum tui_layout_type);
 /* Switch to the next layout.  */
 extern void tui_next_layout ();
 
+/* Remove some windows from the layout, leaving only the focused
+   window and the command window; if no window has the focus, then
+   some other window is chosen to remain.  */
+extern void tui_remove_some_windows ();
+
 /* Apply the current layout.  */
 extern void tui_apply_current_layout ();
 
index 74bf32d53b724abfb96feb4e8862851241191461..280af8acce9cbc45a84f4fea4e9edcf34d22e5e9 100644 (file)
@@ -162,28 +162,8 @@ tui_rl_delete_other_windows (int notused1, int notused2)
     tui_rl_switch_mode (0 /* notused */, 0 /* notused */);
 
   if (tui_active)
-    {
-      enum tui_layout_type new_layout;
-
-      new_layout = tui_current_layout ();
+    tui_remove_some_windows ();
 
-      /* Kill one window.  */
-      switch (new_layout)
-       {
-       case SRC_COMMAND:
-       case SRC_DATA_COMMAND:
-       case SRC_DISASSEM_COMMAND:
-       default:
-         new_layout = SRC_COMMAND;
-         break;
-
-       case DISASSEM_COMMAND:
-       case DISASSEM_DATA_COMMAND:
-         new_layout = DISASSEM_COMMAND;
-         break;
-       }
-      tui_set_layout (new_layout);
-    }
   return 0;
 }