Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update property list (language bar) #122

Merged
merged 1 commit into from
Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/IBusChewingEngine-input-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void ibus_chewing_engine_property_activate(IBusEngine * engine,
prop_state);
Self *self = SELF(engine);

if (STRING_EQUALS(prop_name, "InputMode")) {
if (STRING_EQUALS(prop_name, "chiEng_prop")) {
/* Toggle Chinese <-> English */
ibus_chewing_pre_edit_toggle_chi_eng_mode(self->icPreEdit);
IBUS_CHEWING_LOG(INFO,
Expand All @@ -92,11 +92,14 @@ void ibus_chewing_engine_property_activate(IBusEngine * engine,
}
}
self_refresh_property(self, prop_name);
} else if (STRING_EQUALS(prop_name, "chewing_alnumSize_prop")) {
} else if (STRING_EQUALS(prop_name, "alnumSize_prop")) {
/* Toggle Full <-> Half */
chewing_set_ShapeMode(self->icPreEdit->context,
!chewing_get_ShapeMode(self->icPreEdit->context));
self_refresh_property(self, prop_name);
} else if (STRING_EQUALS(prop_name, "setup_prop")) {
/* open preferences window */
system(QUOTE_ME(LIBEXEC_DIR) "/ibus-setup-chewing");
} else {
IBUS_CHEWING_LOG(DEBUG,
"property_activate(-, %s, %u) not recognized",
Expand Down
6 changes: 4 additions & 2 deletions src/IBusChewingEngine-signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ void ibus_chewing_engine_start(IBusChewingEngine * self)
if (!ibus_chewing_engine_has_status_flag
(self, ENGINE_FLAG_PROPERTIES_REGISTERED)) {
IBUS_ENGINE_GET_CLASS(self)->property_show(IBUS_ENGINE(self),
"InputMode");
"chiEng_prop");
IBUS_ENGINE_GET_CLASS(self)->property_show(IBUS_ENGINE(self),
"chewing_alnumSize_prop");
"alnumSize_prop");
IBUS_ENGINE_GET_CLASS(self)->property_show(IBUS_ENGINE(self),
"setup_prop");
ibus_engine_register_properties(IBUS_ENGINE(self), self->prop_list);
ibus_chewing_engine_set_status_flag(self,
ENGINE_FLAG_PROPERTIES_REGISTERED);
Expand Down
161 changes: 89 additions & 72 deletions src/IBusChewingEngine.gob
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,41 @@ class IBus:Chewing:Engine from IBus:Engine {

public IBusProperty *chieng_prop = {
g_object_ref_sink(ibus_property_new
("InputMode", PROP_TYPE_NORMAL,
("chiEng_prop",
PROP_TYPE_NORMAL,
SELF_GET_CLASS(self)->chieng_prop_label_chi,
NULL,
SELF_GET_CLASS(self)->chieng_prop_tooltip_chi,
TRUE, TRUE,
PROP_STATE_UNCHECKED, NULL))
SELF_GET_CLASS(self)->chieng_prop_tooltip,
TRUE,
TRUE,
PROP_STATE_UNCHECKED,
NULL))
} destroywith g_object_unref;

public IBusProperty *alnumSize_prop = {
g_object_ref_sink(ibus_property_new
("chewing_alnumSize_prop", PROP_TYPE_NORMAL,
SELF_GET_CLASS(self)->alnumSize_prop_label_half,
NULL, NULL, TRUE, TRUE,
PROP_STATE_UNCHECKED, NULL))
("alnumSize_prop",
PROP_TYPE_NORMAL,
SELF_GET_CLASS(self)->alnumSize_prop_label_half,
NULL,
SELF_GET_CLASS(self)->alnumSize_prop_tooltip,
TRUE,
TRUE,
PROP_STATE_UNCHECKED,
NULL))
} destroywith g_object_unref;

public IBusProperty *setup_prop = {
g_object_ref_sink(ibus_property_new
("setup_prop",
PROP_TYPE_NORMAL,
SELF_GET_CLASS(self)->setup_prop_label,
NULL,
SELF_GET_CLASS(self)->setup_prop_tooltip,
TRUE,
TRUE,
PROP_STATE_UNCHECKED,
NULL))
} destroywith g_object_unref;

public IBusPropList *prop_list = {
Expand All @@ -223,45 +244,50 @@ class IBus:Chewing:Engine from IBus:Engine {
} destroywith XCloseDisplay;

classwide IBusText *chieng_prop_label_chi = {
g_object_ref_sink(ibus_text_new_from_static_string(_("Chi")))
g_object_ref_sink(ibus_text_new_from_static_string(_("Chinese Mode")))
};
classwide IBusText *chieng_prop_label_eng = {
g_object_ref_sink(ibus_text_new_from_static_string(_("Eng")))
};
classwide IBusText *chieng_prop_tooltip_chi = {
g_object_ref_sink(ibus_text_new_from_static_string
(_("Click to switch to English")))
g_object_ref_sink(ibus_text_new_from_static_string(_("Alphanumeric Mode")))
};
classwide IBusText *chieng_prop_tooltip_eng = {
classwide IBusText *chieng_prop_tooltip = {
g_object_ref_sink(ibus_text_new_from_static_string
(_("Click to switch to Chinese")))
(_("Click to toggle Chinese/Alphanumeric Mode")))
};
classwide IBusText *chieng_prop_symbol_chi = {
g_object_ref_sink(ibus_text_new_from_static_string("中"))
};
classwide IBusText *chieng_prop_symbol_eng = {
g_object_ref_sink(ibus_text_new_from_static_string("英"))
};

classwide IBusText *alnumSize_prop_label_full = {
g_object_ref_sink(ibus_text_new_from_static_string(_("Full")))
g_object_ref_sink(ibus_text_new_from_static_string(_("Fullwidth Form")))
};
classwide IBusText *alnumSize_prop_label_half = {
g_object_ref_sink(ibus_text_new_from_static_string(_("Half")))
g_object_ref_sink(ibus_text_new_from_static_string(_("Halfwidth Form")))
};
classwide IBusText *alnumSize_prop_tooltip_full = {
classwide IBusText *alnumSize_prop_tooltip = {
g_object_ref_sink(ibus_text_new_from_static_string
(_("Click to switch to Half")))
};
classwide IBusText *alnumSize_prop_tooltip_half = {
g_object_ref_sink(ibus_text_new_from_static_string
(_("Click to switch to Full")))
(_("Click to toggle Halfwidth/Fullwidth Form")))
};
classwide IBusText *alnumSize_prop_symbol_full = {
g_object_ref_sink(ibus_text_new_from_static_string("全"))
};
classwide IBusText *alnumSize_prop_symbol_half = {
g_object_ref_sink(ibus_text_new_from_static_string("半"))
};

classwide IBusText *setup_prop_label = {
g_object_ref_sink(ibus_text_new_from_static_string(_("Chewing Preferences")))
};
classwide IBusText *setup_prop_tooltip = {
g_object_ref_sink(ibus_text_new_from_static_string
(_("Click to configure IBus-Chewing")))
};
classwide IBusText *setup_prop_symbol = {
g_object_ref_sink(ibus_text_new_from_static_string("訂"))
};

classwide IBusText *emptyText = {
g_object_ref_sink(ibus_text_new_from_static_string(""))
};
Expand Down Expand Up @@ -314,6 +340,7 @@ class IBus:Chewing:Engine from IBus:Engine {
/* init properties */
ibus_prop_list_append(self->prop_list, self->chieng_prop);
ibus_prop_list_append(self->prop_list, self->alnumSize_prop);
ibus_prop_list_append(self->prop_list, self->setup_prop);

ibus_chewing_engine_set_status_flag(self, ENGINE_FLAG_INITIALIZED);

Expand Down Expand Up @@ -368,9 +395,9 @@ class IBus:Chewing:Engine from IBus:Engine {
}
} else if (ibus_chewing_pre_edit_has_flag(self->icPreEdit, FLAG_SYNC_FROM_KEYBOARD)) {
IBUS_CHEWING_LOG(DEBUG, "restore_mode() FLAG_SYNC_FROM_KEYBOARD");
chewing_set_ChiEngMode(self->icPreEdit->context, (is_caps_lock(self))? 0: CHINESE_MODE);
chewing_set_ChiEngMode(self->icPreEdit->context, (is_caps_lock(self)) ? 0 : CHINESE_MODE);
}
self_refresh_property(self, "InputMode");
self_refresh_property(self, "chiEng_prop");
}
}

Expand All @@ -396,58 +423,45 @@ class IBus:Chewing:Engine from IBus:Engine {
ibus_chewing_systray_chi_eng_icon_refresh_value(self);
}

if (STRING_EQUALS(prop_name, "InputMode")) {
if (STRING_EQUALS(prop_name, "chiEng_prop")) {

ibus_property_set_label(self->chieng_prop,
ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit) ?
SELF_GET_CLASS(self)->chieng_prop_label_chi :
SELF_GET_CLASS(self)->chieng_prop_label_eng);

if (ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit)) {
/* Chinese */
ibus_property_set_label(self->chieng_prop,
SELF_GET_CLASS(self)->chieng_prop_label_chi);
ibus_property_set_tooltip(self->chieng_prop,
SELF_GET_CLASS(self)->chieng_prop_tooltip_chi);
#if IBUS_CHECK_VERSION(1, 5, 0)
ibus_property_set_symbol(self->chieng_prop,
SELF_GET_CLASS(self)->chieng_prop_symbol_chi);
#endif
} else {
/* English */
ibus_property_set_label(self->chieng_prop,
SELF_GET_CLASS(self)->chieng_prop_label_eng);
ibus_property_set_tooltip(self->chieng_prop,
SELF_GET_CLASS(self)->chieng_prop_tooltip_eng);
#if IBUS_CHECK_VERSION(1, 5, 0)
ibus_property_set_symbol(self->chieng_prop,
SELF_GET_CLASS(self)->chieng_prop_symbol_eng);
ibus_property_set_symbol(self->chieng_prop,
ibus_chewing_pre_edit_get_chi_eng_mode(self->icPreEdit) ?
SELF_GET_CLASS(self)->chieng_prop_symbol_chi :
SELF_GET_CLASS(self)->chieng_prop_symbol_eng);
#endif
}

ibus_engine_update_property(IBUS_ENGINE(self), self->chieng_prop);

} else if (STRING_EQUALS(prop_name, "chewing_alnumSize_prop")) {
} else if (STRING_EQUALS(prop_name, "alnumSize_prop")) {

ibus_property_set_label(self->alnumSize_prop,
chewing_get_ShapeMode(self->icPreEdit->context) ?
SELF_GET_CLASS(self)->alnumSize_prop_label_full :
SELF_GET_CLASS(self)->alnumSize_prop_label_half);

if (chewing_get_ShapeMode(self->icPreEdit->context)) {
/* Full-Sized Shape */
ibus_property_set_label(self->alnumSize_prop,
SELF_GET_CLASS(self)->alnumSize_prop_label_full);
ibus_property_set_tooltip(self->alnumSize_prop,
SELF_GET_CLASS(self)->alnumSize_prop_tooltip_full);
#if IBUS_CHECK_VERSION(1, 5, 0)
ibus_property_set_symbol(self->alnumSize_prop,
SELF_GET_CLASS(self)->alnumSize_prop_symbol_full);
#endif
} else {
/* Half-Sized Shape */
ibus_property_set_label(self->alnumSize_prop,
SELF_GET_CLASS(self)->alnumSize_prop_label_half);
ibus_property_set_tooltip(self->alnumSize_prop,
SELF_GET_CLASS(self)->alnumSize_prop_tooltip_half);
#if IBUS_CHECK_VERSION(1, 5, 0)
ibus_property_set_symbol(self->alnumSize_prop,
SELF_GET_CLASS(self)->alnumSize_prop_symbol_half);
ibus_property_set_symbol(self->alnumSize_prop,
chewing_get_ShapeMode(self->icPreEdit->context) ?
SELF_GET_CLASS(self)->alnumSize_prop_symbol_full :
SELF_GET_CLASS(self)->alnumSize_prop_symbol_half);
#endif
}

if (self->_priv->statusFlags & ENGINE_FLAG_PROPERTIES_REGISTERED)
ibus_engine_update_property(IBUS_ENGINE(self),self->alnumSize_prop);
ibus_engine_update_property(IBUS_ENGINE(self), self->alnumSize_prop);

} else if (STRING_EQUALS(prop_name, "setup_prop")) {
#if IBUS_CHECK_VERSION(1, 5, 0)
ibus_property_set_symbol(self->setup_prop,
SELF_GET_CLASS(self)->setup_prop_symbol);
#endif
ibus_engine_update_property(IBUS_ENGINE(self), self->setup_prop);
}
#endif
}
Expand All @@ -460,8 +474,9 @@ class IBus:Chewing:Engine from IBus:Engine {
*/
public void refresh_property_list(self) {
#ifndef UNIT_TEST
self_refresh_property(self, "InputMode");
self_refresh_property(self, "chewing_alnumSize_prop");
self_refresh_property(self, "chiEng_prop");
self_refresh_property(self, "alnumSize_prop");
self_refresh_property(self, "setup_prop");
#endif
}

Expand All @@ -474,15 +489,17 @@ class IBus:Chewing:Engine from IBus:Engine {
public void hide_property_list(self) {
#ifndef UNIT_TEST
IBUS_ENGINE_GET_CLASS(self)->property_hide(IBUS_ENGINE(self),
"chewing_alnumSize_prop");
"alnumSize_prop");
#endif
}

private IBusProperty *get_ibus_property_by_name(self, const gchar * prop_name) {
if (STRING_EQUALS(prop_name, "InputMode")) {
if (STRING_EQUALS(prop_name, "chiEng_prop")) {
return self->chieng_prop;
} else if (STRING_EQUALS(prop_name, "chewing_alnumSize_prop")) {
} else if (STRING_EQUALS(prop_name, "alnumSize_prop")) {
return self->alnumSize_prop;
} else if (STRING_EQUALS(prop_name, "setup_prop")) {
return self->setup_prop;
}
IBUS_CHEWING_LOG(MSG, "get_ibus_property_by_name(%s): NULL is returned", prop_name);
return NULL;
Expand Down
2 changes: 2 additions & 0 deletions src/IBusChewingSystray.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ void ibus_chewing_systray_chi_eng_toggle_callback(IBusChewingSystrayIcon *

ibus_chewing_pre_edit_toggle_chi_eng_mode(iEngine->icPreEdit);
ibus_chewing_systray_chi_eng_icon_refresh_value(iEngine);
ibus_chewing_engine_refresh_property_list(iEngine);
}

/**
Expand All @@ -139,6 +140,7 @@ void ibus_chewing_systray_full_half_toggle_callback(IBusChewingSystrayIcon

ibus_chewing_pre_edit_toggle_full_half_mode(iEngine->icPreEdit);
ibus_chewing_systray_chi_eng_icon_refresh_value(iEngine);
ibus_chewing_engine_refresh_property_list(iEngine);
}

IBusChewingSystrayIcon
Expand Down