locked
How to 'reopen' a TooWindow in one Add-in RRS feed

  • Question

  • I have this code to detect when the user closes a toolwindow that it's created by my add-in:

    ((EnvDTE80.Events)this.toolWin.DTE.Events).WindowVisibilityEvents[this.toolWin].WindowHiding += new _dispWindowVisibilityEvents_WindowHidingEventHandler(Connect_WindowHiding); 

    And:

    void Connect_WindowHiding(Window window) 
     { 
    // my code
     }

    In "my code" i want in some cases, to "reopen" my toolwindow (this.toolWin)  i.e. show again my closed toolWindow.

    I have tried with this:

    void Connect_WindowHiding(Window window)
    {
       DialogResult result = ...
    
      if (result.Equals(DialogResult.Cancel))
      {
       // this.applicationObject it's of DTE2 type
      // MyAddinDE2.Connect.MyAddinDE2 it's fro call the Exec method of my Addin
       this.applicationObject.ExecuteCommand("MyAddinDE2.Connect.MyAddinDE2");
       }
    }
    


    But it doesn't work. It calls the Exec method, but at the end, my ToolWindow it's not open.

    I have tried to do this in the OnStartupComplete method and my toolWindows it's open in this case.

     

    public void OnStartupComplete(ref Array custom)
    {
     this.applicationObject.ExecuteCommand("MyAddinDE2.Connect.MyAddinDE2");
    }

    How could it be posible?

    Anybody knows the way to open the toolwindow "by code" after it is closed?

    If I click at the ToolWindow option with the user interface, it works but I need to do this by code.

    Thanks,

    J. Cloquell

     

    But, is there any way to 'reopen' the toolbar




    Tuesday, June 14, 2011 2:08 PM

Answers

  • Yes, you need to hold a reference to the toolwindow (EnvDTE.Window) at class level and call toolWindow.Visible = true when you want to make it visible.

    The sample that provided creates a toolbar button that when clicked, shows a toolwindow. The user can close it, but if the user clicks the toolbar button again, it shows it again. Did you try it (before adding your own modifications)?


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    • Marked as answer by jcloquell Tuesday, June 21, 2011 4:10 PM
    Thursday, June 16, 2011 9:16 PM
  • Ok. I have discovered the reason because my ToolWindow remains not visible. I put this.toolWindow.Visible = true inside the Window_Showing event and this event, at the end of his execution, puts this variable to false!

    The solutión, put again the Visible property to true at the Window_Showing event.

     

    Greetings

    • Marked as answer by jcloquell Tuesday, June 21, 2011 4:13 PM
    Tuesday, June 21, 2011 4:13 PM

All replies

  • See how to to this in my article:

    HOWTO: Create a dockable toolwindow from a Visual Studio .NET add-in

    http://www.mztools.com/articles/2006/MZ2006007.aspx


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Wednesday, June 15, 2011 5:33 AM
  • Sorry, I have read your article and I tryed something like this:

    void Connect_WindowHidding(Window Window)
    {
    
      Microsoft.Win32.RegistryKey registryKey;
      int myToolWindowVisible;
    
      myToolWindowVisible = TOOLWINDOW_INVISIBLE;
    
      if(NeededToSave)
      {
        AskForSave();
      }
    
      if(this.toolWin.Visible)
      {
         myToolWindowVisible = TOOLWINDOW_VISIBLE;
      }
    
      registryKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"Software\Microsoft.DocExplorer.MyToolWindow");
      registryKey.SetValue("MyToolWindowVisible", myToolWindowVisible);
      registryKey.Close(); 
    
    
    }

    Note: AskForSave, changes the toolWin.Visible atributte to true by the way of executing:  this.applicationObject.ExecuteCommand("MyAddinDE2.Connect.MyAddinDE2");

    But my ToolWindow it's not visible at the end.

    I don't understand why it's needed to insert at the registry this entry. And when? At any change of the toolWin.Visible atributte?

    How it's used the registry entry to show the toolWindow?

    If something it's not clare, please ask me.

    Thanks.


     

    Wednesday, June 15, 2011 10:49 AM
  • Can you re-think your design? It is already quite rare for a toolwindow to request to save changes (AFAIK, no built-in VS toolwindow does this), but definitely t is not a good design to make the window visible again when the user has made it not visible by closing it. 

    Anyway the registry entry should not be used there, only when the add-in is unloaded or loaded, and it is used to persist the visibility state between VS sessions


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Wednesday, June 15, 2011 9:36 PM
  • Thanks, but is there any way to make a toolWindow visible after the close operation?

    It's rare, I know, but i need to do this because my toolWindow contains an editor an it's important to save the changes.

    Thanks again.

    J.Cloquell

    Thursday, June 16, 2011 8:16 AM
  • Yes, you need to hold a reference to the toolwindow (EnvDTE.Window) at class level and call toolWindow.Visible = true when you want to make it visible.

    The sample that provided creates a toolbar button that when clicked, shows a toolwindow. The user can close it, but if the user clicks the toolbar button again, it shows it again. Did you try it (before adding your own modifications)?


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    • Marked as answer by jcloquell Tuesday, June 21, 2011 4:10 PM
    Thursday, June 16, 2011 9:16 PM
  • Yes, I have tried with it. If I use the toolbar button, I can reopen at any time my ToolWindow but I have tried with this.toolWindow.Visible = true in my Window_Showing event and the toolWindow remains not visible (I hold a reference at class level). 
    It's only needed to have the Visible property to true?

    It's strange because for me it doesn't work.


    Monday, June 20, 2011 7:19 AM
  • Ok. I have discovered the reason because my ToolWindow remains not visible. I put this.toolWindow.Visible = true inside the Window_Showing event and this event, at the end of his execution, puts this variable to false!

    The solutión, put again the Visible property to true at the Window_Showing event.

     

    Greetings

    • Marked as answer by jcloquell Tuesday, June 21, 2011 4:13 PM
    Tuesday, June 21, 2011 4:13 PM