mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-07 18:22:50 -06:00
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.
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user