minibar: adding a start category menu

+ The start category menu can be turned off by passing the option
  {startcat_menu:false} when starting the minibar.
+ Documentation updates.
This commit is contained in:
hallgren
2011-10-18 15:21:49 +00:00
parent 3b428fc5ba
commit 5e867cec29
4 changed files with 32 additions and 8 deletions

View File

@@ -167,11 +167,14 @@ Some implementation details:
matching completions. matching completions.
(You can now use names of people when constructing sentences in the Letter (You can now use names of people when constructing sentences in the Letter
grammar, for example.) grammar, for example.)
<li>[Added 2011-10-18] Added a button to display some grammar info and a
start category menu. The start category menu can be turned off by passing
the option <code>{startcat_menu:false}</code> when starting the minibar.
</ul> </ul>
<hr> <hr>
<small class=modtime> <small class=modtime>
<!-- hhmts start --> Last modified: Mon Aug 22 19:31:37 CEST 2011 <!-- hhmts end --> <!-- hhmts start --> Last modified: Tue Oct 18 17:18:42 CEST 2011 <!-- hhmts end -->
</small> </small>
<address> <address>
<a href="http://www.cs.chalmers.se/~hallgren/">TH</a> <a href="http://www.cs.chalmers.se/~hallgren/">TH</a>

View File

@@ -90,6 +90,7 @@ full API.
<dt>http://localhost:41296/grammars/Foods.pgf <dt>http://localhost:41296/grammars/Foods.pgf
<dd>{"name":"Foods", <dd>{"name":"Foods",
"userLanguage":"FoodsEng", "userLanguage":"FoodsEng",
"startcat":"Comment",
"categories":["Comment","Float","Int","Item","Kind","Quality","String"], "categories":["Comment","Float","Int","Item","Kind","Quality","String"],
"functions":["Boring","Cheese","Delicious","Expensive","Fish","Fresh", "functions":["Boring","Cheese","Delicious","Expensive","Fish","Fresh",
"Italian","Mod","Pizza","Pred","That","These","This","Those","Very", "Italian","Mod","Pizza","Pred","That","These","This","Those","Very",
@@ -145,7 +146,7 @@ full API.
</dl> </dl>
<hr> <hr>
<div class=modtime><small> <div class=modtime><small>
<!-- hhmts start --> Last modified: Sun Aug 21 10:52:43 CEST 2011 <!-- hhmts end --> <!-- hhmts start --> Last modified: Tue Oct 18 16:36:36 CEST 2011 <!-- hhmts end -->
</small></div> </small></div>
<address><a href="http://www.cse.chalmers.se/~hallgren/">TH</a></address> <address><a href="http://www.cse.chalmers.se/~hallgren/">TH</a></address>

View File

@@ -9,6 +9,7 @@ function Input(server,translations,opts) { // Input object constructor
this.options={ this.options={
delete_button_text: "⌫", delete_button_text: "⌫",
default_source_language: null, default_source_language: null,
startcat_menu: true,
random_button: true, random_button: true,
} }
@@ -22,9 +23,12 @@ function Input(server,translations,opts) { // Input object constructor
this.surface=div_id("surface"); this.surface=div_id("surface");
this.words=div_id("words"); this.words=div_id("words");
this.from_menu=empty("select"); this.from_menu=empty("select");
this.startcat_menu=empty("select")
with(this) { with(this) {
appendChildren(main,[surface,words]); appendChildren(main,[surface,words]);
if(options.startcat_menu)
appendChildren(menus,[text(" Startcat: "),startcat_menu])
appendChildren(menus,[text(" From: "),from_menu]) appendChildren(menus,[text(" From: "),from_menu])
appendChildren(buttons, appendChildren(buttons,
[button(options.delete_button_text,bind(delete_last,this),"H"), [button(options.delete_button_text,bind(delete_last,this),"H"),
@@ -38,14 +42,28 @@ function Input(server,translations,opts) { // Input object constructor
this.previous=null; this.previous=null;
this.from_menu.onchange=bind(this.change_language,this); this.from_menu.onchange=bind(this.change_language,this);
this.startcat_menu.onchange=bind(this.clear_all,this);
} }
Input.prototype.change_grammar=function (grammar) { Input.prototype.change_grammar=function (grammar) {
update_language_menu(this.from_menu,grammar); update_language_menu(this.from_menu,grammar);
set_initial_language(this.options,this.from_menu,grammar); set_initial_language(this.options,this.from_menu,grammar);
this.update_startcat_menu(grammar)
this.change_language(); this.change_language();
} }
Input.prototype.update_startcat_menu=function (grammar) {
var menu=this.startcat_menu;
menu.innerHTML="";
var cats=grammar.categories;
for(var cat in cats) menu.appendChild(option(cats[cat],cats[cat]))
if(grammar.startcat) menu.value=grammar.startcat;
else {
insertFirst(menu,option("Default",""));
menu.value="";
}
}
Input.prototype.change_language=function () { Input.prototype.change_language=function () {
this.current.from=this.from_menu.value; this.current.from=this.from_menu.value;
this.clear_all(); this.clear_all();
@@ -73,7 +91,8 @@ Input.prototype.get_completions=function() {
with(this) { with(this) {
//debug("get_completions "); //debug("get_completions ");
words.innerHTML="..."; words.innerHTML="...";
server.complete({from:current.from,input:current.input}, server.complete({from:current.from,input:current.input,
cat:startcat_menu.value},
bind(show_completions,this)); bind(show_completions,this));
} }
} }
@@ -83,7 +102,7 @@ Input.prototype.show_completions=function(complete_output) {
//debug("show_completions "); //debug("show_completions ");
var completions=complete_output[0].completions; var completions=complete_output[0].completions;
var emptycnt=add_completions(completions) var emptycnt=add_completions(completions)
if(true/*emptycnt>0*/) translations.translateFrom(current); if(true/*emptycnt>0*/) translations.translateFrom(current,startcat_menu.value);
else translations.clear(); else translations.clear();
if(surface.typed && emptycnt==completions.length) { if(surface.typed && emptycnt==completions.length) {
if(surface.typed.value=="") remove_typed_input(); if(surface.typed.value=="") remove_typed_input();
@@ -198,7 +217,7 @@ Input.prototype.generate_random=function() {
function lin_random(abs) { function lin_random(abs) {
t.server.linearize({tree:abs[0].tree,to:t.current.from},show_random); t.server.linearize({tree:abs[0].tree,to:t.current.from},show_random);
} }
t.server.get_random({},lin_random); t.server.get_random({cat:t.startcat_menu.value},lin_random);
} }
Input.prototype.add_words=function(s) { Input.prototype.add_words=function(s) {

View File

@@ -38,8 +38,9 @@ Translations.prototype.clear=function() {
this.main.innerHTML=""; this.main.innerHTML="";
} }
Translations.prototype.translateFrom=function(current) { Translations.prototype.translateFrom=function(current,startcat) {
this.current=current; this.current=current;
this.startcat=startcat;
this.get_translations(); this.get_translations();
} }
@@ -47,10 +48,10 @@ Translations.prototype.get_translations=function() {
with(this) { with(this) {
var c=current; var c=current;
if(options.show_grouped_translations) if(options.show_grouped_translations)
server.translategroup({from:c.from,input:c.input}, server.translategroup({from:c.from,input:c.input,cat:startcat},
bind(show_groupedtranslations,this)); bind(show_groupedtranslations,this));
else else
server.translate({from:c.from,input:c.input}, server.translate({from:c.from,input:c.input,cat:startcat},
bind(show_translations,this)); bind(show_translations,this));
} }
} }