From bd3b5120748f2a3dfa59ed4b48a3214d63f35501 Mon Sep 17 00:00:00 2001 From: hallgren Date: Wed, 21 Nov 2012 17:13:21 +0000 Subject: [PATCH] minibar+syntax editor integration, work in progress 2 + Transfer current astract syntax tree when activating the syntax editor from the minibar. + Add options to start the minibar with given input. You need to include the current grammar url, the current language and the input, like this: initial_grammar: "/grammars/Foods.pgf", initial: { from: "FoodsEng", input:["that","fish","is","fresh"]} + Fix a style sheet clash. --- src/www/minibar/minibar_input.js | 45 ++++++++++++++++++------------- src/www/minibar/minibar_online.js | 6 ++--- src/www/syntax-editor/editor.css | 2 +- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/www/minibar/minibar_input.js b/src/www/minibar/minibar_input.js index dd32b6f05..67576c8e8 100644 --- a/src/www/minibar/minibar_input.js +++ b/src/www/minibar/minibar_input.js @@ -2,11 +2,12 @@ /* --- Input object --------------------------------------------------------- */ function Input(server,translations,opts) { // Input object constructor - this.server=server; - this.translations=translations; + var t=this + t.server=server; + t.translations=translations; // Default values for options: - this.options={ + t.options={ delete_button_text: "⌫", default_source_language: null, startcat_menu: true, @@ -15,34 +16,42 @@ function Input(server,translations,opts) { // Input object constructor } // Apply supplied options - if(opts) for(var o in opts) this.options[o]=opts[o]; + if(opts) for(var o in opts) t.options[o]=opts[o]; // User interface elements - this.main=empty("div"); - this.menus=empty("span"); - this.buttons=empty("span"); - this.surface=div_id("surface"); - this.words=div_id("words"); - this.from_menu=empty("select"); - this.startcat_menu=empty("select") + t.main=empty("div"); + t.menus=empty("span"); + t.buttons=empty("span"); + t.surface=div_id("surface"); + t.words=div_id("words"); + t.from_menu=empty("select"); + t.startcat_menu=empty("select") - with(this) { + with(t) { appendChildren(main,[surface,words]); if(options.startcat_menu) appendChildren(menus,[text(" Startcat: "),startcat_menu]) appendChildren(menus,[text(" From: "),from_menu]) appendChildren(buttons, - [button(options.delete_button_text,bind(delete_last,this),"H"), - button("Clear",bind(clear_all,this),"L")]); + [button(options.delete_button_text,bind(delete_last,t),"H"), + button("Clear",bind(clear_all,t),"L")]); if(options.random_button) - buttons.appendChild(button("Random",bind(generate_random,this),"R")); + buttons.appendChild(button("Random",bind(generate_random,t),"R")); + + with(options) { + if(initial_grammar && initial && initial.from && initial.input) { + t.local=mi_local(initial_grammar) + t.local.put("from",initial.from) + t.local.put("current",initial) + } + } } /* --- Input client state initialization --- */ - this.current={from: null, input: [] }; + t.current={from: null, input: [] }; - this.from_menu.onchange=bind(this.change_language,this); - this.startcat_menu.onchange=bind(this.change_startcat,this); + t.from_menu.onchange=bind(t.change_language,t); + t.startcat_menu.onchange=bind(t.change_startcat,t); } Input.prototype.change_grammar=function (grammar) { diff --git a/src/www/minibar/minibar_online.js b/src/www/minibar/minibar_online.js index b1c1ad86f..bf3f3f6de 100644 --- a/src/www/minibar/minibar_online.js +++ b/src/www/minibar/minibar_online.js @@ -19,20 +19,20 @@ var minibar_options= { try_google: true } -/* + if(window.Editor) // Syntax editor loaded? minibar_options.abstract_action=function(tree) { var editor_options = { target: "editor", initial: { grammar: minibar.grammar_menu.value, // hmm startcat: minibar.input.startcat_menu.value, // hmm - ast: tree + abstr: tree } } minibar.minibar.style.display="none" minibar.editor=new Editor(server,editor_options) } -*/ + if(/^\?\/tmp\//.test(location.search)) { var args=decodeURIComponent(location.search.substr(1)).split(" ") if(args[0]) online_options.grammars_url=args[0]; diff --git a/src/www/syntax-editor/editor.css b/src/www/syntax-editor/editor.css index 1675372f7..29f45a7e7 100644 --- a/src/www/syntax-editor/editor.css +++ b/src/www/syntax-editor/editor.css @@ -7,7 +7,7 @@ body.syntax_editor { display:none; } -select#to_menu +#editor select#to_menu { height: 10em; position: absolute;