|
Hello World Operation |
Top Previous Next |
|
The Hello World Operation is a minimal operation that can be created with just the following steps:
[VB.NET]
Public Class HelloWorldOperation Inherits OperationBase ... End Class [C#]
public class HelloWorldOperation: OperationBase { ... }
[VB.NET]
Protected Overrides Sub OnInitialize(ByVal operationInfo As OperationInfo)
operationInfo.TargetNetLanguages = NetLanguage.CSharp Or NetLanguage.VisualBasic Or NetLanguage.JSharp operationInfo.TargetProjectItemKinds = ProjectItemKind.SourceCode operationInfo.TargetIDEs = IDE.VSNET Or IDE.Macros
operationInfo.CommandName = "HelloWorldOperation" operationInfo.CommandImageIndex = 59 ' The office button image number operationInfo.CommandAvailability = CommandAvailability.DesignTime Or CommandAvailability.DebugTime
' You can honor the language of the add-in Select Case MyBase.UILanguage
Case UILanguage.Spanish ' In this sample, we will honor only the Spanish language operationInfo.CommandCaption = "Operación Hola mundo..."
Case Else ' Default to English language operationInfo.CommandCaption = "Hello World Operation..."
End Select
' This operation does not use result window operationInfo.ShowResultsCommandName = ""
End Sub [C#]
protected override void OnInitialize(OperationInfo operationInfo) { operationInfo.TargetNetLanguages = NetLanguage.CSharp | NetLanguage.VisualBasic | NetLanguage.JSharp; operationInfo.TargetProjectItemKinds = ProjectItemKind.SourceCode; operationInfo.TargetIDEs = IDE.VSNET | IDE.Macros;
operationInfo.CommandName = "HelloWorldOperation"; operationInfo.CommandImageIndex = 59; // The office button image number operationInfo.CommandAvailability = CommandAvailability.DesignTime | CommandAvailability.DebugTime;
// You can honor the language of the add-in switch (base.UILanguage) { case UILanguage.Spanish: // In this sample, we will honor only the Spanish language operationInfo.CommandCaption = "Operación Hola mundo..."; break;
default: // Default to English language operationInfo.CommandCaption = "Hello World Operation..."; break; }
//This operation does not use result window operationInfo.ShowResultsCommandName = "";
}
[VB.NET]
Protected Overrides Sub OnExecuteOperationInProjectItem( _ ByVal adminOptions As AdminOptionsBase, _ ByVal userOptions As UserOptions, _ ByVal projectItem As EnvDTE.ProjectItem, _ ByVal startEditPoint As EnvDTE.EditPoint, _ ByVal endEditPoint As EnvDTE.EditPoint, _ ByVal designerHost As System.ComponentModel.Design.IDesignerHost, _ ByRef cancel As Boolean)
If MessageBox.Show("Now performing 'Hello World' operation on project item " & _ projectItem.Name, "Hello World Operation", MessageBoxButtons.OKCancel, _ MessageBoxIcon.Information) = DialogResult.Cancel Then
cancel = True
End If
End Sub [C#]
protected override void OnExecuteOperationInProjectItem( AdminOptionsBase adminOptions, UserOptions userOptions, EnvDTE.ProjectItem projectItem, EnvDTE.EditPoint startEditPoint, EnvDTE.EditPoint endEditPoint, System.ComponentModel.Design.IDesignerHost designerHost, ref bool cancel) { if (MessageBox.Show("Now performing 'Hello World' operation on project item " + projectItem.Name, "Hello World Operation", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.Cancel)
cancel = true;
} |