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

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/find_dialog.dart';
                     53: part 'src/help_dialog.dart';
                     54: part 'src/insert_panel.dart';
                     55: part 'src/left_panel.dart';
                     56: part 'src/locale.dart';
                     57: part 'src/menu.dart';
                     58: part 'src/menubar.dart';
                     59: part 'src/menu_item.dart';
                     60: part 'src/node_factory.dart';
1.5     ! damieng    61: part 'src/file_chooser.dart';
1.1       damieng    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:   
                    109:   // check parameters for a config and file to open
                    110:   String file = null;
                    111:   String config = null;
1.5     ! damieng   112:   String saveURL = null; // URL for saving file, will trigger the display of the save menu
        !           113:   bool application = false; // Desktop application (open and quit menus)
1.3       damieng   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];
1.5     ! damieng   129:     else if (lparam[0] == 'application' && lparam[1] == 'true')
        !           130:       application = true;
1.3       damieng   131:   }
1.5     ! damieng   132:   doc = new DaxeDocument();
        !           133:   page = new WebPage(application:application);
1.3       damieng   134:   if (saveURL != null)
                    135:     doc.saveURL = saveURL;
                    136:   if (config != null && file != null)
                    137:     page.openDocument(file, config).then((v) => completer.complete());
                    138:   else if (config != null)
                    139:     page.newDocument(config).then((v) => completer.complete());
                    140:   else {
                    141:     h.window.alert(Strings.get('daxe.missing_config'));
                    142:     completer.completeError(Strings.get('daxe.missing_config'));
                    143:   }
                    144:   return(completer.future);
                    145: }
                    146: 
                    147: /**
1.1       damieng   148:  * Adds a custom display type. Two constructors are required to define the display type:
                    149:  * 
                    150:  * * one to create a new node, with the element reference in the schema as a parameter;
                    151:  *   [Config] methods can be used via doc.cfg to obtain useful information with the reference.
                    152:  * * another one to create a new Daxe node based on a DOM [x.Node];
                    153:  *   it takes the future [DaxeNode] parent as a 2nd parameter.
                    154:  */
                    155: void addDisplayType(String displayType, ConstructorFromRef cref, ConstructorFromNode cnode) {
                    156:   NodeFactory.addDisplayType(displayType, cref, cnode);
                    157: }
                    158: 
                    159: /**
                    160:  * Adds a custom function which can be called by name with a menu defined in the configuration file.
                    161:  */
                    162: void addCustomFunction(String functionName, ActionFunction fct) {
                    163:   customFunctions[functionName] = fct;
                    164: }

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