forked from GitHub/gf-core
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:
@@ -259,6 +259,25 @@ function toggleHidden(el) {
|
||||
el.classList.add("hidden")
|
||||
}
|
||||
|
||||
// Update the selected options in a menu that allow multiple selections
|
||||
function updateMultiMenu(menu,selection) {
|
||||
var set=toSet(selection)
|
||||
var os=menu.options
|
||||
for(var i=0;i<os.length;i++)
|
||||
os[i].selected=set[os[i].value] || false
|
||||
}
|
||||
|
||||
/* --- Document data extraction --------------------------------------------- */
|
||||
|
||||
// List the selected options in a menu that allows multiple selections
|
||||
function multiMenuSelections(menu) {
|
||||
var selection=[]
|
||||
var os=menu.options;
|
||||
for(var i=0;i<os.length;i++)
|
||||
if(os[i].selected) selection.push(os[i].value)
|
||||
return selection
|
||||
}
|
||||
|
||||
/* --- Debug ---------------------------------------------------------------- */
|
||||
|
||||
function debug(s) {
|
||||
@@ -369,3 +388,10 @@ function shuffle(a) {
|
||||
for(i=0;i<a.length;i++) swap(a,i,Math.floor(Math.random()*a.length))
|
||||
return a;
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<!-- Common -->
|
||||
<script type="text/javascript" src="../js/grammar_manager.js"></script>
|
||||
<script type="text/javascript" src="../js/support.js"></script>
|
||||
<script type="text/JavaScript" src="../js/localstorage.js"></script>
|
||||
<script type="text/javascript" src="../js/pgf_online.js"></script>
|
||||
|
||||
<!-- Editor -->
|
||||
|
||||
@@ -77,12 +77,7 @@ function EditorMenu(editor,opts) {
|
||||
if (t.options.show_to_menu) {
|
||||
appendChildren(t.container, [text(" To: "), t.ui.to_toggle, t.ui.to_menu]);
|
||||
t.ui.to_menu.onchange = function(){
|
||||
var languages = new Array();
|
||||
for (i in t.ui.to_menu.options) {
|
||||
var opt = t.ui.to_menu.options[i];
|
||||
if (opt.selected)
|
||||
languages.push(opt.value);
|
||||
}
|
||||
var languages = multiMenuSelections(t.ui.to_menu)
|
||||
t.gm.change_languages(languages);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,8 +35,11 @@ if(window.Minibar) // Minibar loaded?
|
||||
initial_grammar: editor.menu.ui.grammar_menu.value, // hmm
|
||||
initial: {
|
||||
from: langFrom,
|
||||
input: s.split(" ") // is it that easy?
|
||||
input: s.split(" "), // is it that easy?
|
||||
startcat: editor.menu.ui.startcat_menu.value // hmm
|
||||
},
|
||||
initial_toLangs: multiMenuSelections(editor.menu.ui.to_menu), // hmm
|
||||
|
||||
// get us back to the editor!
|
||||
abstract_action: function(tree) {
|
||||
var opts = {
|
||||
|
||||
Reference in New Issue
Block a user