[svn] r6118: AssemblyInfo.cs CtcComponents CtcComponents/Guids.h
CtcComponents/PkgCmd.ctc CtcComponents/Pk...
nazgul
svnadmin at nemerle.org
Sun Feb 12 16:23:36 CET 2006
Log:
New, public version of VS plugin
Author: nazgul
Date: Sun Feb 12 16:23:16 2006
New Revision: 6118
Added:
AssemblyInfo.cs (contents, props changed)
CtcComponents/
CtcComponents/Guids.h (contents, props changed)
CtcComponents/PkgCmd.ctc (contents, props changed)
CtcComponents/PkgCmdID.h (contents, props changed)
NemerleFileNode.cs (contents, props changed)
NemerleLanguage.cs (contents, props changed)
NemerleMenus.cs (contents, props changed)
NemerleProject.cs (contents, props changed)
NemerleProject.csproj (contents, props changed)
NemerleProject.sln (contents, props changed)
ProjectBase/
ProjectBase/Misc/
PropertyPages.cs (contents, props changed)
Resources/
Resources.cs (contents, props changed)
Resources.resources (contents, props changed)
Resources.resx (contents, props changed)
Templates/
Templates/ProjectItems/
Templates/ProjectItems/Class.n (contents, props changed)
Templates/Projects/
Templates/Projects/AssemblyInfo.n (contents, props changed)
Templates/Projects/NemerleApp.nproj (contents, props changed)
Templates/Projects/Program.n (contents, props changed)
TokenProcessor.cs (contents, props changed)
Added: AssemblyInfo.cs
==============================================================================
--- (empty file)
+++ AssemblyInfo.cs Sun Feb 12 16:23:16 2006
@@ -0,0 +1,62 @@
+
+using System;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+//
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+//
+[assembly: AssemblyTitle("Nemerle Language Plugin")]
+[assembly: AssemblyDescription("Nemerle language extensibility package for Microsoft Visual Studio")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("University of Wroclaw")]
+[assembly: AssemblyProduct("Nemerle Language Plugin")]
+[assembly: AssemblyCopyright("")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+//
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+
+[assembly: AssemblyVersion("8.0.*")]
+
+//
+// In order to sign your assembly you must specify a key to use. Refer to the
+// Microsoft .NET Framework documentation for more information on assembly signing.
+//
+// Use the attributes below to control which key is used for signing.
+//
+// Notes:
+// (*) If no key is specified, the assembly is not signed.
+// (*) KeyName refers to a key that has been installed in the Crypto Service
+// Provider (CSP) on your machine. KeyFile refers to a file which contains
+// a key.
+// (*) If the KeyFile and the KeyName values are both specified, the
+// following processing occurs:
+// (1) If the KeyName can be found in the CSP, that key is used.
+// (2) If the KeyName does not exist and the KeyFile does exist, the key
+// in the KeyFile is installed into the CSP and used.
+// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
+// When specifying the KeyFile, the location of the KeyFile should be
+// relative to the project output directory which is
+// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
+// located in the project directory, you would specify the AssemblyKeyFile
+// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
+// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
+// documentation for more information on this.
+//
+[assembly: AssemblyDelaySign(false)]
+[assembly: AssemblyKeyFile("")]
+[assembly: AssemblyKeyName("")]
+
+[assembly: CLSCompliant(false)]
Added: CtcComponents/Guids.h
==============================================================================
--- (empty file)
+++ CtcComponents/Guids.h Sun Feb 12 16:23:16 2006
@@ -0,0 +1,15 @@
+
+//
+// This file is used to define the Guids used to identify the command groups
+// created by the sample.
+//
+
+
+// Guid of this package
+// {090A3C1C-16B5-4190-A25B-DC274A1AE54F}
+#define guidNemerleProjectPkg { 0x90a3c1c, 0x16b5, 0x4190, { 0xa2, 0x5b, 0xdc, 0x27, 0x4a, 0x1a, 0xe5, 0x4f } }
+
+// Guid of the command set containing the command IDs of this package
+// {01AF15E0-B973-481a-8BC1-F3DCDF837FE1}
+#define guidNemerleProjectCmdSet { 0x1af15e0, 0xb973, 0x481a, { 0x8b, 0xc1, 0xf3, 0xdc, 0xdf, 0x83, 0x7f, 0xe1 } }
+
Added: CtcComponents/PkgCmd.ctc
==============================================================================
--- (empty file)
+++ CtcComponents/PkgCmd.ctc Sun Feb 12 16:23:16 2006
@@ -0,0 +1,142 @@
+
+//
+// This is the file that defines the actual layout and type of the commands.
+// It is divided in different sections (e.g. command definition, command
+// placement, ...), with each defining a specific set of properties.
+// See the comment before each section for more details about how to
+// use it.
+//
+
+
+// The CTC compiler (the tool that translates this file into the binary
+// format that VisualStudio will consume) has the ability to run a preprocessor
+// on the ctc file; this preprocessor is (usually) the C++ preprocessor, so
+// it is possible to define includes and macros with the same syntax used
+// in C++ files. Using this ability of the compiler here, we include some files
+// defining some of the constants that we will use inside the file.
+
+#include "stdidcmd.h" // This is the file that defines the IDs for all the
+ // commands exposed by VisualStudio.
+
+#include "vsshlids.h" // This header contains the command ids for the menus
+ // provided by the shell.
+
+#include "msobtnid.h" // Definition of some CTC specific constants. In this sample
+ // we use it for the IDs inside the guidOfficeIcon group.
+
+#include "Guids.h" // This is the file with the definition of the Guid
+ // specific for this sample.
+
+#include "PkgCmdId.h" // Definition of the IDs of the commands and CTC elements
+ // specific for this sample.
+
+
+// The first section of this file is the CMDS_SECTION. This is where we define
+// the commands, menus and menu groups. This section uses a Guid to identify the
+// package that provides the command defined inside it.
+CMDS_SECTION guidNemerleProjectPkg
+
+ // Inside this section we have different sub-sections: one for the menus, another
+ // for the menu groups, one for the buttons (the actual commands), one for the combos
+ // and the last one for the bitmaps used. Each element is identified by a command id that
+ // is a unique pair of guid and numeric identifier; the guid part of the identifier is usually
+ // called "command set" and is used to group different command inside a logically related
+ // group; your package should define its own command set in order to avoid collisions
+ // with command ids defined by other packages.
+
+ // This is the sub-section that defines the menus and toolbars.
+ MENUS_BEGIN
+
+ // To define an element in this group we need an ID, a parent group, a display priority,
+ // a menu type, a name and a default text.
+ // In this example we define a toolbar, so its menu type is TOOLBAR; also notice that we
+ // use the menu as parent for itself because this it is not supposed to have any parent.
+
+ // Menu's ID Parent Priority Type Name Text
+
+ MENUS_END
+
+ // In this section we can define new menu groups. A menu group is a container for
+ // other menus or buttons (commands); from a visual point of view you can see the
+ // group as the part of a menu contained between two lines. The parent of a group
+ // must be a menu.
+ NEWGROUPS_BEGIN
+
+ // To define a menu group we have to specify its ID, the parent menu and its display priority.
+ // In this case we use as parent menu the Tools menu of VS; its ID is defined in vsshlids.h
+
+ // Group's ID Parent Priority
+ guidNemerleProjectCmdSet:CodeFileGroup, guidSHLMainMenu:IDM_VS_MENU_PROJECT, 0x600;
+
+ NEWGROUPS_END
+
+ // Button section.
+ // This section defines the elements the user can interact with, like a menu command or a button
+ // or combo box in a toolbar.
+ BUTTONS_BEGIN
+
+ // An element inside this section is defined by its ID and must specify a parent group, a display
+ // priority, an image, a type, some visibility flags (optional) and a default text.
+
+ // Command ID, Parent Group Priority, Image, Type, Visibility, Text
+ guidNemerleProjectCmdSet:cmdidSetAsMain, guidNemerleProjectCmdSet:CodeFileGroup, 0x100, guidOfficeIcon:msotcidNoIcon, BUTTON, , "Set as Main";
+
+ BUTTONS_END
+
+ // The bitmaps section is used to define the bitmaps that are used for the commands.
+ BITMAPS_BEGIN
+ // The bitmap id is defined in a way that is a little bit different from the others:
+ // the declaration starts with a guid for the bitmap strip, then there is the resource id of the
+ // bitmap strip containing the bitmaps and then there are the numeric ids of the elements used
+ // inside a button definition. An important aspect of this declaration is that the element id
+ // must be the actual index (1-based) of the bitmap inside the bitmap strip.
+ // In this example we have a bitmap strip with resource id 300 and that contains only one
+ // element; we want to define as ID for this element guidMenuAndCommandsCmdSet:bmpArrow, so we
+ // have to define bmpArrow as 1 and is the delaration of the bitmap:
+
+ // Command set ResourceID, Id element1, Id element2, ..., Id elementN;
+ BITMAPS_END
+
+CMDS_END // End of the command definition section.
+
+
+// Inside this section, we have the ability to place menu groups inside some other menu or
+// menu / commands inside other groups.
+// For instance, it is possible to place one of VisualStudio's menus or commands inside one of our
+// groups or one of our groups inside a menu defined somewhere else.
+CMDPLACEMENT_SECTION
+
+ // Here we place two commands inside the empty menu group we created in the NEWGROUPS section.
+ // The elements are:
+ // ID of the element to place ID of the parent group Priority
+ guidNemerleProjectCmdSet:CodeFileGroup, guidSHLMainMenu:IDM_VS_CTXT_ITEMNODE, 0x600;
+CMDPLACEMENT_END
+
+
+// This section is where you can associate a command with a keyboard shortcut; this association is
+// valid within a specific UI context, that is when the shell is inside a specific mode, e.g. during
+// debugging, editing a file or when the user is using a specific designer.
+KEYBINDINGS_SECTION
+
+ // To define a binding, we have to specify the sequence of keys to press to activate the command
+ // (keystate); the syntax to use is <key>[:<special keys>] where the special keys section can be
+ // empty. The accepted special keys and their representation are:
+ // Alt - A
+ // Control - C
+ // Shift - S
+ // Windows Key - W
+ // For example, if you want to define a binding for <Control>C the definition will be 'C':C; if the
+ // binding is <Control><Alt>C, then the keybinding is 'C':AC.
+ //
+ // Notice that Visual Studio has a lot of components and commands, so it can be difficult to find a
+ // key binding not used by somebody else; if the key bindings are conflicting only one will be used
+ // and one problem is that the shell will not inform the user that a conflict was found. The only
+ // way to detect the problem is to start Visual Studio under debugger, try to execute any command
+ // and look if there is a message in the output window about a duplicated accelerator found.
+ //
+ // In this example we want to use the <Control><1> accelerator for the first command defined in
+ // the BUTTON section above, so this is its definition:
+
+ // Command ID when available emulation keybinding
+
+KEYBINDINGS_END
Added: CtcComponents/PkgCmdID.h
==============================================================================
--- (empty file)
+++ CtcComponents/PkgCmdID.h Sun Feb 12 16:23:16 2006
@@ -0,0 +1,23 @@
+
+//
+// Definition of the numeric part of the IDs for the CTC elements of this
+// package.
+//
+
+/////////////////////////////////////////////////////////////////////
+// Menus
+//
+
+/////////////////////////////////////////////////////////////////////
+// Menu Groups
+//
+#define CodeFileGroup 0x2001
+
+/////////////////////////////////////////////////////////////////////
+// Commands
+//
+#define cmdidSetAsMain 0x3001
+
+/////////////////////////////////////////////////////////////////////
+// Bitmaps
+//
Added: NemerleFileNode.cs
==============================================================================
--- (empty file)
+++ NemerleFileNode.cs Sun Feb 12 16:23:16 2006
@@ -0,0 +1,90 @@
+
+using System;
+using System.Text;
+using System.Diagnostics;
+using System.Globalization;
+using System.IO;
+using System.Runtime.InteropServices;
+using Microsoft.VisualStudio;
+using Microsoft.VisualStudio.Shell.Interop;
+using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Package;
+using Microsoft.Win32;
+using EnvDTE;
+using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
+using OleConstants = Microsoft.VisualStudio.OLE.Interop.Constants;
+using VsCommands = Microsoft.VisualStudio.VSConstants.VSStd97CmdID;
+using VsCommands2K = Microsoft.VisualStudio.VSConstants.VSStd2KCmdID;
+
+namespace NemerleProject
+{
+ class NemerleNode : FileNode
+ {
+ internal NemerleNode(ProjectNode root, ProjectElement e)
+ : base(root, e)
+ {
+ //this.NodeProperties = new NemerleFileNodeProperties(this);
+ }
+
+ protected override int ExecCommandOnNode(Guid guidCmdGroup, uint cmd, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
+ {
+ Debug.Assert(this.ProjectMgr != null, "The NemerleFileNode has no project manager");
+
+ if (this.ProjectMgr == null)
+ {
+ throw new InvalidOperationException();
+ }
+
+ if (guidCmdGroup == Menus.guidNemerleProjectCmdSet)
+ {
+ if (cmd == (uint)Menus.SetAsMain.ID)
+ {
+ // Set the MainFile project property to the Filename of this Node
+ ((NemerleProjectNode)this.ProjectMgr).SetProjectProperty(NemerleProjectFileConstants.MainFile, this.GetRelativePath());
+ return VSConstants.S_OK;
+ }
+ }
+ return base.ExecCommandOnNode(guidCmdGroup, cmd, nCmdexecopt, pvaIn, pvaOut);
+ }
+
+ /// <summary>
+ /// Handles the menuitems
+ /// </summary>
+ protected override int QueryStatusOnNode(Guid guidCmdGroup, uint cmd, IntPtr pCmdText, ref QueryStatusResult result)
+ {
+ if (guidCmdGroup == Microsoft.VisualStudio.Shell.VsMenus.guidStandardCommandSet97)
+ {
+ switch ((VsCommands)cmd)
+ {
+ case VsCommands.AddNewItem:
+ case VsCommands.AddExistingItem:
+ case VsCommands.ViewCode:
+ result |= QueryStatusResult.SUPPORTED | QueryStatusResult.ENABLED;
+ return VSConstants.S_OK;
+ }
+ }
+
+ else if (guidCmdGroup == Menus.guidNemerleProjectCmdSet)
+ {
+ if (cmd == (uint)Menus.SetAsMain.ID)
+ {
+ result |= QueryStatusResult.SUPPORTED | QueryStatusResult.ENABLED;
+ return VSConstants.S_OK;
+ }
+ }
+ return base.QueryStatusOnNode(guidCmdGroup, cmd, pCmdText, ref result);
+ }
+
+ protected string GetRelativePath()
+ {
+ string relativePath = Path.GetFileName(this.ItemNode.GetMetadata(ProjectFileConstants.Include));
+ HierarchyNode parent = this.Parent;
+ while (parent != null && !(parent is ProjectNode))
+ {
+ relativePath = Path.Combine(parent.Caption, relativePath);
+ parent = parent.Parent;
+ }
+ return relativePath;
+ }
+ }
+}
Added: NemerleLanguage.cs
==============================================================================
--- (empty file)
+++ NemerleLanguage.cs Sun Feb 12 16:23:16 2006
@@ -0,0 +1,237 @@
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Runtime.InteropServices;
+
+using Microsoft.VisualStudio.Package;
+using Microsoft.VisualStudio.TextManager.Interop;
+
+using NC = Nemerle.Compiler;
+
+//TODO: if you open a single .n file (not a project) then there is no syntax highlight
+//TODO: match_brace finds the pair of braces inside comments (needs real lexer support)
+
+namespace NemerleProject
+{
+ [Guid("0F15B13F-4C95-405f-97A5-7E0E341C4FD3")]
+ class NemerleLanguage : LanguageService
+ {
+ private NemerleColorizer _scanner = null;
+ private LanguagePreferences _preferences = null;
+ private IVsTextLines _buffer = null;
+
+ private TextSpan[] match_braces(ParseRequest req) {
+ int pos;
+ _buffer.GetPositionOfLineIndex(req.Line, req.Col, out pos);
+ --pos;
+ char brace = req.Text[pos];
+ char complement;
+ switch(brace) {
+ case ')':
+ complement = '(';
+ break;
+ case ']':
+ complement = '[';
+ break;
+ case '}':
+ complement = '{';
+ break;
+ default:
+ return null;
+ }
+
+ int nesting = 0;
+
+ do {
+ char curr = req.Text[pos];
+ if(curr == brace)
+ nesting++;
+ else if(curr == complement)
+ nesting--;
+ --pos;
+ }
+ while(pos >= 0 && nesting > 0);
+
+ if(nesting > 0)
+ return null;
+ else {
+ TextSpan[] result = new TextSpan[2];
+ _buffer.GetLineIndexOfPosition(pos + 1, out result[0].iStartLine,
+ out result[0].iStartIndex);
+ result[0].iEndLine = result[0].iStartLine;
+ result[0].iEndIndex = result[0].iStartIndex + 1;
+ result[1].iStartLine = req.Line;
+ result[1].iStartIndex = req.Col - 1;
+ result[1].iEndLine = req.Line;
+ result[1].iEndIndex = req.Col;
+
+ return result;
+ }
+ }
+
+ public override AuthoringScope ParseSource(ParseRequest req) {
+ //System.Diagnostics.Trace.WriteLine(string.Format("ParseSource{0}", req.Reason));
+ if(req.Reason != ParseReason.MatchBraces)
+ return new NemerleAuthoringScope();
+
+ NC.LexerColorizer lexer = new NC.LexerColorizer(req.Text);
+ int state = 0;
+ while(true) {
+ NC.LexerColorizer.SyntaxToken tok = lexer.GetSyntaxToken(ref state);
+ if(tok.Token == NC.SyntaxType.EndOfFile)
+ break;
+ //if(tok.Token == Nemerle.Compiler.SyntaxType.OperatorBrace && tok.
+ }
+
+ return new NemerleAuthoringScope();
+ }
+
+ // This must return the same name the language service was registered with in Visual Studio.
+ public override string Name {
+ get { return "Nemerle"; }
+ }
+
+ public override IScanner GetScanner(IVsTextLines buffer) {
+ if(_scanner == null)
+ _scanner = new NemerleColorizer();
+ this._buffer = buffer;
+
+ return _scanner;
+ }
+
+ public override LanguagePreferences GetLanguagePreferences() {
+ if(_preferences == null) {
+ _preferences = new LanguagePreferences(this.Site, typeof(NemerleLanguage).GUID, "Nemerle Language Service Preferences");
+ _preferences.EnableCodeSense = true; // without this there is no ParseSource
+ _preferences.EnableMatchBraces = true;
+ _preferences.EnableShowMatchingBrace = true; // hilites braces when brace typed
+ _preferences.EnableMatchBracesAtCaret = true; // hilites braces when cursor moved over them
+ //_preferences.IndentStyle = IndentingStyle.Smart;
+ }
+
+ return _preferences;
+ }
+ }
+
+ class NemerleColorizer : IScanner
+ {
+ static NemerleColorizer() {
+ NC.LibraryReferenceManager.LoadMacrosFrom(@"c:\program files\nemerle\Nemerle.Macros.dll");
+ NC.GlobalEnv.Init();
+ }
+
+ public NemerleColorizer() {
+ lexer = new NC.LexerColorizer("");
+ }
+
+ #region IScanner Members
+
+ NC.LexerColorizer lexer;
+
+ // Its calling depends on IVsColorizer.GetStateMaintenanceFlag, which defaults to true.
+ public bool ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo, ref int state) {
+ NC.LexerColorizer.SyntaxToken tok = lexer.GetSyntaxToken(ref state);
+
+ // TokenInfo is only read in *.LanguageService.dll
+ tokenInfo.Trigger = TokenTriggers.None;
+ switch(tok.Token) {
+ case NC.SyntaxType.EndOfFile:
+ return false;
+
+ case NC.SyntaxType.Keyword:
+ tokenInfo.Color = TokenColor.Keyword;
+ tokenInfo.Type = TokenType.Keyword;
+ break;
+
+ case NC.SyntaxType.Identifier:
+ tokenInfo.Color = TokenColor.Identifier;
+ tokenInfo.Type = TokenType.Identifier;
+ break;
+
+ case NC.SyntaxType.OperatorDot:
+ case NC.SyntaxType.OperatorBrace:
+ case NC.SyntaxType.Operator:
+ tokenInfo.Color = TokenColor.Keyword;
+ tokenInfo.Type = TokenType.Operator;
+ switch(tok.Token) {
+ case NC.SyntaxType.OperatorBrace:
+ tokenInfo.Trigger = TokenTriggers.MatchBraces;
+ break;
+ case NC.SyntaxType.OperatorDot:
+ tokenInfo.Trigger = TokenTriggers.MemberSelect;
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case NC.SyntaxType.Comment:
+ tokenInfo.Color = TokenColor.Comment;
+ if(state == 0)
+ tokenInfo.Type = TokenType.LineComment;
+ else
+ tokenInfo.Type = TokenType.Comment;
+ break;
+
+ case NC.SyntaxType.CharLiteral:
+ tokenInfo.Color = TokenColor.String;
+ tokenInfo.Type = TokenType.Literal;
+ break;
+
+ case NC.SyntaxType.IntLiteral:
+ tokenInfo.Color = TokenColor.Number;
+ tokenInfo.Type = TokenType.Literal;
+ break;
+
+ case NC.SyntaxType.StringLiteral:
+ tokenInfo.Color = TokenColor.String;
+ tokenInfo.Type = TokenType.String;
+ break;
+
+ default:
+ tokenInfo.Color = TokenColor.Text;
+ tokenInfo.Type = TokenType.Text;
+ break;
+ }
+
+ tokenInfo.StartIndex = tok.StartPos;
+ tokenInfo.EndIndex = tok.EndPos;
+
+ return true;
+ }
+
+ // The current implementation in *.LanguageService.dll always uses offset 0.
+ public void SetSource(string source, int offset) {
+ lexer.SetString(source, offset);
+ System.Diagnostics.Trace.WriteLine(source);
+ }
+
+ #endregion
+ }
+
+ public class NemerleAuthoringScope : AuthoringScope
+ {
+ public NemerleAuthoringScope()
+ : base() {
+ }
+
+ public override string Goto(Microsoft.VisualStudio.VSConstants.VSStd97CmdID cmd, IVsTextView textView, int line, int col, out TextSpan span) {
+ span = new TextSpan();
+ return null;
+ }
+
+ public override string GetDataTipText(int line, int col, out Microsoft.VisualStudio.TextManager.Interop.TextSpan span) {
+ span = new TextSpan();
+ return null;
+ }
+
+ public override Declarations GetDeclarations(Microsoft.VisualStudio.TextManager.Interop.IVsTextView view, int line, int col, TokenInfo info, ParseReason reason) {
+ return null;
+ }
+
+ public override Methods GetMethods(int line, int col, string name) {
+ return null;
+ }
+ }
+}
Added: NemerleMenus.cs
==============================================================================
--- (empty file)
+++ NemerleMenus.cs Sun Feb 12 16:23:16 2006
@@ -0,0 +1,16 @@
+
+using System;
+using System.ComponentModel.Design;
+
+namespace NemerleProject
+{
+ /// <summary>
+ /// CommandIDs matching the commands defined items from PkgCmdID.h and guids.h
+ /// </summary>
+ public sealed class Menus
+ {
+ internal static readonly Guid guidNemerleProjectCmdSet = new Guid("{01AF15E0-B973-481a-8BC1-F3DCDF837FE1}");
+ internal static readonly CommandID SetAsMain = new CommandID(guidNemerleProjectCmdSet, 0x3001);
+ }
+}
+
Added: NemerleProject.cs
==============================================================================
--- (empty file)
+++ NemerleProject.cs Sun Feb 12 16:23:16 2006
@@ -0,0 +1,262 @@
+
+using System;
+using System.Text;
+using System.Diagnostics;
+using System.Globalization;
+using System.IO;
+using System.Runtime.InteropServices;
+using Microsoft.VisualStudio.Shell.Interop;
+using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Package;
+using Microsoft.Win32;
+using EnvDTE;
+using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
+
+namespace NemerleProject
+{
+ [DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\8.0Exp")]
+ [ProvideProjectFactory(typeof(NemerleProjectFactory), "NemerleProject", "Nemerle Project Files (*.nproj);*.nproj", "nproj", "nproj", "..\\..\\Templates\\Projects")]
+ [ProvideProjectItem(typeof(NemerleProjectFactory), "My Items", "..\\..\\Templates\\ProjectItems", 500)]
+ [ProvideObject(typeof(GeneralPropertyPage))]
+ [ProvideMenuResource(1000, 1)]
+ [PackageRegistration(UseManagedResourcesOnly = true)]
+
+ [ProvideLanguageService(typeof(NemerleLanguage), "Nemerle", 100, CodeSense = true)]
+ [ProvideLanguageExtension(typeof(NemerleLanguage), ".n")]
+
+ [Guid("090A3C1C-16B5-4190-A25B-DC274A1AE54F")] // same as guidNemerleProjectPkg
+ public class NemerleProjectPackage : Microsoft.VisualStudio.Package.ProjectPackage
+ {
+ protected override void Initialize()
+ {
+ base.Initialize();
+
+ this.RegisterProjectFactory(new NemerleProjectFactory(this));
+
+ System.ComponentModel.Design.IServiceContainer serviceContainer = this as System.ComponentModel.Design.IServiceContainer;
+ NemerleLanguage nemerle = new NemerleLanguage();
+ nemerle.SetSite(this);
+ serviceContainer.AddService(typeof(NemerleLanguage), nemerle, true);
+ }
+ }
+
+ [GuidAttribute("0C332D7E-629F-4a3b-9CF0-76E22A722F56")] // same as ProjectGuid (see * below)
+ public class NemerleProjectFactory : Microsoft.VisualStudio.Package.ProjectFactory
+ {
+ public NemerleProjectFactory(NemerleProjectPackage package)
+ : base(package)
+ {
+ }
+
+ protected override Microsoft.VisualStudio.Package.ProjectNode CreateProject()
+ {
+ NemerleProjectNode project = new NemerleProjectNode(this.Package as NemerleProjectPackage);
+ project.SetSite((IOleServiceProvider)((IServiceProvider)this.Package).GetService(typeof(IOleServiceProvider)));
+ return project;
+ }
+ }
+
+ [Guid("00E400C1-5FCE-4204-8B3E-273BDA845EB4")] // not referenced
+ public class NemerleProjectNode : Microsoft.VisualStudio.Package.ProjectNode
+ {
+ private NemerleProjectPackage package;
+
+ public NemerleProjectNode(NemerleProjectPackage pkg)
+ {
+ this.package = pkg;
+ }
+
+ // (*) This Guid must match the Guid you registered under
+ // HKLM\Software\Microsoft\VisualStudio\%version%\Projects.
+ public override Guid ProjectGuid
+ {
+ get
+ {
+ return typeof(NemerleProjectFactory).GUID;
+ }
+ }
+ public override string ProjectType
+ {
+ get
+ {
+ return "Nemerle Project";
+ }
+ }
+
+ /// <summary>
+ /// Overriding to provide project general property page
+ /// </summary>
+ public override Guid[] GetPropertyPageGuids()
+ {
+ Guid[] result = new Guid[1];
+ result[0] = typeof(GeneralPropertyPage).GUID;
+ return result;
+ }
+
+ /// <summary>
+ /// Returns the configuration dependent property pages.
+ /// Specify here a property page. By returning no property page the configuartion dependent properties will be neglected.
+ /// Overriding, but current implementation does nothing
+ /// To provide configuration specific page project property page, this should return an array bigger then 0
+ /// (you can make it do the same as GetPropertyPageGuids() to see its impact)
+ /// </summary>
+ public override Guid[] GetConfigurationDependentPropertyPages()
+ {
+ // TODO: Remove this if fixed.
+ // There is a bug in the \vbdesigner\designer\ApplicationDesigner\ApplicationDesignerView.vb
+ // and we cannot have configuration independent property pages.
+ // See the method GetPropertyPages in that class.
+ if (this.SupportsProjectDesigner)
+ {
+ return this.GetConfigurationIndependentPropertyPages();
+ }
+
+ Guid[] result = new Guid[0];
+ //result[0] = typeof(CSharpApplicationPropPageComClass).GUID;
+ return result;
+ }
+
+ /// <summary>
+ /// Overriding to provide customization of files on add files.
+ /// This will replace tokens in the file with actual value (namespace, class name,...)
+ /// </summary>
+ /// <param name="source">Full path to template file</param>
+ /// <param name="target">Full path to destination file</param>
+ public override void AddFileFromTemplate(string source, string target)
+ {
+ if (!System.IO.File.Exists(source))
+ throw new FileNotFoundException(String.Format("Template file not found: {0}", source));
+
+ TokenProcessor tokenReplacer = new TokenProcessor();
+ tokenReplacer.TheDTE = (DTE)((IServiceProvider)this.package).GetService(typeof(_DTE));
+
+ // The class name is based on the new file name
+ string className = Path.GetFileNameWithoutExtension(target);
+ string namespce = GetFileNamespace(target);
+
+ tokenReplacer.AddReplace("%className%", className, TokenReplaceType.ReplaceString);
+ tokenReplacer.AddReplace("%namespace%", namespce, TokenReplaceType.ReplaceString);
+ try
+ {
+ tokenReplacer.UntokenMiscFile(source, target);
+ }
+ catch (Exception e)
+ {
+ throw new FileLoadException("Failed to add template file to project", target, e);
+ }
+ }
+
+ /// <summary>
+ /// Evaluates if a file is an Nemerle code file based on is extension
+ /// </summary>
+ /// <param name="strFileName">The filename to be evaluated</param>
+ /// <returns>true if is a code file</returns>
+ public override bool IsCodeFile(string strFileName)
+ {
+ // We do not want to assert here, just return silently.
+ if (String.IsNullOrEmpty(strFileName))
+ {
+ return false;
+ }
+ return (String.Compare(Path.GetExtension(strFileName), ".n", StringComparison.OrdinalIgnoreCase) == 0);
+
+ }
+
+ /// <summary>
+ /// Create a file node based on an msbuild item.
+ /// </summary>
+ /// <param name="item">The msbuild item to be analyzed</param>
+ /// <returns>NemerleFileNode or FileNode</returns>
+ public override FileNode CreateFileNode(ProjectElement item)
+ {
+ if (item == null)
+ {
+ throw new ArgumentNullException("item");
+ }
+
+ string include = item.GetMetadata(ProjectFileConstants.Include);
+ if (IsCodeFile(include))
+ {
+ return new NemerleNode(this, item);
+ }
+
+ return base.CreateFileNode(item);
+ }
+
+ // helper methods
+
+ /// <summary>
+ /// The goal here is to reduce the risk of name conflict between 2 classes
+ /// added in different directories. This code does NOT garanty uniqueness.
+ /// To garanty uniqueness, you should change this function to work with
+ /// the language service to verify that the namespace+class generated does
+ /// not conflict.
+ /// </summary>
+ /// <param name="fileFullPath">Full path to the new file</param>
+ /// <returns>Namespace to use for the new file</returns>
+ private string GetFileNamespace(string fileFullPath)
+ {
+ // Get base namespace from the project
+ string namespce = this.GetProjectProperty("RootNamespace");
+ if (String.IsNullOrEmpty(namespce))
+ namespce = Path.GetFileNameWithoutExtension(fileFullPath); ;
+
+ // If the item is added to a subfolder, the name space should reflect this.
+ // This is done so that class names from 2 files with the same name but different
+ // directories don't conflict.
+ string relativePath = Path.GetDirectoryName(fileFullPath);
+ string projectPath = Path.GetDirectoryName(base.FileName);
+ // Our project system only support adding files that are sibling of the project file or that are in subdirectories.
+ if (String.Compare(projectPath, 0, relativePath, 0, projectPath.Length, true, CultureInfo.CurrentCulture) == 0)
+ {
+ relativePath = relativePath.Substring(projectPath.Length);
+ }
+ else
+ {
+ Debug.Fail("Adding an item to the project that is NOT under the project folder.");
+ // We are going to use the full file path for generating the namespace
+ }
+
+ // Get the list of parts
+ int index = 0;
+ string[] pathParts;
+ pathParts = relativePath.Split(Path.DirectorySeparatorChar);
+
+ // Use a string builder with default size being the expected size
+ StringBuilder result = new StringBuilder(namespce, namespce.Length + relativePath.Length + 1);
+ // For each path part
+ while (index < pathParts.Length)
+ {
+ string part = pathParts[index];
+ ++index;
+
+ // This could happen if the path had leading/trailing slash, we want to ignore empty pieces
+ if (String.IsNullOrEmpty(part))
+ continue;
+
+ // If we reach here, we will be adding something, so add a namespace separator '.'
+ result.Append('.');
+
+ // Make sure it starts with a letter
+ if (!char.IsLetter(part, 0))
+ result.Append('N');
+
+ // Filter invalid namespace characters
+ foreach (char c in part)
+ {
+ if (char.IsLetterOrDigit(c))
+ result.Append(c);
+ }
+ }
+ return result.ToString();
+ }
+ }
+
+ /// <summary>
+ /// This class defines constants being used by the Nemerle Project File
+ /// </summary>
+ public static class NemerleProjectFileConstants
+ {
+ public const string MainFile = "MainFile";
+ }
+}
\ No newline at end of file
Added: NemerleProject.csproj
==============================================================================
--- (empty file)
+++ NemerleProject.csproj Sun Feb 12 16:23:16 2006
@@ -0,0 +1,136 @@
+ďťż<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{16041FE4-7A5D-4DFD-9A79-A92B6A81E291}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <StartupObject>
+ </StartupObject>
+ <NoStandardLibraries>false</NoStandardLibraries>
+ <AssemblyName>NemerleProject</AssemblyName>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <SccProjectName>"%24/NemerleProject", YSBAAAAA</SccProjectName>
+ <SccLocalPath>..\..\..</SccLocalPath>
+ <SccAuxPath>
+ </SccAuxPath>
+ <SccProvider>MSSCCI:Microsoft Visual SourceSafe</SccProvider>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <DebugSymbols>true</DebugSymbols>
+ <Optimize>false</Optimize>
+ <OutputPath>.\bin\Debug\</OutputPath>
+ <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <WarningLevel>4</WarningLevel>
+ <IncrementalBuild>false</IncrementalBuild>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+ <DebugSymbols>false</DebugSymbols>
+ <Optimize>true</Optimize>
+ <OutputPath>.\bin\Release\</OutputPath>
+ <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
+ <DefineConstants>TRACE</DefineConstants>
+ <WarningLevel>4</WarningLevel>
+ <IncrementalBuild>false</IncrementalBuild>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="EnvDTE">
+ </Reference>
+ <Reference Include="EnvDTE80" />
+ <Reference Include="Microsoft.VisualStudio.Designer.Interfaces">
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.OLE.Interop">
+ <Name>Microsoft.VisualStudio.OLE.Interop</Name>
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.Package.LanguageService, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ <Reference Include="Microsoft.VisualStudio.Shell">
+ <Name>Microsoft.VisualStudio.Shell</Name>
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.Shell.Interop">
+ <Name>Microsoft.VisualStudio.Shell.Interop</Name>
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0">
+ <Name>Microsoft.VisualStudio.Shell.Interop.8.0</Name>
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.TextManager.Interop">
+ <Name>Microsoft.VisualStudio.TextManager.Interop</Name>
+ </Reference>
+ <Reference Include="Microsoft.VisualStudio.TextManager.Interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ <Reference Include="Nemerle.Compiler, Version=0.9.1.0, Culture=neutral, PublicKeyToken=5291d186334f6101, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\..\..\..\Nemerle\Nemerle.Compiler.dll</HintPath>
+ <Private>True</Private>
+ </Reference>
+ <Reference Include="System">
+ <Name>System</Name>
+ </Reference>
+ <Reference Include="System.Data">
+ <Name>System.Data</Name>
+ </Reference>
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Windows.Forms" />
+ <Reference Include="System.Xml" />
+ <Reference Include="VSLangProj">
+ <Name>VSLangProj</Name>
+ <FusionName>VSLangProj, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</FusionName>
+ <SpecificVersion>True</SpecificVersion>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="AssemblyInfo.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="NemerleLanguage.cs" />
+ <Compile Include="NemerleFileNode.cs" />
+ <Compile Include="NemerleMenus.cs" />
+ <Compile Include="Resources.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="NemerleProject.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="PropertyPages.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="TokenProcessor.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ </ItemGroup>
+ <ItemGroup>
+ <CtcFile Include="CtcComponents\PkgCmd.ctc">
+ <ResourceName>1000</ResourceName>
+ </CtcFile>
+ <None Include="CtcComponents\Guids.h" />
+ <None Include="CtcComponents\PkgCmdID.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <EmbeddedResource Include="Resources.resx">
+ <MergeWithCTO>true</MergeWithCTO>
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Templates\ProjectItems\Class.n" />
+ <None Include="Templates\Projects\AssemblyInfo.n" />
+ <None Include="Templates\Projects\NemerleApp.nproj" />
+ <None Include="Templates\Projects\Program.n" />
+ </ItemGroup>
+ <PropertyGroup>
+ <TargetRegistryRoot>Software\Microsoft\VisualStudio\8.0Exp</TargetRegistryRoot>
+ <RegisterOutputPackage>true</RegisterOutputPackage>
+ <RegisterWithCodebase>true</RegisterWithCodebase>
+ </PropertyGroup>
+ <PropertyGroup>
+ <ProjectBasePath>..\..\..\Common\Source\CSharp\Project</ProjectBasePath>
+ </PropertyGroup>
+ <!-- This import the files which makes up the project base classes -->
+ <Import Project="$(ProjectBasePath)\ProjectBase.Files" />
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
+ <Import Project="..\..\..\Tools\Build\Microsoft.VsSDK.targets" />
+ <ProjectExtensions>
+ <VisualStudio>
+ </VisualStudio>
+ </ProjectExtensions>
+</Project>
\ No newline at end of file
Added: NemerleProject.sln
==============================================================================
--- (empty file)
+++ NemerleProject.sln Sun Feb 12 16:23:16 2006
@@ -0,0 +1,44 @@
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NemerleProject", "NemerleProject.csproj", "{16041FE4-7A5D-4DFD-9A79-A92B6A81E291}"
+ ProjectSection(ProjectDependencies) = postProject
+ {3E207E0B-59BC-4F56-A9D9-BC8C5BFF2621} = {3E207E0B-59BC-4F56-A9D9-BC8C5BFF2621}
+ EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Package", "..\..\..\Common\Source\CSharp\NativeHierarchyWrapper\NativeHierarchyWrapper.vcproj", "{3E207E0B-59BC-4F56-A9D9-BC8C5BFF2621}"
+EndProject
+Global
+ GlobalSection(SourceCodeControl) = preSolution
+ SccNumberOfProjects = 3
+ SccProjectName0 = \u0022$/NemerleProject\u0022,\u0020YSBAAAAA
+ SccLocalPath0 = ..\\..\\..
+ SccProvider0 = MSSCCI:Microsoft\u0020Visual\u0020SourceSafe
+ CanCheckoutShared = false
+ SccProjectFilePathRelativizedFromConnection0 = Samples\\NemerleIntegration\\NemerleProject\\
+ SccProjectUniqueName1 = ..\\..\\..\\Common\\Source\\CSharp\\NativeHierarchyWrapper\\NativeHierarchyWrapper.vcproj
+ SccLocalPath1 = ..\\..\\..
+ CanCheckoutShared = false
+ SccProjectFilePathRelativizedFromConnection1 = Common\\Source\\CSharp\\NativeHierarchyWrapper\\
+ SccProjectUniqueName2 = NemerleProject.csproj
+ SccLocalPath2 = ..\\..\\..
+ CanCheckoutShared = false
+ SccProjectFilePathRelativizedFromConnection2 = Samples\\NemerleIntegration\\NemerleProject\\
+ EndGlobalSection
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Mixed Platforms = Debug|Mixed Platforms
+ Release|Mixed Platforms = Release|Mixed Platforms
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {16041FE4-7A5D-4DFD-9A79-A92B6A81E291}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {16041FE4-7A5D-4DFD-9A79-A92B6A81E291}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {16041FE4-7A5D-4DFD-9A79-A92B6A81E291}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {16041FE4-7A5D-4DFD-9A79-A92B6A81E291}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {3E207E0B-59BC-4F56-A9D9-BC8C5BFF2621}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
+ {3E207E0B-59BC-4F56-A9D9-BC8C5BFF2621}.Debug|Mixed Platforms.Build.0 = Debug|Win32
+ {3E207E0B-59BC-4F56-A9D9-BC8C5BFF2621}.Release|Mixed Platforms.ActiveCfg = Release|Win32
+ {3E207E0B-59BC-4F56-A9D9-BC8C5BFF2621}.Release|Mixed Platforms.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
Added: PropertyPages.cs
==============================================================================
--- (empty file)
+++ PropertyPages.cs Sun Feb 12 16:23:16 2006
@@ -0,0 +1,219 @@
+
+using System;
+using Microsoft.VisualStudio;
+using Microsoft.VisualStudio.Shell.Interop;
+using Microsoft.VisualStudio.Shell;
+using Microsoft.VisualStudio.Package;
+using System.Runtime.InteropServices;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.IO;
+
+namespace NemerleProject
+{
+ [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
+ internal sealed class LocDisplayNameAttribute : DisplayNameAttribute
+ {
+ private string name;
+
+ public LocDisplayNameAttribute(string name)
+ {
+ this.name = name;
+ }
+
+ public override string DisplayName
+ {
+ get
+ {
+ string result = SR.GetString(this.name);
+
+ if (result == null)
+ {
+ Debug.Assert(false, "String resource '" + this.name + "' is missing");
+ result = this.name;
+ }
+
+ return result;
+ }
+ }
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage"]/*' />
+ [ComVisible(true), Guid("02D0F94B-3D9E-4f57-9B02-3342AC32252E")] // not referenced
+ public class GeneralPropertyPage : SettingsPage
+ {
+ private string assemblyName;
+ private OutputType outputType;
+ private string defaultNamespace;
+ private string startupObject;
+ private string applicationIcon;
+ private PlatformType targetPlatform = PlatformType.v2;
+ private string targetPlatformLocation;
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.GeneralPropertyPage"]/*' />
+ public GeneralPropertyPage()
+ {
+ this.Name = SR.GetString(SR.GeneralCaption);
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.GetClassName"]/*' />
+ public override string GetClassName()
+ {
+ return this.GetType().FullName;
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.BindProperties"]/*' />
+ protected override void BindProperties()
+ {
+ if (this.ProjectMgr == null)
+ {
+ Debug.Assert(false);
+ return;
+ }
+
+ this.assemblyName = this.ProjectMgr.GetProjectProperty("AssemblyName", true);
+
+ string outputType = this.ProjectMgr.GetProjectProperty("OutputType", false);
+
+ if (outputType != null && outputType.Length > 0)
+ try { this.outputType = (OutputType)Enum.Parse(typeof(OutputType), outputType); } catch { } //Should only fail if project file is corrupt
+
+ this.defaultNamespace = this.ProjectMgr.GetProjectProperty("RootNamespace", false);
+ this.startupObject = this.ProjectMgr.GetProjectProperty("StartupObject", false);
+ this.applicationIcon = this.ProjectMgr.GetProjectProperty("ApplicationIcon", false);
+
+ string targetPlatform = this.ProjectMgr.GetProjectProperty("TargetPlatform", false);
+
+ if (targetPlatform != null && targetPlatform.Length > 0)
+ try { this.targetPlatform = (PlatformType)Enum.Parse(typeof(PlatformType), targetPlatform); } catch { }
+
+ this.targetPlatformLocation = this.ProjectMgr.GetProjectProperty("TargetPlatformLocation", false);
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.ApplyChanges"]/*' />
+ protected override int ApplyChanges()
+ {
+ if (this.ProjectMgr == null)
+ {
+ Debug.Assert(false);
+ return VSConstants.E_INVALIDARG;
+ }
+
+ this.ProjectMgr.SetProjectProperty("AssemblyName", this.assemblyName);
+ this.ProjectMgr.SetProjectProperty("OutputType", this.outputType.ToString());
+ this.ProjectMgr.SetProjectProperty("RootNamespace", this.defaultNamespace);
+ this.ProjectMgr.SetProjectProperty("StartupObject", this.startupObject);
+ this.ProjectMgr.SetProjectProperty("ApplicationIcon", this.applicationIcon);
+ this.ProjectMgr.SetProjectProperty("TargetPlatform", this.targetPlatform.ToString());
+ this.ProjectMgr.SetProjectProperty("TargetPlatformLocation", this.targetPlatformLocation);
+ this.IsDirty = false;
+
+ return VSConstants.S_OK;
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.AssemblyName"]/*' />
+ [SRCategoryAttribute(SR.Application)]
+ [LocDisplayName(SR.AssemblyName)]
+ [SRDescriptionAttribute(SR.AssemblyNameDescription)]
+ public string AssemblyName
+ {
+ get { return this.assemblyName; }
+ set { this.assemblyName = value; this.IsDirty = true; }
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.OutputType"]/*' />
+ [SRCategoryAttribute(SR.Application)]
+ [LocDisplayName(SR.OutputType)]
+ [SRDescriptionAttribute(SR.OutputTypeDescription)]
+ public OutputType OutputType
+ {
+ get { return this.outputType; }
+ set { this.outputType = value; this.IsDirty = true; }
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.DefaultNamespace"]/*' />
+ [SRCategoryAttribute(SR.Application)]
+ [LocDisplayName(SR.DefaultNamespace)]
+ [SRDescriptionAttribute(SR.DefaultNamespaceDescription)]
+ public string DefaultNamespace
+ {
+ get { return this.defaultNamespace; }
+ set { this.defaultNamespace = value; this.IsDirty = true; }
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.StartupObject"]/*' />
+ [SRCategoryAttribute(SR.Application)]
+ [LocDisplayName(SR.StartupObject)]
+ [SRDescriptionAttribute(SR.StartupObjectDescription)]
+ public string StartupObject
+ {
+ get { return this.startupObject; }
+ set { this.startupObject = value; this.IsDirty = true; }
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.ApplicationIcon"]/*' />
+ [SRCategoryAttribute(SR.Application)]
+ [LocDisplayName(SR.ApplicationIcon)]
+ [SRDescriptionAttribute(SR.ApplicationIconDescription)]
+ public string ApplicationIcon
+ {
+ get { return this.applicationIcon; }
+ set { this.applicationIcon = value; this.IsDirty = true; }
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.ProjectFile"]/*' />
+ [SRCategoryAttribute(SR.Project)]
+ [LocDisplayName(SR.ProjectFile)]
+ [SRDescriptionAttribute(SR.ProjectFileDescription)]
+ public string ProjectFile
+ {
+ get { return Path.GetFileName(this.ProjectMgr.ProjectFile); }
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.ProjectFolder"]/*' />
+ [SRCategoryAttribute(SR.Project)]
+ [LocDisplayName(SR.ProjectFolder)]
+ [SRDescriptionAttribute(SR.ProjectFolderDescription)]
+ public string ProjectFolder
+ {
+ get { return Path.GetDirectoryName(this.ProjectMgr.ProjectFolder); }
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.OutputFile"]/*' />
+ [SRCategoryAttribute(SR.Project)]
+ [LocDisplayName(SR.OutputFile)]
+ [SRDescriptionAttribute(SR.OutputFileDescription)]
+ public string OutputFile
+ {
+ get
+ {
+ switch (this.outputType)
+ {
+ case OutputType.Exe: return this.assemblyName + ".exe";
+
+ default: return this.assemblyName + ".dll";
+ }
+ }
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.TargetPlatform"]/*' />
+ [SRCategoryAttribute(SR.Project)]
+ [LocDisplayName(SR.TargetPlatform)]
+ [SRDescriptionAttribute(SR.TargetPlatformDescription)]
+ public PlatformType TargetPlatform
+ {
+ get { return this.targetPlatform; }
+ set { this.targetPlatform = value; IsDirty = true; }
+ }
+
+ /// <include file='doc\PropertyPages.uex' path='docs/doc[@for="GeneralPropertyPage.TargetPlatformLocation"]/*' />
+ [SRCategoryAttribute(SR.Project)]
+ [LocDisplayName(SR.TargetPlatformLocation)]
+ [SRDescriptionAttribute(SR.TargetPlatformLocationDescription)]
+ public string TargetPlatformLocation
+ {
+ get { return this.targetPlatformLocation; }
+ set { this.targetPlatformLocation = value; IsDirty = true; }
+ }
+ }
+}
Added: Resources.cs
==============================================================================
--- (empty file)
+++ Resources.cs Sun Feb 12 16:23:16 2006
@@ -0,0 +1,160 @@
+ďťż
+namespace NemerleProject
+{
+ using System;
+ using System.Reflection;
+ using System.Globalization;
+ using System.Resources;
+ using System.Text;
+ using System.Threading;
+ using System.ComponentModel;
+ using System.Security.Permissions;
+
+ [AttributeUsage(AttributeTargets.All)]
+ internal sealed class SRDescriptionAttribute : DescriptionAttribute
+ {
+
+ private bool replaced = false;
+
+ public SRDescriptionAttribute(string description) : base(description)
+ {
+ }
+
+ public override string Description
+ {
+ get
+ {
+ if (!replaced)
+ {
+ replaced = true;
+ DescriptionValue = SR.GetString(base.Description);
+ }
+ return base.Description;
+ }
+ }
+ }
+
+ [AttributeUsage(AttributeTargets.All)]
+ internal sealed class SRCategoryAttribute : CategoryAttribute
+ {
+
+ public SRCategoryAttribute(string category) : base(category)
+ {
+ }
+
+ protected override string GetLocalizedString(string value)
+ {
+ return SR.GetString(value);
+ }
+ }
+ internal sealed class SR
+ {
+ internal const string Application = "Application";
+ internal const string GeneralCaption = "GeneralCaption";
+ internal const string AssemblyName = "AssemblyName";
+ internal const string AssemblyNameDescription = "AssemblyNameDescription";
+ internal const string OutputType = "OutputType";
+ internal const string OutputTypeDescription = "OutputTypeDescription";
+ internal const string DefaultNamespace = "DefaultNamespace";
+ internal const string DefaultNamespaceDescription = "DefaultNamespaceDescription";
+ internal const string StartupObject = "StartupObject";
+ internal const string StartupObjectDescription = "StartupObjectDescription";
+ internal const string ApplicationIcon = "ApplicationIcon";
+ internal const string ApplicationIconDescription = "ApplicationIconDescription";
+ internal const string Project = "Project";
+ internal const string ProjectFile = "ProjectFile";
+ internal const string ProjectFileDescription = "ProjectFileDescription";
+ internal const string ProjectFolder = "ProjectFolder";
+ internal const string ProjectFolderDescription = "ProjectFolderDescription";
+ internal const string OutputFile = "OutputFile";
+ internal const string OutputFileDescription = "OutputFileDescription";
+ internal const string TargetPlatform = "TargetPlatform";
+ internal const string TargetPlatformDescription = "TargetPlatformDescription";
+ internal const string TargetPlatformLocation = "TargetPlatformLocation";
+ internal const string TargetPlatformLocationDescription = "TargetPlatformLocationDescription";
+
+ static SR loader = null;
+ ResourceManager resources;
+
+ private static Object s_InternalSyncObject;
+ private static Object InternalSyncObject
+ {
+ get
+ {
+ if (s_InternalSyncObject == null)
+ {
+ Object o = new Object();
+ Interlocked.CompareExchange(ref s_InternalSyncObject, o, null);
+ }
+ return s_InternalSyncObject;
+ }
+ }
+
+ internal SR()
+ {
+ resources = new System.Resources.ResourceManager("Resources", this.GetType().Assembly);
+ }
+
+ private static SR GetLoader()
+ {
+ if (loader == null)
+ {
+ lock (InternalSyncObject)
+ {
+ if (loader == null)
+ {
+ loader = new SR();
+ }
+ }
+ }
+
+ return loader;
+ }
+
+ private static CultureInfo Culture
+ {
+ get { return null/*use ResourceManager default, CultureInfo.CurrentUICulture*/; }
+ }
+
+ public static ResourceManager Resources
+ {
+ get
+ {
+ return GetLoader().resources;
+ }
+ }
+
+ public static string GetString(string name, params object[] args)
+ {
+ SR sys = GetLoader();
+ if (sys == null)
+ return null;
+ string res = sys.resources.GetString(name, SR.Culture);
+
+ if (args != null && args.Length > 0)
+ {
+ return String.Format(CultureInfo.CurrentCulture, res, args);
+ }
+ else
+ {
+ return res;
+ }
+ }
+
+ public static string GetString(string name)
+ {
+ SR sys = GetLoader();
+ if (sys == null)
+ return null;
+ return sys.resources.GetString(name, SR.Culture);
+ }
+
+ public static object GetObject(string name)
+ {
+ SR sys = GetLoader();
+ if (sys == null)
+ return null;
+ return sys.resources.GetObject(name, SR.Culture);
+ }
+}
+}
Added: Resources.resources
==============================================================================
Binary file. No diff available.
Added: Resources.resx
==============================================================================
Binary file. No diff available.
Added: Templates/ProjectItems/Class.n
==============================================================================
--- (empty file)
+++ Templates/ProjectItems/Class.n Sun Feb 12 16:23:16 2006
@@ -0,0 +1,13 @@
+#region Using directives
+
+using System;
+using System.Text;
+
+#endregion
+
+namespace %namespace%
+{
+ class %className%
+ {
+ }
+}
Added: Templates/Projects/AssemblyInfo.n
==============================================================================
--- (empty file)
+++ Templates/Projects/AssemblyInfo.n Sun Feb 12 16:23:16 2006
@@ -0,0 +1,29 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+//
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+//
+[assembly: AssemblyTitle("")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+//
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+
+[assembly: AssemblyVersion("1.0.*")]
Added: Templates/Projects/NemerleApp.nproj
==============================================================================
--- (empty file)
+++ Templates/Projects/NemerleApp.nproj Sun Feb 12 16:23:16 2006
@@ -0,0 +1,38 @@
+<Project
+ DefaultTargets="Build"
+ xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{0C332D7E-629F-4a3b-9CF0-76E22A722F56}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <RootNamespace>Application</RootNamespace>
+ <AssemblyName>Application</AssemblyName>
+ </PropertyGroup>
+
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Reference Include="Nemerle.Compiler" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <Compile Include="Program.n" />
+ <Compile Include="AssemblyInfo.n" />
+ </ItemGroup>
+
+
+ <Import Project="$(PROGRAMFILES)\Nemerle\Nemerle.MSBuild.targets" />
+</Project>
Added: Templates/Projects/Program.n
==============================================================================
--- (empty file)
+++ Templates/Projects/Program.n Sun Feb 12 16:23:16 2006
@@ -0,0 +1,18 @@
+#region Using directives
+
+using System;
+using System.Text;
+
+#endregion
+
+namespace %namespace%
+{
+ class %className%
+ {
+ static Main (args : array [string]) : void
+ {
+ Console.WriteLine("Hello");
+
+ }
+ }
+}
Added: TokenProcessor.cs
==============================================================================
--- (empty file)
+++ TokenProcessor.cs Sun Feb 12 16:23:16 2006
@@ -0,0 +1,388 @@
+
+using System;
+using System.Collections;
+using System.Globalization;
+using System.Text;
+
+namespace NemerleProject
+{
+ public enum TokenReplaceType
+ {
+ ReplaceString,
+ ReplaceNumber,
+ ReplaceCode
+ }
+
+ /// <summary>
+ /// Contain a number of functions that handle token replacement
+ /// </summary>
+ public class TokenProcessor
+ {
+ // Internal fields
+ private EnvDTE.DTE DTE;
+ private ArrayList listToReplace;
+ private ArrayList listToDelete;
+
+ // Initialization
+ public TokenProcessor()
+ {
+ DTE = null;
+
+ listToReplace = new ArrayList();
+ listToDelete = new ArrayList();
+ }
+
+
+ public void AddReplace(string token, string replacement, TokenReplaceType ReplaceType)
+ {
+ listToReplace.Add(new ReplacePair(token, replacement, ReplaceType));
+ }
+
+ public void AddDelete(string tokenStart, string tokenEnd)
+ {
+ listToDelete.Add(new DeletePair(tokenStart, tokenEnd));
+ }
+
+ // NOTE: This function will accept a subset of the characters that can create an
+ // identifier name: there are other unicode char that can be inside the name, but
+ // this function will not allow. By now it can work this way, but when and if the
+ // VSIP package will handle also languages different from english, this function
+ // must be changed.
+ private bool IsValidIdentifierChar(char c)
+ {
+ if ( (c>='a') && (c<='z') )
+ {
+ return true;
+ }
+ if ( (c>='A') && (c<='Z') )
+ {
+ return true;
+ }
+ if (c == '_')
+ {
+ return true;
+ }
+ if ( (c>='0') && (c<='9') )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ private bool IsValidIdentifierStartChar(char c)
+ {
+ if ( !IsValidIdentifierChar(c) )
+ {
+ return false;
+ }
+ if ( (c>='0') && (c<='9') )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ // region Accessors
+ public EnvDTE.DTE TheDTE
+ {
+ set
+ {
+ DTE = value;
+ }
+ }
+
+ /// <summary>
+ /// Look if every required field is set
+ /// This is called by all accessor method and the result is cached
+ /// so that we don't have to do the check every time a token processing
+ /// function is called
+ /// </summary>
+ private bool IsReady
+ {
+ get
+ {
+ bool isReady = DTE != null;
+ return isReady;
+ }
+ }
+
+ // TokenProcessing
+ /// <summary>
+ /// Call function with same name to remove token and save the result.
+ /// </summary>
+ /// <param name="file">File = source = destination</param>
+ public void UntokenMiscFile(string file)
+ {
+ // Source and destination have same name
+ UntokenMiscFile(file, file);
+ }
+
+ /// <summary>
+ /// For all known token, replace token with correct value
+ /// </summary>
+ /// <param name="source">File of the source file</param>
+ /// <param name="destination">File of the destination file</param>
+ public void UntokenMiscFile(string source, string destination)
+ {
+ if (!this.IsReady)
+ throw new ArgumentNullException("TokenProcessor not initialized properly");
+
+ string fileExt = System.IO.Path.GetExtension(destination);
+
+ EnvDTE.Window CurrentFile = DTE.OpenFile(
+ EnvDTE.Constants.vsViewKindTextView,
+ source);
+ ReplaceAllTokens(CurrentFile);
+ CurrentFile.Document.Save(destination);
+ CurrentFile.Close(EnvDTE.vsSaveChanges.vsSaveChangesYes);
+ }
+
+ /// <summary>
+ /// Replace all tokens in a project item (the project file itself or an object inside the project)
+ /// </summary>
+ /// <param name="projectItem">The item to untokenize</param>
+ public void UntokenProjectFile(EnvDTE.ProjectItem projectItem)
+ {
+ if (!IsReady)
+ throw new ArgumentNullException("TokenProcessor not initialized properly");
+
+ // Find the kind of item we are processing.
+ string itemName = projectItem.Name;
+
+ EnvDTE.Window CurrentFile = projectItem.Open(EnvDTE.Constants.vsViewKindTextView);
+ ReplaceAllTokens(CurrentFile);
+ CurrentFile.Close(EnvDTE.vsSaveChanges.vsSaveChangesYes);
+ }
+
+ /// <summary>
+ /// Replace all tokens in a file that has already been open in the shell
+ /// </summary>
+ /// <param name="FileToProcess">An open file in the shell</param>
+ private void ReplaceAllTokens(EnvDTE.Window FileToProcess)
+ {
+ if (!IsReady)
+ throw new ArgumentNullException("TokenProcessor not initialized properly");
+
+ EnvDTE.TextDocument document = FileToProcess.Document.Object("TextDocument") as EnvDTE.TextDocument;
+
+ // Optional Items (remove)
+ // Do this first as this will remove token that would otherwise be replaced
+ foreach(DeletePair pair in listToDelete)
+ DeleteBetweenTokens(document, pair.TokenStart, pair.TokenEnd);
+
+ // Optional Items (replace)
+ foreach(ReplacePair pair in listToReplace)
+ ReplaceToken(document, pair.Token, pair.Replacement());
+ }
+
+ /// <summary>
+ /// Replace all instances of the token with the replacement string
+ /// in the document (open in VS)
+ /// </summary>
+ /// <param name="document">VS document</param>
+ /// <param name="token">Token to be replaced</param>
+ /// <param name="replaceWith">Text to replace the token with</param>
+ private void ReplaceToken(EnvDTE.TextDocument document, string token, string replaceWith)
+ {
+ if (!IsReady)
+ throw new ArgumentNullException("TokenProcessor not initialized properly");
+
+ EnvDTE.TextRanges textRanges = null;
+ int findOptions = (int)EnvDTE.vsFindOptions.vsFindOptionsFromStart+
+ (int)EnvDTE.vsFindOptions.vsFindOptionsMatchCase+
+ (int)EnvDTE.vsFindOptions.vsFindOptionsMatchWholeWord;
+
+ //Replace all the text that matches token with thr replaceWith text:
+ document.ReplacePattern(token, replaceWith, findOptions, ref textRanges);
+ }
+
+ /// <summary>
+ /// Deletes the text between two tokens, and deletes the tokens it's self
+ /// </summary>
+ /// <param name="projectItem">The project item to make the replacements within.</param>
+ /// <param name="token1">The first token to search for.</param>
+ /// <param name="token2">The second token to search for.</param>
+ private void DeleteBetweenTokens(EnvDTE.TextDocument textDocument, string token1, string token2)
+ {
+ EnvDTE.EditPoint unusedEditPoint = null;
+ EnvDTE.TextRanges textRanges = null;
+ EnvDTE.EditPoint tokenEndPoint;
+ EnvDTE.EditPoint tokenStartPoint;
+ int findOptions;
+ findOptions = (int)EnvDTE.vsFindOptions.vsFindOptionsMatchCase + (int)EnvDTE.vsFindOptions.vsFindOptionsMatchWholeWord;
+
+ //Create edit points for searching:
+ tokenEndPoint = textDocument.StartPoint.CreateEditPoint();
+ tokenStartPoint = textDocument.StartPoint.CreateEditPoint();
+
+ //Loop while all start / end tokens can be found:
+ while (tokenStartPoint.FindPattern(token1, findOptions, ref unusedEditPoint, ref textRanges))
+ {
+ if (tokenEndPoint.FindPattern(token2, findOptions, ref tokenEndPoint, ref textRanges))
+ {
+ //Move the selection to bracket the start / end tokens:
+ textDocument.Selection.MoveToPoint(tokenStartPoint, false);
+ textDocument.Selection.MoveToPoint(tokenEndPoint, true);
+
+ //Delete the selection:
+ textDocument.Selection.Delete(1);
+ }
+ else
+ {
+ break;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Produce a string with the following format:
+ /// 0x01020304, 0x0506, 0x0708, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10
+ /// </summary>
+ /// <param name="guid"></param>
+ /// <returns></returns>
+ public string GuidToForm1(Guid guid)
+ {
+ byte [] GuidBytes = guid.ToByteArray();
+ StringBuilder ResultingStr = new StringBuilder(80);
+
+ // First 4 bytes
+ int i = 0;
+ int Number = 0;
+ for(i=0;i<4; ++i)
+ {
+ int CurrentByte = GuidBytes[i];
+ Number += CurrentByte<<(8*i);
+ }
+ UInt32 FourBytes = (UInt32)Number;
+ ResultingStr.AppendFormat(CultureInfo.InvariantCulture, "0x{0}", FourBytes.ToString("X"));
+
+ // 2 chunks of 2 bytes
+ for(int j=0; j<2; ++j)
+ {
+ Number = 0;
+ for(int k=0;k<2; ++k)
+ {
+ int CurrentByte = GuidBytes[i++];
+ Number += CurrentByte<<(8*k);
+ }
+ UInt16 TwoBytes = (UInt16)Number;
+ ResultingStr.AppendFormat(CultureInfo.InvariantCulture, ", 0x{0}", TwoBytes.ToString("X"));
+ }
+
+ // 8 chunks of 1 bytes
+ for(int j=0; j<8; ++j)
+ {
+ ResultingStr.AppendFormat(CultureInfo.InvariantCulture, ", 0x{0}", GuidBytes[i++].ToString("X"));
+ }
+
+ return ResultingStr.ToString();
+ }
+
+ /// <summary>
+ /// Produce a string with the following format:
+ /// 0x01020304, 0x0506, 0x0708, { 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 }
+ /// </summary>
+ /// <param name="guid"></param>
+ /// <returns></returns>
+ private string GuidToForm2(Guid guid)
+ {
+ byte [] GuidBytes = guid.ToByteArray();
+ StringBuilder ResultingStr= new StringBuilder(80);
+
+ // First 4 bytes
+ int i = 0;
+ int Number = 0;
+ for(i=0;i<4; ++i)
+ {
+ int CurrentByte = GuidBytes[i];
+ Number += CurrentByte<<(8*i);
+ }
+ UInt32 FourBytes = (UInt32)Number;
+ ResultingStr.AppendFormat(CultureInfo.InvariantCulture, "0x{0}", FourBytes.ToString("X"));
+
+ // 2 chunks of 2 bytes
+ for(int j=0; j<2; ++j)
+ {
+ Number = 0;
+ for(int k=0;k<2; ++k)
+ {
+ int CurrentByte = GuidBytes[i++];
+ Number += CurrentByte<<(8*k);
+ }
+ UInt16 TwoBytes = (UInt16)Number;
+ ResultingStr.AppendFormat(CultureInfo.InvariantCulture, ", 0x{0}", TwoBytes.ToString("X"));
+ }
+
+ // 8 chunks of 1 bytes
+ ResultingStr.AppendFormat(CultureInfo.InvariantCulture, ", {{ 0x{0}", GuidBytes[i++].ToString("X"));
+ for(int j=1; j<8; ++j)
+ {
+ ResultingStr.AppendFormat(CultureInfo.InvariantCulture, ", 0x{0}", GuidBytes[i++].ToString("X"));
+ }
+ ResultingStr.Append(" }");
+
+ return ResultingStr.ToString();
+ }
+ }
+
+ // Storage classes for tokens
+ class ReplacePair
+ {
+ private string token;
+ private string replacement;
+ private TokenReplaceType replaceType;
+
+ public ReplacePair(string stringToReplace, string stringToReplaceWith, TokenReplaceType ReplaceType)
+ {
+ token = stringToReplace;
+ replacement = stringToReplaceWith;
+ replaceType = ReplaceType;
+ }
+
+ /// <summary>
+ /// Token that needs to be replaced
+ /// </summary>
+ public string Token
+ {
+ get {return token;}
+ }
+
+ /// <summary>
+ /// String to replace the token with
+ /// </summary>
+ public string Replacement()
+ {
+ return replacement;
+ }
+ }
+
+ class DeletePair
+ {
+ private string tokenStart;
+ private string tokenEnd;
+
+ public DeletePair(string blockStart, string blockEnd)
+ {
+ tokenStart = blockStart;
+ tokenEnd = blockEnd;
+ }
+
+ /// <summary>
+ /// Token marking the begining of the block to delete
+ /// </summary>
+ public string TokenStart
+ {
+ get {return tokenStart;}
+ }
+
+ /// <summary>
+ /// Token marking the end of the block to delete
+ /// </summary>
+ public string TokenEnd
+ {
+ get {return tokenEnd;}
+ }
+ }
+}
More information about the svn
mailing list