Genii Weblog

Midas: Even if it "doesn't do that", it can often do that

Wed 6 Feb 2008, 11:51 AM



by Ben Langhinrichs
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.

What has been said:


672.1. Jan Van Puyvelde
(06/02/2008 11:16)

People who don't have access to your product need to do it manually. Not by removing and re-adding, but by

1. putting a line break after every attachment

2. selecting all paragraphs and creating a bullet list

3. using CTRL+UP/DOWN to reorder the list items

4. removing the bullets and line breaks

Your customer will be happy he doesn't need to do the above !


672.2. Ben Langhinrichs
(02/06/2008 11:25 AM)

Jan - Clever workaround! It would still be a pain with twenty attachments, but it is a way to do it for those who don't have Midas. Thanks!