Skip to content

Commit

Permalink
Removed dual pane demo, also added hyperlink blocking methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ainslec committed May 5, 2017
1 parent 25d0463 commit 93c47b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class PromptlyPanel extends Composite {

private PromptlyListener _listener = DEFAULT_LISTENER;
private boolean _isCommandLineMode = true;
private boolean _collectKeyEvents = true;
private boolean _collectMouseEvents = true;
private boolean _collectKeyEventsWhenInNonCommandLineMode = true;
private boolean _collectMouseEventsWhenInNonCommandLineMode = true;

private FlowPanel _caret;
private FlowPanel _outerPanel; // Panel that fills all available space
Expand All @@ -68,7 +68,10 @@ public class PromptlyPanel extends Composite {
private int _commandCacheLimit = 0;
private int _commandCacheNextInsertionIndex = 0;
private boolean _cacheOverflowed = false;
private boolean _blockingHyperlinks;



private int _commandCacheUserCursorIndex = -1; // The is the next index to be displayed to the user
private int _commandCacheUserCursorLimit = -1; // This is the limit of the cursor, so we don't loop around indefinately

Expand All @@ -84,7 +87,7 @@ public class PromptlyPanel extends Composite {
event.preventDefault();
}
} else {
if (_collectMouseEvents) {
if (_collectMouseEventsWhenInNonCommandLineMode) {
if (_isCommandLineMode) {
setFocusToTextArea();
} else {
Expand All @@ -97,6 +100,7 @@ public class PromptlyPanel extends Composite {
}
};


public PromptlyPanel() {
_outerPanel = new FlowPanel() {
//RepeatingCommand _cmd = null;
Expand Down Expand Up @@ -189,7 +193,7 @@ protected void onAttach() {
@Override
public void onKeyDown(KeyDownEvent event) {

if (_collectKeyEvents /* Collection of events can be halted */) {
if (_collectKeyEventsWhenInNonCommandLineMode /* Collection of events can be halted */) {
if (event.getNativeKeyCode() == KeyCodes.KEY_C && event.isControlKeyDown()) {
_listener.onControlCPressedInAllModes(PromptlyPanel.this);
event.stopPropagation();
Expand Down Expand Up @@ -424,10 +428,10 @@ public final void clearScreen() {
/**
*
* @param commandLineMode Sets whether command line (prompt mode) is enabled or disabled.
* @param collectKeyEvents If not in command line mode, sets whether keyboard events are collected or ignored.
* @param collectMouseEvents If not in command line mode, sets whether mouse events are collected or ignored (DOES NOT APPLY TO VISIBLE HYPERLINKS)
* @param collectKeyEventsWhenInNonCommandLineMode If not in command line mode, sets whether keyboard events are collected or ignored.
* @param collectMouseEventsWhenInNonCommandLineMode If not in command line mode, sets whether mouse events are collected or ignored (DOES NOT APPLY TO VISIBLE HYPERLINKS)
*/
public final void setCommandLineMode(final boolean commandLineMode, final boolean collectKeyEvents, final boolean collectMouseEvents /* adv = default to true */) {
public final void setCommandLineMode(final boolean commandLineMode, final boolean collectKeyEventsWhenInNonCommandLineMode, final boolean collectMouseEventsWhenInNonCommandLineMode /* adv = default to true */) {
ScheduledCommand cmd = new ScheduledCommand() {
@Override
public void execute() {
Expand All @@ -436,7 +440,6 @@ public void execute() {
setCommandLineText("");
}
}

showCaret(commandLineMode);
if (commandLineMode != isCommandLineMode()) {
boolean refocusOnCommandLine = (!_isCommandLineMode) && commandLineMode;
Expand All @@ -445,12 +448,9 @@ public void execute() {
setFocusToTextArea();
}
}

_collectKeyEvents = collectKeyEvents;
_collectMouseEvents = collectMouseEvents;
_collectKeyEventsWhenInNonCommandLineMode = collectKeyEventsWhenInNonCommandLineMode;
_collectMouseEventsWhenInNonCommandLineMode = collectMouseEventsWhenInNonCommandLineMode;
}


};
Scheduler.get().scheduleDeferred(cmd);
}
Expand Down Expand Up @@ -514,11 +514,11 @@ public boolean isClearTextboxOnCarriageReturnPressed() {
}

public boolean isCollectKeyEvents() {
return _collectKeyEvents;
return _collectKeyEventsWhenInNonCommandLineMode;
}

public boolean isCollectMouseEvents() {
return _collectMouseEvents;
return _collectMouseEventsWhenInNonCommandLineMode;
}

public boolean isCommandLineMode() {
Expand Down Expand Up @@ -696,4 +696,13 @@ public String getPromptChar() {
return promptChar;
}

public void setBlockingHyperlinks(boolean blockingHyperlinks) {
_blockingHyperlinks = blockingHyperlinks;
}


public boolean isBlockingHyperlinks() {
return _blockingHyperlinks;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ FlowPanel toGwtWidget(final PromptlyPanel promptlyPanel, boolean withFormatting,
ClickHandler handler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
callback.onClick(promptlyPanel, text, event.getClientX(), event.getClientY());
if (!promptlyPanel.isBlockingHyperlinks()) {
callback.onClick(promptlyPanel, text, event.getClientX(), event.getClientY());
}
}
};
spanElement.addDomHandler(handler , ClickEvent.getType());
Expand Down

0 comments on commit 93c47b7

Please sign in to comment.