add fillCommandCandidates(string) implementation.
authorPeng Wu <alexepico@gmail.com>
Thu, 6 May 2010 08:24:28 +0000 (16:24 +0800)
committerPeng Wu <alexepico@gmail.com>
Wed, 19 May 2010 02:09:33 +0000 (10:09 +0800)
src/ExtEditor.cc

index 3f0addf..f4a2d7d 100644 (file)
@@ -88,9 +88,11 @@ ExtEditor::updateStateFromInput()
 bool
 ExtEditor::fillCommandCandidates()
 {
+
+    /* try to replace this with fillCommandCandidates("") call. */
     clearLookupTable();
 
-    /* fill Candidates here. */
+    /* fill candidates here. */
     const GArray * commands = ibus_engine_plugin_get_available_commands(m_lua_plugin);
     for ( int i = 0; i < commands->len; ++i){
         lua_command_t * command = &g_array_index(commands, lua_command_t, i);
@@ -105,6 +107,21 @@ ExtEditor::fillCommandCandidates()
 bool
 ExtEditor::fillCommandCandidates(std::string prefix)
 {
+    clearLookupTable();
+
+    /* fill candidates here. */
+    int len = prefix.length();
+    const char * prefix_str = prefix.c_str();
+    const GArray * commands = ibus_engine_plugin_get_available_commands(m_lua_plugin);
+    for ( int i = 0; i < commands->len; ++i){
+        lua_command_t * command = &g_array_index(commands, lua_command_t, i);
+        if ( strncmp(prefix_str, command->command_name, len) == 0){
+            m_lookup_table.appendLabel(Text(command->command_name));
+            m_lookup_table.appendCandidate(Text(command->description));
+        }
+    }
+
+    sendLookupTable();
     return true;
 }