Tag Archives: C#

PowerPoint LaTeX

Hey everybody :-)
I only wanted to point out that I've uploaded a new and improved version of PowerPoint LaTeX at http://code.google.com/p/powerpointtools/ - it now supports MiKTeX \o/

I've also finally added a project page for it to this blog.
More updates might follow soon if I find enough spare time :-)
Cheers,
Andreas

Extending Java and Javac

Today I want to write about something I've been working ages ago - specifically in March I wanted to see if I can extend a Java compiler to support LINQ´ expressions, too.

I probably spend more time on finding a good open-source compiler to experiment with than I later spent on trying things out, so let me share my preferred source with you: http://openjdk.java.net/ is a good address to start with.
More specifically http://openjdk.java.net/groups/compiler/ contains some valuable information about the way the compiler works.
A nice thing is that there is a branch that has added support for ANTLR which makes added language a tad bit easier since you get to change a grammar file instead of tweaking hand-written lexers and parsers. More info about it can be found at http://openjdk.java.net/projects/compiler-grammar/.
You can download the source code from http://hg.openjdk.java.net/ - don't follow the link to http://hg.openjdk.java.net/compiler-grammar/compiler-grammar, that one will only allow you to download part of the branch´.

I didn't come around to add support for LINQ in the end, but to get known to the compiler and the ANTLR grammer, I added support for the var keyword as known from C#, which allows for automatic type deduction and for anonymous objects (again using the C# syntax). Thus my changes allowed for the following to compile and execute correctly:

public class Test {
	public  static void main(String[] args) {
		// automatic type deduction
		var t = Math.atan(1);
		System.out.println( t );

		// anonymous type
		var i = new { Amount = 108, message = "hello" };
		System.out.println( i.Amount );
	}
}

Read more »

PowerPoint Tools

I've finally managed to upload a version of my PowerPoint LaTeX add-in for PowerPoint 2007.

I'm just going to post a short Vimeo video here that shows how inline formulas work (the main feature):

I've tried to work on the add-in during my spring vacation but somehow I have instead spent all my time watching four seasons of House M.D. (which was totally worth it though :-) ).

There are still some features like support for MikeTeX, code clean-ups, small bugfixes and a preference window that I should work on, but I don't plan on selling it, so I don't really care if it's still somewhat work in progress.
I'm going to continue working on it when I have to use PowerPoint again.

You can check it out (and another add-in dubbed Language Painter that I wrote to fix some annoyances when writing presentations in languages different from your keyboard layout) at http://code.google.com/p/powerpointtools/.


Read more »

Visual TorqueScript #3.75

Another minor update, which I'm mostly using to publish a useful patch.
I've forgotten to mention that I've already created a custom settings page for my Visual TorqueScript projects. Yesterday night (before going to bed) I decided to add a configuration dependent page, too.
As you'll see it's very Torsion-esque, which is intentional and I plan to support .torsion files directly (as project files) later-on.

The main reason is that Torsion rocks and there is no reason to have yet another project file format for TorqueScript projects.

I hope that it will also be an incentive for people to give my plugin a try (if I ever release it).

A few notes (programatically so to speak :D ):

  • Again the managed project framework is awesome and once you figure out where to look for things you'll certainly find eternal bliss, too..
  • I generally derive from SettingsPage directly, because I don't want any of the regular faff in my project.
  • Don't forget to publish your pages via ProvideObject (or ProvideClass from my previous post)
  • You don't need to create your own GUIDs for everything. Classses are automatically provided with a unique GUID - try it and access typeof(SomeClassWithoutGuidAttribute).GUID and it'll still work.
    (If I said something wrong, please correct me..)
  • SettingsPage has an IsDirty property which you have to set, when a property is changed (to update the Apply button state).
    It results in pretty ugly copy'n'paste code, because you can't use default property accessors anymore.
    To fix this I spent an hour or two and I've come up with an elegant (in my opinion) patch to fix the issue:

    Index: ProjectBase/SettingsPage.cs
    ===================================================================
    --- ProjectBase/SettingsPage.cs	(revision 10)
    +++ ProjectBase/SettingsPage.cs	(working copy)
    @@ -27,7 +27,26 @@
    
     namespace Microsoft.VisualStudio.Package
     {
    +    // Added to make it easier to edit pages [9/10/2008 Andreas]
    
    +    class SettingsPagePropertyDescriptor : DesignPropertyDescriptor
    +    {
    +        public SettingsPagePropertyDescriptor(PropertyDescriptor prop)
    +            : base(prop)
    +        {
    +        }
    +
    +        public override void SetValue(object component, object value)
    +        {
    +            if (component is SettingsPage)
    +            {
    +                SettingsPage page = (SettingsPage)component;
    +                page.IsDirty = true;
    +            }
    +            base.SetValue(component, value);
    +        }
    +    }
    +
         /// <summary>
         /// The base class for property pages.
         /// </summary>
    @@ -78,7 +97,7 @@
                 get { return this.grid; }
             }
    
    -        protected bool IsDirty
    +        protected internal bool IsDirty
             {
                 get
                 {
    @@ -203,6 +222,13 @@
    
             #endregion
    
    +        #region overriden methods.
    +        public override DesignPropertyDescriptor CreateDesignPropertyDescriptor(PropertyDescriptor propertyDescriptor)
    +        {
    +            return new SettingsPagePropertyDescriptor(propertyDescriptor);
    +        }
    +        #endregion
    +
             #region IPropertyPage methods.
             public virtual void Activate(IntPtr parent, RECT[] pRect, int bModal)
             {
    @@ -410,6 +436,8 @@
                     try
                     {
                         Marshal.WriteIntPtr(ppUnk, p);
    +                    // Reset IsDirty before rebinding all properties [9/10/2008 Andreas]
    +                    IsDirty = false;
                         this.BindProperties();
                         // BUGBUG -- this is really bad casting a pointer to "int"...
                         this.grid.SetSelectedObjects(1, ppUnk.ToInt32());
    

    It also contains a one-line fix to reset IsDirty when reloading the page or switching configurations (ie. any time the properties are reset to their old value).

Cheers,
Black

Visual TorqueScript #3.5

Small update: After hours and hours of error and trial (and implementing a few interfaces by using Copy&Paste wisely), I've finally managed to get Visual Studio to load my debug engine.

This looks gorgeous, doesn't it?

A few notes for those interested in writing Debug Engines:

  • See my previous post for the ProvideDebugEngine helper attribute
  • There exists a really nice managed debug engine example, that isn't part of the SDK.
    You can find it here.
  • You are required to set a PortSupplier, even if the documentation says otherwise (this was a major source of frustration in the last hour).
  • Since ProvideDebugEngine requires a Type for PortSupplier, I've been using this stub class:
        /// <summary>
        /// The class is just a stub for use with ProvideDebugEngine.
        /// It seems it's mandatory to provide a PortSupplier GUID with a debug engine.
        /// </summary>
        [Guid("708C1ECA-FF48-11D2-904F-00C04FA302A1")]
        internal sealed class DefaultPortSupplier
        {
        }
    
  • I've also added another attribute (ProvideClass) for convenience to register a class directly (it's the same as using ProvideObject on the current class type).
    Since the code is quite short, I'm going to supply it directly:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Microsoft.VisualStudio.Shell
    {
        /// <summary>
        /// This is just a wrapper for ProvideObject to provide the class the attribute is used on
        /// </summary>
        [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
        class ProvideClass : RegistrationAttribute
        {
            public override void Register(RegistrationAttribute.RegistrationContext context)
            {
                ProvideObjectAttribute objectProvider = new ProvideObjectAttribute(context.ComponentType);
                objectProvider.Register(context);
            }
    
            public override void Unregister(RegistrationAttribute.RegistrationContext context)
            {
                ProvideObjectAttribute objectProvider = new ProvideObjectAttribute(context.ComponentType);
                objectProvider.Unregister(context);
            }
        }
    }
    

And yes, I love the tag :-)
Cheers,
Andreas

Visual TorqueScript #3

I've spent a part of the last two days cursing the managed project framework (it's a bliss, too, and I'm thankful that it's available at the same time), because it is too different from what I need, and I'll probably end up rewriting most of it to use different approaches and not use MSBuild anymore.

I've spent more time, however, on reading up on Debug Engines in Visual Studio 2008 and I've started work on my own yesterday. To be honest, I haven't really started to work on it, I've rather spent the evening and most of today figuring out how to register a debug engine at all and write attributes for that, so that it becomes an automated process, just like it's done for Packages and Language Services by using attributes like ProvidePackage and ProvideLanguageService.

The code has turned out pretty nicely and now you can use the attributes like this, for example, to register a debg engine:

    [ProvideDebugEngine("{5887F58F-3B7F-401d-95CE-A7BADA1E4D7D}", "TorqueScript Debug Engine",
        Attach = true, ProgramProvider = typeof(VSTorqueScript_DebugEngine))]
    [ProvideIncompatibleEngineInfo( "{5887F58F-3B7F-401d-95CE-A7BADA1E4D7A}" )]
    [ProvideIncompatibleEngineInfo( "{5887F58F-3B7F-401d-95CE-A7BADA1E4D7F}" )]
    [ProvideAutoSelectIncompatibleEngineInfo( "{5887F58F-3B7F-401d-95CE-A7BADA1E4D7F}" )]
    [ProvideObject(VSTorqueScript_DebugEngine)
    [Guid(GuidList.guidVSTorqueScript_DebugEngineString)]
    public sealed class VSTorqueScript_DebugEngine
...

In my opinion this looks pretty neat - and it works.. \o/
I really love the whole concept of attributes and the way they make coding a lot easier (even though it's hard to find information about useful attributes, as you only find out they exist when you stumble over them or write them on your own).

You can find the code here: http://www.icculus.org/~black/weblog/VS_DebugEngine/

A few notes:

  • The implementation was done making heavy use of copy&paste and quick replace (I copied the table containing the help description of the metrics into the source file and reworked it using RE magic to look the way it does now)
  • At first I used Type.GetProperties to enumerate all properties and write them out into the registry but that bloated the resulting registry entry, of course. Because of this I later switched to the HashTable approach that I first found in SDK's implementation of ProvideLanguageServiceAttribute.
  • The restriction that all attribute parameters must be constant expressions forced me to make a few changes - at first I had Guid properties and for the incompatible engines list I expected a Guid[], which didn't work. I changed the Guids to Strings and added the Provide*EngineInfo attributes instead of the incompatible engines list (same for the autoselect one, of course).
  • The Provide*EngineInfo attributes contained their registry code at first. This was ugly because they kind of required a ProvideDebugEngine attribute to exist, too, which I couldn't enforce. Later I changed them to be pure value holders and moved all registry code into ProvideDebugEngine.
    Now nothing happens if you don't supply a ProvideDebugEngine attribute, too.

Now I'll try to start to work on the actual Debug Engine for TorqueScript.

Cheers,
Andreas