use of org.rstudio.studio.client.common.Value in project rstudio by rstudio.
the class WebTextInput method promptForTextWithOption.
@Override
public void promptForTextWithOption(String title, String label, String initialValue, final boolean usePasswordMask, String extraOptionPrompt, boolean extraOptionDefault, int selectionStart, int selectionLength, String okButtonCaption, final ProgressOperationWithInput<PromptWithOptionResult> okOperation, Operation cancelOperation) {
// This variable introduces a level of pointer indirection that lets us
// get around passing TextEntryModalDialog a reference to itself in its
// own constructor.
final Value<TextEntryModalDialog> pDialog = new Value<TextEntryModalDialog>(null);
final TextEntryModalDialog dialog = new TextEntryModalDialog(title, label, initialValue, usePasswordMask, extraOptionPrompt, extraOptionDefault, false, selectionStart, selectionLength, okButtonCaption, 300, new ProgressOperationWithInput<String>() {
@Override
public void execute(String input, ProgressIndicator indicator) {
PromptWithOptionResult result = new PromptWithOptionResult();
result.input = input;
result.extraOption = pDialog.getValue().getExtraOption();
okOperation.execute(result, indicator);
}
}, cancelOperation) {
@Override
protected void positionAndShowDialog(final Command onCompleted) {
setPopupPositionAndShow(new PositionCallback() {
@Override
public void setPosition(int offsetWidth, int offsetHeight) {
int left = (Window.getClientWidth() / 2) - (offsetWidth / 2);
int top = (Window.getClientHeight() / 2) - (offsetHeight / 2);
if (usePasswordMask)
top = 50;
setPopupPosition(left, top);
onCompleted.execute();
}
});
}
};
pDialog.setValue(dialog, false);
dialog.showModal();
}
use of org.rstudio.studio.client.common.Value in project rstudio by rstudio.
the class PdfJsWindow method navigateTo.
public static void navigateTo(final PdfJsWindow win, final PdfLocation pdfLocation) {
double factor = win.getCurrentScale() * 96 / 72;
final double x = pdfLocation.getX() * factor;
final double y = pdfLocation.getY() * factor;
final double w = pdfLocation.getWidth() * factor;
final double h = pdfLocation.getHeight() * factor;
final Value<Integer> retries = new Value<Integer>(0);
// Sometimes pageContainer is null during load, so retry every 100ms
// until it's not, or we've tried 40 times.
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
@Override
public boolean execute() {
Element pageContainer = win.getDocument().getElementById("pageContainer" + pdfLocation.getPage());
if (pageContainer == null) {
retries.setValue(retries.getValue() + 1);
return retries.getValue() < 40;
}
if (pdfLocation.isFromClick()) {
final DivElement div = win.getDocument().createDivElement();
div.getStyle().setPosition(Style.Position.ABSOLUTE);
div.getStyle().setTop(y, Unit.PX);
div.getStyle().setLeft(x, Unit.PX);
div.getStyle().setWidth(w, Unit.PX);
div.getStyle().setHeight(h, Unit.PX);
div.getStyle().setBackgroundColor("rgba(0, 126, 246, 0.1)");
div.getStyle().setProperty("transition", "opacity 4s");
// use DomUtils to set transition styles so gwt doesn't assert
// an invalid style name (no camelCase) in debug mode
DomUtils.setStyle(div, "-moz-transition", "opacity 4s");
DomUtils.setStyle(div, "-webkit-transition", "opacity 4s");
pageContainer.appendChild(div);
Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {
@Override
public boolean execute() {
div.getStyle().setOpacity(0.0);
return false;
}
}, 2000);
}
// scroll to the page
win.goToPage(pdfLocation.getPage());
// if the target isn't on-screen then scroll to it
SyncTexCoordinates boundary = getBoundaryCoordinates(win, false);
if (boundary != null && pdfLocation.getY() > boundary.getY()) {
Element container = getViewerContainer(win);
container.setScrollTop(Math.max(0, DomUtils.topRelativeTo(getViewerContainer(win), pageContainer) + (int) y - 180));
}
win.focus();
return false;
}
}, 100);
}
use of org.rstudio.studio.client.common.Value in project rstudio by rstudio.
the class AceEditorWidget method setChunkLineExecState.
public void setChunkLineExecState(int start, int end, int state) {
for (int i = start; i <= end; i++) {
for (int j = 0; j < lineExecState_.size(); j++) {
int row = lineExecState_.get(j).getRow();
if (row == i) {
if (state == ChunkRowExecState.LINE_QUEUED || state == ChunkRowExecState.LINE_NONE) {
// we're cleaning up state, or queuing a line that still has
// state -- detach it immediately
lineExecState_.get(j).detach();
} else {
lineExecState_.get(j).setState(state);
}
break;
}
}
if (state == ChunkRowExecState.LINE_QUEUED) {
// queued state: introduce to the editor
final Value<ChunkRowExecState> execState = new Value<ChunkRowExecState>(null);
execState.setValue(new ChunkRowExecState(editor_, i, state, new Command() {
@Override
public void execute() {
lineExecState_.remove(execState.getValue());
}
}));
lineExecState_.add(execState.getValue());
}
}
}
Aggregations