Annotation of modules/damieng/graphical_editor/daxe/lib/daxe.dart, revision 1.4

1.1       damieng     1: /*
                      2:   This file is part of Daxe.
                      3: 
                      4:   Daxe is free software: you can redistribute it and/or modify
                      5:   it under the terms of the GNU General Public License as published by
                      6:   the Free Software Foundation, either version 3 of the License, or
                      7:   (at your option) any later version.
                      8: 
                      9:   Daxe is distributed in the hope that it will be useful,
                     10:   but WITHOUT ANY WARRANTY; without even the implied warranty of
                     11:   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     12:   GNU General Public License for more details.
                     13: 
                     14:   You should have received a copy of the GNU General Public License
                     15:   along with Daxe.  If not, see <http://www.gnu.org/licenses/>.
                     16: */
                     17: 
                     18: /**
                     19:  * Daxe - Dart XML Editor
                     20:  * The goal of this project is to replace the Jaxe Java applet in WebJaxe, but Daxe
                     21:  * could be used to edit XML documents online in any other application.
                     22:  * 
                     23:  * The URL must have the file and config parameters with the path to the XML file and Jaxe config file.
                     24:  * It can also have a save parameter with the path to a server script to save the document.
                     25:  */
                     26: library daxe;
                     27: 
                     28: import 'dart:async';
                     29: import 'dart:collection';
                     30: //import 'dart:convert';
                     31: import 'dart:html' as h;
                     32: 
                     33: //import 'package:meta/meta.dart';
                     34: //import 'package:js/js.dart' as js;
                     35: 
                     36: import 'src/xmldom/xmldom.dart' as x;
                     37: import 'src/strings.dart';
                     38: 
                     39: import 'src/interface_schema.dart';
                     40: import 'src/wxs/wxs.dart' show DaxeWXS, WXSException;
                     41: import 'src/simple_schema.dart';
                     42: import 'src/nodes/nodes.dart';
                     43: 
                     44: part 'src/attribute_dialog.dart';
                     45: part 'src/css_map.dart';
                     46: part 'src/cursor.dart';
                     47: part 'src/daxe_document.dart';
                     48: part 'src/daxe_exception.dart';
                     49: part 'src/config.dart';
                     50: part 'src/daxe_node.dart';
                     51: part 'src/daxe_attr.dart';
                     52: //part 'src/file_open_dialog.dart';
                     53: part 'src/find_dialog.dart';
                     54: part 'src/help_dialog.dart';
                     55: part 'src/insert_panel.dart';
                     56: part 'src/left_panel.dart';
                     57: part 'src/locale.dart';
                     58: part 'src/menu.dart';
                     59: part 'src/menubar.dart';
                     60: part 'src/menu_item.dart';
                     61: part 'src/node_factory.dart';
                     62: part 'src/position.dart';
                     63: part 'src/node_offset_position.dart';
                     64: part 'src/left_offset_position.dart';
                     65: part 'src/right_offset_position.dart';
                     66: part 'src/source_window.dart';
1.4     ! damieng    67: part 'src/symbol_dialog.dart';
1.1       damieng    68: part 'src/tag.dart';
                     69: part 'src/toolbar.dart';
                     70: part 'src/toolbar_item.dart';
                     71: part 'src/toolbar_box.dart';
                     72: part 'src/toolbar_menu.dart';
                     73: part 'src/toolbar_button.dart';
                     74: part 'src/toolbar_style_info.dart';
                     75: part 'src/tree_item.dart';
                     76: part 'src/tree_panel.dart';
                     77: part 'src/undoable_edit.dart';
                     78: part 'src/unknown_element_dialog.dart';
                     79: part 'src/validation_dialog.dart';
                     80: part 'src/web_page.dart';
                     81: 
                     82: 
                     83: typedef void ActionFunction();
                     84: 
                     85: /// The current web page
                     86: WebPage page;
                     87: /// The current XML document
                     88: DaxeDocument doc;
                     89: Map<String,ActionFunction> customFunctions = new Map<String,ActionFunction>();
                     90: 
                     91: void main() {
                     92:   NodeFactory.addCoreDisplayTypes();
                     93:   
                     94:   Strings.load().then((bool b) {
1.3       damieng    95:     initDaxe();
1.2       damieng    96:   }).catchError((e) {
                     97:     h.document.body.appendText('Error when loading the strings in LocalStrings_en.properties.');
1.1       damieng    98:   });
                     99: }
                    100: 
                    101: /**
1.3       damieng   102:  * This Future can be used to initialize Daxe and customize the user interface afterwards.
                    103:  * The display types and the strings have to be loaded before this method is called.
                    104:  * In the Daxe application, the results of the Future are not used.
                    105:  */
                    106: Future initDaxe() {
                    107:   Completer completer = new Completer();
                    108:   doc = new DaxeDocument();
                    109:   page = new WebPage();
                    110:   
                    111:   // check parameters for a config and file to open
                    112:   String file = null;
                    113:   String config = null;
                    114:   String saveURL = null;
                    115:   h.Location location = h.window.location;
                    116:   String search = location.search;
                    117:   if (search.startsWith('?'))
                    118:     search = search.substring(1);
                    119:   List<String> parameters = search.split('&');
                    120:   for (String param in parameters) {
                    121:     List<String> lparam = param.split('=');
                    122:     if (lparam.length != 2)
                    123:       continue;
                    124:     if (lparam[0] == 'config')
                    125:       config = lparam[1];
                    126:     else if (lparam[0] == 'file')
                    127:       file = Uri.decodeComponent(lparam[1]);
                    128:     else if (lparam[0] == 'save')
                    129:       saveURL = lparam[1];
                    130:   }
                    131:   if (saveURL != null)
                    132:     doc.saveURL = saveURL;
                    133:   if (config != null && file != null)
                    134:     page.openDocument(file, config).then((v) => completer.complete());
                    135:   else if (config != null)
                    136:     page.newDocument(config).then((v) => completer.complete());
                    137:   else {
                    138:     h.window.alert(Strings.get('daxe.missing_config'));
                    139:     completer.completeError(Strings.get('daxe.missing_config'));
                    140:   }
                    141:   return(completer.future);
                    142: }
                    143: 
                    144: /**
1.1       damieng   145:  * Adds a custom display type. Two constructors are required to define the display type:
                    146:  * 
                    147:  * * one to create a new node, with the element reference in the schema as a parameter;
                    148:  *   [Config] methods can be used via doc.cfg to obtain useful information with the reference.
                    149:  * * another one to create a new Daxe node based on a DOM [x.Node];
                    150:  *   it takes the future [DaxeNode] parent as a 2nd parameter.
                    151:  */
                    152: void addDisplayType(String displayType, ConstructorFromRef cref, ConstructorFromNode cnode) {
                    153:   NodeFactory.addDisplayType(displayType, cref, cnode);
                    154: }
                    155: 
                    156: /**
                    157:  * Adds a custom function which can be called by name with a menu defined in the configuration file.
                    158:  */
                    159: void addCustomFunction(String functionName, ActionFunction fct) {
                    160:   customFunctions[functionName] = fct;
                    161: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>