SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

How To Write an Item Template Wizard

Last post 02-07-2008 10:18 PM by rrogers. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 02-03-2008 1:37 PM

    How To Write an Item Template Wizard

    Hello,

    I have created a new Item Template for use in my projects.  I would like to create a Wizard for the Template to prompt the user for some parameters and then have the substitutions made in the generated output.  I have looked high and low and the only references I can find are for VisualStudio using the IDE IWizard interface.  So my question is how do I wrtite a template wizard as I described for SharpDevelop templates?

    Thanks

    Randy

  • 02-03-2008 7:55 PM In reply to

    Re: How To Write an Item Template Wizard

    The simplest way is to take a look at the Unit Test template. It does not use a wizard but allows you to customise various properties before the file is created.

    If you need a wizard there does seem to be some code to support this in file and project templates but I'm not sure if this works since none of the SharpDevelop templates currently define any wizards. How it seems to work is you add a <Wizard> element to your template and specify a tree path to a set of DialogPanels you have defined in a custom addin. In the addin you implement a set of classes that are IWizardPanels to give you your wizard dialogs.  At the moment there's no examples of this and I'm not sure if the code still works. If you can't do the same as the Unit Test template and want a wizard I'll see if I can create an example.

  • 02-04-2008 1:28 PM In reply to

    Re: How To Write an Item Template Wizard

    Hi Matt,

    Thanks for the quick response.  I have looked at the UnitTest template and it uses <Properties>.  I did try this in my template but the only data type I could use was system.boolean which is not sufficient for what I would like to do.  If you try something other than boolean I get some error about not being in the dictionary which made no sense to me as I am pretty green in this environment.  Does SharpDevelop or ICSharp have an IWizard interface?  I am new to this and can only find examples that are written for visual studio.  If I had a working example that prompted the user for a string and then substituted the users response for a symbol in the template I would be away to the races.

     I am surprised that no one had attemplted this as it seems like a very powerful way to leverage the templates.  In my case, I have a file browsing template that only needs a few things set differently and it would be 95% of what i need and thus increasing productivity.

    Thanks for your assistance

    Randy

  • 02-04-2008 11:43 PM In reply to

    Re: How To Write an Item Template Wizard

    I'm assuming you would like to be able to specify a custom string for the template. It doesn't look like that is supported. Only boolean and enums are.

    Having some way to specify a custom string in the template like we do with the Unit Test template is probably going to be much easier to implement than having to implement a wizard. Supporting strings will involve changing SharpDevelop so this might make it into SharpDevelop 3.0. If you want it in an earlier version it will probably need an addin.

  • 02-05-2008 1:42 PM In reply to

    Re: How To Write an Item Template Wizard

    Hi Matt,

    Thanks again for your interest in my project.  I will try to be a bit clearer on what I would like to be able to do, if possible.  I am actually using a product called clarion# from soft velocity who have licenced the sharpdevelop ide for their use.  So, please ignore any non-c# constructs in my example template.  Lets say I have a template like this:

    <?xml version="1.0"?>
    <Template author="Keystone Computer Resources" version="1.0">
       
        <Config
              name        = "Keystone Update Form"
              icon        = "ClarionNet.File.Form"
              category    = "Clarion.Net"
              subcategory = "${res:Templates.File.Categories.WindowsApplications}"
              defaultname = "Form${Number}.cln"
              language    = "Clarion.Net"/>
        
        <Description>Test</Description>
        <parameters>
         <parameter name="$Param1$" value="" />
         <parameter name="$Param2$" value="" />
        </parameters>
        <Files>
      <File name="${Path}/${FileNameWithoutExtension}.Designer.cln" DependentUpon="${FileName}" language="Clarion.Net">
           <![CDATA[${StandardHeader.Clarion#}
     
     MEMBER('')

     USING(System)
     USING(System.Drawing)
     USING(System.Windows.Forms)
     USING(Keystone.UIControls)
       
     NAMESPACE(${StandardNamespace})

    MyTest PROCEDURE()
      CODE
        MessageBox.Show('$Param1$ + ' ' + '$Param2$')
    </File>
    </Files>
    </Template>

    Given the above template here is what I would like to happen:
    User selects NewItem in the Project pad
    Selected Template (mine) is read and Parameter Array constructed
    Call my assembly so that it has access to the parameter array
    My assembly uses a dialog to prompt the user for Param1 and Param2 values
    User enters 'Hello' and 'World' and presses ok (finish) button.
    Return to SharpDevelop process which should substitute the parameter values for the defined parameters so that the MessageBox statement looks like this in the generated output:
    MessageBox.Show('Hello' + ' ' + 'World')

    I hope that is a bit clearer.  obviously my actual template is much more complex but this gives the basic idea.  So now my question again, is this possible? and, if so, how?

    Kind Regards
    Randy

  • 02-06-2008 9:53 PM In reply to

    Re: How To Write an Item Template Wizard

    The parameters are only defined in the template and you want some way of allowing the user to enter values for them. Plus you're using Clarion.NET so modifying the SharpDevelop code is not an option. Clarion.NET looks like it is based on SharpDevelop 2.x.

    I think you can do what you want with a custom addin providing a Wizard. Taking a look at the SharpDevelop source code it seems that each panel/dialog in your wizard has access to a Properties class (via CustomizationObject) which contains a FileTemplate object. From the FileTemplate you can access the properties defined in your template. So you should be able to allow the user to set values for these properties. You'll probably need to use properties of the form ${PropertyName} in order for them to be overwritten in the template.

    I think there should be a wizard sample available with SharpDevelop so I'll probably create one in the next few days time permitting.c

  • 02-07-2008 12:26 AM In reply to

    Re: How To Write an Item Template Wizard

    Hi Matt,
    Yes Clarion.NET is based on SharpDevelop 2.0.
    A working example would be most beneficial as I am not sure how I would debug one that I might attempt to write from scratch.
    Along the same lines, I created a simple template similar to the one I posted earlier.  Even with the parameter values 'hard-coded' in the template, it does not seem to do the replacements.  In the VS documentation it talks about making a change to the .vstemplate to allow parameter replacement.  I could not find such a file in the SharpDevelop folders on my machine.  Any ideas?
    Thanks
    Randy

  • 02-07-2008 9:24 PM In reply to

    Re: How To Write an Item Template Wizard

    SharpDevelop most likely ignores properties unless they're bools or enums. The VS documentation will not apply to SharpDevelop templates.

    I think the best bet is if I look at creating a working wizard sample based on the template you posted above. You'll have to try it with Clarion.NET.

  • 02-07-2008 10:18 PM In reply to

    Re: How To Write an Item Template Wizard

    Hello Matt,
    Wow that is a great offer.  Thank you very much.
    note I have changed the tag to CustomParameters as I saw that in some vs docs
    also followed $parametername$ naming convention.
    Kind Regards
    Randy

    To simplify testing I am providing a complete template here:

    <?xml version="1.0"?>
    <Template author="Randy Rogers" version="1.0">
       
        <Config
              name        = "Program File"
              icon        = "ClarionNet.File.EmptyFile"
              category    = "Clarion.Net"
              defaultname = "Program${Number}.cln"
              language    = "Clarion.Net"/>
        
        <Description>Create Sample Program File</Description>
       
        <CustomParameters>
         <CustomParameter Name="$param1$" Value="Hello" />
         <CustomParameter Name="$param2$" Value="World!" />
        </CustomParameters>
       
        <Files>
            <File name="${FullName}" language="Clarion.Net"><![CDATA[
       PROGRAM
       NAMESPACE(${StandardNamespace})
       MAP
       END
       CODE
          MESSAGE('${param1}' & ' ' & '${param2}')
    ]]></File>
        </Files>   
       
        <AdditionalOptions/>
    </Template>

Page 1 of 1 (9 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.