Pregunta

I'm currently trying to implement a simple Add-In for InfoPath 2010 Filler/Editor mode, which adds a few buttons on the "Insert" ribbon, which upon clicking inserts some "template" data from another source.

It works fine but the thing that's annoying me is that when the user has no field selected, it remains enabled while all of the other buttons on the insert toolbar somehow "know" that nothing can be inserted in the current context and are therefore disabled.

The MSDN documentation on how to interact with the underlying XDocument is perfectly adequate, but what I'm struggling to figure out is how to interact or get information from the editing UI.

This is what I'd like to have:

  • An event that gets fired when the user changes from field to field on the form
  • Then be able to tell what kind of field the user is currently entering data into (i.e. rich text, plain text etc), so the extra buttons can be enabled or disabled as needed.

I thought this would be fairly simple but I've spent nearly a day looking through everything I can find, and have come up empty!

Or have I completely missed the point here?

¿Fue útil?

Solución

Several months later I can finally answer my own question. Not that anyone uses InfoPath filler, but just in case anyone does, here's my solution:

There's several points to my original question.

1) Event that gets fired when the user changes from field to field:

This turns out to be specified in the Ribbon Button XML as the "getEnabled" attribute. InfoPath calls the specified function each time it thinks the button may need to be enabled or disabled. On mine I specified: getEnabled="OnButtonGetEnabled", then implemented a small function:

    public bool OnButtonGetEnabled(Office.IRibbonControl control)
    {
        ribbon.Invalidate();
        return HaveRichTextFieldSelected(GetContextXPath());
    }

in my case 'ribbon' is my instance of Office.IRibbonUI. Calling 'Invalidate()' is pretty important otherwise InfoPath only ends up calling this once.

2) How to determine the type of the field the user has selected.

I'm still not happy with my solution for this but at least I now have something that works.

I've written two functions:

1: GetContextXPath() which calls Globals.ThisAddIn.Application.ActiveWindow.XDocument.View.GetContextNodes(), builds an XPath string from the result (walking backwards through the DOM tree)

2: HaveRichTextFieldSelected() which checks if the specified XPath is of type 'rich' in the manifest (whose DOM tree is under Globals.ThisAddIn.Application.ActiveWindow.XDocument.Solution.DOM)

Anyway I'm not posting all of the code involved here as it's too much for an SO answer, but this should give someone with some common sense a clue as to how to implement this.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top