Skip to content

Commit

Permalink
Interrupt button should only appear when needed
Browse files Browse the repository at this point in the history
This has always been the case on the main Console pane title bar; this commit brings the same behavior to the tab-mode Console toolbar button.
  • Loading branch information
jcheng5 committed Feb 22, 2012
1 parent 599b84a commit cbf75e2
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 49 deletions.
71 changes: 71 additions & 0 deletions src/gwt/src/org/rstudio/core/client/layout/DelayFadeInHelper.java
@@ -0,0 +1,71 @@
/*
* DelayFadeInHelper.java
*
* Copyright (C) 2009-11 by RStudio, Inc.
*
* This program is licensed to you under the terms of version 3 of the
* GNU Affero General Public License. This program is distributed WITHOUT
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
*
*/
package org.rstudio.core.client.layout;

import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Widget;

public class DelayFadeInHelper
{
public DelayFadeInHelper(Widget widget)
{
widget_ = widget;
}

public void beginShow()
{
hide();

final Object nonce = new Object();
nonce_ = nonce;
new Timer()
{
@Override
public void run()
{
if (nonce_ == nonce)
{
animation_ = new FadeInAnimation(
widget_, 1, null);
animation_.run(250);
}
}
}.schedule(750);
}

public void hide()
{
stopPending();
widget_.setVisible(false);
// jcheng: The next line shouldn't be necessary since we just set visible
// to false, but there was an annoying bug where it seemed the Stop
// button's visibility was being set to true when the Compile PDF panel is
// introduced. For some reason opacity is not affected, so this fixes it.
widget_.getElement().getStyle().setOpacity(0.0);
}

private void stopPending()
{
nonce_ = null;
if (animation_ != null)
{
animation_.cancel();
animation_ = null;
}
}

private Object nonce_;
private FadeInAnimation animation_;

private final Widget widget_;
}
Expand Up @@ -13,11 +13,17 @@
package org.rstudio.studio.client.workbench.views.console;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.inject.Inject;
import org.rstudio.core.client.command.CommandBinder;
import org.rstudio.core.client.command.Handler;
import org.rstudio.core.client.layout.DelayFadeInHelper;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.workbench.commands.Commands;
import org.rstudio.studio.client.workbench.events.BusyEvent;
import org.rstudio.studio.client.workbench.events.BusyHandler;
import org.rstudio.studio.client.workbench.views.console.events.ConsolePromptEvent;
import org.rstudio.studio.client.workbench.views.console.events.ConsolePromptHandler;
import org.rstudio.studio.client.workbench.views.console.events.SendToConsoleEvent;
import org.rstudio.studio.client.workbench.views.console.events.SendToConsoleHandler;

Expand All @@ -29,6 +35,7 @@ public interface Display
{
void bringToFront();
void focus();
IsWidget getConsoleInterruptButton();
}

@Inject
Expand All @@ -45,6 +52,29 @@ public void onSendToConsole(SendToConsoleEvent event)
});

((Binder) GWT.create(Binder.class)).bind(commands, this);

fadeInHelper_ = new DelayFadeInHelper(
view_.getConsoleInterruptButton().asWidget());
events.addHandler(BusyEvent.TYPE, new BusyHandler()
{
@Override
public void onBusy(BusyEvent event)
{
if (event.isBusy())
fadeInHelper_.beginShow();
else
fadeInHelper_.hide();
}
});

events.addHandler(ConsolePromptEvent.TYPE, new ConsolePromptHandler()
{
@Override
public void onConsolePrompt(ConsolePromptEvent event)
{
fadeInHelper_.hide();
}
});
}

@Handler
Expand All @@ -58,6 +88,7 @@ public Display getDisplay()
{
return view_ ;
}


private final DelayFadeInHelper fadeInHelper_;
private final Display view_;
}
Expand Up @@ -14,11 +14,10 @@

import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.inject.Inject;
import org.rstudio.core.client.layout.FadeInAnimation;
import org.rstudio.core.client.layout.DelayFadeInHelper;
import org.rstudio.core.client.widget.ToolbarButton;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.workbench.commands.Commands;
Expand All @@ -33,6 +32,8 @@ public class ConsoleInterruptButton extends Composite
public ConsoleInterruptButton(EventBus events,
Commands commands)
{
fadeInHelper_ = new DelayFadeInHelper(this);

// The SimplePanel wrapper is necessary for the toolbar button's "pushed"
// effect to work.
SimplePanel panel = new SimplePanel();
Expand All @@ -54,9 +55,15 @@ public ConsoleInterruptButton(EventBus events,
public void onBusy(BusyEvent event)
{
if (event.isBusy())
beginShow();
{
fadeInHelper_.beginShow();
commands_.interruptR().setEnabled(true);
}
else
hide();
{
fadeInHelper_.hide();
commands_.interruptR().setEnabled(false);
}
}
});

Expand All @@ -72,7 +79,8 @@ public void onBusy(BusyEvent event)
{
public void onConsolePrompt(ConsolePromptEvent event)
{
hide();
fadeInHelper_.hide();
commands_.interruptR().setEnabled(false);
}
});
}
Expand All @@ -87,49 +95,8 @@ public int getHeight()
return height_;
}

private void beginShow()
{
hide();

commands_.interruptR().setEnabled(true);

final Object nonce = new Object();
nonce_ = nonce;
new Timer()
{
@Override
public void run()
{
if (nonce_ == nonce)
{
animation_ = new FadeInAnimation(
ConsoleInterruptButton.this, 1, null);
animation_.run(250);
}
}
}.schedule(750);
}

private void hide()
{
stopPending();
setVisible(false);
commands_.interruptR().setEnabled(false);
}

private void stopPending()
{
nonce_ = null;
if (animation_ != null)
{
animation_.cancel();
animation_ = null;
}
}

private Object nonce_;
private final DelayFadeInHelper fadeInHelper_;
private final int width_;
private final int height_;
private FadeInAnimation animation_;
private final Commands commands_;
}
Expand Up @@ -12,13 +12,15 @@
*/
package org.rstudio.studio.client.workbench.views.console;

import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Provider;
import org.rstudio.core.client.theme.res.ThemeStyles;
import org.rstudio.core.client.widget.CanFocus;
import org.rstudio.core.client.widget.Toolbar;
import org.rstudio.core.client.widget.ToolbarButton;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.workbench.commands.Commands;
import org.rstudio.studio.client.workbench.ui.WorkbenchPane;
Expand Down Expand Up @@ -54,6 +56,12 @@ public void focus()
shell_.getDisplay().focus();
}

@Override
public IsWidget getConsoleInterruptButton()
{
return consoleInterruptButton_;
}

public int getCharacterWidth()
{
return shell_.getDisplay().getCharacterWidth();
Expand All @@ -67,7 +75,8 @@ protected Toolbar createMainToolbar()
workingDir_.setStyleName(ThemeStyles.INSTANCE.subtitle());
toolbar.addLeftWidget(workingDir_);
toolbar.addLeftWidget(commands_.goToWorkingDir().createToolbarButton());
toolbar.addRightWidget(commands_.interruptR().createToolbarButton());
consoleInterruptButton_ = commands_.interruptR().createToolbarButton();
toolbar.addRightWidget(consoleInterruptButton_);
return toolbar;
}

Expand Down Expand Up @@ -100,4 +109,5 @@ public void onSelected()
private final Commands commands_;
private Shell shell_;
private Label workingDir_;
private ToolbarButton consoleInterruptButton_;
}

0 comments on commit cbf75e2

Please sign in to comment.