Skip to content

Commit

Permalink
Merge pull request #26 from omicronlab/feature/dictionary-support
Browse files Browse the repository at this point in the history
Feature/dictionary support
  • Loading branch information
sarim committed Jul 7, 2012
2 parents 9cbd6ef + e799f19 commit 83095ee
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 124 deletions.
2 changes: 0 additions & 2 deletions autocorrect.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ var db =
":-S": ":-S",
":-SS": ":-SS",
":-t": ":-t",
":\ufb01": ":\ufb01",
":-\ufb01": ":-\ufb01",
":u": ":u",
":-w": ":-w",
":x": ":x",
Expand Down
42 changes: 36 additions & 6 deletions avropref.ui
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</packing>
</child>
<child>
<object class="GtkSwitch" id="switch_auxtxt">
<object class="GtkSwitch" id="switch_preview">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
Expand All @@ -79,7 +79,7 @@
</packing>
</child>
<child>
<object class="GtkSwitch" id="switch_lutable">
<object class="GtkSwitch" id="switch_dict">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
Expand All @@ -92,6 +92,36 @@
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">Commit newline on Enter/Return key:</property>
<property name="justify">right</property>
<property name="width_chars">25</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="switch_newline">
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="use_action_appearance">False</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
Expand All @@ -101,7 +131,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
Expand All @@ -120,7 +150,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
Expand All @@ -134,7 +164,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
Expand All @@ -152,7 +182,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
Expand Down
14 changes: 1 addition & 13 deletions avroregexlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,9 @@ AvroRegex.prototype = {
},
{
"find":"a",
"replace":"(([অএ]্যা?)|[অআএ]|([‍‌]?(্য)?া)|(য়া))?",
"replace":"(([অএ]্যা?)|[অআএ]|([‍‌]?(্য)?া)|(য়া))",
"rules":
[
{
"matches":
[
{
"type":"prefix",
"scope":"punctuation",
"value":"",
"negative":"FALSE"
}
],
"replace":"(([অএ]্যা?)|[অআএ]|([‍‌]?(্য)?া)|(য়া))"
}
]
},
{
Expand Down
19 changes: 12 additions & 7 deletions com.omicronlab.avro.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="com.omicronlab.avro" path="/com/omicronlab/avro/">
<key type="b" name="switch-auxtxt">
<key type="b" name="switch-preview">
<default>true</default>
<summary>switch-auxtxt</summary>
<description>Whether Auxiliary (English) Text will be shown</description>
<summary>switch-preview</summary>
<description>Whether Preview window (auxiliary text, suggestions) will be shown</description>
</key>
<key type="b" name="switch-lutable">
<key type="b" name="switch-dict">
<default>true</default>
<summary>switch-lutable</summary>
<description>Whether Dictionary Suggestion will be shown</description>
<summary>switch-dict</summary>
<description>Whether dictionary suggestions will be shown</description>
</key>
<key type="b" name="switch-newline">
<default>false</default>
<summary>switch-newline</summary>
<description>Whether enter key should commit newline after applying candidate</description>
</key>
<key type="i" name="lutable-size">
<default>16</default>
<summary>lutable-size</summary>
<description>Dictionary Suggestion Lookup Table Size</description>
<description>Dictionary suggestion lookup table size</description>
</key>
<key type="i" name="cboxorient">
<default>0</default>
Expand Down
30 changes: 0 additions & 30 deletions dbsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,36 +119,6 @@ DBSearch.prototype = {
case 'z':
tableList = ["h", "j", "jh", "z"];
break;
case '1':
tableList = ["e"];
break;
case '2':
tableList = ["d"];
break;
case '3':
tableList = ["t"];
break;
case '4':
tableList = ["c"];
break;
case '5':
tableList = ["p"];
break;
case '6':
tableList = ["ch"];
break;
case '7':
tableList = ["s"];
break;
case '8':
tableList = ["aa"];
break;
case '9':
tableList = ["n"];
break;
case '0':
tableList = ["sh"];
break;
default:
break;
}
Expand Down
61 changes: 42 additions & 19 deletions main-gjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ if (bus.is_connected()) {

} else if (keyval == IBus.Return || keyval == IBus.space || keyval == IBus.Tab) {
if (engine.buffertext.length > 0){
if (keyval == IBus.Return && engine.buffertext.length > 0 && engine.currentSuggestions.length > 1){
if (keyval == IBus.Return && engine.buffertext.length > 0 && engine.currentSuggestions.length > 1 && (!engine.setting_switch_newline)){
commitCandidate(engine);
return true;
} else {
Expand Down Expand Up @@ -225,18 +225,31 @@ if (bus.is_connected()) {
engine.setting = Gio.Settings.new("com.omicronlab.avro");

//set up a asynchronous callback for instant change later
engine.setting.connect('changed',function(){readSetting(engine);});
engine.setting.connect('changed',
function(){
readSetting(engine);
});

//read manually first time
readSetting(engine);
}


function readSetting(engine){
engine.setting_switch_auxtxt = engine.setting.get_boolean('switch-auxtxt');
engine.setting_switch_lutable = engine.setting.get_boolean('switch-lutable');
engine.setting_switch_preview = engine.setting.get_boolean('switch-preview');
engine.setting_switch_dict = engine.setting.get_boolean('switch-dict');
engine.setting_switch_newline = engine.setting.get_boolean('switch-newline');
engine.lookuptable.set_orientation(engine.setting.get_int('cboxorient'));
engine.lookuptable.set_page_size(engine.setting.get_int('lutable-size'));
engine.setting_lutable_size = engine.setting.get_int('lutable-size');
engine.lookuptable.set_page_size(engine.setting_lutable_size);

if (!engine.setting_switch_preview){
engine.setting_switch_dict = false;
}

var dictPref = suggestionBuilder.getPref();
dictPref.dictEnable = engine.setting_switch_dict;
suggestionBuilder.setPref(dictPref);
}


Expand All @@ -254,34 +267,43 @@ if (bus.is_connected()) {

function updateCurrentSuggestions(engine){
var suggestion = suggestionBuilder.suggest(engine.buffertext);
engine.currentSuggestions = suggestion['words'].slice(0);
engine.currentSuggestions = suggestion['words'].slice(0, engine.setting_lutable_size);
engine.currentSelection = suggestion['prevSelection'];

fillLookupTable (engine);
}


function fillLookupTable (engine){
var auxiliaryText = IBus.Text.new_from_string(engine.buffertext);
if (engine.setting_switch_auxtxt)
engine.update_auxiliary_text(auxiliaryText, true);
engine.lookuptable.clear();

engine.currentSuggestions.forEach(function(word){
let wtext = IBus.Text.new_from_string(word);
//default, ibus sets "1,2,3,4...." as label, i didn't find how to hide it,but a empty string can partially hide it
let wlabel = IBus.Text.new_from_string('');;
engine.lookuptable.append_candidate(wtext);
engine.lookuptable.append_label(wlabel);
});
if (engine.setting_switch_preview){
var auxiliaryText = IBus.Text.new_from_string(engine.buffertext);
engine.update_auxiliary_text(auxiliaryText, true);

if (engine.setting_switch_dict){
engine.lookuptable.clear();

engine.currentSuggestions.forEach(function(word){
let wtext = IBus.Text.new_from_string(word);
//default, ibus sets "1,2,3,4...." as label, i didn't find how to hide it,but a empty string can partially hide it
let wlabel = IBus.Text.new_from_string('');;
engine.lookuptable.append_candidate(wtext);
engine.lookuptable.append_label(wlabel);
});
}
}

preeditCandidate(engine);
}


function preeditCandidate(engine){
engine.lookuptable.set_cursor_pos(engine.currentSelection);
engine.update_lookup_table_fast(engine.lookuptable,true);
if (engine.setting_switch_preview){
if (engine.setting_switch_dict){
engine.lookuptable.set_cursor_pos(engine.currentSelection);
engine.update_lookup_table_fast(engine.lookuptable,true);
}
}

var preeditText = IBus.Text.new_from_string(engine.currentSuggestions[engine.currentSelection]);
engine.update_preedit_text(preeditText, engine.currentSuggestions[engine.currentSelection].length, true);
Expand Down Expand Up @@ -387,6 +409,7 @@ if (bus.is_connected()) {
}

component.add_engine(avroenginedesc);

if (exec_by_ibus) {
bus.request_name("org.freedesktop.IBus.Avro", 0);
} else {
Expand Down
21 changes: 17 additions & 4 deletions pref.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,27 @@ function runpref() {
builder.add_from_file(eevars.get_pkgdatadir() + "/avropref.ui");

let prefwindow = builder.get_object("window1");
let switch_auxtxt = builder.get_object("switch_auxtxt");
let switch_lutable = builder.get_object("switch_lutable");
let switch_preview = builder.get_object("switch_preview");
let switch_dict = builder.get_object("switch_dict");
let switch_newline = builder.get_object("switch_newline");
let lutable_size = builder.get_object("lutable_size");
let cboxorient = builder.get_object("cboxorient");

switch_preview.connect("notify::active", function(widget, data){
if (!switch_preview.get_active()){
switch_dict.set_active(false);
}
});

//Initialize after loading
if (!switch_preview.get_active()){
switch_dict.set_active(false);
}

let setting = Gio.Settings.new("com.omicronlab.avro")
setting.bind("switch-auxtxt", switch_auxtxt, "active", Gio.SettingsBindFlags.DEFAULT)
setting.bind("switch-lutable", switch_lutable, "active", Gio.SettingsBindFlags.DEFAULT)
setting.bind("switch-preview", switch_preview, "active", Gio.SettingsBindFlags.DEFAULT)
setting.bind("switch-dict", switch_dict, "active", Gio.SettingsBindFlags.DEFAULT)
setting.bind("switch-newline", switch_newline, "active", Gio.SettingsBindFlags.DEFAULT)
setting.bind("lutable-size", lutable_size, "value", Gio.SettingsBindFlags.DEFAULT)
setting.bind("cboxorient", cboxorient, "active", Gio.SettingsBindFlags.DEFAULT)

Expand Down
Loading

0 comments on commit 83095ee

Please sign in to comment.