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

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';
                     67: part 'src/tag.dart';
                     68: part 'src/toolbar.dart';
                     69: part 'src/toolbar_item.dart';
                     70: part 'src/toolbar_box.dart';
                     71: part 'src/toolbar_menu.dart';
                     72: part 'src/toolbar_button.dart';
                     73: part 'src/toolbar_style_info.dart';
                     74: part 'src/tree_item.dart';
                     75: part 'src/tree_panel.dart';
                     76: part 'src/undoable_edit.dart';
                     77: part 'src/unknown_element_dialog.dart';
                     78: part 'src/validation_dialog.dart';
                     79: part 'src/web_page.dart';
                     80: 
                     81: 
                     82: typedef void ActionFunction();
                     83: 
                     84: /// The current web page
                     85: WebPage page;
                     86: /// The current XML document
                     87: DaxeDocument doc;
                     88: Map<String,ActionFunction> customFunctions = new Map<String,ActionFunction>();
                     89: 
                     90: void main() {
                     91:   NodeFactory.addCoreDisplayTypes();
                     92:   
                     93:   Strings.load().then((bool b) {
1.3     ! damieng    94:     initDaxe();
1.2       damieng    95:   }).catchError((e) {
                     96:     h.document.body.appendText('Error when loading the strings in LocalStrings_en.properties.');
1.1       damieng    97:   });
                     98: }
                     99: 
                    100: /**
1.3     ! damieng   101:  * This Future can be used to initialize Daxe and customize the user interface afterwards.
        !           102:  * The display types and the strings have to be loaded before this method is called.
        !           103:  * In the Daxe application, the results of the Future are not used.
        !           104:  */
        !           105: Future initDaxe() {
        !           106:   Completer completer = new Completer();
        !           107:   doc = new DaxeDocument();
        !           108:   page = new WebPage();
        !           109:   
        !           110:   // check parameters for a config and file to open
        !           111:   String file = null;
        !           112:   String config = null;
        !           113:   String saveURL = null;
        !           114:   h.Location location = h.window.location;
        !           115:   String search = location.search;
        !           116:   if (search.startsWith('?'))
        !           117:     search = search.substring(1);
        !           118:   List<String> parameters = search.split('&');
        !           119:   for (String param in parameters) {
        !           120:     List<String> lparam = param.split('=');
        !           121:     if (lparam.length != 2)
        !           122:       continue;
        !           123:     if (lparam[0] == 'config')
        !           124:       config = lparam[1];
        !           125:     else if (lparam[0] == 'file')
        !           126:       file = Uri.decodeComponent(lparam[1]);
        !           127:     else if (lparam[0] == 'save')
        !           128:       saveURL = lparam[1];
        !           129:   }
        !           130:   if (saveURL != null)
        !           131:     doc.saveURL = saveURL;
        !           132:   if (config != null && file != null)
        !           133:     page.openDocument(file, config).then((v) => completer.complete());
        !           134:   else if (config != null)
        !           135:     page.newDocument(config).then((v) => completer.complete());
        !           136:   else {
        !           137:     h.window.alert(Strings.get('daxe.missing_config'));
        !           138:     completer.completeError(Strings.get('daxe.missing_config'));
        !           139:   }
        !           140:   return(completer.future);
        !           141: }
        !           142: 
        !           143: /**
1.1       damieng   144:  * Adds a custom display type. Two constructors are required to define the display type:
                    145:  * 
                    146:  * * one to create a new node, with the element reference in the schema as a parameter;
                    147:  *   [Config] methods can be used via doc.cfg to obtain useful information with the reference.
                    148:  * * another one to create a new Daxe node based on a DOM [x.Node];
                    149:  *   it takes the future [DaxeNode] parent as a 2nd parameter.
                    150:  */
                    151: void addDisplayType(String displayType, ConstructorFromRef cref, ConstructorFromNode cnode) {
                    152:   NodeFactory.addDisplayType(displayType, cref, cnode);
                    153: }
                    154: 
                    155: /**
                    156:  * Adds a custom function which can be called by name with a menu defined in the configuration file.
                    157:  */
                    158: void addCustomFunction(String functionName, ActionFunction fct) {
                    159:   customFunctions[functionName] = fct;
                    160: }

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