summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi Sumita <hsumita@chromium.org>2012-06-07 11:26:19 +0900
committerHiroshi Sumita <hsumita@chromium.org>2012-06-07 11:26:19 +0900
commit0576f6090561dfdd4281d89e971dc9384faad0b1 (patch)
treef577c4e9e706d28d406c793b83321227b3010e9d
parentad58ca3fb07c35eedcaf2edc2e9e7f19c8b46138 (diff)
downloadpyzy-0576f6090561dfdd4281d89e971dc9384faad0b1.tar.gz
Implements InputContext::Observer::updateInputText and updateCursor
BUG=None TEST=Manual Review URL: https://codereview.appspot.com/6298043
-rw-r--r--configure.ac2
-rw-r--r--src/PyZyBopomofoContext.cc18
-rw-r--r--src/PyZyDoublePinyinContext.cc21
-rw-r--r--src/PyZyFullPinyinContext.cc14
-rw-r--r--src/PyZyInputContext.h18
-rw-r--r--src/PyZyPhoneticContext.cc15
-rw-r--r--src/PyZyPhoneticContext.h2
-rw-r--r--src/PyZyPinyinContext.cc2
-rw-r--r--src/PyZySpecialPhraseTable.cc2
9 files changed, 88 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac
index 8862b53..97dbb1f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,7 +24,7 @@ m4_define([pyzy_released], [1])
m4_define([pyzy_major_version], [0])
m4_define([pyzy_minor_version], [0])
-m4_define([pyzy_micro_version], [6])
+m4_define([pyzy_micro_version], [7])
m4_define([pyzy_interface_age], [0])
m4_define([pyzy_binary_age],
[m4_eval(100 * pyzy_minor_version + pyzy_micro_version)])
diff --git a/src/PyZyBopomofoContext.cc b/src/PyZyBopomofoContext.cc
index e561a66..d1fa762 100644
--- a/src/PyZyBopomofoContext.cc
+++ b/src/PyZyBopomofoContext.cc
@@ -62,6 +62,8 @@ BopomofoContext::insert (char ch)
return true;
m_text.insert (m_cursor++, ch);
+ updateInputText ();
+ updateCursor ();
if (G_UNLIKELY (!(m_config.option & PINYIN_INCOMPLETE_PINYIN))) {
updateSpecialPhrases ();
@@ -80,6 +82,7 @@ BopomofoContext::insert (char ch)
updateAuxiliaryText ();
}
}
+
return true;
}
@@ -91,7 +94,8 @@ BopomofoContext::removeCharBefore (void)
m_cursor --;
m_text.erase (m_cursor, 1);
-
+ updateInputText ();
+ updateCursor ();
updateSpecialPhrases ();
updatePinyin ();
@@ -105,6 +109,7 @@ BopomofoContext::removeCharAfter (void)
return false;
m_text.erase (m_cursor, 1);
+ updateInputText ();
updatePreeditText ();
updateAuxiliaryText ();
@@ -131,6 +136,8 @@ BopomofoContext::removeWordBefore (void)
m_text.erase (cursor, m_cursor - cursor);
m_cursor = cursor;
+ updateInputText ();
+ updateCursor ();
updateSpecialPhrases ();
updatePhraseEditor ();
update ();
@@ -144,6 +151,7 @@ BopomofoContext::removeWordAfter (void)
return false;
m_text.erase (m_cursor, -1);
+ updateInputText ();
updatePreeditText ();
updateAuxiliaryText ();
return true;
@@ -156,6 +164,7 @@ BopomofoContext::moveCursorLeft (void)
return false;
m_cursor --;
+ updateCursor ();
updateSpecialPhrases ();
updatePinyin ();
@@ -169,7 +178,7 @@ BopomofoContext::moveCursorRight (void)
return false;
m_cursor ++;
-
+ updateCursor ();
updateSpecialPhrases ();
updatePinyin ();
@@ -192,6 +201,7 @@ BopomofoContext::moveCursorLeftByWord (void)
m_pinyin_len -= p.len;
m_pinyin.pop_back ();
+ updateCursor ();
updateSpecialPhrases ();
updatePhraseEditor ();
update ();
@@ -215,6 +225,7 @@ BopomofoContext::moveCursorToBegin (void)
m_pinyin.clear ();
m_pinyin_len = 0;
+ updateCursor ();
updateSpecialPhrases ();
updatePhraseEditor ();
update ();
@@ -229,6 +240,7 @@ BopomofoContext::moveCursorToEnd (void)
return false;
m_cursor = m_text.length ();
+ updateCursor ();
updateSpecialPhrases ();
updatePinyin ();
@@ -345,6 +357,8 @@ BopomofoContext::commit (CommitType type)
}
resetContext ();
+ updateInputText ();
+ updateCursor ();
update ();
PhoneticContext::commitText (m_buffer);
}
diff --git a/src/PyZyDoublePinyinContext.cc b/src/PyZyDoublePinyinContext.cc
index 7788f75..7a7372a 100644
--- a/src/PyZyDoublePinyinContext.cc
+++ b/src/PyZyDoublePinyinContext.cc
@@ -81,6 +81,8 @@ DoublePinyinContext::insert (char ch)
return false;
}
else {
+ updateInputText ();
+ updateCursor ();
if (updateSpecialPhrases ()) {
update ();
}
@@ -92,6 +94,8 @@ DoublePinyinContext::insert (char ch)
}
}
else {
+ updateInputText ();
+ updateCursor ();
updateSpecialPhrases ();
updatePhraseEditor ();
update ();
@@ -107,6 +111,8 @@ DoublePinyinContext::removeCharBefore (void)
m_cursor --;
m_text.erase (m_cursor, 1);
+ updateInputText ();
+ updateCursor ();
if (updatePinyin (false)) {
updateSpecialPhrases ();
@@ -132,6 +138,8 @@ DoublePinyinContext::removeCharAfter (void)
return false;
m_text.erase (m_cursor, 1);
+ updateInputText ();
+
if (updateSpecialPhrases ()) {
update ();
}
@@ -151,6 +159,8 @@ DoublePinyinContext::removeWordBefore (void)
if (G_UNLIKELY (m_cursor > m_pinyin_len)) {
m_text.erase (m_pinyin_len, m_cursor - m_pinyin_len);
m_cursor = m_pinyin_len;
+ updateInputText ();
+ updateCursor ();
if (updateSpecialPhrases ()) {
update ();
}
@@ -164,6 +174,8 @@ DoublePinyinContext::removeWordBefore (void)
m_pinyin.pop_back ();
m_text.erase (m_pinyin_len, m_cursor - m_pinyin_len);
m_cursor = m_pinyin_len;
+ updateInputText ();
+ updateCursor ();
updateSpecialPhrases ();
updatePhraseEditor ();
update ();
@@ -179,6 +191,8 @@ DoublePinyinContext::removeWordAfter (void)
return false;
m_text.erase (m_cursor);
+ updateInputText ();
+
if (updateSpecialPhrases ()) {
update ();
}
@@ -196,6 +210,7 @@ DoublePinyinContext::moveCursorLeft (void)
return false;
m_cursor --;
+ updateCursor ();
if (m_cursor >= m_pinyin_len) {
if (updateSpecialPhrases ()) {
@@ -233,6 +248,7 @@ DoublePinyinContext::moveCursorRight (void)
return false;
m_cursor ++;
+ updateCursor ();
if (updatePinyin (false)) {
updateSpecialPhrases ();
updatePhraseEditor ();
@@ -258,6 +274,7 @@ DoublePinyinContext::moveCursorLeftByWord (void)
if (G_UNLIKELY (m_cursor > m_pinyin_len)) {
m_cursor = m_pinyin_len;
+ updateCursor ();
if (updateSpecialPhrases ()) {
update ();
}
@@ -269,6 +286,7 @@ DoublePinyinContext::moveCursorLeftByWord (void)
else {
m_cursor = m_pinyin_len = m_pinyin.back ().begin;
m_pinyin.pop_back ();
+ updateCursor ();
updateSpecialPhrases ();
updatePhraseEditor ();
update ();
@@ -292,6 +310,7 @@ DoublePinyinContext::moveCursorToBegin (void)
m_cursor = 0;
m_pinyin.clear ();
m_pinyin_len = 0;
+ updateCursor ();
updateSpecialPhrases ();
updatePhraseEditor ();
update ();
@@ -306,6 +325,8 @@ DoublePinyinContext::moveCursorToEnd (void)
return false;
m_cursor = m_text.length ();
+ updateCursor ();
+
if (updatePinyin (false)) {
updateSpecialPhrases ();
updatePhraseEditor ();
diff --git a/src/PyZyFullPinyinContext.cc b/src/PyZyFullPinyinContext.cc
index 148478b..06ddd80 100644
--- a/src/PyZyFullPinyinContext.cc
+++ b/src/PyZyFullPinyinContext.cc
@@ -49,6 +49,8 @@ FullPinyinContext::insert (char ch)
return true;
m_text.insert (m_cursor++, ch);
+ updateInputText ();
+ updateCursor ();
if (G_UNLIKELY (!(m_config.option & PINYIN_INCOMPLETE_PINYIN))) {
updateSpecialPhrases ();
@@ -78,7 +80,8 @@ FullPinyinContext::removeCharBefore (void)
m_cursor --;
m_text.erase (m_cursor, 1);
-
+ updateInputText ();
+ updateCursor ();
updateSpecialPhrases ();
updatePinyin ();
@@ -92,6 +95,7 @@ FullPinyinContext::removeCharAfter (void)
return false;
m_text.erase (m_cursor, 1);
+ updateInputText ();
updatePreeditText ();
updateAuxiliaryText ();
@@ -118,6 +122,8 @@ FullPinyinContext::removeWordBefore (void)
m_text.erase (cursor, m_cursor - cursor);
m_cursor = cursor;
+ updateInputText ();
+ updateCursor ();
updateSpecialPhrases ();
updatePhraseEditor ();
update ();
@@ -131,6 +137,7 @@ FullPinyinContext::removeWordAfter (void)
return false;
m_text.erase (m_cursor, -1);
+ updateInputText ();
updatePreeditText ();
updateAuxiliaryText ();
return true;
@@ -143,6 +150,7 @@ FullPinyinContext::moveCursorLeft (void)
return false;
m_cursor --;
+ updateCursor ();
updateSpecialPhrases ();
updatePinyin ();
@@ -156,6 +164,7 @@ FullPinyinContext::moveCursorRight (void)
return false;
m_cursor ++;
+ updateCursor ();
updateSpecialPhrases ();
updatePinyin ();
@@ -178,6 +187,7 @@ FullPinyinContext::moveCursorLeftByWord (void)
m_pinyin_len -= p.len;
m_pinyin.pop_back ();
+ updateCursor ();
updateSpecialPhrases ();
updatePhraseEditor ();
update ();
@@ -200,6 +210,7 @@ FullPinyinContext::moveCursorToBegin (void)
m_pinyin.clear ();
m_pinyin_len = 0;
+ updateCursor ();
updateSpecialPhrases ();
updatePhraseEditor ();
update ();
@@ -213,6 +224,7 @@ FullPinyinContext::moveCursorToEnd (void)
return false;
m_cursor = m_text.length ();
+ updateCursor ();
updateSpecialPhrases ();
updatePinyin ();
diff --git a/src/PyZyInputContext.h b/src/PyZyInputContext.h
index 49304a3..2043cc4 100644
--- a/src/PyZyInputContext.h
+++ b/src/PyZyInputContext.h
@@ -89,6 +89,7 @@ public:
public:
virtual ~Observer () { }
+
/**
* \brief Notifies a commit text.
* @param context InputContext instance which triggered this method.
@@ -101,6 +102,23 @@ public:
const std::string &commit_text) = 0;
/**
+ * \brief Notifies input text is changed.
+ * @param context InputContext instance which triggered this method.
+ *
+ * This method is triggered by InputContext when input text is
+ * changed.
+ */
+ virtual void inputTextChanged (const InputContext * context) = 0;
+
+ /**
+ * \brief Notifies cursor is changed.
+ * @param context InputContext instance which triggered this method.
+ *
+ * This method is triggered by InputContext when cursor is changed.
+ */
+ virtual void cursorChanged (const InputContext * context) = 0;
+
+ /**
* \brief Notifies preedit text is changed.
* @param context InputContext instance which triggered this method.
*
diff --git a/src/PyZyPhoneticContext.cc b/src/PyZyPhoneticContext.cc
index dca2bab..a775688 100644
--- a/src/PyZyPhoneticContext.cc
+++ b/src/PyZyPhoneticContext.cc
@@ -66,6 +66,7 @@ PhoneticContext::reset (void)
{
resetContext ();
update ();
+ updateInputText ();
}
void
@@ -75,6 +76,18 @@ PhoneticContext::commitText (const std::string & commit_text)
}
void
+PhoneticContext::updateInputText (void)
+{
+ m_observer->inputTextChanged (this);
+}
+
+void
+PhoneticContext::updateCursor (void)
+{
+ m_observer->cursorChanged (this);
+}
+
+void
PhoneticContext::updateCandidates (void)
{
m_focused_candidate = 0;
@@ -197,7 +210,7 @@ PhoneticContext::resetCandidate (size_t i)
i -= m_special_phrases.size ();
if (m_phrase_editor.resetCandidate (i)) {
- updateCandidates();
+ updateCandidates ();
}
return true;
diff --git a/src/PyZyPhoneticContext.h b/src/PyZyPhoneticContext.h
index 20ebfcd..5d64188 100644
--- a/src/PyZyPhoneticContext.h
+++ b/src/PyZyPhoneticContext.h
@@ -109,6 +109,8 @@ protected:
virtual void resetContext (void);
virtual void update (void);
virtual void commitText (const std::string & commit_text);
+ virtual void updateInputText (void);
+ virtual void updateCursor (void);
virtual void updateCandidates (void);
virtual void updateAuxiliaryText (void);
virtual void updatePreeditText (void);
diff --git a/src/PyZyPinyinContext.cc b/src/PyZyPinyinContext.cc
index bf17aff..a2b6a51 100644
--- a/src/PyZyPinyinContext.cc
+++ b/src/PyZyPinyinContext.cc
@@ -62,6 +62,8 @@ PinyinContext::commit (CommitType type)
}
resetContext ();
+ updateInputText ();
+ updateCursor ();
update ();
PhoneticContext::commitText (m_buffer);
}
diff --git a/src/PyZySpecialPhraseTable.cc b/src/PyZySpecialPhraseTable.cc
index 206d396..fd37079 100644
--- a/src/PyZySpecialPhraseTable.cc
+++ b/src/PyZySpecialPhraseTable.cc
@@ -43,7 +43,7 @@ private:
SpecialPhraseTable::SpecialPhraseTable (const std::string &config_dir)
{
char * path =
- g_build_filename (config_dir.c_str(), "pyzy", "phrases.txt", NULL);
+ g_build_filename (config_dir.c_str(), "phrases.txt", NULL);
load ("phrases.txt") ||
load (path) ||