Genii Weblog


Civility in critiquing the ideas of others is no vice. Rudeness in defending your own ideas is no virtue.


Wed 6 Feb 2008, 11:51 AM
One of the things I have found, and have heard from many developers over the years, is that even if the Midas Rich Text LSX does not explicitly have a feature, it is not uncommon to be able to do what you want anyway.  For example, today I had a user ask:
I've searched in vain looking for a way in Notes Client to sort the attachments (alphabetically by File Name) in a rich text field. Do you know of any way to do this? 

I have a documents with about 20 files attached in a rich text field. The user wants to have these sorted without having to remove and add them in the correct order.
Now, I happen to remember thinking that this was not available in Midas for some reason, even though it makes some sense to me, but I tried anyway using the amazingly versatile Sort method:

   Call rtitem.ConnectBackend(doc.Handle, "Body", True)
   Set rtchunk = rtitem.DefineChunk("File *")
   Call rtchunk.Sort("FileName")
   rtitem.Save

but sure enough, it didn't work.  Midas needs something to sort on, and I had not added the ability for it to use filenames (although I certainly will for the next release).  But I wanted a solution now, so I though for a few minutes and realized that I just needed each file attachment to have a text version of the name to use for sorting, but only temporarily.  Since I know there is already a graphic inside the file hotspot (inside geeky term for the part you click to get the attachment), I just used a couple of other minor Midas properties and methods and changed the code to add the text, sort on it, then remove it again.  Here is the code:

   Call rtitem.ConnectBackend(doc.Handle, "Body", True)
   Set rtchunk = rtitem.DefineChunk("File 1")
   While rtchunk.Exists
      Set rtchunk2 = rtitem.DefineChunk("Inside "+rtchunk.Definition+"; Graphic 1")
      If rtchunk2.Exists Then
         Call rtchunk2.AppendText(rtchunk.OriginalFileName, "Plain")
      End If
      rtchunk.GetNextTarget
   Wend
   Set rtchunk = rtitem.DefineChunk("File *")
   Call rtchunk.Sort("Text")
   rtchunk.Text = ""
   rtitem.Save

And what do you know, it works perfectly.  Even though my temptation was to say, "it doesn't do that", it turns out it really does.

Copyright © 2008 Genii Software Ltd.

Tags: