mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
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:
@@ -167,11 +167,14 @@ Some implementation details:
|
||||
matching completions.
|
||||
(You can now use names of people when constructing sentences in the Letter
|
||||
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>
|
||||
|
||||
<hr>
|
||||
<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>
|
||||
<address>
|
||||
<a href="http://www.cs.chalmers.se/~hallgren/">TH</a>
|
||||
|
||||
@@ -90,6 +90,7 @@ full API.
|
||||
<dt>http://localhost:41296/grammars/Foods.pgf
|
||||
<dd>{"name":"Foods",
|
||||
"userLanguage":"FoodsEng",
|
||||
"startcat":"Comment",
|
||||
"categories":["Comment","Float","Int","Item","Kind","Quality","String"],
|
||||
"functions":["Boring","Cheese","Delicious","Expensive","Fish","Fresh",
|
||||
"Italian","Mod","Pizza","Pred","That","These","This","Those","Very",
|
||||
@@ -145,7 +146,7 @@ full API.
|
||||
</dl>
|
||||
<hr>
|
||||
<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>
|
||||
<address><a href="http://www.cse.chalmers.se/~hallgren/">TH</a></address>
|
||||
|
||||
@@ -9,6 +9,7 @@ function Input(server,translations,opts) { // Input object constructor
|
||||
this.options={
|
||||
delete_button_text: "⌫",
|
||||
default_source_language: null,
|
||||
startcat_menu: true,
|
||||
random_button: true,
|
||||
}
|
||||
|
||||
@@ -22,9 +23,12 @@ function Input(server,translations,opts) { // Input object constructor
|
||||
this.surface=div_id("surface");
|
||||
this.words=div_id("words");
|
||||
this.from_menu=empty("select");
|
||||
this.startcat_menu=empty("select")
|
||||
|
||||
with(this) {
|
||||
appendChildren(main,[surface,words]);
|
||||
if(options.startcat_menu)
|
||||
appendChildren(menus,[text(" Startcat: "),startcat_menu])
|
||||
appendChildren(menus,[text(" From: "),from_menu])
|
||||
appendChildren(buttons,
|
||||
[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.from_menu.onchange=bind(this.change_language,this);
|
||||
this.startcat_menu.onchange=bind(this.clear_all,this);
|
||||
}
|
||||
|
||||
Input.prototype.change_grammar=function (grammar) {
|
||||
update_language_menu(this.from_menu,grammar);
|
||||
set_initial_language(this.options,this.from_menu,grammar);
|
||||
this.update_startcat_menu(grammar)
|
||||
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 () {
|
||||
this.current.from=this.from_menu.value;
|
||||
this.clear_all();
|
||||
@@ -73,7 +91,8 @@ Input.prototype.get_completions=function() {
|
||||
with(this) {
|
||||
//debug("get_completions ");
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -83,7 +102,7 @@ Input.prototype.show_completions=function(complete_output) {
|
||||
//debug("show_completions ");
|
||||
var completions=complete_output[0].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();
|
||||
if(surface.typed && emptycnt==completions.length) {
|
||||
if(surface.typed.value=="") remove_typed_input();
|
||||
@@ -198,7 +217,7 @@ Input.prototype.generate_random=function() {
|
||||
function lin_random(abs) {
|
||||
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) {
|
||||
|
||||
@@ -38,8 +38,9 @@ Translations.prototype.clear=function() {
|
||||
this.main.innerHTML="";
|
||||
}
|
||||
|
||||
Translations.prototype.translateFrom=function(current) {
|
||||
Translations.prototype.translateFrom=function(current,startcat) {
|
||||
this.current=current;
|
||||
this.startcat=startcat;
|
||||
this.get_translations();
|
||||
}
|
||||
|
||||
@@ -47,10 +48,10 @@ Translations.prototype.get_translations=function() {
|
||||
with(this) {
|
||||
var c=current;
|
||||
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));
|
||||
else
|
||||
server.translate({from:c.from,input:c.input},
|
||||
server.translate({from:c.from,input:c.input,cat:startcat},
|
||||
bind(show_translations,this));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user