diff options
| author | Peng Wu <alexepico@gmail.com> | 2010-05-11 19:03:11 +0800 |
|---|---|---|
| committer | Peng Wu <alexepico@gmail.com> | 2010-05-19 10:09:33 +0800 |
| commit | 539d0d0bb455ebc79477a4adc3c51520c95beec0 (patch) | |
| tree | 6157829affc38c9d2d673a8104b6a19eb92faf57 /src/ExtEditor.cc | |
| parent | 4a56a37823f7cf93a89f9fea0afedcdbe3ce69d1 (diff) | |
| download | ibus-libpinyin-539d0d0bb455ebc79477a4adc3c51520c95beec0.tar.gz ibus-libpinyin-539d0d0bb455ebc79477a4adc3c51520c95beec0.tar.xz ibus-libpinyin-539d0d0bb455ebc79477a4adc3c51520c95beec0.zip | |
refact code into updateStateFromInput and fixes compiling errors.
Diffstat (limited to 'src/ExtEditor.cc')
| -rw-r--r-- | src/ExtEditor.cc | 83 |
1 files changed, 51 insertions, 32 deletions
diff --git a/src/ExtEditor.cc b/src/ExtEditor.cc index d849c9a..97b3e7e 100644 --- a/src/ExtEditor.cc +++ b/src/ExtEditor.cc @@ -58,56 +58,27 @@ ExtEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers) { g_return_val_if_fail( 'i' == keyval, FALSE); if ( 'i' == keyval ) { - m_input.insert(m_cursor_pos, keyval); + m_input.insert(m_cursor_pos, 1, keyval); m_cursor_pos++; } - //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.insert(m_cursor_pos, keyval); + m_input.insert(m_cursor_pos, 1, keyval); m_cursor_pos++; } - //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; default: //Here is the appended argment. { g_return_val_if_fail( 'i' == m_input[0], FALSE); if (isprint(keyval)){ - m_input.insert(m_cursor_pos, keyval); + m_input.insert(m_cursor_pos, 1, keyval); m_cursor_pos++; } - - //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; } @@ -156,6 +127,18 @@ ExtEditor::updateStateFromInput() { /* Do parse and candidates update here. */ /* prefix i double check here. */ + if ( !m_input.length() ) + return false; + if ( ! 'i' == m_input[0] ){ + g_warning("i is expected in m_input string.\n"); + return false; + } + + m_mode = LABEL_LIST_COMMANDS; + if ( 1 == m_input.length() ){ + fillCommandCandidates(); + return true; + } /* Check m_input len, and update auxiliary string meanwhile. * 1. only "i", dispatch to fillCommandCandidates(void). * 2. "i" with one charactor, @@ -163,6 +146,42 @@ ExtEditor::updateStateFromInput() * 3. "i" with two charactor or more, * dispatch to fillCommand(std::string, const char * argument). */ + + if ( isalpha(m_input[1])){ + m_mode = LABEL_LIST_COMMANDS; + if ( m_input.length() == 2){ + fillCommandCandidates(m_input.substr(1,1).c_str()); + return true; + } else if ( m_input.length() == 3) { + 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) { + m_mode = LABEL_NONE; + clearLookupTable(); + m_lookup_table.clear(); + sendLookupTable(); + 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; + + //fillCommandCandidates(...).(list or single value.) + } + } + else if ( isdigit(m_input[1]) ){ + m_mode = LABEL_LIST_NUMBERS; + //Generate Chinese number. + //fillChineseNumber(). (Label use digit.) + } + return true; } |
