From 1e71bba21116ce83e76501c2e60f85ba6113e82d Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Wed, 21 Aug 2019 15:37:23 -0500 Subject: [PATCH] #51 wip --- src/jexer/TSplitPane.java | 22 ++++++++++++++++++---- src/jexer/TTerminalWidget.java | 28 +++++++++++++++++++--------- src/jexer/TWidget.java | 32 +++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 14 deletions(-) diff --git a/src/jexer/TSplitPane.java b/src/jexer/TSplitPane.java index 5a65736..a9d6cdb 100644 --- a/src/jexer/TSplitPane.java +++ b/src/jexer/TSplitPane.java @@ -587,15 +587,29 @@ public class TSplitPane extends TWidget { remove(false); if (keep == null) { + if (myParent instanceof TSplitPane) { + // TSplitPane has a left/right/top/bottom link to me + // somewhere, remove it. + ((TSplitPane) myParent).removeWidget(this); + } + // Nothing is left of either pane. Remove me and bail out. return null; } - keep.setParent(myParent, false); - keep.setDimensions(getX(), getY(), getWidth(), getHeight()); - keep.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, getWidth(), - getHeight())); + if (myParent instanceof TSplitPane) { + // TSplitPane has a left/right/top/bottom link to me + // somewhere, replace me with keep. + ((TSplitPane) myParent).replaceWidget(this, keep); + } else { + keep.setParent(myParent, false); + keep.setDimensions(getX(), getY(), getWidth(), getHeight()); + keep.onResize(new TResizeEvent(TResizeEvent.Type.WIDGET, getWidth(), + getHeight())); + } + // System.err.println("\nAfter removeSplit():\n" + myParent.toPrettyString()); + return keep; } diff --git a/src/jexer/TTerminalWidget.java b/src/jexer/TTerminalWidget.java index 7a93f4e..39d761c 100644 --- a/src/jexer/TTerminalWidget.java +++ b/src/jexer/TTerminalWidget.java @@ -384,6 +384,14 @@ public class TTerminalWidget extends TScrollableWidget // Update the scroll bars reflowData(); + if (!isDrawable()) { + // We lost the connection, onShellExit() called an action + // that ultimately removed this widget from the UI + // hierarchy, so no one cares if we update the display. + // Bail out. + return; + } + if ((scrollback == null) || emulator.isReading()) { scrollback = copyBuffer(emulator.getScrollbackBuffer()); display = copyBuffer(emulator.getDisplayBuffer()); @@ -820,17 +828,19 @@ public class TTerminalWidget extends TScrollableWidget public void onShellExit() { TApplication app = getApplication(); if (app != null) { - app.invokeLater(new Runnable() { - public void run() { - if (closeAction != null) { + if (closeAction != null) { + // We have to put this action inside invokeLater() because it + // could be executed during draw() when syncing with ECMA48. + app.invokeLater(new Runnable() { + public void run() { closeAction.DO(TTerminalWidget.this); } - if (getApplication() != null) { - getApplication().postEvent(new TMenuEvent( - TMenu.MID_REPAINT)); - } - } - }); + }); + } + if (getApplication() != null) { + getApplication().postEvent(new TMenuEvent( + TMenu.MID_REPAINT)); + } } } diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index 5d2612b..ba18989 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -1243,6 +1243,25 @@ public abstract class TWidget implements Comparable { return window.getApplication().getTheme(); } + /** + * See if this widget can be drawn onto a screen. + * + * @return true if this widget is part of the hierarchy that can draw to + * a screen + */ + public final boolean isDrawable() { + if ((window == null) + || (window.getScreen() == null) + || (parent == null) + ) { + return false; + } + if (parent == this) { + return true; + } + return (parent.isDrawable()); + } + /** * Draw my specific widget. When called, the screen rectangle I draw * into is already setup (offset and clipping). @@ -1255,7 +1274,7 @@ public abstract class TWidget implements Comparable { * Called by parent to render to TWindow. Note package private access. */ final void drawChildren() { - if (window == null) { + if (!isDrawable()) { return; } @@ -1310,6 +1329,12 @@ public abstract class TWidget implements Comparable { // Draw me draw(); + if (!isDrawable()) { + // An action taken by a draw method unhooked me from the UI. + // Bail out. + return; + } + assert (visible == true); // Continue down the chain. Draw the active child last so that it @@ -1317,6 +1342,11 @@ public abstract class TWidget implements Comparable { for (TWidget widget: children) { if (widget.isVisible() && (widget != activeChild)) { widget.drawChildren(); + if (!isDrawable()) { + // An action taken by a draw method unhooked me from the UI. + // Bail out. + return; + } } } if (activeChild != null) { -- 2.27.0