Closed Bug 479283 Opened 15 years ago Closed 15 years ago

add some scriptability to nsIMsgDBView for message pane work

Categories

(MailNews Core :: Backend, defect)

x86
Windows XP
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Thunderbird 3.0b3

People

(Reporter: Bienvenu, Assigned: Bienvenu)

Details

Attachments

(1 file, 1 obsolete file)

DavidA was asking for a view method to select a set of messages. I thought, instead of adding a view method to do that, I'd expose some api's on the view so he could write it in js, and not have to get a headache looking at nsMsgDBView.cpp. This patch exposes enough functionality to do that and a bit more.
Attachment #363162 - Flags: superreview?(neil)
Attachment #363162 - Flags: review?(neil)
with this patch, you can write things like the following:

function AddThreadIndexToSelection(index)
{
  let thread = gDBView.getThreadContainingIndex(index);
  let flags = gDBView.getFlagsAt(index);
  let treeView = gDBView.QueryInterface(Components.interfaces.nsITreeView);
  if (flags & Components.interfaces.nsMsgMessageFlags.Elided)
    treeView.toggleOpenState(index);

  let selection = treeView.selection;
  selection.rangedSelect(index, index, true);
  let numChildren = thread.numChildren;
  for (let i = 1; i < numChildren; i++)
  {
    let child = thread.getChildHdrAt(i);
    let childIndex = gDBView.findIndexOfMsgHdr(child, false);
    if (childIndex != -1)
      selection.rangedSelect(childIndex, childIndex, true);
  }
}

N.B. - you wouldn't want to actually implement selectthread this way, since it's much more efficient to just select from the start of the thread to the end of the thread, but I wanted to be able to test findIndexOfMsgHdr. Also, you could determine the elided bit from nsITreeView but in general it might be useful to expose the view flags.
Comment on attachment 363162 [details] [diff] [review]
expose some nsIMsgDBView functionality

>+  if (m_viewFlags & nsMsgViewFlagsType::kThreadedDisplay)
>+  {
>+    nsMsgViewIndex threadIndex = ThreadIndexOfMsgHdr(aMsgHdr);
>+    if (threadIndex != nsMsgViewIndex_None)
>+    {
>+      if (m_flags[threadIndex] & nsMsgMessageFlags::Elided)
>+        ExpandByIndex(threadIndex, nsnull);
>+      *aIndex = FindHdr(aMsgHdr, threadIndex);
>+    }
>+  }
But what happens if we don't find the thread index?
(In reply to comment #2)

> But what happens if we don't find the thread index?

we should return nsMsgViewIndex_None - I'll attach a new patch.
I've also taken away the extra braces around the else clauses because I think the code reads fine w/o them (sometimes they can be helpful if the code is complicated...)
Attachment #363162 - Attachment is obsolete: true
Attachment #363320 - Flags: superreview?(neil)
Attachment #363320 - Flags: review?(neil)
Attachment #363162 - Flags: superreview?(neil)
Attachment #363162 - Flags: review?(neil)
Comment on attachment 363320 [details] [diff] [review]
address Neil's comment

>-  virtual nsresult GetThreadContainingIndex(nsMsgViewIndex index, nsIMsgThread **thread);
>+//  virtual nsresult GetThreadContainingIndex(nsMsgViewIndex index, nsIMsgThread **thread);
I don't think this is correct ;-)
Attachment #363320 - Flags: superreview?(neil)
Attachment #363320 - Flags: superreview+
Attachment #363320 - Flags: review?(neil)
Attachment #363320 - Flags: review+
fix checked in, with commented out line removed -  davida, let me know if there's other things you'd like to do with views from js.
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.