Last week at the PDC was Oslo's big coming out party. If you haven't heard Oslo is a new set of technologies from Microsoft relating to model-driven development. The three main parts of Oslo are:
1) A language: The M language is a language for writing stuff down. You write down the things you need to drive your application. The things could be application configuration data, or application specific data, or data which is actually your application. How exactly you use M is largely up to you. There is also MGrammar which I'll be covering more in future posts.
2) A repository: There needs to be a place to hold all this data, so Oslo has a SQL Server 2008 database named the "Repository". The Repository is full of models, both models that Microsoft has created, as well as models you might want to create. Microsoft has created a large number of models that they think will be useful for us as developers. Things like endpoints, service contracts, workflows, as well as other data our applications will need. You can choose to put your models made in M into the Repository, or you can put your models into your own database. The choice I think will largely be based on whether you want your models to be able interact with Microsoft's models, and whether the Repository becomes your main application database.
3) A visual tool: To view the models in the Repository they've create a visual tool named "Quadrant" (this is a code-name hence the quotes). "Quadrant" is a tool for viewing models for those of you who are visual/spatial people. Some people like text - so they have M. Some people like drawings - so they Quadrant. Quadrant is a highly customizable general purpose data viewing and editing tool.
Those are the three "main" pieces, but there are other pieces as well. To create a great editing experience for M, the Oslo team built a tool called IntelliPad (or IPad) for short. IPad is a customizable text editor that has support for the M language. Here is a screenshot of IPad in action:
In this picture I'm using M to generate "Reach SQL" which is SQL that isn't limited to the Repository. The test.m buffer is in "MMode" which means there are additional commands available that wouldn't be available if I where editing any other kind of text file. The other buffer is generated from the M in the test.m buffer, and I made this happen by going to the MMode menu and selecting "Reach SQL".
If you want to see Repository SQL you can use the MMode menu and select "Repository SQL".
In this case I am beginning a model to represent a blog. I've created an M type named BlogEntryType, and then an extent (the name for storage space in M) named BlogEntry. You can see on the right that the M will generate a table named BlogEntry with the appropriate columns. As Scott points out one of the nice features of this system for developers even if you aren't using the Repository is that you will be able to check-in the m file to source control and doing all the usual source control type things on it.
That's all a brief introduction to Oslo and IPad. The purpose of this post (indicated by the title) is that IPad is super customizable. When I was at the last Oslo "SDR" like event a few weeks ago, I asked for a feature in IPad - the "Open Folder in Windows Explorer" feature from Visual Studio 2008 which I find to be the most useful simple feature in Visual Studio I think for all time.
Chris Sells (who is a PM on Oslo) said "You add it". Which is a very typical Chris response, but at least in this case it is possible since IPad's whole system of commands is totally customizable.
Harry will happy that this is forcing me to learn about IronPython, although I have to admit I was able to make it work without much actual learning of the IronPython language.
Almost all of IPad's commands are actually written in Python. These commands are registered with IPad when IPad first starts, and the commands are implemented by manipulating the interface to IPad's object model.
The main command file is Commands.py which is in the Oslo install directory under Bin\Intellipad\Settings. It contains almost all of the standard mode commands. To add a new command, all I had to do was add a new .py file to that directory. IPad seems to search at least that directory for .py files and loads up all the commands found inside into the environment.
Each command has at least one IronPython function, which represents the "Execution" of method of the command. This function is annotated with an "attribute" (which I think may be added by the IPad team, I can't seem to find any reference to attribute support in IronPython - Harry?).
The Metadata.CommandExecuted "attribute" tells IPad this is a definition of a command. It has three parameters, the IPad object that should execute the command, the name of the command, and the keyboard shortcut (which is optional). Here is my CommandExecuted function defintion from the MyCommands.py file I created in the settings directory:
import sys import System import Microsoft import Common @Metadata.CommandExecuted('{Microsoft.Intellipad}BufferView', '{Microsoft.Intellipad}OpenExplorerAtBuffer', 'Ctrl+B') def OpenExplorerAtBufferExecute(target, sender, args): from System.Diagnostics import Process from System.IO import Path, File exists = False file = sender.Buffer.Uri.AbsolutePath exists = File.Exists(file) if exists: Process.Start(Path.GetDirectoryName(file))
The first argument of the CommandExecuted can either be (as far as I can tell so far) the BufferView object which represents the current buffer, or the HostWindow object which seems to represent IPad itself. OpenExplorerAtBuffer is the name I gave this command, and Ctrl+B is the keyboard short cut. The code is pretty easy, I just find the path of the buffer and if it exists (since a buffer in IPad might not have been saved yet) I just call Process.Start at the directory to open explorer.
Each command can optionally have a function that IPad will call to find out if the command should even be available at a particular time, so I added that one as well:
@Metadata.CommandCanExecute('{Microsoft.Intellipad}BufferView', '{Microsoft.Intellipad}OpenExplorerAtBuffer') def CanOpenExplorerAtBuffer(target, sender, args): from System.IO import Path, File file = sender.Buffer.Uri.AbsolutePath args.CanExecute = File.Exists(file)
The "CommandCanExecute" function just checks to see if the file exists and returns the args.CanExecute as true or false, if true the command is active, if false the command is not.
The next step was to add my command to a menu, since I tend to be a mouse/keyboard developer (sometimes I use the mouse at odd times - just the way my hands work I guess). To add a command to IPad at all times, I edited the MenuBar.xcml file which is in the Intellipad\Settings\VisualStudio folder, and drives the default menu (other IPad "Modes" can have additional menu items merged, as the MMode mode does with the MMode menu). I added a new item under the File menu:
<act:Exports xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:act='clr-namespace:System.ComponentModel.Activation;assembly=Activation' xmlns:mis='clr-namespace:Microsoft.Intellipad.Shell;assembly=Microsoft.Intellipad.Framework' xmlns:mi='clr-namespace:Microsoft.Intellipad;assembly=Microsoft.Intellipad.Core' xmlns:mih='clr-namespace:Microsoft.Intellipad.Host;assembly=Microsoft.Intellipad.Core' > <act:Export Name='{}{Microsoft.Intellipad}MenuBar' xmlns:mti='Microsoft.Intellipad' > <Menu> <Menu.Resources> <mi:FileNameConverter x:Key='fileNameConverter' /> <mi:ModeToMenuItemConverter x:Key='modeToMenuItemConverter' /> </Menu.Resources> <MenuItem Header='_File'> <MenuItem Header='_New' Command='{mis:NamedCommand Name=mti:New}' /> <MenuItem Header='_Open' Command='{mis:NamedCommand Name=mti:Open}' /> <MenuItem Header='Open _Project' Command='{mis:NamedCommand Name=mti:OpenProject}' /> <MenuItem Header='_Save' Command='{mis:NamedCommand Name=mti:Save}' /> <MenuItem Header='Save _As' Command='{mis:NamedCommand Name=mti:SaveAs}' /> <MenuItem Header='_Close Buffer' Command='{mis:NamedCommand Name=mti:CloseBuffer}' /> <MenuItem Header='Open _Buffer Folder In Explorer' Command='{mis:NamedCommand Name=mti:OpenExplorerAtBuffer}' /> <Separator /> <!-- rest of file omitted--> </act:Exports>
So adding the command allowed me to to Ctrl+B from any buffer and get the windows explorer folder of the current buffer to open. Changing the MenuBar.xcml file enabled me to get the menu item on the File Menu:
All in all I find IPad to be a really interesting and powerful text editor - but being able to customize the menus and commands with such ease I think is just another example of the cool work the Oslo team is doing for us as developers.
Comments [1]
Remember Me