UModel IDE plug-ins must implement the IUModelPlugIn interface. The code below shows a simple implementation of this interface. It adds a menu item and a separator (available with UModel) to the Edit menu. Clicking the menu item will display a message box with the text "Hello, World!".
Note: | Since this sample displays a message box, ensure that your C# project also references System.Windows.Forms. To do this, right-click References in Solution Explorer, select Add Reference, and browse for the System.Windows.Forms assembly). |
using System;
using System.Collections.Generic;
using System.Text;
using UModelPlugInLib;
namespace HelloWorldPlugIn
{
public class MyHelloWorldUModelPlugIn : IUModelPlugIn
{
#region IUModelPlugIn Members
public string GetDescription()
{
return "HelloWorldPlugIn;HelloWorldPlugIn demonstrates a simple implementation of an IDE plug-in for UModel";
}
public string GetUIModifications()
{
return "<ConfigurationData>" +
"<Modifications>" +
// add "Hello World..." to Edit menu
"<Modification>" +
"<Action>Add</Action>" +
"<UIElement type=\"MenuItem\">" +
"<ID>1</ID>" +
"<Name>Hello world...</Name>" +
"<Info>My hello world</Info>" +
"<Place>0</Place>" +
"<MenuID>101</MenuID>" +
"<Parent>:Edit</Parent>" +
"</UIElement>" +
"</Modification>" +
// add Separator to Edit menu
"<Modification>" +
"<Action>Add</Action>" +
"<UIElement type=\"MenuItem\">" +
"<ID>0</ID>" +
"<Place>1</Place>" +
"<MenuID>101</MenuID>" +
"<Parent>:Edit</Parent>" +
"</UIElement>" +
"</Modification>" +
// finish modification description
"</Modifications>" +
"</ConfigurationData>";
}
public void OnInitialize(object pUModel)
{
// before processing DDE or batch commands
}
public void OnRunning(object pUModel)
{
// DDE or batch commands are processed; application is fully initialized
}
public void OnShutdown(object pUModel)
{
// application will shutdown; release all unused objects
}
public UModelUpdateAction OnUpdateCommand(int nID, object pUModel)
{
if (nID == 1)
return UModelUpdateAction.UModelUpdateAction_Enable;
return UModelUpdateAction.UModelUpdateAction_Disable;
}
public void OnCommand(int nID, object pUModel)
{
System.Windows.Forms.MessageBox.Show("Hello world!");
}
#endregion
}
}
|