Skip to content

Commit

Permalink
Display page number of the lookup table (#148)
Browse files Browse the repository at this point in the history
* Use auxtext to display page numbers of lookup tabel.
 * Add an option. Default = Disabled.
  • Loading branch information
hiunnhue authored Sep 18, 2020
1 parent 70a1935 commit c1e7f0d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/IBusChewingApplier.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ gboolean
return TRUE;
}

gboolean showPageNumber_apply_callback(PropertyContext * ctx, gpointer userData)
{
/* Use MkdgProperty directly, no need to call IBusChewingEngine */
return TRUE;
}

gboolean
phraseChoiceRearward_apply_callback
(PropertyContext * ctx, gpointer userData) {
Expand Down
9 changes: 9 additions & 0 deletions src/IBusChewingEngine-signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ void refresh_aux_text(IBusChewingEngine * self)
/* Make auxText (text to be displayed in auxiliary candidate window).
* Use auxText to show messages from libchewing, such as "已有:".
*/

gboolean showPageNumber =
ibus_chewing_pre_edit_get_property_boolean(self->icPreEdit,
"show-page-number");

if (chewing_aux_Length(self->icPreEdit->context) > 0) {
IBUS_CHEWING_LOG(INFO, "update_aux_text() chewing_aux_Length=%x",
chewing_aux_Length(self->icPreEdit->context));
Expand All @@ -282,6 +287,10 @@ void refresh_aux_text(IBusChewingEngine * self)
IBUS_CHEWING_LOG(INFO, "update_aux_text() auxStr=%s", auxStr);
self->auxText = g_object_ref_sink(ibus_text_new_from_string(auxStr));
g_free(auxStr);
} else if (showPageNumber && (chewing_cand_TotalPage(self->icPreEdit->context) > 0)) {
int TotalPage = chewing_cand_TotalPage(self->icPreEdit->context);
int currentPage = chewing_cand_CurrentPage(self->icPreEdit->context) + 1;
self->auxText = g_object_ref_sink(ibus_text_new_from_printf("(%i/%i)", currentPage, TotalPage));
} else {
/* clear out auxText, otherwise it will be displayed continually. */
self->auxText = g_object_ref_sink(ibus_text_new_from_static_string(""));
Expand Down
10 changes: 9 additions & 1 deletion src/IBusChewingProperties.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,19 @@ MkdgPropertySpec propSpecs[] = {
{
G_TYPE_UINT, "cand-per-page", PAGE_SELECTING,
N_("Candidate per page"),
IBUS_CHEWING_PROPERTIES_SUBSECTION, "10", NULL, NULL, 8, 10,
IBUS_CHEWING_PROPERTIES_SUBSECTION, "5", NULL, NULL, 4, 10,
candPerPage_apply_callback, 0,
N_("Number of candidate per page."),
NULL}
,
{
G_TYPE_BOOLEAN, "show-page-number", PAGE_SELECTING,
N_("Show page number"),
IBUS_CHEWING_PROPERTIES_SUBSECTION, "0", NULL, NULL, 0, 1,
showPageNumber_apply_callback, 0,
N_("Display the page number of the candidate list."),
NULL}
,
{
G_TYPE_BOOLEAN, "phrase-choice-from-last", PAGE_SELECTING,
N_("Choose phrases from backward"),
Expand Down
3 changes: 3 additions & 0 deletions src/IBusChewingProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ gboolean capslockToggleChinese_apply_callback(PropertyContext * ctx,
gboolean phraseChoiceRearward_apply_callback(PropertyContext * ctx,
gpointer userData);

gboolean showPageNumber_apply_callback(PropertyContext * ctx,
gpointer userData);

gboolean spaceAsSelection_apply_callback(PropertyContext * ctx,
gpointer userData);

Expand Down

0 comments on commit c1e7f0d

Please sign in to comment.