#51 wip
[fanfix.git] / examples / JexerTilingWindowManager2.java
index bef3637119b7d676ce2ecd27dbcc406979d3e074..accbf739317bf0212c1c7aa07c6fb2e934b84b11 100644 (file)
@@ -88,37 +88,58 @@ public class JexerTilingWindowManager2 extends TApplication {
     protected boolean onMenu(TMenuEvent event) {
         if (event.getId() == MENU_SPLIT_VERTICAL) {
             if (root == null) {
+                assert (getDesktop().getActiveChild() == null);
                 createRootTerminal();
                 return true;
             }
-            TWidget active = root.getActiveChild();
+            TWidget active = getDesktop().getActiveChild();
             TSplitPane split = active.splitVertical(false,
-                new TTerminalWidget(getDesktop(), active.getX(),
+                new TTerminalWidget(active, active.getX(),
                     active.getY(), active.getWidth(), active.getHeight(),
                     new TAction() {
                         public void DO() {
-                            // TODO
+                            if (source.getParent() instanceof TSplitPane) {
+                                ((TSplitPane) source.getParent()).removeSplit(source, true);
+                            } else if (source == root) {
+                                assert (root != null);
+                                root.remove();
+                                root = null;
+                            }
                         }
                     }));
             if (active == root) {
                 root = split;
             }
+            System.err.println("\nAfter vertical split:");
+            System.err.println(getDesktop().toPrettyString());
             return true;
         }
         if (event.getId() == MENU_SPLIT_HORIZONTAL) {
             if (root == null) {
+                assert (getDesktop().getActiveChild() == null);
                 createRootTerminal();
                 return true;
             }
-            TWidget active = root.getActiveChild();
+            TWidget active = getDesktop().getActiveChild();
             TSplitPane split = active.splitHorizontal(false,
-                new TTerminalWidget(getDesktop(), active.getX(),
+                new TTerminalWidget(active, active.getX(),
                     active.getY(), active.getWidth(), active.getHeight(),
                     new TAction() {
                         public void DO() {
-                            // TODO
+                            if (source.getParent() instanceof TSplitPane) {
+                                ((TSplitPane) source.getParent()).removeSplit(source, true);
+                            } else if (source == root) {
+                                assert (root != null);
+                                root.remove();
+                                root = null;
+                            }
                         }
                     }));
+            if (active == root) {
+                root = split;
+            }
+            System.err.println("\nAfter horizontal split:");
+            System.err.println(getDesktop().toPrettyString());
             return true;
         }
 
@@ -134,10 +155,9 @@ public class JexerTilingWindowManager2 extends TApplication {
             getDesktop().getWidth(), getDesktop().getHeight(),
             new TAction() {
                 public void DO() {
-                    TWidget target = (TWidget) data;
-                    if (target.getParent() instanceof TPanel) {
-                        ((TSplitPane) target.getParent().getParent()).removeSplit(target, true);
-                    } else {
+                    if (source.getParent() instanceof TSplitPane) {
+                        ((TSplitPane) source.getParent()).removeSplit(source, true);
+                    } else if (source == root) {
                         assert (root != null);
                         root.remove();
                         root = null;