diff options
| author | hallgren <hallgren@chalmers.se> | 2013-04-12 18:29:15 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2013-04-12 18:29:15 +0000 |
| commit | d35790e656fe70f0fa258fb8fb84aa65f9887616 (patch) | |
| tree | c3cf3663e450d3a7163cf7aaabcae8fe2c9b081f /src/www/minibar | |
| parent | 1d0f9372f4c74075a98bc824568ceedb80f6cd78 (diff) | |
GF cloud: work on syntax editor integration
+ The syntax editor is now accessible from the Simple Translaton Tool.
+ The minibar now automatically provides access to the syntax editor (provided
the necessary JavaScript files and style sheets have been loaded).
+ Preparations for making the syntax editor accessible from the grammar editor.
Diffstat (limited to 'src/www/minibar')
| -rw-r--r-- | src/www/minibar/minibar.html | 4 | ||||
| -rw-r--r-- | src/www/minibar/minibar.js | 78 | ||||
| -rw-r--r-- | src/www/minibar/minibar_online.js | 40 |
3 files changed, 73 insertions, 49 deletions
diff --git a/src/www/minibar/minibar.html b/src/www/minibar/minibar.html index 0255cdb70..06aa77a54 100644 --- a/src/www/minibar/minibar.html +++ b/src/www/minibar/minibar.html @@ -15,7 +15,7 @@ <body class=minibar> <h2>Minibar online</h2> <div id=minibar></div> -<div id=editor></div> +<div id=syntax_editor></div> <noscript>This page doesn't works unless JavaScript is enabled.</noscript> @@ -27,7 +27,7 @@ & <a href="http://www.grammaticalframework.org:41296/translate/">Translator</a>] </small> <small class=modtime> -HTML <!-- hhmts start -->Last modified: Thu Apr 4 16:50:57 CEST 2013 <!-- hhmts end --> +HTML <!-- hhmts start -->Last modified: Fri Apr 12 20:06:19 CEST 2013 <!-- hhmts end --> </small> <div id="debug" class="hidden"></div> diff --git a/src/www/minibar/minibar.js b/src/www/minibar/minibar.js index e65141ca2..a7a368ae4 100644 --- a/src/www/minibar/minibar.js +++ b/src/www/minibar/minibar.js @@ -37,8 +37,12 @@ function Minibar(server,opts) { } // Apply supplied options + this.server=server; if(opts) for(var o in opts) this.options[o]=opts[o]; + /* --- Syntax editor integration ---------------------------------------- */ + if(!this.options.abstract_action) this.integrate_syntax_editor() + /* --- Creating the components of the minibar --------------------------- */ this.translations=new Translations(server,this.options) this.input=new Input(server,this.translations,this.options) @@ -57,24 +61,84 @@ function Minibar(server,opts) { menubar.appendChild(button("Help",bind(open_help,this))); append_extra_buttons(extra,options); } - this.hide = function() { - this.minibar.style.display="none"; - } - this.show = function() { - this.minibar.style.display="block"; + this.set_hidden = function(b) { + this.hidden=b + this.minibar.style.display= b ? "none" : "" } + this.hide = function() { this.set_hidden(true); } + this.show = function() { this.set_hidden(false); } /* --- Minibar client state initialisation ------------------------------ */ this.grammar=null; - this.server=server; - /* --- Main program, this gets things going ----------------------------- */ with(this) { server.get_grammarlists(bind(show_grammarlist,this)); } } +Minibar.prototype.integrate_syntax_editor=function() { + var minibar=this + var editor_target="syntax_editor" + var e=element(editor_target) + if(!e || !window.Editor) return + + e.style.display="none" + minibar.options.abstract_action=function(tree) { + var editor_options = { + target: editor_target, + show_startcat_menu: minibar.input.options.startcat_menu, + initial: { grammar: minibar.grammar_menu.value, // hmm + startcat: minibar.input.startcat_menu.value, // hmm + languages: minibar.translations.toLangs, // hmm + abstr: tree + }, + lin_action: function(new_input,langFrom) { + console.log(editor.menu.ui.grammar_menu.value) + var grammar_url=editor.menu.ui.grammar_menu.value // hmm + || minibar.server.current_grammar_url // hmm + var startcat=editor.get_startcat() + || minibar.input.startcat_menu.value // hmm + var toLangs=gm.languages // hmm + minibar.input.set_input_for(grammar_url, + {from:langFrom, + startcat:startcat, + input:gf_lex(new_input)}) + minibar.translations.set_toLangs_for(grammar_url,toLangs) + + //Better: keep editor around and reactivate it next time: + editor.hide() + // ... + + //Easier: delete the editor and create a new one next time: + clear(editor.container) + editor=minibar.editor=null; + + // Even if the grammar is the same as before, this call is + // what eventually triggers the new_input to be loaded: + minibar.select_grammar(grammar_url) + + // Make the minibar visible again + minibar.show() + } + } + minibar.hide() + var gm = new GrammarManager(minibar.server,editor_options); + var editor=minibar.editor=new Editor(gm,editor_options) + editor.show() + } +} + +Minibar.prototype.get_current_input=function(cont) { + var t=this + if(!t.hidden) cont(gf_unlex(t.input.current.input)) + else { + var tree=t.editor.get_ast() + function pick(lins) { cont(lins[0].text) } + t.server.linearize({tree:tree,to:t.input.current.from},pick) + } +} + Minibar.prototype.show_grammarlist=function(dir,grammar_names,dir_count) { var t=this; var first_time= !t.grammar_menu diff --git a/src/www/minibar/minibar_online.js b/src/www/minibar/minibar_online.js index c969caa52..92b6c0ebf 100644 --- a/src/www/minibar/minibar_online.js +++ b/src/www/minibar/minibar_online.js @@ -19,46 +19,6 @@ 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 - languages: minibar.translations.toLangs, // hmm - abstr: tree - }, - lin_action: function(new_input,langFrom) { - var grammar_url=editor.menu.ui.grammar_menu.value // hmm - var startcat=editor.menu.ui.startcat_menu.value // hmm - var toLangs=gm.languages // hmm - minibar.input.set_input_for(grammar_url, - {from:langFrom, - startcat:startcat, - input:gf_lex(new_input)}) - minibar.translations.set_toLangs_for(grammar_url,toLangs) - - //Easier: delete the editor and create a new one next time: - clear(editor.container) - editor=null; - - //Better: keep editor around and reactivate it next time: - //editor.container.style.display="none" - - // Even if the grammar is the same as before, this call is - // what eventually triggers the new_input to be loaded: - minibar.select_grammar(grammar_url) - - // Make the minibar visible again - minibar.minibar.style.display="" - } - } - minibar.minibar.style.display="none" // Hide the minibar - var gm = new GrammarManager(server,editor_options); - var editor=new Editor(gm,editor_options) - } - if(/^\?\/tmp\//.test(location.search)) { var args=decodeURIComponent(location.search.substr(1)).split(" ") if(args[0]) online_options.grammars_url=args[0]; |
