What's The Best Way to Hide a Task Pane By Default (Then Show It On Demand)?

Add-in Express™ Support Service
That's what is more important than anything else

What's The Best Way to Hide a Task Pane By Default (Then Show It On Demand)?
 
Colin McGraw




Posts: 5
Joined: 2013-09-11
I have a plugin that supports Word, Excel and PowerPoint. My plugin uses a task pane that shouldn't be shown until an existing document is loaded.

It seems like something that should be pretty simple, but I'm having to jump through a considerable amount of hoops to make it work.

What I want to do is have, for example, an ADXWordTaskPane.CurrentTaskPaneInstance visible property set to false, but CurrentTaskPaneInstance is null on startup, even though the task pane shows itself when opening Office.

I've resorted to tracking a Boolean "ShouldShow" property and setting the visible property of the task pane to false in ADXBeforeTaskPaneShow if ShouldShow is false, but that approach feels terribly clumsy and I have to duplicate the code for Excel, Word and PowerPoint task panes.

Is there a better way that immediately springs to mind?
Posted 16 Sep, 2013 12:27:49 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Colin,

In the ADXBeforeTaskPaneShow event of the task pane class, you set this.Visible = false if you need the pane not to show. I would have ShouldShow on the add-in module. I would trace application (document) events to modify this property as required. As to the panes, they would have just this code line in the ADXBeforeTaskPaneShow event handler (a raw sketch):

this.Visible = {project name e.g. MyAddin1}.{add-in module name e.g. AddinModule}.CurrentInstance.ShouldShow; 



Andrei Smolin
Add-in Express Team Leader
Posted 17 Sep, 2013 04:48:29 Top
Colin McGraw




Posts: 5
Joined: 2013-09-11
Thanks for the answer.

I'm encountering a frustrating issue with the approach, however. Here is my current setup:

1. I set the "ShouldShow" property on DocumentOpen/ProtectedViewWindowOpen.
2. I examine the "ShouldShow" property in ADXBeforeTaskPaneShow and set visibility accordingly.
3. I also explicitly set the visibility of CurrentTaskPaneInstance if it's not null on DocumentOpen/ProtectedViewWindowOpen in case 2 occurred before 1.

In some cases it works, but when I'm directly opening a document from a SharePoint site when Word is closed, then 2 occurs before 1, and the ProtectedViewWindowOpen event never fires, so 3 never occurs and I haven't found a good way to ensure the task pane is visible when it needs to be.

Oddly, if Word is already open then it all works properly!

Can you identify a better approach or suggest some other workaround?

EDIT: So I've gotten so far as to figure out that ADXBeforeTaskPaneInstance still fires in my circumstances, and I've further determined that I can reevaluate the visibility condition in an asynchronous method call. It's ugly, however, because it hangs the UI until it's done with the evaluation, which doesn't always return true. I'm basically betting that things will finish in a second and a half or be acceptable to the user otherwise.

It's working technically, but do you guys have any better ideas?


private void WordDiscussionTaskPane_ADXBeforeTaskPaneShow(object sender, ADXBeforeTaskPaneShowEventArgs e)
{
      var addIn = (AddinModule)WordTaskPanesManager.AddinModule;
      if (!addIn.ShouldShowTaskPane)
      {
          this.BeginInvoke(
             (Action)(
                 () =>
                 {
                    var tries = 0;
                    while (tries++ < 3 && !addIn.ShouldShowTaskPane)
                    {
                        Thread.Sleep(500);
                        //this sets ShouldShowTaskPane to true in some conditions
                        addIn.EvaluateDocumentOpen();
                        if (addIn.ShouldShowTaskPane)
                        {
                            this.Visible = true;
                            this.Refresh();
                        }
                    }
                }
            )
        );

        this.Visible = false;
    }
}
Posted 25 Sep, 2013 15:25:42 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Colin,

I would suggest that you add another event like WindowActivate to your step #1 where the ShouldShow property is "calculated". That is, you need to find an event that fires on opening a document from a SharePoint site before the ADXBeforeTaskPaneShow event; and handle that event so that the ShouldShow property has the right value.
Posted 26 Sep, 2013 06:10:10 Top