Find/Replace functionlity for IMT
Posted by mholmes on 07 Feb 2008 in Activity log
While the blog was down yesterday, I began working on adding find/replace functionality to the application. The Find/Replace dialog box is one I've already created for my Markin program, and which I'll open-source so it can be used in IMT. The key issue is figuring out how to find hits, store info about them, and jump to them. We have to create a special unit to handle this functionality, for clarity/separation, and it should include:
- An enumerated type for containers: contTypes = [ctHeader, ctAnnTitle, ctAnnText, ctCatId, ctCatDescription].
- A class which can store our current position/a hit position -- maybe TimtSelection. The data is presumably this:
- Current container type (header, annotation title, annotation text, category id, or category description))
- Item index (0 for header, annotation number for anns, cat number for cats).
- Offset of cursor.
- Selection length. Obviously this will normally be the same as the length of the search text, but we will presumably also store the original cursor position and selection, and restore it after a search/replace operation; and in the long run, there may be regexp functionality.
- SelText. This is the text itself, and may help with a sanity check if the document has changed since the text was found.
- A list class for storing these objects (for when FindAll is used).
- A method for searching text (taking into account the Down, WholeWord and MatchCase) from the cursor position, and reporting back the correct offset and length (taking into account the preceding text length, if going downwards).
- A method for finding the next container to search, based on the current container (this can be modelled on my similar code from Markin).
- A method for making visible a container in which a hit is found, selecting the hit, scrolling it into view, and setting the application and form focus appropriately. This method will have to accept a TimtSelection object, do a sanity check on the data, show the appropriate container, and select the text; if the selection turns out not to match the SelText, it might also show an error message, or try to do another Find to correct the problem.
- Implementations of all the functions required by the TmdhReplaceDialog Setup routine. Most of these will be wrappers that just call methods detailed above.
- GUI elements in the Main and AnnDlg forms -- presumably an action, and associated menu and toolbar items.
Spent time working out the details above, then started coding the unit; I've done about a third of it.