Skip to content

Commit ae4ebd1

Browse files
azoitllaeubi
authored andcommitted
Postponing BrowserFunction registration after Dom is ready #662
In order to avoid race conditions for registering browser functions the browser function registration of the RichTextEditor is moved to a point when the document is ready. Fixes: #662 See also: eclipse-platform/eclipse.platform.swt#2449
1 parent 7cf9d9d commit ae4ebd1

File tree

1 file changed

+33
-30
lines changed
  • widgets/richtext/org.eclipse.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext

1 file changed

+33
-30
lines changed

widgets/richtext/org.eclipse.nebula.widgets.richtext/src/org/eclipse/nebula/widgets/richtext/RichTextEditor.java

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -248,40 +248,11 @@ public RichTextEditor(final Composite parent, final RichTextEditorConfiguration
248248

249249
browser.setUrl(templateURL.toString());
250250

251-
browserFunctions.add(new ModifyFunction(browser, "textModified"));
252-
browserFunctions.add(new KeyPressedFunction(browser, "keyPressed"));
253-
browserFunctions.add(new KeyReleasedFunction(browser, "keyReleased"));
254-
browserFunctions.add(new FocusInFunction(browser, "focusIn"));
255-
browserFunctions.add(new FocusOutFunction(browser, "focusOut"));
256-
browserFunctions.add(new JavaExecutionStartedFunction(browser, "javaExecutionStarted"));
257-
browserFunctions.add(new JavaExecutionFinishedFunction(browser, "javaExecutionFinished"));
258-
browserFunctions.add(new BrowserFunction(browser, "customizeToolbar") {
259-
@Override
260-
public Object function(final Object[] arguments) {
261-
RichTextEditor.this.editorConfig.customizeToolbar();
262-
return super.function(arguments);
263-
}
264-
});
265-
browserFunctions.add(new BrowserFunction(browser, "getAllOptions") {
266-
@Override
267-
public Object function(final Object[] arguments) {
268-
// transform the configuration options map into an Object array
269-
// necessary as map is not a supported return value
270-
final Map<String, Object> options = RichTextEditor.this.editorConfig.getAllOptions();
271-
final Object[] result = new Object[options.size()*2];
272-
int i = 0;
273-
for (final Map.Entry<String, Object> entry : options.entrySet()) {
274-
result[i++] = entry.getKey();
275-
result[i++] = entry.getValue() != null ? entry.getValue() : "";
276-
}
277-
return result;
278-
}
279-
});
280-
281251
browser.addProgressListener(new ProgressListener() {
282252

283253
@Override
284254
public void completed(final ProgressEvent event) {
255+
createBrowserFunctions();
285256
browser.evaluate("initEditor();");
286257

287258
CKEDITOR_ALT = (Double) browser.evaluate("return getCKEditorALT()");
@@ -366,6 +337,38 @@ public Object function(final Object[] arguments) {
366337
@Override
367338
public void changed(final ProgressEvent event) {
368339
}
340+
});
341+
}
342+
343+
private void createBrowserFunctions() {
344+
browserFunctions.add(new ModifyFunction(browser, "textModified"));
345+
browserFunctions.add(new KeyPressedFunction(browser, "keyPressed"));
346+
browserFunctions.add(new KeyReleasedFunction(browser, "keyReleased"));
347+
browserFunctions.add(new FocusInFunction(browser, "focusIn"));
348+
browserFunctions.add(new FocusOutFunction(browser, "focusOut"));
349+
browserFunctions.add(new JavaExecutionStartedFunction(browser, "javaExecutionStarted"));
350+
browserFunctions.add(new JavaExecutionFinishedFunction(browser, "javaExecutionFinished"));
351+
browserFunctions.add(new BrowserFunction(browser, "customizeToolbar") {
352+
@Override
353+
public Object function(final Object[] arguments) {
354+
RichTextEditor.this.editorConfig.customizeToolbar();
355+
return super.function(arguments);
356+
}
357+
});
358+
browserFunctions.add(new BrowserFunction(browser, "getAllOptions") {
359+
@Override
360+
public Object function(final Object[] arguments) {
361+
// transform the configuration options map into an Object array
362+
// necessary as map is not a supported return value
363+
final Map<String, Object> options = RichTextEditor.this.editorConfig.getAllOptions();
364+
final Object[] result = new Object[options.size()*2];
365+
int i = 0;
366+
for (final Map.Entry<String, Object> entry : options.entrySet()) {
367+
result[i++] = entry.getKey();
368+
result[i++] = entry.getValue() != null ? entry.getValue() : "";
369+
}
370+
return result;
371+
}
369372
});
370373
}
371374

0 commit comments

Comments
 (0)