mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-03 16:22:52 -06:00
minibar/syntax editor integration improvements
Work in progress on preserving the start category and selected target languages when switching between the minibar and the syntax editor.
This commit is contained in:
@@ -90,7 +90,6 @@ Input.prototype.change_language=function () {
|
||||
}
|
||||
|
||||
Input.prototype.set_input_for=function(grammar_url,initial) {
|
||||
var t=this
|
||||
var local=mi_local(grammar_url)
|
||||
local.put("from",initial.from)
|
||||
local.put("current",{from:initial.from,input:initial.input})
|
||||
|
||||
@@ -26,12 +26,18 @@ if(window.Editor) // Syntax editor loaded?
|
||||
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
|
||||
minibar.input.set_input_for(grammar_url,langFrom,
|
||||
gf_lex(new_input))
|
||||
var startcat=editor.menu.ui.startcat_menu.value // hmm
|
||||
var toLangs=multiMenuSelections(editor.menu.ui.to_menu) // 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)
|
||||
@@ -59,7 +65,7 @@ if(/^\?\/tmp\//.test(location.search)) {
|
||||
if(args[1]) minibar_options.initial_grammar=args[1];
|
||||
}
|
||||
else if(window.localStorage) {
|
||||
var s=localStorage["gf.editor.simple.grammardir"]
|
||||
var s=window.localStorage["gf.editor.simple.grammardir"]
|
||||
if(s) var editor_dir=JSON.parse(s);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,10 +29,9 @@ function Translations(server,opts) {
|
||||
appendChildren(this.menus,[text(" To: "), this.to_menu])
|
||||
tom.onchange=bind(this.change_language,this);
|
||||
var o=this.options
|
||||
if(o.initial_grammar && o.initial_toLangs) {
|
||||
var local=mt_local(o.initial_grammar);
|
||||
local.put("toLangs",o.initial_toLangs)
|
||||
}
|
||||
if(o.initial_grammar && o.initial_toLangs)
|
||||
this.set_toLangs_for(o.initial_grammar,o.initial_toLangs)
|
||||
|
||||
/* // This seems triggers weird scrolling behavior in Firefox and Chrome:
|
||||
tom.onmouseover=function() { var n=tom.options.length;
|
||||
tom.size=n<12 ? n : 12; }
|
||||
@@ -51,12 +50,10 @@ Translations.prototype.change_grammar=function(grammar) {
|
||||
insertFirst(t.to_menu,option("All","All"));
|
||||
t.to_menu.value="All";
|
||||
var toLangs=t.local.get("toLangs")
|
||||
if(toLangs) {
|
||||
if(toLangs && toLangs.length>0) {
|
||||
t.toLangs=toLangs
|
||||
t.toSet=toSet(toLangs)
|
||||
var os=to_menu.options
|
||||
for(var i=0;i<os.length;i++)
|
||||
os[i].selected=t.toSet[os[i].value] || false
|
||||
updateMultiMenu(t.to_menu,toLangs)
|
||||
}
|
||||
else {
|
||||
t.toLangs=["All"]
|
||||
@@ -68,18 +65,17 @@ Translations.prototype.clear=function() {
|
||||
this.main.innerHTML="";
|
||||
}
|
||||
|
||||
Translations.prototype.set_toLangs_for=function(grammar_url,toLangs) {
|
||||
var local=mt_local(grammar_url)
|
||||
local.put("toLangs",toLangs)
|
||||
}
|
||||
|
||||
Translations.prototype.change_language=function() {
|
||||
var toLangs=[]
|
||||
var os=to_menu.options;
|
||||
for(var i=0;i<os.length;i++)
|
||||
if(os[i].selected) {
|
||||
toLangs.push(os[i].value)
|
||||
toSet[os[i].value]=true;
|
||||
}
|
||||
this.toLangs=toLangs
|
||||
this.toSet=toSet(toLangs)
|
||||
this.local.put("toLangs",toLangs)
|
||||
this.get_translations();
|
||||
var t=this
|
||||
t.toLangs=multiMenuSelections(t.to_menu)
|
||||
t.toSet=toSet(t.toLangs)
|
||||
t.local.put("toLangs",t.toLangs)
|
||||
t.get_translations();
|
||||
}
|
||||
|
||||
Translations.prototype.translateFrom=function(current,startcat,lin_action) {
|
||||
@@ -292,10 +288,3 @@ function draw_brackets(b) {
|
||||
title:(b.fun||"_")+":"+b.cat+" "+b.fid+":"+b.index},
|
||||
b.children.map(draw_brackets))
|
||||
}
|
||||
|
||||
// Convert an array of strings to a set (for quick & easy membership tests)
|
||||
function toSet(a) {
|
||||
var set={}
|
||||
for(var i=0;i<a.length;i++) set[a[i]]=true
|
||||
return set
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user