Skip to content

Commit

Permalink
Restore lookup table after dict edit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ueno committed Dec 22, 2011
1 parent 2415a0c commit 81f981c
Showing 1 changed file with 46 additions and 28 deletions.
74 changes: 46 additions & 28 deletions src/engine.vala
Expand Up @@ -125,7 +125,6 @@ class SkkEngine : IBus.Engine {
} }
}); });


var empty_text = new IBus.Text.from_static_string ("");
context.notify["preedit"].connect (() => { context.notify["preedit"].connect (() => {
var text = new IBus.Text.from_string (context.preedit); var text = new IBus.Text.from_string (context.preedit);
text.append_attribute (IBus.AttrType.UNDERLINE, text.append_attribute (IBus.AttrType.UNDERLINE,
Expand All @@ -136,40 +135,59 @@ class SkkEngine : IBus.Engine {
text.get_length (), text.get_length (),
text.get_length () > 0); text.get_length () > 0);
}); });
context.candidates.notify["cursor-pos"].connect (() => { context.notify["candidates"].connect ((s, p) => {
if (context.candidates.cursor_pos >= pagination_start) { update_candidates ();
lookup_table.set_cursor_pos (
context.candidates.cursor_pos - pagination_start);
update_lookup_table (lookup_table, true);
var candidate = context.candidates.get ();
if (show_annotation && candidate.annotation != null) {
var text = new IBus.Text.from_string (
candidate.annotation);
update_auxiliary_text (text, true);
} else {
update_auxiliary_text (empty_text, false);
}
} else {
update_lookup_table (lookup_table, false);
update_auxiliary_text (empty_text, false);
}
});
context.candidates.populated.connect (() => {
lookup_table.clear ();
for (var i = pagination_start;
i < context.candidates.size;
i++) {
var text = new IBus.Text.from_string (
context.candidates[i].output);
lookup_table.append_candidate (text);
}
}); });
context.notify["input-mode"].connect ((s, p) => { context.notify["input-mode"].connect ((s, p) => {
update_input_mode (); update_input_mode ();
}); });
update_candidates ();
update_input_mode (); update_input_mode ();
} }


void populate_lookup_table () {
lookup_table.clear ();
for (var i = pagination_start;
i < context.candidates.size;
i++) {
var text = new IBus.Text.from_string (
context.candidates[i].output);
lookup_table.append_candidate (text);
}
}

void set_lookup_table_cursor_pos () {
var empty_text = new IBus.Text.from_static_string ("");
var cursor_pos = context.candidates.cursor_pos - pagination_start;
if (cursor_pos >= 0 &&
cursor_pos < lookup_table.get_number_of_candidates ()) {
lookup_table.set_cursor_pos (cursor_pos);
update_lookup_table (lookup_table, true);
var candidate = context.candidates.get ();
if (show_annotation && candidate.annotation != null) {
var text = new IBus.Text.from_string (
candidate.annotation);
update_auxiliary_text (text, true);
} else {
update_auxiliary_text (empty_text, false);
}
} else {
update_lookup_table (lookup_table, false);
update_auxiliary_text (empty_text, false);
}
}

void update_candidates () {
context.candidates.populated.connect (() => {
populate_lookup_table ();
});
context.candidates.notify["cursor-pos"].connect (() => {
set_lookup_table_cursor_pos ();
});
populate_lookup_table ();
set_lookup_table_cursor_pos ();
}

void update_input_mode () { void update_input_mode () {
// update the state of menu item // update the state of menu item
var _prop = input_mode_props.get (context.input_mode); var _prop = input_mode_props.get (context.input_mode);
Expand Down

0 comments on commit 81f981c

Please sign in to comment.