none
VSX getting the selected file and using IVsSingleFileGenerator

    Question

  • Hi

    I am trying to add several new functions to a package i developed for our team. One of these functions is to create a new file based on the file selected in the solution explorer and the menu option selected. I have created my dynamic menu items that are on the solution explorer and it looks like i need to use IVsSingleFileGenerator as shown in this sample.

    The trouble i am having is getting the file i have selected and either reading it or passing it into a single file generator. I would rather generate the file from this context menu than from a custom tool action

    Any help would be appreciated


    Friday, April 01, 2011 10:40 AM

Answers

All replies

  • Looks like this will get me the path of the file

    UIHierarchy solutionExplorer = _applicationObject.ToolWindows.SolutionExplorer;
    
              var items = solutionExplorer.SelectedItems as Array;
    
              if (items == null || items.Length != 2)
    
              {
    
                return;
    
              }
    
              String strFile1 = String.Empty;
    
              UIHierarchyItem item1 = items.GetValue(0) as UIHierarchyItem;
    
              foreach (UIHierarchyItem hierarchyItem in items)
    
              {
    
                ProjectItem prjItem = hierarchyItem.Object as ProjectItem;
    
                string prjPath = prjItem.Properties.Item("FullPath").Value.ToString();
    
              }
    

    which i can then use to pass into the generate funtion of the ivs single file generator.

     

    Is this the best approach?

    Friday, April 01, 2011 2:21 PM
  • Hi kerrance76,

     

    Thanks for your post.

    As far as I know, this sample is use to generate classes from xsd files,

    if that is what you expected,

    you can pass in he file's full path and xml content into Generate() method.

    if not, could you please let me know your scenario and I can help look for some workarounds.

     


    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.

    Monday, April 04, 2011 9:31 AM
  • Hi.

    The idea is that i will have a template xml file;


    <?
    xml version="1.0" encoding="utf-8"?> <Class Name=""> <Property Name="" Type="" Default="" StringID=""/> </Class>

     

    This will then be populated depending on the requirements


    <
    Class Name="TestClass"> <Property Name="Prop1" Type="String" Default="" StringID="1"/> <Property Name="Prop2" Type="bool" Default="False" StringID="2"/> </Class>

     

    I would then like to generate a class file from these settings along the lines of.

     

    [Serializable]
    public class TestClass
    {
    
     private string _prop1 = "";
     private bool _prop2 = false;
    
     public String Prop1
     {
     get { return _prop1; }
     set { _prop1 = value; }
     }
    
     public int Prop1Tag
     {
     get { return (int)StringIDs.Prop1Tag; }
     }
    
     public bool Prop2
     {
     get { return _prop2; }
     set { _prop2 = value; }
     }
    
     public int Prop2Tag
     {
     get { return (int)StringIDs.Prop2Tag; }
     }
    
     enum StringIDs
     {
     Prop1StringID = 1,
     Prop2StringID = 2
     }
    }
    

     

    This is of course only a very basic sample. I have added a context menu item that only displays on our template file, when we then select this option the class is generated and added to the solution. As far as I can see i need to read the xml file and then parse it, generate the new class and add it to the solution. I thought I would be able to do this with the single file generator.


    Kerry


    Monday, April 04, 2011 10:21 AM
  • Hi Kerry,

     

    Thanks for your post.

    I'm not sure if you issue is resovled or not.

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

    Meanwhile, you can download the ironpython sample

    http://code.msdn.microsoft.com/IPyIntegration

    It is a complete sample includes singlefilegenerator.


    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 Victor_Chen Monday, April 11, 2011 9:48 AM
    Tuesday, April 05, 2011 8:39 AM
  • Hi.

    No at the moment I havent resolved my issue as I wasnt sure wether I should be using the single file generator any more. After a quick look at the sample you linked to it may be just what i am looking for.

    Thanks

    Tuesday, April 05, 2011 9:31 AM
  • Hi Kerrance76,

     

    I'm going to close this issue, if you have further questions, be free to let me know.


    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.

    Monday, April 11, 2011 9:48 AM