diff --git a/src/www/js/grammar_manager.js b/src/www/js/grammar_manager.js index a2bf3b830..11d13d71c 100644 --- a/src/www/js/grammar_manager.js +++ b/src/www/js/grammar_manager.js @@ -20,7 +20,7 @@ function GrammarManager(server,opts) { this.options = { initial: {} }; - this.hooks = { + this.actions = { onload: [ function(gm){ debug("default action: onload"); } ], @@ -36,13 +36,13 @@ function GrammarManager(server,opts) { } // Apply supplied options -// if(opts) for(var o in opts) this.options[o]=opts[o]; + if(opts) for(var o in opts) this.options[o]=opts[o]; /* --- Client state initialisation -------------------------------------- */ this.server = server; this.grammar = null; // current grammar - // this.grammars=[]; - // this.grammar_dirs=[]; + this.grammars=[]; + this.grammar_dirs=[]; this.startcat = null; // current startcat this.languages = []; // current languages (empty means all langs) @@ -71,17 +71,23 @@ GrammarManager.prototype.onload=function(dir,grammar_names,dir_count) { /* --- Registering / unregistering actions to hooks ------------------------- */ GrammarManager.prototype.register_action=function(hook,action) { - this.hooks[hook].push(action); + var hookring = this.actions[hook]; + hookring.push(action); } GrammarManager.prototype.unregister_action=function(hook,action) { - // TODO! + var hookring = this.actions[hook]; + for (var f=0; f < hookring.length; f++) { + if (hookring[f] == action) { + hookring = Array.remove(hookring, f); + } + } } // Execute actions for a given hook // TODO: any number of arguments GrammarManager.prototype.run_actions=function(hook,arg1,arg2,arg3) { - var acts = this.hooks[hook]; + var acts = this.actions[hook]; for (f in acts) { acts[f](arg1,arg2,arg3); } @@ -147,11 +153,11 @@ GrammarManager.prototype.update_language_list=function(grammar) { // Replace the options in the menu with the languages in the grammar var langs=grammar.languages; for(var i=0; iSyntax Editor
- +
diff --git a/src/www/syntax-editor/editor.js b/src/www/syntax-editor/editor.js index 031a461a2..41360c53f 100644 --- a/src/www/syntax-editor/editor.js +++ b/src/www/syntax-editor/editor.js @@ -1,20 +1,4 @@ /* --- Main Editor object --------------------------------------------------- */ -/* When creating the object, stuff gets called in this order: -new EditorMenu - server.get_grammarlists - EditorMenu.show_grammarlist - EditorMenu.change_grammar - server.switch_to_other_grammar - server.get_grammar_info - EditorMenu.update_startcat_menu - EditorMenu.update_language_menu - Editor.change_grammar - Editor.get_grammar_constructors - Editor.start_fresh - Editor.update_current_node(); - Editor.redraw_tree(); - Editor.get_refinements(); -*/ function Editor(gm,opts) { var t = this; /* --- Configuration ---------------------------------------------------- */ @@ -64,11 +48,6 @@ function Editor(gm,opts) { /* --- Register Grammar Manager hooks ----------------------------------- */ this.gm.register_action("change_grammar",function(grammar){ debug("Editor: change grammar"); - var startcat0 = t.options.initial.startcat; - if (elem(startcat0, grammar.categories)) - t.startcat = startcat0; - else - t.startcat = null; t.get_grammar_constructors(bind(t.start_fresh,t)); }); this.gm.register_action("change_startcat",function(startcat){ @@ -124,19 +103,19 @@ Editor.prototype.get_startcat=function() { } // TODO -Editor.prototype.initialize_from=function(opts) { - var t=this; - if (opts.startcat) - t.options.initial_startcat=opts.startcat; - t.change_grammar(); - if (opts.abstr) - t.import_ast(opts.abstr); -} +// Editor.prototype.initialize_from=function(opts) { +// var t=this; +// if (opts.startcat) +// t.options.initial_startcat=opts.startcat; +// t.change_grammar(); +// if (opts.abstr) +// t.import_ast(opts.abstr); +// } // Called after changing grammar or startcat Editor.prototype.start_fresh=function () { var t = this; - t.ast = new AST(null, t.get_startcat()); + t.ast = new AST(null, t.get_startcat()); if (t.options.initial.abstr) { t.import_ast(t.options.initial.abstr); } diff --git a/src/www/syntax-editor/editor_menu.js b/src/www/syntax-editor/editor_menu.js index e207133e7..31927a26e 100644 --- a/src/www/syntax-editor/editor_menu.js +++ b/src/www/syntax-editor/editor_menu.js @@ -107,7 +107,7 @@ EditorMenu.prototype.hook_onload=function(dir,grammar_names,dir_count) { appendChildren(t.ui.grammar_menu, map(opt, grammar_names)); function pick_first_grammar() { if(t.timeout) clearTimeout(t.timeout),t.timeout=null; - var grammar0=t.options.initial.grammar; + var grammar0=t.gm.options.initial.grammar; if(!grammar0) grammar0=t.grammars[0]; t.ui.grammar_menu.value=grammar0; // t.change_grammar(); @@ -139,16 +139,11 @@ EditorMenu.prototype.update_startcat_menu=function(grammar) { menu.innerHTML=""; var cats=grammar.categories; for(var cat in cats) menu.appendChild(option(cats[cat],cats[cat])) -// var startcat=this.local.get("startcat") || grammar.startcat; - var startcat0 = t.options.initial.startcat; + var startcat0 = t.gm.options.initial.startcat; if (elem(startcat0, cats)) menu.value = startcat0; else menu.value = grammar.startcat; - // else { - // insertFirst(menu,option("Default","")); - // menu.value=""; - // } } /* --- Langugage (to) menu -------------------------------------------------- */ @@ -168,9 +163,8 @@ EditorMenu.prototype.update_language_menu=function(menu,grammar) { if(!hasPrefix(ln,"Disamb")) { var lp=langpart(ln,grammar.name); var opt=option(lp,ln); - if (elem(lp, t.options.initial.languages)) { + if (elem(lp, t.gm.options.initial.languages)) { opt.selected=true; - t.editor.languages.push(opt.value); } menu.appendChild(opt); } diff --git a/src/www/syntax-editor/editor_online.js b/src/www/syntax-editor/editor_online.js index 5ca81c9fa..56e8a9de3 100644 --- a/src/www/syntax-editor/editor_online.js +++ b/src/www/syntax-editor/editor_online.js @@ -4,12 +4,9 @@ var server_options = { } var editor_options = { target: "editor", - // initial: { - // grammar: "http://localhost:41296/grammars/Phrasebook.pgf", - // startcat: "Proposition", - // languages: ["Eng","Swe","Ita"], - // abstr: "PropOpenDate (SuperlPlace TheMostExpensive School) Tomorrow" - // }, + initial: { +// abstr: "PropOpenDate (SuperlPlace TheMostExpensive School) Tomorrow" + }, show: { grammar_menu: true, startcat_menu: true,