minibar: add buttons to use generated translations as input

This functionality was available in the origial Fridge Poetry app, but has been
missing in minibar until now.
This commit is contained in:
hallgren
2012-04-18 16:26:49 +00:00
parent 6dc12cfed9
commit ff812613c8
2 changed files with 35 additions and 17 deletions

View File

@@ -119,13 +119,19 @@ Input.prototype.get_completions=function() {
}
Input.prototype.show_completions=function(complete_output) {
with(this) {
var self=this;
function switch_input(lin) {
with(self) {
local.put("current",{from:lin.to,input:lin.text.split(" ")})
from_menu.value=lin.to;
change_language()
}
}
with(self) {
//debug("show_completions ");
var completions=complete_output[0].completions;
var emptycnt=add_completions(completions)
if(true/*emptycnt>0*/)
translations.translateFrom(current,startcat_menu.value);
else translations.clear();
translations.translateFrom(current,startcat_menu.value,switch_input);
if(surface.typed && emptycnt==completions.length) {
if(surface.typed.value=="") remove_typed_input();
}

View File

@@ -42,9 +42,10 @@ Translations.prototype.clear=function() {
this.main.innerHTML="";
}
Translations.prototype.translateFrom=function(current,startcat) {
Translations.prototype.translateFrom=function(current,startcat,lin_action) {
this.current=current;
this.startcat=startcat;
this.lin_action=lin_action;
this.get_translations();
}
@@ -59,18 +60,24 @@ Translations.prototype.get_translations=function() {
}
}
Translations.prototype.tdt=function(tree_btn,txt) {
with(this) {
return options.show_trees ? tda([tree_btn,txt]) : td(txt);
}
}
Translations.prototype.target_lang=function() {
with(this) return langpart(to_menu.value,grammar.name);
}
Translations.prototype.show_translations=function(translationResults) {
with(this) {
var self=this;
function tdt(tree_btn,s,action) {
var txt=text(s);
if(action) {
txt=node("span",{onclick:action},[txt])
//txt=button(s,action)
}
return self.options.show_trees ? tda([tree_btn,text(" "),txt]) : td(txt)
}
function act(lin) {
return self.lin_action ? function() { self.lin_action(lin) } : null
}
with(self) {
var trans=main;
//var to=target_lang(); // wrong
var to=to_menu.value;
@@ -96,16 +103,21 @@ Translations.prototype.show_translations=function(translationResults) {
tr([th(text("Abstract: ")),
tdt(node("span",{},[abstree_button(t.tree),
alignment_button(t.tree)]),
text(" "+t.tree))]));
t.tree)]));
for(var i=0;i<lin.length;i++) {
if(lin[i].to==to)
trans.single_translation.push(lin[i].text);
if(lin[i].to==current.from && lin[i].brackets)
bra=lin[i].brackets;
if(to=="All" || lin[i].to==to)
tbody.appendChild(tr([th(text(langpart(lin[i].to,grammar.name)+": ")),
tdt(parsetree_button(t.tree,lin[i].to),
text(lin[i].text))]));
if(to=="All" || lin[i].to==to) {
var langcode=langpart(lin[i].to,grammar.name)
//var hdr=text(langcode+": ")
var hdr=button(langcode,act(lin[i]))
//hdr.disabled=lin[i].to==current.from
var btn=parsetree_button(t.tree,lin[i].to)
tbody.appendChild(tr([th(hdr),
tdt(btn,lin[i].text)]));
}
}
trans.appendChild(wrap("table",tbody));
}