#6331 disable key binding handle when any 'Window' opened (#8473)

Signed-off-by: Yevhen Vydolob <evidolob@codenvy.com>
6.19.x
Yevhen Vydolob 2018-01-29 12:09:04 +02:00 committed by GitHub
parent 0c78fa9820
commit 0b4d01ea2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 6 deletions

View File

@ -52,6 +52,9 @@ public interface KeyBindingAgent {
*/
Scheme getActive();
/** Change active scheme using his identifier */
void setActive(@NotNull String scheme);
/**
* Register a new scheme
*
@ -70,13 +73,16 @@ public interface KeyBindingAgent {
/** List registered schemes */
List<Scheme> getSchemes();
/** Change active scheme using his identifier */
void setActive(@NotNull String scheme);
/**
* @return keyboard shortcut for the action with the specified <code>actionId</code> or an null if
* the action doesn't have any keyboard shortcut.
*/
@Nullable
CharCodeWithModifiers getKeyBinding(@NotNull String actionId);
/** Disable key binding agent. It's may be used when some modal window are shown. */
void disable();
/** Enable key binding agent back. */
void enable();
}

View File

@ -55,6 +55,7 @@ public class KeyBindingManager implements KeyBindingAgent {
private String activeScheme;
private ActionManager actionManager;
private boolean disabled;
@Inject
public KeyBindingManager(ActionManager actionManager) {
@ -74,6 +75,11 @@ public class KeyBindingManager implements KeyBindingAgent {
new EventListener() {
@Override
public void handleEvent(Event event) {
if (disabled) {
return;
}
SignalEvent signalEvent = SignalEventUtils.create(event, false);
if (signalEvent == null) {
return;
@ -206,4 +212,14 @@ public class KeyBindingManager implements KeyBindingAgent {
return getGlobal().getKeyBinding(actionId);
}
}
@Override
public void disable() {
disabled = true;
}
@Override
public void enable() {
disabled = false;
}
}

View File

@ -29,7 +29,9 @@ import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.ui.Widget;
import elemental.js.dom.JsElement;
import javax.inject.Inject;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.api.keybinding.KeyBindingAgent;
import org.eclipse.che.ide.ui.button.ButtonAlignment;
import org.vectomatic.dom.svg.ui.SVGResource;
@ -52,6 +54,7 @@ public abstract class Window implements IsWidget {
private boolean isShowing;
private View view;
private KeyBindingAgent keyBinding;
protected Window() {
this(true);
@ -61,15 +64,20 @@ public abstract class Window implements IsWidget {
view = new View(resources, showBottomPanel);
}
public void setWidget(Widget widget) {
view.addContentWidget(widget);
handleViewEvents();
@Inject
protected void setKeyBinding(KeyBindingAgent keyBinding) {
this.keyBinding = keyBinding;
}
public Widget getWidget() {
return view.getContent();
}
public void setWidget(Widget widget) {
view.addContentWidget(widget);
handleViewEvents();
}
/**
* ensureDebugId on the current window container. ensureDebugId id + "-headerLabel" on the window
* control bar title
@ -108,6 +116,10 @@ public abstract class Window implements IsWidget {
return;
}
if (keyBinding != null) {
keyBinding.enable();
}
isShowing = false;
// Animate the popup out of existence.
@ -226,6 +238,10 @@ public abstract class Window implements IsWidget {
return;
}
if (keyBinding != null) {
keyBinding.disable();
}
isShowing = true;
// Attach the popup to the body.