summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2018-06-06 16:57:42 +0800
committerPeng Wu <alexepico@gmail.com>2018-06-06 16:57:42 +0800
commite9cb1572f84785cada0e5434d1b992ba1298b1a4 (patch)
treea15b27c15cb590a1d3ba92f1aec82e1136099376 /src
parentde688e73654da6a7ace797f35e34275daa4980d3 (diff)
downloadibus-libpinyin-e9cb1572f84785cada0e5434d1b992ba1298b1a4.tar.gz
ibus-libpinyin-e9cb1572f84785cada0e5434d1b992ba1298b1a4.tar.xz
ibus-libpinyin-e9cb1572f84785cada0e5434d1b992ba1298b1a4.zip
re-factor commit method
Diffstat (limited to 'src')
-rw-r--r--src/PYLibPinyin.cc14
-rw-r--r--src/PYLibPinyin.h8
-rw-r--r--src/PYPBopomofoEditor.cc21
-rw-r--r--src/PYPBopomofoEditor.h3
-rw-r--r--src/PYPPhoneticEditor.cc7
-rw-r--r--src/PYPPhoneticEditor.h5
-rw-r--r--src/PYPPinyinEditor.cc21
-rw-r--r--src/PYPPinyinEditor.h5
8 files changed, 32 insertions, 52 deletions
diff --git a/src/PYLibPinyin.cc b/src/PYLibPinyin.cc
index 4157854..1f94ba6 100644
--- a/src/PYLibPinyin.cc
+++ b/src/PYLibPinyin.cc
@@ -203,7 +203,7 @@ LibPinyinBackEnd::modified (void)
}
gboolean
-LibPinyinBackEnd::importPinyinDictionary (const char * filename)
+LibPinyinBackEnd::importPinyinDictionary (const char *filename)
{
/* user phrase library should be already loaded here. */
FILE * dictfile = fopen (filename, "r");
@@ -253,7 +253,7 @@ LibPinyinBackEnd::importPinyinDictionary (const char * filename)
}
gboolean
-LibPinyinBackEnd::exportPinyinDictionary (const char * filename)
+LibPinyinBackEnd::exportPinyinDictionary (const char *filename)
{
/* user phrase library should be already loaded here. */
FILE * dictfile = fopen (filename, "w");
@@ -289,7 +289,7 @@ LibPinyinBackEnd::exportPinyinDictionary (const char * filename)
}
gboolean
-LibPinyinBackEnd::clearPinyinUserData (const char * target)
+LibPinyinBackEnd::clearPinyinUserData (const char *target)
{
if (0 == strcmp ("all", target)) {
pinyin_mask_out (m_pinyin_context, 0x0, 0x0);
@@ -310,14 +310,12 @@ LibPinyinBackEnd::clearPinyinUserData (const char * target)
gboolean
LibPinyinBackEnd::rememberUserInput (pinyin_instance_t * instance,
- gint index)
+ const gchar * phrase)
{
/* pre-check the incomplete pinyin keys, prepare pinyin string,
remember user input. */
- gchar * sentence = NULL;
- pinyin_get_sentence (instance, index, &sentence);
- pinyin_remember_user_input (instance, sentence, -1);
- g_free (sentence);
+ pinyin_remember_user_input (instance, phrase, -1);
+
/* save later,
will mark modified from pinyin/bopomofo editor. */
return TRUE;
diff --git a/src/PYLibPinyin.h b/src/PYLibPinyin.h
index a451d8f..2ad1321 100644
--- a/src/PYLibPinyin.h
+++ b/src/PYLibPinyin.h
@@ -50,11 +50,11 @@ public:
void freeChewingInstance (pinyin_instance_t *instance);
void modified (void);
- gboolean importPinyinDictionary (const char * filename);
- gboolean exportPinyinDictionary (const char * filename);
- gboolean clearPinyinUserData (const char * target);
+ gboolean importPinyinDictionary (const char *filename);
+ gboolean exportPinyinDictionary (const char *filename);
+ gboolean clearPinyinUserData (const char *target);
- gboolean rememberUserInput (pinyin_instance_t * instance, gint index);
+ gboolean rememberUserInput (pinyin_instance_t *instance, const gchar *phrase);
/* use static initializer in C++. */
static LibPinyinBackEnd & instance (void) { return *m_instance; }
diff --git a/src/PYPBopomofoEditor.cc b/src/PYPBopomofoEditor.cc
index 599d195..688fb5f 100644
--- a/src/PYPBopomofoEditor.cc
+++ b/src/PYPBopomofoEditor.cc
@@ -302,7 +302,7 @@ BopomofoEditor::updatePinyin (void)
}
void
-BopomofoEditor::commit (gint index)
+BopomofoEditor::commit (const gchar *str)
{
if (G_UNLIKELY (m_text.empty ()))
return;
@@ -310,16 +310,7 @@ BopomofoEditor::commit (gint index)
m_buffer.clear ();
/* sentence candidate */
- char *tmp = NULL;
- pinyin_get_sentence (m_instance, index, &tmp);
- if (tmp) {
- if (m_props.modeSimp ()) {
- m_buffer << tmp;
- } else {
- SimpTradConverter::simpToTrad (tmp, m_buffer);
- }
- g_free (tmp);
- }
+ m_buffer << str;
/* text after pinyin */
const gchar *p = m_text.c_str() + m_pinyin_len;
@@ -339,11 +330,13 @@ BopomofoEditor::commit (gint index)
++p;
}
- pinyin_train(m_instance, index);
if (m_config.rememberEveryInput ())
- LibPinyinBackEnd::instance ().rememberUserInput (m_instance, index);
+ LibPinyinBackEnd::instance ().rememberUserInput (m_instance, str);
LibPinyinBackEnd::instance ().modified();
- PhoneticEditor::commit ((const gchar *)m_buffer);
+
+ Text text (m_buffer.c_str ());
+ commitText (text);
+
reset();
}
diff --git a/src/PYPBopomofoEditor.h b/src/PYPBopomofoEditor.h
index cc6a6f4..3035011 100644
--- a/src/PYPBopomofoEditor.h
+++ b/src/PYPBopomofoEditor.h
@@ -52,8 +52,9 @@ protected:
virtual void updatePreeditText ();
virtual void updateAuxiliaryText ();
virtual void updatePinyin (void);
+ virtual void commit (const gchar *str);
+ using PhoneticEditor::commit;
- void commit (gint index = 0);
void reset ();
gboolean insert (gint ch);
diff --git a/src/PYPPhoneticEditor.cc b/src/PYPPhoneticEditor.cc
index bbf40f7..6c66053 100644
--- a/src/PYPPhoneticEditor.cc
+++ b/src/PYPPhoneticEditor.cc
@@ -305,13 +305,6 @@ PhoneticEditor::update (void)
updateAuxiliaryText ();
}
-void
-PhoneticEditor::commit (const gchar *str)
-{
- StaticText text(str);
- commitText (text);
-}
-
guint
PhoneticEditor::getPinyinCursor ()
{
diff --git a/src/PYPPhoneticEditor.h b/src/PYPPhoneticEditor.h
index 77b9fbd..96421fd 100644
--- a/src/PYPPhoneticEditor.h
+++ b/src/PYPPhoneticEditor.h
@@ -58,13 +58,15 @@ public:
virtual void updateLookupTable ();
virtual void updateLookupTableFast ();
virtual gboolean fillLookupTable ();
+ virtual void commit (const gchar *str) = 0;
protected:
SelectCandidateAction selectCandidateInternal (EnhancedCandidate & candidate);
gboolean selectCandidate (guint i);
gboolean selectCandidateInPage (guint i);
- void commit (const gchar *str);
+ void commit () { selectCandidate (0); }
+
guint getPinyinCursor (void);
guint getLookupCursor (void);
@@ -82,7 +84,6 @@ protected:
virtual gboolean moveCursorRightByWord (void);
virtual gboolean moveCursorToBegin (void);
virtual gboolean moveCursorToEnd (void);
- virtual void commit (gint index = 0) = 0;
virtual void updateAuxiliaryText (void) = 0;
virtual void updatePreeditText (void) = 0;
virtual void updatePinyin (void) = 0;
diff --git a/src/PYPPinyinEditor.cc b/src/PYPPinyinEditor.cc
index 2cbd41b..14b6832 100644
--- a/src/PYPPinyinEditor.cc
+++ b/src/PYPPinyinEditor.cc
@@ -199,7 +199,7 @@ PinyinEditor::processKeyEvent (guint keyval, guint keycode,
}
void
-PinyinEditor::commit (gint index)
+PinyinEditor::commit (const gchar *str)
{
if (G_UNLIKELY (m_text.empty ()))
return;
@@ -207,16 +207,7 @@ PinyinEditor::commit (gint index)
m_buffer.clear ();
/* sentence candidate */
- char *tmp = NULL;
- pinyin_get_sentence (m_instance, index, &tmp);
- if (tmp) {
- if (m_props.modeSimp ()) {
- m_buffer << tmp;
- } else {
- SimpTradConverter::simpToTrad (tmp, m_buffer);
- }
- g_free (tmp);
- }
+ m_buffer << str;
/* text after pinyin */
const gchar *p = m_text.c_str() + m_pinyin_len;
@@ -228,11 +219,13 @@ PinyinEditor::commit (gint index)
m_buffer << p;
}
- pinyin_train (m_instance, index);
if (m_config.rememberEveryInput ())
- LibPinyinBackEnd::instance ().rememberUserInput (m_instance, index);
+ LibPinyinBackEnd::instance ().rememberUserInput (m_instance, str);
LibPinyinBackEnd::instance ().modified ();
- PhoneticEditor::commit ((const gchar *)m_buffer);
+
+ Text text (m_buffer.c_str ());
+ commitText (text);
+
reset();
}
diff --git a/src/PYPPinyinEditor.h b/src/PYPPinyinEditor.h
index a9b690a..8829fd8 100644
--- a/src/PYPPinyinEditor.h
+++ b/src/PYPPinyinEditor.h
@@ -40,8 +40,6 @@ protected:
gboolean processPunct (guint keyval, guint keycode, guint modifiers);
gboolean processFunctionKey (guint keyval, guint keycode, guint modifiers);
- void commit (gint index = 0);
-
virtual void updateAuxiliaryText (void) = 0;
virtual void updateLookupTable (void);
virtual void updatePreeditText (void);
@@ -49,6 +47,9 @@ protected:
virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers);
virtual void updatePinyin (void) = 0;
+ virtual void commit (const gchar *str);
+ using PhoneticEditor::commit;
+
};
};