diff options
-rw-r--r-- | lua/lua-plugin.h | 7 | ||||
-rw-r--r-- | src/PYEngine.cc | 1 | ||||
-rw-r--r-- | src/PYExtEditor.cc | 24 | ||||
-rw-r--r-- | src/PYExtEditor.h | 6 | ||||
-rw-r--r-- | src/PYPLuaConverterCandidates.cc | 18 | ||||
-rw-r--r-- | src/PYPLuaConverterCandidates.h | 6 | ||||
-rw-r--r-- | src/PYPLuaTriggerCandidates.cc | 18 | ||||
-rw-r--r-- | src/PYPLuaTriggerCandidates.h | 6 | ||||
-rw-r--r-- | src/PYPPhoneticEditor.cc | 10 | ||||
-rw-r--r-- | src/PYPPhoneticEditor.h | 4 | ||||
-rw-r--r-- | src/PYPPinyinEngine.cc | 59 | ||||
-rw-r--r-- | src/PYPPinyinEngine.h | 6 | ||||
-rw-r--r-- | src/PYPSuggestionEditor.cc | 10 | ||||
-rw-r--r-- | src/PYPSuggestionEditor.h | 2 |
14 files changed, 106 insertions, 71 deletions
diff --git a/lua/lua-plugin.h b/lua/lua-plugin.h index ebb2b2a..f6f5ada 100644 --- a/lua/lua-plugin.h +++ b/lua/lua-plugin.h @@ -23,6 +23,10 @@ #ifndef LUA_PLUGIN_H #define LUA_PLUGIN_H +#include <glib.h> + +G_BEGIN_DECLS + #include <lua.h> #include <lualib.h> #include <lauxlib.h> @@ -187,4 +191,7 @@ const lua_command_candidate_t * ibus_engine_plugin_get_retval(IBusEnginePlugin * GArray * ibus_engine_plugin_get_retvals(IBusEnginePlugin * plugin); void ibus_engine_plugin_free_candidate(lua_command_candidate_t * candidate); + +G_END_DECLS + #endif diff --git a/src/PYEngine.cc b/src/PYEngine.cc index 291f2f2..5ec1d27 100644 --- a/src/PYEngine.cc +++ b/src/PYEngine.cc @@ -21,6 +21,7 @@ #include "PYEngine.h" #include <cstring> +#include "lua-plugin.h" #include "PYPPinyinEngine.h" #include "PYPBopomofoEngine.h" diff --git a/src/PYExtEditor.cc b/src/PYExtEditor.cc index 9a34f51..9190d32 100644 --- a/src/PYExtEditor.cc +++ b/src/PYExtEditor.cc @@ -154,31 +154,15 @@ ExtEditor::ExtEditor (PinyinProperties & props, Config & config) m_candidate (NULL), m_candidates (NULL) { - m_lua_plugin = ibus_engine_plugin_new (); - - loadLuaScript ( ".." G_DIR_SEPARATOR_S "lua" G_DIR_SEPARATOR_S "base.lua")|| - loadLuaScript (PKGDATADIR G_DIR_SEPARATOR_S "base.lua"); - - gchar * path = g_build_filename (g_get_user_config_dir (), - "ibus", "libpinyin", "user.lua", NULL); - loadLuaScript(path); - g_free(path); -} - -int -ExtEditor::loadLuaScript (std::string filename) -{ - return !ibus_engine_plugin_load_lua_script (m_lua_plugin, filename.c_str ()); } -void -ExtEditor::resetLuaState () +gboolean +ExtEditor::setLuaPlugin (IBusEnginePlugin *plugin) { - g_object_unref (m_lua_plugin); - m_lua_plugin = ibus_engine_plugin_new (); + m_lua_plugin = plugin; + return TRUE; } - gboolean ExtEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers) { diff --git a/src/PYExtEditor.h b/src/PYExtEditor.h index 746b288..792e9b0 100644 --- a/src/PYExtEditor.h +++ b/src/PYExtEditor.h @@ -21,13 +21,10 @@ #ifndef __PY_EXT_EDITOR_ #define __PY_EXT_EDITOR_ -extern "C" { #include "lua-plugin.h" -} namespace PY { - class ExtEditor : public Editor { public: ExtEditor (PinyinProperties & props, Config & config); @@ -41,8 +38,7 @@ public: virtual void reset (void); virtual void candidateClicked (guint index, guint button, guint state); - int loadLuaScript (std::string filename); - void resetLuaState (void); + gboolean setLuaPlugin (IBusEnginePlugin *plugin); private: bool updateStateFromInput (void); diff --git a/src/PYPLuaConverterCandidates.cc b/src/PYPLuaConverterCandidates.cc index 2031306..dcd7390 100644 --- a/src/PYPLuaConverterCandidates.cc +++ b/src/PYPLuaConverterCandidates.cc @@ -30,23 +30,13 @@ using namespace PY; LuaConverterCandidates::LuaConverterCandidates (Editor *editor) { m_editor = editor; - - m_lua_plugin = ibus_engine_plugin_new (); - - loadLuaScript ( ".." G_DIR_SEPARATOR_S "lua" G_DIR_SEPARATOR_S "base.lua")|| - loadLuaScript (PKGDATADIR G_DIR_SEPARATOR_S "base.lua"); - - gchar * path = g_build_filename (g_get_user_config_dir (), - "ibus", "libpinyin", "user.lua", NULL); - loadLuaScript(path); - g_free(path); } -int -LuaConverterCandidates::loadLuaScript (std::string filename) +gboolean +LuaConverterCandidates::setLuaPlugin (IBusEnginePlugin * plugin) { - return !ibus_engine_plugin_load_lua_script - (m_lua_plugin, filename.c_str ()); + m_lua_plugin = plugin; + return TRUE; } gboolean diff --git a/src/PYPLuaConverterCandidates.h b/src/PYPLuaConverterCandidates.h index 4270670..5290c15 100644 --- a/src/PYPLuaConverterCandidates.h +++ b/src/PYPLuaConverterCandidates.h @@ -22,9 +22,7 @@ #ifndef __PY_LIB_PINYIN_LUA_CONVERTER_CANDIDATES_H_ #define __PY_LIB_PINYIN_LUA_CONVERTER_CANDIDATES_H_ -extern "C" { #include "lua-plugin.h" -} #include <vector> #include "PYPointer.h" @@ -39,6 +37,8 @@ public: LuaConverterCandidates (Editor *editor); public: + gboolean setLuaPlugin (IBusEnginePlugin * plugin); + gboolean setConverter (const char * lua_function_name); gboolean processCandidates (std::vector<EnhancedCandidate> & candidates); @@ -48,8 +48,6 @@ public: protected: std::vector<EnhancedCandidate> m_candidates; - int loadLuaScript (std::string filename); - Pointer<IBusEnginePlugin> m_lua_plugin; }; diff --git a/src/PYPLuaTriggerCandidates.cc b/src/PYPLuaTriggerCandidates.cc index 420d5a4..9109b74 100644 --- a/src/PYPLuaTriggerCandidates.cc +++ b/src/PYPLuaTriggerCandidates.cc @@ -30,23 +30,13 @@ using namespace PY; LuaTriggerCandidates::LuaTriggerCandidates (Editor *editor) { m_editor = editor; - - m_lua_plugin = ibus_engine_plugin_new (); - - loadLuaScript ( ".." G_DIR_SEPARATOR_S "lua" G_DIR_SEPARATOR_S "base.lua")|| - loadLuaScript (PKGDATADIR G_DIR_SEPARATOR_S "base.lua"); - - gchar * path = g_build_filename (g_get_user_config_dir (), - "ibus", "libpinyin", "user.lua", NULL); - loadLuaScript(path); - g_free(path); } -int -LuaTriggerCandidates::loadLuaScript (std::string filename) +gboolean +LuaTriggerCandidates::setLuaPlugin (IBusEnginePlugin *plugin) { - return !ibus_engine_plugin_load_lua_script - (m_lua_plugin, filename.c_str ()); + m_lua_plugin = plugin; + return TRUE; } gboolean diff --git a/src/PYPLuaTriggerCandidates.h b/src/PYPLuaTriggerCandidates.h index 0e6b275..8ca5b46 100644 --- a/src/PYPLuaTriggerCandidates.h +++ b/src/PYPLuaTriggerCandidates.h @@ -22,9 +22,7 @@ #ifndef __PY_LIB_PINYIN_LUA_TRIGGER_CANDIDATES_H_ #define __PY_LIB_PINYIN_LUA_TRIGGER_CANDIDATES_H_ -extern "C" { #include "lua-plugin.h" -} #include "PYPointer.h" #include "PYPEnhancedCandidates.h" @@ -38,13 +36,13 @@ public: LuaTriggerCandidates (Editor *editor); public: + gboolean setLuaPlugin (IBusEnginePlugin *plugin); + gboolean processCandidates (std::vector<EnhancedCandidate> & candidates); SelectCandidateAction selectCandidate (EnhancedCandidate & enhanced); protected: - int loadLuaScript (std::string filename); - Pointer<IBusEnginePlugin> m_lua_plugin; }; diff --git a/src/PYPPhoneticEditor.cc b/src/PYPPhoneticEditor.cc index b989312..ae3b685 100644 --- a/src/PYPPhoneticEditor.cc +++ b/src/PYPPhoneticEditor.cc @@ -45,6 +45,16 @@ PhoneticEditor::~PhoneticEditor (){ } gboolean +PhoneticEditor::setLuaPlugin (IBusEnginePlugin *plugin) +{ +#ifdef IBUS_BUILD_LUA_EXTENSION + m_lua_trigger_candidates.setLuaPlugin (plugin); + m_lua_converter_candidates.setLuaPlugin (plugin); +#endif + return TRUE; +} + +gboolean PhoneticEditor::processSpace (guint keyval, guint keycode, guint modifiers) { diff --git a/src/PYPPhoneticEditor.h b/src/PYPPhoneticEditor.h index a084ab6..6d0e539 100644 --- a/src/PYPPhoneticEditor.h +++ b/src/PYPPhoneticEditor.h @@ -21,6 +21,8 @@ #ifndef __PY_LIB_PINYIN_BASE_EDITOR_H_ #define __PY_LIB_PINYIN_BASE_EDITOR_H_ +#include "lua-plugin.h" + #include <vector> #include <pinyin.h> #include "PYLookupTable.h" @@ -61,6 +63,8 @@ public: virtual gboolean fillLookupTable (); virtual void commit (const gchar *str) = 0; + gboolean setLuaPlugin (IBusEnginePlugin *plugin); + protected: virtual SelectCandidateAction selectCandidateInternal (EnhancedCandidate & candidate); gboolean selectCandidate (guint i); diff --git a/src/PYPPinyinEngine.cc b/src/PYPPinyinEngine.cc index fab6e84..311726a 100644 --- a/src/PYPPinyinEngine.cc +++ b/src/PYPPinyinEngine.cc @@ -52,14 +52,21 @@ PinyinEngine::PinyinEngine (IBusEngine *engine) { gint i; + initLuaPlugin (); + m_double_pinyin = PinyinConfig::instance ().doublePinyin (); - if (m_double_pinyin) - m_editors[MODE_INIT].reset - (new DoublePinyinEditor (m_props, PinyinConfig::instance ())); - else - m_editors[MODE_INIT].reset - (new FullPinyinEditor (m_props, PinyinConfig::instance ())); + if (m_double_pinyin) { + PhoneticEditor *editor = new DoublePinyinEditor + (m_props, PinyinConfig::instance ()); + m_editors[MODE_INIT].reset (editor); + editor->setLuaPlugin (m_lua_plugin); + } else { + PhoneticEditor *editor = new FullPinyinEditor + (m_props, PinyinConfig::instance ()); + m_editors[MODE_INIT].reset (editor); + editor->setLuaPlugin (m_lua_plugin); + } m_editors[MODE_PUNCT].reset (new PunctEditor (m_props, PinyinConfig::instance ())); @@ -82,8 +89,12 @@ PinyinEngine::PinyinEngine (IBusEngine *engine) m_editors[MODE_STROKE].reset (new Editor (m_props, PinyinConfig::instance ())); #endif - m_editors[MODE_SUGGESTION].reset - (new SuggestionEditor (m_props, PinyinConfig::instance ())); + { + SuggestionEditor *editor = new SuggestionEditor + (m_props, PinyinConfig::instance ()); + m_editors[MODE_SUGGESTION].reset (editor); + editor->setLuaPlugin (m_lua_plugin); + } m_props.signalUpdateProperty ().connect (std::bind (&PinyinEngine::updateProperty, this, _1)); @@ -100,6 +111,28 @@ PinyinEngine::~PinyinEngine (void) { } +gboolean +PinyinEngine::initLuaPlugin (void) +{ + m_lua_plugin = ibus_engine_plugin_new (); + + loadLuaScript ( ".." G_DIR_SEPARATOR_S "lua" G_DIR_SEPARATOR_S "base.lua")|| + loadLuaScript (PKGDATADIR G_DIR_SEPARATOR_S "base.lua"); + + gchar * path = g_build_filename (g_get_user_config_dir (), + "ibus", "libpinyin", "user.lua", NULL); + loadLuaScript(path); + g_free(path); + + return TRUE; +} + +gboolean +PinyinEngine::loadLuaScript (const char * filename) +{ + return !ibus_engine_plugin_load_lua_script (m_lua_plugin, filename); +} + /* keep synced with bopomofo engine. */ gboolean PinyinEngine::processAccelKeyEvent (guint keyval, guint keycode, @@ -284,14 +317,20 @@ PinyinEngine::focusIn (void) * or switch full/double pinyin when pinyin config is changed.*/ if (PinyinConfig::instance ().doublePinyin ()) { if (!m_double_pinyin) { - m_editors[MODE_INIT].reset (new DoublePinyinEditor (m_props, PinyinConfig::instance ())); + PhoneticEditor *editor = new DoublePinyinEditor + (m_props, PinyinConfig::instance ()); + m_editors[MODE_INIT].reset (editor); + editor->setLuaPlugin (m_lua_plugin); connectEditorSignals (m_editors[MODE_INIT]); } m_double_pinyin = TRUE; } else { if (m_double_pinyin) { - m_editors[MODE_INIT].reset (new FullPinyinEditor (m_props, PinyinConfig::instance ())); + PhoneticEditor *editor = new FullPinyinEditor + (m_props, PinyinConfig::instance ()); + m_editors[MODE_INIT].reset (editor); + editor->setLuaPlugin (m_lua_plugin); connectEditorSignals (m_editors[MODE_INIT]); } m_double_pinyin = FALSE; diff --git a/src/PYPPinyinEngine.h b/src/PYPPinyinEngine.h index 666368a..975ccbc 100644 --- a/src/PYPPinyinEngine.h +++ b/src/PYPPinyinEngine.h @@ -22,6 +22,8 @@ #ifndef __PY_LIB_PINYIN_PINYIN_ENGINE_H_ #define __PY_LIB_PINYIN_PINYIN_ENGINE_H_ +#include "lua-plugin.h" + #include "PYEngine.h" #include "PYPinyinProperties.h" @@ -48,6 +50,9 @@ public: void candidateClicked (guint index, guint button, guint state); private: + gboolean initLuaPlugin (void); + gboolean loadLuaScript (const char * filename); + gboolean processPunct (guint keyval, guint keycode, guint modifiers); void showSetupDialog (void); @@ -76,6 +81,7 @@ private: EditorPtr m_editors[MODE_LAST]; EditorPtr m_fallback_editor; + Pointer<IBusEnginePlugin> m_lua_plugin; }; }; diff --git a/src/PYPSuggestionEditor.cc b/src/PYPSuggestionEditor.cc index ba98fb6..0dfc85a 100644 --- a/src/PYPSuggestionEditor.cc +++ b/src/PYPSuggestionEditor.cc @@ -51,6 +51,16 @@ SuggestionEditor::~SuggestionEditor (void) } gboolean +SuggestionEditor::setLuaPlugin (IBusEnginePlugin *plugin) +{ +#ifdef IBUS_BUILD_LUA_EXTENSION + m_lua_trigger_candidates.setLuaPlugin (plugin); + m_lua_converter_candidates.setLuaPlugin (plugin); +#endif + return TRUE; +} + +gboolean SuggestionEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers) { //IBUS_SHIFT_MASK is removed. diff --git a/src/PYPSuggestionEditor.h b/src/PYPSuggestionEditor.h index 8276a6a..1acb9f6 100644 --- a/src/PYPSuggestionEditor.h +++ b/src/PYPSuggestionEditor.h @@ -51,6 +51,8 @@ public: virtual void reset (void); virtual void candidateClicked (guint index, guint button, guint state); + gboolean setLuaPlugin (IBusEnginePlugin *plugin); + protected: virtual SelectCandidateAction selectCandidateInternal (EnhancedCandidate & candidate); |