diff options
author | Peng Wu <alexepico@gmail.com> | 2010-05-10 15:56:32 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2010-05-19 10:09:33 +0800 |
commit | cedc8d5c6968deae7936a59a608184d91edd5121 (patch) | |
tree | 03f91ab9400c3c88b4bf8f4bcf95cf3f535fd1be /src | |
parent | 2f0cb527ea398e0ee8debe86231fd20a0e12d30f (diff) | |
download | ibus-pinyin-cedc8d5c6968deae7936a59a608184d91edd5121.tar.gz |
begin to implement input logic for ibus-pinyin lua module.
Diffstat (limited to 'src')
-rw-r--r-- | src/ExtEditor.cc | 61 | ||||
-rw-r--r-- | src/ExtEditor.h | 2 |
2 files changed, 57 insertions, 6 deletions
diff --git a/src/ExtEditor.cc b/src/ExtEditor.cc index b1a4b21..4bd3933 100644 --- a/src/ExtEditor.cc +++ b/src/ExtEditor.cc @@ -7,7 +7,8 @@ namespace PY { */ ExtEditor::ExtEditor (PinyinProperties & props) - : Editor (props) + : Editor (props), + m_mode(LABEL_NONE) { m_lua_plugin = ibus_engine_plugin_new(); @@ -44,15 +45,63 @@ ExtEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers) if ( modifiers ) return FALSE; + //handle backspace here. + //handle page/cursor up/down here. + //handle label key select here. + /* Remember the input string. */ - switch (keyval){ - case IBUS_a ... IBUS_z: + switch(m_input.length()){ + case 0: //Empty input string. + { + g_return_val_if_fail( 'i' == keyval, FALSE); + if ( 'i' == keyval ) + m_input += keyval; + //move to updateStateFromInput. + m_mode = LABEL_NONE; + } + break; + case 1 ... 2: // Only contains 'i' in input string. + { + g_return_val_if_fail( 'i' == m_input[0], FALSE); + if ( isalnum(keyval) ) + m_input += keyval; + //move to updateStateFromInput. + if ( isalpha(m_input[1])) + m_mode = LABEL_LIST_COMMANDS; + else if ( isdigit(m_input[1]) ){ + m_mode = LABEL_LIST_NUMBERS; + } + } break; - case IBUS_0 ... IBUS_9: - case IBUS_KP_0 ... IBUS_KP_9: + default: //Here is the appended argment. + { + g_return_val_if_fail( 'i' == m_input[0], FALSE); + if (isprint(keyval)) + m_input += keyval; + + //move to updateStateFromInput. + if ( isalpha(m_input[1])) { + std::string command_name = m_input.substr(1,2); + + const lua_command_t * command = ibus_engine_plugin_lookup_command(m_lua_plugin, command_name.c_str()); + if ( NULL == command) + return FALSE; + + std::string label = command->leading; + + if ( "digit" == label ) + m_mode = LABEL_LIST_DIGIT; + else if ( "alpha" == label ) + m_mode = LABEL_LIST_ALPHA; + else + m_mode = LABEL_LIST_NONE; + }else if ( isdigit(m_input[1])) { + //Generate Chinese number in updateStateFromInput. + g_assert(LABEL_LIST_NUMBERS == m_mode); + } + } break; } - /* Deal other staff with updateStateFromInput(). */ updateStateFromInput(); return FALSE; diff --git a/src/ExtEditor.h b/src/ExtEditor.h index 030efdd..91711ef 100644 --- a/src/ExtEditor.h +++ b/src/ExtEditor.h @@ -16,6 +16,7 @@ namespace PY { enum ExtEditorLabelMode{ LABEL_NONE, + LABEL_LIST_NUMBERS, LABEL_LIST_COMMANDS, LABEL_LIST_NONE, LABEL_LIST_DIGIT, @@ -54,6 +55,7 @@ private: void updatePreeditText(); void updateAuxiliaryText(); + ExtEditorLabelMode m_mode; Pointer<IBusEnginePlugin> m_lua_plugin; std::string m_input; |