--- modules/damieng/graphical_editor/daxe/lib/daxe.dart 2015/05/11 15:17:54 1.2 +++ modules/damieng/graphical_editor/daxe/lib/daxe.dart 2015/05/11 20:48:20 1.3 @@ -91,43 +91,56 @@ void main() { NodeFactory.addCoreDisplayTypes(); Strings.load().then((bool b) { - doc = new DaxeDocument(); - page = new WebPage(); - - // check parameters for a config and file to open - String file = null; - String config = null; - String saveURL = null; - h.Location location = h.window.location; - String search = location.search; - if (search.startsWith('?')) - search = search.substring(1); - List parameters = search.split('&'); - for (String param in parameters) { - List lparam = param.split('='); - if (lparam.length != 2) - continue; - if (lparam[0] == 'config') - config = lparam[1]; - else if (lparam[0] == 'file') - file = Uri.decodeComponent(lparam[1]); - else if (lparam[0] == 'save') - saveURL = lparam[1]; - } - if (saveURL != null) - doc.saveURL = saveURL; - if (config != null && file != null) - page.openDocument(file, config); - else if (config != null) - page.newDocument(config); - else - h.window.alert(Strings.get('daxe.missing_config')); + initDaxe(); }).catchError((e) { h.document.body.appendText('Error when loading the strings in LocalStrings_en.properties.'); }); } /** + * This Future can be used to initialize Daxe and customize the user interface afterwards. + * The display types and the strings have to be loaded before this method is called. + * In the Daxe application, the results of the Future are not used. + */ +Future initDaxe() { + Completer completer = new Completer(); + doc = new DaxeDocument(); + page = new WebPage(); + + // check parameters for a config and file to open + String file = null; + String config = null; + String saveURL = null; + h.Location location = h.window.location; + String search = location.search; + if (search.startsWith('?')) + search = search.substring(1); + List parameters = search.split('&'); + for (String param in parameters) { + List lparam = param.split('='); + if (lparam.length != 2) + continue; + if (lparam[0] == 'config') + config = lparam[1]; + else if (lparam[0] == 'file') + file = Uri.decodeComponent(lparam[1]); + else if (lparam[0] == 'save') + saveURL = lparam[1]; + } + if (saveURL != null) + doc.saveURL = saveURL; + if (config != null && file != null) + page.openDocument(file, config).then((v) => completer.complete()); + else if (config != null) + page.newDocument(config).then((v) => completer.complete()); + else { + h.window.alert(Strings.get('daxe.missing_config')); + completer.completeError(Strings.get('daxe.missing_config')); + } + return(completer.future); +} + +/** * Adds a custom display type. Two constructors are required to define the display type: * * * one to create a new node, with the element reference in the schema as a parameter;