From c73be50f5fc2ec417b84da7d0d64aef4da4cd05c Mon Sep 17 00:00:00 2001 From: Dmitry Shnurenko Date: Fri, 12 Feb 2016 14:31:02 +0200 Subject: [PATCH] IDEX-3819: Add smart auto-scroll to command's output. Signed-off-by: Dmitry Shnurenko --- .../CommandOutputConsolePresenter.java | 2 - .../console/DefaultOutputConsole.java | 2 - .../console/OutputConsoleView.java | 3 - .../console/OutputConsoleViewImpl.java | 92 +++++++++---------- 4 files changed, 46 insertions(+), 53 deletions(-) diff --git a/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/java/org/eclipse/che/ide/extension/machine/client/outputspanel/console/CommandOutputConsolePresenter.java b/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/java/org/eclipse/che/ide/extension/machine/client/outputspanel/console/CommandOutputConsolePresenter.java index 532db46df5..5d3ad6bf13 100644 --- a/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/java/org/eclipse/che/ide/extension/machine/client/outputspanel/console/CommandOutputConsolePresenter.java +++ b/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/java/org/eclipse/che/ide/extension/machine/client/outputspanel/console/CommandOutputConsolePresenter.java @@ -113,7 +113,6 @@ public class CommandOutputConsolePresenter implements CommandOutputConsole, Outp @Override protected void onMessageReceived(String result) { view.print(result, result.endsWith("\r")); - view.scrollBottom(); } @Override @@ -159,7 +158,6 @@ public class CommandOutputConsolePresenter implements CommandOutputConsole, Outp return; } view.print(error, false); - view.scrollBottom(); } } diff --git a/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/java/org/eclipse/che/ide/extension/machine/client/outputspanel/console/DefaultOutputConsole.java b/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/java/org/eclipse/che/ide/extension/machine/client/outputspanel/console/DefaultOutputConsole.java index 008270378a..d3575b7478 100644 --- a/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/java/org/eclipse/che/ide/extension/machine/client/outputspanel/console/DefaultOutputConsole.java +++ b/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/java/org/eclipse/che/ide/extension/machine/client/outputspanel/console/DefaultOutputConsole.java @@ -49,7 +49,6 @@ public class DefaultOutputConsole implements OutputConsole { */ public void printText(String text) { view.print(text, text.endsWith("\r")); - view.scrollBottom(); } /** @@ -68,7 +67,6 @@ public class DefaultOutputConsole implements OutputConsole { } view.print(text, isRepeat); - view.scrollBottom(); } /** {@inheritDoc} */ diff --git a/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/java/org/eclipse/che/ide/extension/machine/client/outputspanel/console/OutputConsoleView.java b/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/java/org/eclipse/che/ide/extension/machine/client/outputspanel/console/OutputConsoleView.java index d7454efeb6..5175e36c27 100644 --- a/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/java/org/eclipse/che/ide/extension/machine/client/outputspanel/console/OutputConsoleView.java +++ b/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/java/org/eclipse/che/ide/extension/machine/client/outputspanel/console/OutputConsoleView.java @@ -36,9 +36,6 @@ public interface OutputConsoleView extends View { } - private static final OutputConsoleViewUiBinder UI_BINDER = GWT.create(OutputConsoleViewUiBinder.class); - - private ActionDelegate delegate; + private static final OutputConsoleViewUiBinder UI_BINDER = GWT.create(OutputConsoleViewUiBinder.class); + private static final int SCROLL_STEP = 3; @UiField DockLayoutPanel consolePanel; - @UiField - FlowPanel commandPanel; - + FlowPanel commandPanel; @UiField - FlowPanel previewPanel; - + FlowPanel previewPanel; @UiField - Label commandTitle; - + Label commandTitle; @UiField - Label commandLabel; - + Label commandLabel; @UiField - ScrollPanel scrollPanel; - + ScrollPanel scrollPanel; @UiField - FlowPanel consoleLines; - + FlowPanel consoleLines; @UiField - Anchor previewUrlLabel; - - /** scroll events to the bottom if view is visible */ - private boolean scrollBottomRequired = false; + Anchor previewUrlLabel; /** If true - next printed line should replace the previous one. */ private boolean carriageReturn; + private int mouseDelta; + private int scrollLinesCount; + private boolean scrolled; @Inject public OutputConsoleViewImpl() { initWidget(UI_BINDER.createAndBindUi(this)); + + MouseWheelHandler mouseWheelHandler = new MouseWheelHandler() { + @Override + public void onMouseWheel(MouseWheelEvent event) { + if (event.isNorth() && !scrolled) { + scrolled = true; + + mouseDelta = scrollLinesCount; + } + + mouseDelta += event.isSouth() ? SCROLL_STEP : -SCROLL_STEP; + + if (mouseDelta < 0) { + mouseDelta = 0; + } + } + }; + + consoleLines.addDomHandler(mouseWheelHandler, MouseWheelEvent.getType()); } @Override public void setDelegate(ActionDelegate delegate) { - this.delegate = delegate; } @Override @@ -121,33 +132,22 @@ public class OutputConsoleViewImpl extends Composite implements OutputConsoleVie PreElement pre = DOM.createElement("pre").cast(); pre.setInnerText(message.isEmpty() ? " " : message); consoleLines.getElement().appendChild(pre); + + scrollBottom(); } - @Override - public void scrollBottom() { + private void scrollBottom() { /** scroll bottom immediately if view is visible */ - if (scrollPanel.getElement().getOffsetParent() != null) { + if (mouseDelta >= scrollLinesCount) { scrollPanel.scrollToBottom(); - return; + + scrolled = false; + + mouseDelta = scrollLinesCount + SCROLL_STEP; } - /** otherwise, check the visibility periodically and scroll the view when it's visible */ - if (!scrollBottomRequired) { - scrollBottomRequired = true; - - Scheduler.get().scheduleFixedPeriod(new Scheduler.RepeatingCommand() { - @Override - public boolean execute() { - if (scrollPanel.getElement().getOffsetParent() != null) { - scrollPanel.scrollToBottom(); - scrollBottomRequired = false; - return false; - } - return true; - } - }, 1000); + if (!carriageReturn) { + scrollLinesCount++; } } - - -} +} \ No newline at end of file