summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2014-09-23 14:13:51 +0800
committerPeng Wu <alexepico@gmail.com>2014-09-23 14:13:51 +0800
commita7bb6ec0493aa97f8f03ab22d5831794234b6a4f (patch)
tree79e17bf0ef9ca3b4d841905a0020599705ac93e3
parent239be6e233e41790759a3e8894f9986074336b21 (diff)
downloadibus-libzhuyin-a7bb6ec0493aa97f8f03ab22d5831794234b6a4f.tar.gz
ibus-libzhuyin-a7bb6ec0493aa97f8f03ab22d5831794234b6a4f.tar.xz
ibus-libzhuyin-a7bb6ec0493aa97f8f03ab22d5831794234b6a4f.zip
write class UserSymbolListAllSection
-rw-r--r--src/Makefile.am2
-rw-r--r--src/ZYZUserSymbolListAllSection.cc59
-rw-r--r--src/ZYZUserSymbolListAllSection.h2
3 files changed, 62 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index c58ff0d..5c987f5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -44,6 +44,7 @@ ibus_engine_libzhuyin_c_sources = \
ZYZBuiltinSymbolSection.cc \
ZYZPhoneticSection.cc \
ZYZBopomofoSymbolSection.cc \
+ ZYZUserSymbolListAllSection.cc \
ZYFallbackEditor.cc \
ZYEngine.cc \
ZYZZhuyinEngine.cc \
@@ -71,6 +72,7 @@ ibus_engine_libzhuyin_h_sources = \
ZYZBuiltinSymbolSection.h \
ZYZPhoneticSection.h \
ZYZBopomofoSymbolSection.h \
+ ZYZUserSymbolListAllSection.h \
ZYPointer.h \
ZYProperty.h \
ZYRawEditor.h \
diff --git a/src/ZYZUserSymbolListAllSection.cc b/src/ZYZUserSymbolListAllSection.cc
index af67962..5437d2d 100644
--- a/src/ZYZUserSymbolListAllSection.cc
+++ b/src/ZYZUserSymbolListAllSection.cc
@@ -49,8 +49,67 @@ UserSymbolListAllSection::~UserSymbolListAllSection ()
gboolean
UserSymbolListAllSection::loadUserSymbolFile (const gchar * filename)
{
+ printf ("load %s.\n", filename);
gboolean retval = m_user_symbols.loadFromFile (filename);
return retval;
}
+bool
+UserSymbolListAllSection::initCandidates (zhuyin_instance_t * instance,
+ const String & lookup)
+{
+ if (!lookup)
+ return false;
+
+ m_candidates.clear ();
+
+ assert ("`" == lookup);
+ m_lookup = lookup;
+
+ /* cache the symbols. */
+ const std::vector<String> & indexes = m_user_symbols.getIndexes ();
+ for (size_t i = 0; i < indexes.size (); ++i) {
+ m_candidates.push_back (indexes[i]);
+ }
+
+ return true;
+}
+
+bool
+UserSymbolListAllSection::fillLookupTableByPage ()
+{
+ LookupTable & lookup_table = getLookupTable ();
+
+ guint len = m_candidates.size ();
+
+ guint filled_nr = lookup_table.size ();
+ guint page_size = lookup_table.pageSize ();
+
+ /* fill lookup table by libzhuyin get candidates. */
+ guint need_nr = MIN (page_size, len - filled_nr);
+ g_assert (need_nr >=0);
+ if (need_nr == 0)
+ return FALSE;
+
+ for (guint i = filled_nr; i < filled_nr + need_nr; i++) {
+ if (i >= len) /* no more candidates */
+ break;
+
+ Text text (m_candidates[i]);
+ lookup_table.appendCandidate (text);
+ }
+
+ return TRUE;
+}
+
+int
+UserSymbolListAllSection::selectCandidate (guint index)
+{
+ if (index >= m_candidates.size ())
+ return 0;
+
+ m_choice = m_candidates[index];
+ return m_choice.utf8Length ();
+}
+
};
diff --git a/src/ZYZUserSymbolListAllSection.h b/src/ZYZUserSymbolListAllSection.h
index 9b7bec4..2c728b4 100644
--- a/src/ZYZUserSymbolListAllSection.h
+++ b/src/ZYZUserSymbolListAllSection.h
@@ -49,7 +49,7 @@ protected:
std::vector<String> m_candidates;
SymbolLookup m_user_symbols;
-}
+};
};