locked
Add-In Solution Explorer how to force file icon status update RRS feed

  • Question

  • Hi,

    In my add-in i generate some CS, C++ files from IDL files, and i place generated files in the project, when Proejct is clean, the generated files are remove from disk but not from the project.

    If i close the project after clean, when i next open the project, the solution explorer show an icon for this files that doesn't exit on disk, with a red mark, when my add-in receive the project opened event, it generate the missing files, but the icon with the red mark doesn't automatically change, it change only when the user clicks the file, or when the user.

    Is there a way that my add-in could inform solution explorer to update the icons, once my add-in has regenerated the missing files?

     

    Thanks

    Tuesday, February 8, 2011 4:05 PM

Answers

  • Hi Pepone,

     

    Thanks for your post.

    To update the files' icon, you can try to unload and reload project in the addin,

    the following blog talks about how to unload/reload project with

    DTE.ExecuteCommand()

    http://blogs.msdn.com/b/jjameson/archive/2009/03/11/visual-studio-macros-for-unloading-reloading-projects.aspx

    you can populate them to your addin.

    If you have further questions, be free to let me know.

     

     

    Best Regards,

    Ziwei Chen

     


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by pepone.onrez Friday, February 11, 2011 4:50 PM
    Thursday, February 10, 2011 3:23 AM
  • I posted some managed code that can select a project by name here, that may help. As for what you have above, specifically

    CComQIPtr<IVsUIHierarchy> spUIHierarchy(pHierarchy);

    QI in native code is roughly an as cast in managed code, so

    IVsUIHierarchy spUIHierarchy = pHierarch as IVsUISHierarchy;

    the EXPANDFLAGS come from this enum

    You can call ExpandItem via the interop interface of IVsUIHierarchy

    You don't need to call Release (the CLR will do this for the underlying COM object).


    Ryan

    • Marked as answer by pepone.onrez Friday, February 11, 2011 4:51 PM
    Thursday, February 10, 2011 11:08 PM
  • Commands in VS can have state that is dependent on activation, specifically the Refresh command will only have a handler in the command route when the solution explorer window is active. The code I linked was simply a wrapper that selects a project in the solution explorer. If you have to refresh to update the state then you can't do it if the solution explorer is not the active window it appears (note: I didn't verify this, I am just going off what you have said). Changing activation/selection can be made mostly invisible if you remember which window was active and which node was selected before you run your code and simply restore this state afterwards.

    Ryan

    • Marked as answer by pepone.onrez Friday, February 11, 2011 4:51 PM
    Friday, February 11, 2011 4:21 PM

All replies

  • Hi Pepone,

     

    Thanks for your post.

    To update the files' icon, you can try to unload and reload project in the addin,

    the following blog talks about how to unload/reload project with

    DTE.ExecuteCommand()

    http://blogs.msdn.com/b/jjameson/archive/2009/03/11/visual-studio-macros-for-unloading-reloading-projects.aspx

    you can populate them to your addin.

    If you have further questions, be free to let me know.

     

     

    Best Regards,

    Ziwei Chen

     


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by pepone.onrez Friday, February 11, 2011 4:50 PM
    Thursday, February 10, 2011 3:23 AM
  • Hi Victor,

    In my case will be better if i can execute the Solution Explorer "Refresh" command. But i don't now how to execute this command from my add-in, i have enabled VSIP logging, but the Canonical name and Localized name aren't set, i have the Guid, GuidID and CmdID, is posible to execute the command knowing that values, as far as i know, DTE.ExecuteCommand  requires the Canonical name.

    Regards,

    Jose

    • Marked as answer by pepone.onrez Thursday, February 10, 2011 4:17 PM
    • Unmarked as answer by pepone.onrez Thursday, February 10, 2011 6:43 PM
    Thursday, February 10, 2011 2:34 PM
  • Hi

     

    I have found how to call the command by Guid CmdId in the following mztools how to

    http://www.mztools.com/articles/2008/MZ2008013.aspx

     

    But i not sure why the Solution Explorer refresh command isAvailable is always false, so i cannot call it, any ideas?

     

    Regards,

    Jose

    • Marked as answer by pepone.onrez Thursday, February 10, 2011 4:17 PM
    • Unmarked as answer by pepone.onrez Thursday, February 10, 2011 6:43 PM
    Thursday, February 10, 2011 4:05 PM
  • I have found the issue, i was calling the command inside the BuildEvents OnBuildBegin event, and seems that at this point the command is disabled, if i call it from BuildEvents OnBuildDone it works.
    • Marked as answer by pepone.onrez Thursday, February 10, 2011 4:17 PM
    • Unmarked as answer by pepone.onrez Thursday, February 10, 2011 6:43 PM
    Thursday, February 10, 2011 4:15 PM
  • To get this working i need to be able to change the selected project in solution explorer, I have search the forum on how to do that and i have found the following code

     

    CComPtr<IVsUIShell> spUiShell = this->GetVsSiteCache().GetCachedService<IVsUIShell, SID_SVsUIShell>();
      CComPtr<IVsSolution> spSolution;
      CComPtr<IVsWindowFrame> spIVsWindowFrame;
      CComQIPtr<IVsUIHierarchyWindow> spUIHierWin;
    
      this->GetVsSiteCache().QueryCachedService<IVsSolution, SID_SVsSolution>(&spSolution);
    
      // Get IVsUIHierarchyWindow from Solution Explorer toolwindow.
      if (spUiShell && SUCCEEDED(spUiShell->FindToolWindow(FTW_fForceCreate, GUID_SolutionExplorer, 
       &spIVsWindowFrame)))
      {
       CComVariant varDocView;
       if (SUCCEEDED(spIVsWindowFrame->GetProperty(VSFPROPID_DocView, &varDocView)))
         spUIHierWin = varDocView.punkVal;
      }
      
      if (spSolution && spUIHierWin)
      {
       CComPtr<IEnumHierarchies> spHierarchies;
       spSolution->GetProjectEnum(EPF_UNLOADEDINSOLUTION, GUID_NULL, &spHierarchies);
    
       // force selection of each unloaded project in solution explorer
       IVsHierarchy* pHierarchy;
       BOOL bFirstItem = TRUE;
       while (spHierarchies->Next(1, &pHierarchy, NULL) == S_OK)
       {
         CComQIPtr<IVsUIHierarchy> spUIHierarchy(pHierarchy);
         EXPANDFLAGS expandFlags = bFirstItem ? EXPF_SelectItem : EXPF_AddSelectItem;
         spUIHierWin->ExpandItem(spUIHierarchy, VSITEMID_ROOT, expandFlags);
         pHierarchy->Release();
         bFirstItem = FALSE;
       }
    
       // execute the Project.ReloadProject command
       spUiShell->PostExecCommand(&CLSID_StandardCommandSet97, cmdidReloadProject, 0, NULL);
    

    Can anybody help me to translate that to C#, in the context of an add-in

     

     I specially usure about that portion of the code

     

    CComQIPtr<IVsUIHierarchy> spUIHierarchy(pHierarchy);
    EXPANDFLAGS expandFlags = bFirstItem ? EXPF_SelectItem : EXPF_AddSelectItem;
    spUIHierWin->ExpandItem(spUIHierarchy, VSITEMID_ROOT, expandFlags);
    pHierarchy->Release();
    bFirstItem = FALSE;
    
    

    Regards,

    Jose

    Thursday, February 10, 2011 8:58 PM
  • Hi Pepone,

     

    Thanks for your post.

    To update the files' icon, you can try to unload and reload project in the addin,

    the following blog talks about how to unload/reload project with

    DTE.ExecuteCommand()

    http://blogs.msdn.com/b/jjameson/archive/2009/03/11/visual-studio-macros-for-unloading-reloading-projects.aspx

    you can populate them to your addin.

    If you have further questions, be free to let me know.

     

     

    Best Regards,

    Ziwei Chen

     


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This is what i actually doing and it works, but i will prefer to solve that without need to set SolutionExplorer as active window, that is a bit of pain, any ideas how to implement that without require the SolutionExplorer to be the active window.

    Regards,

    Jose

    Thursday, February 10, 2011 9:54 PM
  • I posted some managed code that can select a project by name here, that may help. As for what you have above, specifically

    CComQIPtr<IVsUIHierarchy> spUIHierarchy(pHierarchy);

    QI in native code is roughly an as cast in managed code, so

    IVsUIHierarchy spUIHierarchy = pHierarch as IVsUISHierarchy;

    the EXPANDFLAGS come from this enum

    You can call ExpandItem via the interop interface of IVsUIHierarchy

    You don't need to call Release (the CLR will do this for the underlying COM object).


    Ryan

    • Marked as answer by pepone.onrez Friday, February 11, 2011 4:51 PM
    Thursday, February 10, 2011 11:08 PM
  • I have tried the code you link, and i found the same problem, the Solution Explorer need to be active for it to work, and this isn't nice for usability, i don't want to change the user active window, and if possible will be better to not change the user selection , did you have any idea of how can i refresh the icon state, without change the current selection.

     

    Friday, February 11, 2011 3:58 PM
  • Commands in VS can have state that is dependent on activation, specifically the Refresh command will only have a handler in the command route when the solution explorer window is active. The code I linked was simply a wrapper that selects a project in the solution explorer. If you have to refresh to update the state then you can't do it if the solution explorer is not the active window it appears (note: I didn't verify this, I am just going off what you have said). Changing activation/selection can be made mostly invisible if you remember which window was active and which node was selected before you run your code and simply restore this state afterwards.

    Ryan

    • Marked as answer by pepone.onrez Friday, February 11, 2011 4:51 PM
    Friday, February 11, 2011 4:21 PM