2010-09-15 80 views
0

其实我想修改替换词功能拼写检查器Firefox-Addon:我如何覆盖UI功能?

我想(在我自己的Firefox扩展)的OnInit

original_replaceWord = InlineSpellCheckerUI.replaceWord; 

InlineSpellCheckerUI.replaceWord = function() 
{ 
    // things i would like to do (i.e. set the Cursor to another spot in the editor) 

    // call of the original function 
    return original_replaceWord.apply(this, arguments); 
}; 

但是这似乎并没有工作,因为当我更换一个missspelled字这个函数没有被调用。

我如何找到正确的功能?我需要覆盖哪一个?

THX的任何建议

+0

见InlineSpellCheckerUI源在http://mxr.mozilla.org/firefox/source/toolkit/content/inlineSpellCheckUI.js并设法找到你需要重写的功能。 – 2010-09-15 10:43:19

+0

嗯,会试一试 – Thariama 2010-09-15 10:55:39

回答

1

试试这个 :(这是错误的请参阅下面的更新)

original_replaceWord = InlineSpellCheckerUI.replaceWord; 

InlineSpellCheckerUI.prototype.replaceWord = function() 
{ 
    // things i would like to do (i.e. set the Cursor to another spot in the editor) 

    // call of the original function 
    return original_replaceWord.apply(this, arguments); 
}; 

UPDATE

InlineSpellCheckerUI不具备replaceWord功能。 replaceWord功能在nsIInlineSpellChecker接口中定义,该接口由C++中的mozInlineSpellChecker类实现。所以你不能覆盖replaceWord函数。但是,您可以使用下面的代码覆盖InlineSpellCheckerUI中的replaceMisspelling函数。我认为它应该符合你的目的。

let original_replaceMisspelling = InlineSpellCheckerUI.replaceMisspelling; 

InlineSpellCheckerUI.replaceMisspelling = function() 
{ 
    // things i would like to do (i.e. set the Cursor to another spot in the editor) 

    // call of the original function 
    return original_replaceMisspelling.apply(this, arguments); 
}; 
+0

不幸的是,这并没有奏效。我评论了原来的功能,但我仍然能够替换拼写错误的单词。难道拼写检查机制使用另一个函数? – Thariama 2010-09-15 10:21:25

+0

因为我认为我覆盖了错误的功能 - 这个伎俩。非常感谢你! – Thariama 2010-09-15 11:39:29