Ariel, Wow, I really appreciate your thoughtful reply!
Thank you, Erik On Thu, Mar 26, 2015 at 5:58 AM, Ariel Constenla-Haile <arie...@apache.org> wrote: > Hi Erik, > > On Mon, Mar 23, 2015 at 10:55:00PM -0400, Erik Engstrom wrote: > > Hey developers, > > > > I'd like to work on a fix for issue #121672, but I'm not sure where to > look > > in the source code for the word count function. Could anyone give me a > hint > > as to where to look? > > I only know a little about application framework, not Writer code; but > this is what I'd do to find the code. There are different approaches, > but I will search the UNO command (you could also search the dialog > title in src files): > > - Start from the UI. The menu that triggers the Word Count dialog has > the text "Word Count". All commands in toolbars and menus are > identified by a single string named the UNO command; this command is > bound to a string describing the feature in the UI, this binding is made > in configuration files under > main/officecfg/registry/data/org/openoffice/Office/UI/ > Let's find the UNO command for this string: > http://opengrok.adfinis-sygroup.org/source/search > Full Search: "Word Count" > File Path: xcu > In Project(s): aoo-trunk > > http://opengrok.adfinis-sygroup.org/source/search?q=%22Word+Count%22&defs=&refs=&path=xcu&hist=&project=aoo-trunk > The string is here: > > http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/officecfg/registry/data/org/openoffice/Office/UI/WriterCommands.xcu#1668 > The command is ".uno:WordCountDialog" > > - the UNO command represents a feature that has states (can be > enabled/disabled, checked/unchecked, etc.) and can be executed > ("dispatched"). Every item in a toolbar/menu/statusbar is managed in > the application framework by a controller that listens for status > updates at a dispatch object, which is also responsible of execute the > feature. > Once you have the UNO command, find where is the code that dispatches > the command and/or provides its state. > In applications based on the application framework (chart2, dbaccess, > reportdesign), this would be rather straight-forward. The other > applications are based on the old SFX2 framework, and is more > complicated to understand. You can find a technical explanation here > > https://wiki.openoffice.org/wiki/Framework/Article/Implementation_of_the_Dispatch_API_In_SFX2 > and some examples in this message > http://markmail.org/message/w2hhxnectkeehdvg > > In the sfx2 world you need to find the slot definition and the shell > interface(s) that has(have) the methods that provide the state and > execution. > We search the UNO command without the protocol part: > Full Search: WordCountDialog > File Path: sdi > > http://opengrok.adfinis-sygroup.org/source/search?q=WordCountDialog&defs=&refs=&path=sdi&hist=&project=aoo-trunk > The slot is defined in main/sw/sdi/swriter.sdi > SfxVoidItem WordCountDialog FN_WORDCOUNT_DIALOG > > With the ID, FN_WORDCOUNT_DIALOG you can search the shell interfaces: > > http://opengrok.adfinis-sygroup.org/source/search?q=FN_WORDCOUNT_DIALOG&defs=&refs=&path=sdi&hist=&project=aoo-trunk > and the implementation: > > http://opengrok.adfinis-sygroup.org/source/search?q=FN_WORDCOUNT_DIALOG&defs=&refs=&path=cxx&hist=&project=aoo-trunk > > The code does basically the same in the different shells: > > http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/sw/source/ui/shells/textsh1.cxx#1357 > > http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/sw/source/ui/shells/annotsh.cxx#452 > > http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/sw/source/ui/shells/frmsh.cxx#273 > > http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/sw/source/ui/shells/drwtxtex.cxx#416 > > http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/sw/source/ui/shells/drawsh.cxx#338 > > You can set a break point in any of them, they lead you to: > > void SwDoc::CountWords( const SwPaM& rPaM, SwDocStat& rStat ) const > > http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/sw/source/core/doc/docedt.cxx#2787 > > void SwTxtNode::CountWords( SwDocStat& rStat, xub_StrLen nStt, xub_StrLen > nEnd ) const > > http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/sw/source/core/txtnode/txtedt.cxx#1939 > > It seams that > > a) word counting is done on a text node basis; this > information is cached on the text node, that is, when you insert a new > word the whole document isn't counted again and again (look for > SetWordCountDirty, it will tell you when this information is > invalidated) > > b) in the end, Writer uses the break iterator API. I do the same in this > extension: > http://extensions.openoffice.org/en/project/word-count-statusbar-controller > I get the word count for the whole document from the document > statistics, so the bug is there too. But for the selection I use the > break iterator manually, and you'll see that the bug isn't reproducible > in the statusbar control (unfortunately there is no way to cache word > count using the API, so the selection word count is limited to a certain > amount of text). In short, I guess that the bug is not in the break > iterator > code but in Writer. > > ------ > > If you wanted to take the other approach, search the dialog title: > > - dialogs are defined in .src files, so search the following: > > http://opengrok.adfinis-sygroup.org/source/search?q=%22Word+Count%22&defs=&refs=&path=src&hist=&project=aoo-trunk > the result is > > http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/sw/source/ui/dialog/wordcountdialog.src#32 > > - Get the ID of the dialog and search it in the source: > ModalDialog DLG_WORDCOUNT > > > http://opengrok.adfinis-sygroup.org/source/search?q=DLG_WORDCOUNT&defs=&refs=&path=cxx&hist=&project=aoo-trunk > > http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/sw/source/ui/dialog/wordcountdialog.cxx#50 > > - SwWordCountDialog will lead you to the dialog factory: > > http://opengrok.adfinis-sygroup.org/source/s?refs=SwWordCountDialog&project=aoo-trunk > > http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/sw/source/ui/dialog/swdlgfact.hxx#78 > > http://opengrok.adfinis-sygroup.org/source/xref/aoo-trunk/main/sw/source/ui/dialog/swdlgfact.cxx#661 > which creates a AbstractSwWordCountDialog > > - search that dialog, you'll get the shells: > > http://opengrok.adfinis-sygroup.org/source/search?q=AbstractSwWordCountDialog&defs=&refs=&path=cxx&hist=&project=aoo-trunk > > ------ > > Hope this helps you getting started. > > > Regards > -- > Ariel Constenla-Haile > La Plata, Argentina >