Annotation of modules/damieng/graphical_editor/daxe/lib/daxe.dart, revision 1.2
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) {
94: doc = new DaxeDocument();
95: page = new WebPage();
96:
97: // check parameters for a config and file to open
98: String file = null;
99: String config = null;
100: String saveURL = null;
101: h.Location location = h.window.location;
102: String search = location.search;
103: if (search.startsWith('?'))
104: search = search.substring(1);
105: List<String> parameters = search.split('&');
106: for (String param in parameters) {
107: List<String> lparam = param.split('=');
108: if (lparam.length != 2)
109: continue;
110: if (lparam[0] == 'config')
111: config = lparam[1];
112: else if (lparam[0] == 'file')
113: file = Uri.decodeComponent(lparam[1]);
114: else if (lparam[0] == 'save')
115: saveURL = lparam[1];
116: }
117: if (saveURL != null)
118: doc.saveURL = saveURL;
119: if (config != null && file != null)
120: page.openDocument(file, config);
121: else if (config != null)
122: page.newDocument(config);
123: else
124: h.window.alert(Strings.get('daxe.missing_config'));
1.2 ! damieng 125: }).catchError((e) {
! 126: h.document.body.appendText('Error when loading the strings in LocalStrings_en.properties.');
1.1 damieng 127: });
128: }
129:
130: /**
131: * Adds a custom display type. Two constructors are required to define the display type:
132: *
133: * * one to create a new node, with the element reference in the schema as a parameter;
134: * [Config] methods can be used via doc.cfg to obtain useful information with the reference.
135: * * another one to create a new Daxe node based on a DOM [x.Node];
136: * it takes the future [DaxeNode] parent as a 2nd parameter.
137: */
138: void addDisplayType(String displayType, ConstructorFromRef cref, ConstructorFromNode cnode) {
139: NodeFactory.addDisplayType(displayType, cref, cnode);
140: }
141:
142: /**
143: * Adds a custom function which can be called by name with a menu defined in the configuration file.
144: */
145: void addCustomFunction(String functionName, ActionFunction fct) {
146: customFunctions[functionName] = fct;
147: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>