到今天总算把LingosHook的全部代码合成在一起了,可以
下载了。。。主要更新如下:
1.支持Tag;(这个功能是第一个留言要求的,当然也确实很需要。。。)
2.增加了图标;(如果这个也算更新的话。。。)
![](http://www.cppblog.com/images/cppblog_com/codejie/LingosHook/lh_logo32.PNG)
更新很少,那是因为这几天写的都是看不见的,为以后再新增功能搭好架子,下面是看不见的更新:
1.数据库
a.重新设计数据库访问机制,由统一管理,改为各自对象分离访问,这样可以更加灵活地添加需要访问对象的数据库对象,且无需修改数据访问对象;
b.结果数据由各自词典对象自己维护,为多词典支持做好准备;
![](http://www.cppblog.com/images/cppblog_com/codejie/LingosHook/lingoshook-db.png)
2.内部对象
a.废弃原有“解析-查询-显示”对象,包括DictResultParser、ResultProcObject、SearchProcObject等对象,改为相对分离的DictObject、DisplayObject、TriggerObject等对象;
b.新的词典关系模式,可更加灵活地添加新的词典。具体说,词典对象内部被称为ParserObject,当前仅支持的一个词典--Vicon EC,对应VICON::CECParser对象。再新增词典对象时,仅需要继承ParserObject,实现其中要求的虚函数,再可注册到系统中即可,其中词典的调用,显示等工作由DictObject统一完成;
class CECParser : public CDictParser
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public:
static const wxString ID;
static const wxString TITLE;
public:
CECParser(int index, const wxString& id, const wxString& title, const wxDateTime& create);
virtual ~CECParser();
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
virtual int Init(CDBAccess::TDatabase& db);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
virtual int ParserHTML(const wxString& html, TinyHtmlParser::CDocumentObject& doc, const TinyHtmlParser::CElementObject* dict, TWordResultMap& result) const;
virtual int GetResult(CDBAccess::TDatabase& db, int wordid, TDictResultMap& result);
virtual int GetResult(CDBAccess::TDatabase& db, int wordid, CDictResult& result);
virtual int SaveResult(CDBAccess::TDatabase& db, int wordid, const CDictResult& result);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
virtual int RemoveResult(CDBAccess::TDatabase& db, int wordid);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
public:
WordClass StrToWC(const wxString& str) const;
const wxString WCToStr(WordClass wc) const;
private:
int GetRecord(TinyHtmlParser::CDocumentObject* doc, const TinyHtmlParser::CElementObject* pr, TWordResultMap& result) const;
int IsWordExist(CDBAccess::TDatabase &db, int wordid);
};
c.分离的对象关系,各对象间,如DictObject,TagObject,DisplayObject等等,不存在必然的联系,统一由TriggerObject进行联系,简单说,此种机制类似回调函数,当某种事件发生时,就会触发TriggerObject的某个函数,如果其它对象需要作出相应的反应时,可将反应函数加入到TriggerObject对象相应的函数中;具体说,如新增了单词时,DictObject会触发TriggerObject对象中的OnWordSave()函数,而在此函数中,会再调用DispyObject的AppendWord()和TagObject的InsertIndex(),由此完成新单词的显示和Tag‘分类’功能;
int CDictObject::SaveWord(const wxString& word, const wxString& html, int& wordid)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
CDBAccess::TQuery query = _db.PrepareStatement("SELECT ROWID, Counter FROM WordTable WHERE Word = ?");
query.Bind(1, word);
CDBAccess::TResult res = query.ExecuteQuery();
if(!res.IsOk())
throw CDBAccess::TException(255, _("SELECT ROWID of WordTable FAILED."));
if(!res.Eof())
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
wordid = res.GetInt(0);
int counter = res.GetInt(1);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
UpdateWordData(wordid, counter + 1);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
g_objTrigger.OnWordUpdate(wordid, word);
}
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
CDBAccess::TQuery query = _db.PrepareStatement("INSERT INTO WordTable (Word, Counter, HTML) VALUES(?, 1, ?)");
query.Bind(1, word);
query.Bind(2, html);
query.ExecuteUpdate();
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
wordid = _db.GetLastRowId().ToLong();
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
g_objTrigger.OnWordSave(wordid, word);
}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
return 0;
}
void CTriggerObject::OnWordSave(int wordid, const wxString& word)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
{
_objDisplay->AppendWord(wordid, word);![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
_objTag->InsertIndex(wordid, _objTag->DefaultTag());
}
3.分类管理
a.新增Tag对象,数据库表,管理、显示界面;
![](http://www.cppblog.com/images/cppblog_com/codejie/LingosHook/lingoshook-tag-result-2.png)
b.目前仅支持Tag分类方式,以后应该会支持‘时间’和‘次数’等分类方式;
![](http://www.cppblog.com/images/cppblog_com/codejie/LingosHook/lingoshook-tag-result-1.png)
4.新的结果显示
a.以单词为“根”,各词典结果为“子分支”方式显示,方便添加多词典结果。
![](http://www.cppblog.com/images/cppblog_com/codejie/LingosHook/lingoshook-main-1.png)
更新说明就这些吧,这次主要能看得见的变化还是Tag的支持,关于Tag的说明和使用,请看这里。
当前未完成的功能有:
1.Date和Counter分类显示方式;
2.在分类显示中删除单词;
3.指定单词的Tag(当前仅有设置缺省一种方法,没法事后管理);
未来可能需要完成的功能有:
1.新增一种词典;
2.在线词典结果的抓取;
3.HTML解析对象容错性支持;
3.界面字体设置;
4.等等。。。