#define DIRECTLOAD
using System;
using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.Office.Core;
using Extensibility;
using EnvDTE;
using SHDocVw;
using mshtml;
namespace WebReports {
#region Read me for Add-in installation and setup information.
// When run, the Add-in wizard prepared the registry for the Add-in.
// At a later time, if the Add-in becomes unavailable for reasons such as:
// 1) You moved this project to a computer other than which is was originally created on.
// 2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
// 3) Registry corruption.
// you will need to re-register the Add-in by building the MyAddin21Setup project
// by right clicking the project in the Solution Explorer, then choosing install.
#endregion
/// <summary>The object for implementing an Add-in.</summary>
/// <seealso class='IDTExtensibility2' />
[GuidAttribute("CAFF8E86-0517-442B-9E00-E4C37419244B"), ProgId("WebReports")]
public class Connect : Object, Extensibility.IDTExtensibility2, IDTCommandTarget {
EnvDTE.Window windowToolWindow;
SHDocVw.WebBrowser Browser = null;
string tempFileName;
string rootPath;
object nullObj = null;
object oMissing = System.Reflection.Missing.Value;
const string COMMANDBARNAME = "WebReports";
const string WEBTOOLSMENU = "Web Reports";
const string DIFFMENU = "Diff Tools";
string LastCommand = String.Empty;
StringCollection CommandStack = new StringCollection();
bool registerCommandBar = false;
/// <summary>Implements the constructor for the Add-in object.</summary>
public Connect() {
tempFileName = Path.GetTempFileName();
rootPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
rootPath = rootPath.Substring(0, rootPath.LastIndexOf('\\'));
}
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface.
/// Receives notification that the Add-in is being loaded.</summary>
/// <param name='application'>Root object of the host application.</param>
/// <param name='connectMode'>Describes how the Add-in is being loaded.</param>
/// <param name='addInInst'>Object representing this Add-in.</param>
/// <seealso class='IDTExtensibility2' />
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom) {
applicationObject = (_DTE)application;
addInInstance = (AddIn)addInInst;
Object nil = System.Reflection.Missing.Value;
if (connectMode == Extensibility.ext_ConnectMode.ext_cm_UISetup) {
// When run, the Add-in wizard prepared the registry for the Add-in.
// At a later time, the Add-in or its commands may become unavailable for reasons such as:
// 1) You moved this project to a computer other than which is was originally created on.
// 2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
// 3) You add new commands or modify commands already defined.
// You will need to re-register the Add-in by building the WebReports project,
// right-clicking the project in the Solution Explorer, and then choosing install.
// Alternatively, you could execute the ReCreateCommands.reg file the Add-in Wizard generated in
// the project directory, or run 'devenv /setup' from a command prompt.
} else if (connectMode == Extensibility.ext_ConnectMode.ext_cm_Startup) {
CommandBar ToolsCmdBar = applicationObject.CommandBars["Tools"];
CommandBarPopup popUp;
CommandBar cmdBar = null;
CommandBar webMenu = null;
CommandBar diffMenu = null;
if (registerCommandBar)
cmdBar = AddCommandBar(COMMANDBARNAME);
popUp = (CommandBarPopup)ToolsCmdBar.Controls.Add(MsoControlType.msoControlPopup, oMissing, oMissing, 1, oMissing);
popUp.Caption = DIFFMENU;
diffMenu = popUp.CommandBar;
popUp = (CommandBarPopup)ToolsCmdBar.Controls.Add(MsoControlType.msoControlPopup, oMissing, oMissing, 2, oMissing);
popUp.Caption = WEBTOOLSMENU;
webMenu = popUp.CommandBar;
AddCommand("FileByType", 2, "File Types", "Lists all used file types of the current project.", "", cmdBar, webMenu);
AddCommand("Oldest", 2, "Oldest files", "List the oldest 50 files.", "", cmdBar, webMenu);
AddCommand("Newest", 2, "Recently changed files", "List the 50 recently changed files.", "", cmdBar, webMenu);
Command cmd = AddCommand("Diff", 3, "File Differences", "Report the file differences.", "", cmdBar, diffMenu);
// and add command to the contextmenu of files in solution explorer
cmd.AddControl(applicationObject.CommandBars["Item"], 3);
cmd = AddCommand("DiffFolder", 3, "Folder Differences", "Report the differences of 2 folders.", "", cmdBar, diffMenu);
// and add command to the contextmenu of folders in solution explorer
cmd.AddControl(applicationObject.CommandBars["Folder"], 2);
cmd = AddCommand("Explore", 4, "Explore", "Open this folder in the standard windows Explorer.", "");
// and add command to the contextmenu of folders and projects in solution explorer
cmd.AddControl(applicationObject.CommandBars["Folder"], 3);
cmd.AddControl(applicationObject.CommandBars["Project"], 10);
cmd.AddControl(applicationObject.CommandBars["Project Node"], 11);
cmd = AddCommand("XsltTransform", 5, "Xslt Transformation", "Transform a file using this xslt.", "", cmdBar, diffMenu);
cmd.AddControl(applicationObject.CommandBars["Item"], 4);
cmd = AddCommand("Backup", 6, "Backup", "Copy this file over to the backup folder.", "");
// and add command to the contextmenu of files in solution explorer
cmd.AddControl(applicationObject.CommandBars["Item"], 5);
} // if
} // OnConnection
/// <summary>Implements the OnDisconnection method of the IDTExtensibility2 interface.
/// Receives notification that the Add-in is being unloaded.</summary>
/// <param name='disconnectMode'>
/// Describes how the Add-in is being unloaded.
/// </param>
/// <param name='custom'>Array of parameters that are host application specific.</param>
/// <seealso class='IDTExtensibility2' />
public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom) {
Command cmd;
CommandBarControl ctrl;
if (disconnectMode == ext_DisconnectMode.ext_dm_HostShutdown) {
File.Delete(tempFileName);
try {
cmd = applicationObject.Commands.Item("WebReports.Explore", -1);
if (cmd != null) cmd.Delete();
cmd = applicationObject.Commands.Item("WebReports.Backup", -1);
if (cmd != null) cmd.Delete();
cmd = applicationObject.Commands.Item("WebReports.Diff", -1);
if (cmd != null) cmd.Delete();
cmd = applicationObject.Commands.Item("WebReports.DiffFolder", -1);
if (cmd != null) cmd.Delete();
cmd = applicationObject.Commands.Item("WebReports.XsltTransform", -1);
if (cmd != null) cmd.Delete();
ctrl = applicationObject.CommandBars["Item"].Controls["File Differences"];
if (ctrl != null) ctrl.Delete(false);
ctrl = applicationObject.CommandBars["Item"].Controls["Xslt Transformation"];
if (ctrl != null) ctrl.Delete(false);
ctrl = applicationObject.CommandBars["Item"].Controls["Backup"];
if (ctrl != null) ctrl.Delete(false);
ctrl = applicationObject.CommandBars["Folder"].Controls["Folder Differences"];
if (ctrl != null) ctrl.Delete(false);
ctrl = applicationObject.CommandBars["Folder"].Controls["Explore"];
if (ctrl != null) ctrl.Delete(false);
ctrl = applicationObject.CommandBars["Project"].Controls["Explore"];
if (ctrl != null) ctrl.Delete(false);
ctrl = applicationObject.CommandBars["Project Node"].Controls["Explore"];
if (ctrl != null) ctrl.Delete(false);
if (registerCommandBar)
applicationObject.Commands.RemoveCommandBar(applicationObject.CommandBars[COMMANDBARNAME]);
} catch (Exception ex) {
ex = ex;
} // try
} // if
} // OnDisconnection
/// <summary>Implements the OnAddInsUpdate method of the IDTExtensibility2 interface.
/// Receives notification that the collection of Add-ins has changed.</summary>
/// <param name='custom'>Array of parameters that are host application specific.</param>
/// <seealso class='IDTExtensibility2' />
public void OnAddInsUpdate(ref System.Array custom) {
} // OnAddInsUpdate
/// <summary>Implements the OnStartupComplete method of the IDTExtensibility2 interface.
/// Receives notification that the host application has completed loading.</summary>
/// <param name='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnStartupComplete(ref System.Array custom) {
object objTemp = null;
if ((applicationObject != null) && (windowToolWindow == null)) {
try {
windowToolWindow = applicationObject.Windows.CreateToolWindow (
addInInstance, "{8856F961-340A-11D0-A96B-00C04FD705A2}",
"WebReports", "{CAFF8E86-0517-442B-9E00-E4C37419244C}", ref objTemp);
} catch (Exception ex) {
ex = ex;
} // try
} // if
// windowToolWindow.Visible = true;
Browser = (SHDocVw.WebBrowser)objTemp;
Browser.Navigate(@"about:blank", ref nullObj, ref nullObj, ref nullObj, ref nullObj);
DWebBrowserEvents2_BeforeNavigate2EventHandler
DBeforeNavigateE = new DWebBrowserEvents2_BeforeNavigate2EventHandler(OnBeforeNavigate2);
Browser.BeforeNavigate2 += DBeforeNavigateE;
} // OnStartupComplete
/// <summary>Implements the OnBeginShutdown method of the IDTExtensibility2 interface.
/// Receives notification that the host application is being unloaded.</summary>
/// <param name='custom'>Array of parameters that are host application specific.</param>
/// <seealso class='IDTExtensibility2' />
public void OnBeginShutdown(ref System.Array custom) {
// close the window.
// VS.NET then remembers where it had been docked.
windowToolWindow.Visible = false;
windowToolWindow.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
} // OnBeginShutdown
/// <summary>Implements the QueryStatus method of the IDTCommandTarget interface.
/// This is called when the command's availability is updated</summary>
/// <param name='commandName'>The name of the command to determine state for.</param>
/// <param name='neededText'>Text that is needed for the command.</param>
/// <param name='status'>The state of the command in the user interface.</param>
/// <param name='commandText'>Text requested by the neededText parameter.</param>
/// <seealso class='Exec' />
public void QueryStatus(string commandName, EnvDTE.vsCommandStatusTextWanted neededText, ref EnvDTE.vsCommandStatus status, ref object commandText) {
if (neededText == EnvDTE.vsCommandStatusTextWanted.vsCommandStatusTextWantedNone) {
if (commandName == "WebReports.FileByType") {
status = vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
} else if (commandName == "WebReports.Oldest") {
status = vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
} else if (commandName == "WebReports.Newest") {
status = vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
} else if (commandName == "WebReports.Diff") {
status = vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
} else if (commandName == "WebReports.XsltTransform") {
status = vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
} else if (commandName == "WebReports.DiffFolder") {
status = vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
} else if (commandName == "WebReports.Explore") {
status = vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
} else if (commandName == "WebReports.Backup") {
status = vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
} // if
} else {
neededText = neededText;
} // if
} // QueryStatus
/// <summary>Implements the Exec method of the IDTCommandTarget interface.
/// This is called when the command is invoked.</summary>
/// <param name='commandName'>The name of the command to execute.</param>
/// <param name='executeOption'>Describes how the command should be run.</param>
/// <param name='varIn'>Parameters passed from the caller to the command handler.</param>
/// <param name='varOut'>Parameters passed from the command handler to the caller.</param>
/// <param name='handled'>Informs the caller if the command was handled or not.</param>
/// <seealso class='Exec' />
public void Exec(string commandName, EnvDTE.vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled) {
handled = false;
StringBuilder sb = null;
StringWriter output = null;
Report report = null;
int ExpectedArgs = 0;
string [] args = null;
int argc = 0;
if (executeOption == EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault) {
if ((applicationObject != null) && (Browser != null)) {
commandName = commandName.ToLower();
System.Diagnostics.Debug.Write(commandName + "\n", "Exec");
try {
if (commandName == "webreports.filebytype") {
report = new WebReports.ReportFileTypes();
} else if (commandName == "webreports.newest") {
report = new WebReports.ReportNewest();
} else if (commandName == "webreports.oldest") {
report = new WebReports.ReportOldest();
} else if (commandName == "webreports.diff") {
report = new WebReports.ReportDiffFiles();
} else if (commandName == "webreports.difffolder") {
report = new WebReports.ReportDiffFolder();
} else if (commandName == "webreports.xslttransform") {
report = new WebReports.ReportXSLT();
} else if (commandName == "webreports.explore") {
ProjectItem p = (ProjectItem)applicationObject.SelectedItems.Item(1).ProjectItem;
string fName;
if (p != null) {
fName = p.get_FileNames(0);
} else {
Project pro = applicationObject.SelectedItems.Item(1).Project;
fName = pro.FullName;
fName = fName.Substring(0, fName.LastIndexOf('\\'));
} // if
openExplorer(fName);
} else if (commandName == "webreports.backup") {
report = new WebReports.BackupFile();
/*
string fName = (string)varIn;
if (fName == null) {
ProjectItem p = (ProjectItem)applicationObject.SelectedItems.Item(1).ProjectItem;
if (p != null)
fName = p.get_FileNames(0);
} // if
System.Windows.Forms.MessageBox.Show("Backup file " + fName + "... ", "Not done");
*/
} // if
if (report != null) {
ExpectedArgs = report.Arguments;
StringCollection cmdArgs = new StringCollection();
if (varIn != null) {
Match m = Regex.Match((string)varIn, @"(('[^']*')|(""[^""]*"")|([^ ]+))\s*");
while (m.Success) {
string arg = m.Groups[1].Value;
if ((arg[0] == '\'') || (arg[0] == '\"'))
arg = arg.Substring(1, arg.Length-2);
cmdArgs.Add(arg);
m = m.NextMatch();
} // while
} // if
// append default argument
if (cmdArgs.Count < ExpectedArgs) {
string s = report.DefaultArgument(applicationObject);
if ((s != null) && (s.Length > 0))
cmdArgs.Add(s);
} // if
// append up to 2 selected project items
if ((cmdArgs.Count < ExpectedArgs) && (applicationObject.SelectedItems.Count > 0)) {
ProjectItem p = (ProjectItem)applicationObject.SelectedItems.Item(1).ProjectItem;
cmdArgs.Add(p.get_FileNames(0));
} // if
if ((cmdArgs.Count < ExpectedArgs) && (applicationObject.SelectedItems.Count > 1)) {
ProjectItem p = (ProjectItem)applicationObject.SelectedItems.Item(2).ProjectItem;
cmdArgs.Add(p.get_FileNames(0));
} // if
if (report.FolderParameter) {
// request for folders
while (cmdArgs.Count < ExpectedArgs) {
// request the folder path
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.Description = String.Format("Select the {0}. folder parameter", cmdArgs.Count+1);
if (argc > 0)
fbd.SelectedPath = args[0];
if (fbd.ShowDialog() == DialogResult.OK)
cmdArgs.Add(fbd.SelectedPath);
else
return; // do not execute this command on cancel.
} // while
} else {
while (cmdArgs.Count < ExpectedArgs) {
// request the file path
OpenFileDialog ofd = new OpenFileDialog();
if (argc > 0)
ofd.InitialDirectory = args[0];
ofd.Filter = "All Files (*.*)|*.*";
ofd.RestoreDirectory = true;
ofd.Title = String.Format("Select the {0}. file", cmdArgs.Count+1);
if (ofd.ShowDialog() == DialogResult.OK)
cmdArgs.Add(ofd.FileName);
else
return; // do not execute this command on cancel.
} // while
}
// copy args to a plain array
args = new string[cmdArgs.Count];
cmdArgs.CopyTo(args, 0);
// build text-version of the command and execute it through the command-Window.
string cmdText = commandName;
foreach (string c in args)
cmdText += " '" + c + "'";
if (cmdText.ToLower().Replace("'", String.Empty).Replace("\"", String.Empty)
!= LastCommand.ToLower().Replace("'", String.Empty).Replace("\"", String.Empty)) {
EnvDTE.Window win = applicationObject.Windows.Item(EnvDTE.Constants.vsWindowKindCommandWindow);
EnvDTE.CommandWindow cmdWin = (EnvDTE.CommandWindow)win.Object;
LastCommand = cmdText.ToLower();
cmdWin.SendInput(cmdText, true);
return; // this function will be called soon again - but with all parameters in the commandline.
} // if
// open the tool-window and start working...
windowToolWindow.Visible = true;
sb = new StringBuilder();
output = new StringWriter(sb);
if ((CommandStack.Count == 0) || (CommandStack[CommandStack.Count-1] != LastCommand))
CommandStack.Add(LastCommand);
try {
report.Render(applicationObject, output, args);
} catch (Exception ex) {
output.WriteLine("<html><body style='FONT-FAMILY: Arial,Verdana; FONT-SIZE: 9pt;'>");
output.WriteLine("<h3>{0} occured</h3>", ex.GetType().Name);
output.WriteLine("<p>{0}", ex.Message);
if (ex.HelpLink != null)
output.WriteLine("<br><br><a href='{0}'>Goto Error</a>", ex.HelpLink);
output.WriteLine("</p>");
output.WriteLine("</body></html>");
} // try
} // if
} catch (ArgumentException ae) {
System.Windows.Forms.MessageBox.Show(ae.Message, COMMANDBARNAME);
} catch (Exception e) {
e = e;
} // try
if (output != null) {
#if DIRECTLOAD
output.Close();
output = null;
sb.Replace("[ROOT]", rootPath);
IHTMLDocument2 hDoc2 = (IHTMLDocument2)Browser.Document;
// clear the document first.
hDoc2.write("");
hDoc2.close();
// write new content.
hDoc2.write(sb.ToString());
hDoc2.close();
#else
StreamWriter outStream = new StreamWriter(tempFileName, false, Encoding.UTF8);
outStream.Write(sb.ToString());
outStream.Close();
string s2 = Browser.LocationURL;
if (Browser.LocationURL != "about:blank") {
object Level = 3; // REFRESH_COMPLETELY
Browser.Refresh2(ref Level);
} else {
Browser.Navigate(tempFileName, ref nullObj, ref nullObj, ref nullObj, ref nullObj);
} // if
#endif
} // if
handled = true;
return;
}
}
} // Exec
/// <summary>This method is attached to the browser event onbeforenavigate2 to capture dte: links</summary>
/// <param name="ob1"></param>
/// <param name="URL">The new url</param>
/// <param name="Flags"></param>
/// <param name="Name"></param>
/// <param name="da"></param>
/// <param name="Head"></param>
/// <param name="Cancel">will set to true if a dte: command was found.</param>
private void OnBeforeNavigate2(Object ob1, ref Object URL, ref Object Flags, ref Object Name, ref Object da, ref Object Head, ref bool Cancel) {
int p;
EnvDTE.Window win;
if (URL != null) {
string url = URL.ToString().ToLower();
url = System.Web.HttpUtility.UrlDecode(url);
System.Diagnostics.Debug.Write(url + "\n", "OnBeforeNav");
if (url.ToLower().StartsWith("res://")) {
// "sometimes" the ie reports a syntax error, but it is not... so reload the page
System.Diagnostics.Debug.Write("OUPS!!!!\n", "OnBeforeNav");
url = "dte:reload";
Cancel = true;
return;
} // if
if (! url.ToLower().StartsWith("dte:")) {
System.Windows.Forms.MessageBox.Show("catch:<" + url + ">", "OnBeforeNavigate2");
} else {
Cancel = true;
// analyse http like url syntax
StringDictionary urlParams = new StringDictionary();
string urlPath;
// analyse all the parameters
p = url.IndexOf('?');
if (p < 0) {
urlPath = url;
} else {
urlPath = url.Substring(0, p);
foreach (string s in url.Substring(p+1).Split('&')) {
string [] param = s.Split('=');
urlParams.Add(param[0].ToLower(), System.Web.HttpUtility.UrlDecode(param[1]));
} // foreach
} // if
if (urlPath == "dte:file") {
string fName = urlParams["file"];
win = applicationObject.ItemOperations.OpenFile(fName, null);
if (urlParams["line"] != null) {
EnvDTE.TextSelection sel = (EnvDTE.TextSelection)win.Document.Selection;
int fLine = int.Parse(urlParams["line"]);
if (urlParams["pos"] == null) {
// a line number is given
sel.GotoLine(fLine, false);
} else {
int fPos = int.Parse(urlParams["pos"]);
sel.MoveToLineAndOffset(fLine, fPos, false);
} // if
} // if
} else if (urlPath == "dte:folder") {
openExplorer(urlParams["folder"]);
} else if (urlPath == "dte:back") {
// go back one command and repeat it
p = CommandStack.Count;
if (p > 1) {
LastCommand = CommandStack[p-2]; // do not record in the commandWindow
CommandStack.RemoveAt(p-1);
p = LastCommand.IndexOf(' ');
if (p > 0) {
applicationObject.ExecuteCommand(LastCommand.Substring(0, p), LastCommand.Substring(p+1));
} else {
applicationObject.ExecuteCommand(LastCommand, String.Empty);
} // if
} // if
} else if (urlPath == "dte:reload") {
// repeat last command. do not record in the commandWindow
p = CommandStack.Count;
if (p >= 1) {
LastCommand = CommandStack[p-1];
p = LastCommand.IndexOf(' ');
if (p > 0) {
applicationObject.ExecuteCommand(LastCommand.Substring(0, p), LastCommand.Substring(p+1));
} else {
applicationObject.ExecuteCommand(LastCommand, String.Empty);
} // if
} // if
} else if (urlPath == "dte:diff") {
string oldFile = urlParams["old"];
string newFile = urlParams["new"];
object param = "'" + newFile + "' '" + oldFile + "'";
bool retBool = false;
Exec("WebReports.Diff", EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault,
ref param, ref nullObj, ref retBool);
} else if (urlPath == "dte:difffolder") {
string oldFile = urlParams["old"];
string newFile = urlParams["new"];
object param = "'" + newFile + "' '" + oldFile + "'";
bool retBool = false;
Exec("WebReports.Diff", EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault,
ref param, ref nullObj, ref retBool);
} else if (urlPath == "dte:transform") {
string xmlFile = urlParams["xml"];
string xsltFile = urlParams["xslt"];
string html = urlParams["html"];
// bool retBool = false;
// Exec("WebReports.XSLTTransform", EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault,
// ref param, ref nullObj, ref retBool);
} else if (urlPath == "dte:copy") {
string srcFile = urlParams["src"];
string destFile = urlParams["dest"];
ShellLib.ShellFileOperation.DeleteFile(destFile);
File.Copy(srcFile, destFile, true);
// repeat last command. do not record in the commandWindow
p = CommandStack.Count;
if (p >= 1) {
LastCommand = CommandStack[p-1];
p = LastCommand.IndexOf(' ');
if (p > 0) {
applicationObject.ExecuteCommand(LastCommand.Substring(0, p), LastCommand.Substring(p+1));
} else {
applicationObject.ExecuteCommand(LastCommand, String.Empty);
} // if
} // if
} else if (urlPath == "dte:backup") {
applicationObject.ExecuteCommand("WebReports.Backup", "'" + urlParams["file"] + "'");
} else {
System.Windows.Forms.MessageBox.Show("catch:<" + url + ">", "OnBeforeNavigate2");
} // if
} // if
} // if
} // OnBeforeNavigate2
/// <summary>Start the Explorer.</summary>
/// <param name="folderName">The folder that should be shown fist.</param>
private void openExplorer (string folderName) {
System.Diagnostics.Process newProcess = new System.Diagnostics.Process();
newProcess.StartInfo.FileName = folderName;
newProcess.StartInfo.UseShellExecute = true;
newProcess.StartInfo.ErrorDialog = true;
newProcess.Start();
} // openExplorer
#region Comfortable Command Bar functions
private static _DTE applicationObject; // why static ?
private AddIn addInInstance;
private CommandBar AddCommandBar (String szName) {
Commands commands = applicationObject.Commands;
CommandBar cmdBar = null;
try {
CommandBar oldCmdBar = applicationObject.CommandBars[szName];
commands.RemoveCommandBar(oldCmdBar);
} catch(System.ArgumentException ex) {
ex = ex; // Thrown if command doesn't already exist.
}
try {
cmdBar = (CommandBar)commands.AddCommandBar(szName, vsCommandBarType.vsCommandBarTypeToolbar, null, 0);
} catch(System.ArgumentException ex) {
ex = ex; // Thrown if command doesn't already exist.
}
return(cmdBar);
}
/// <summary>Add one of the commands, dealing with the errors that might result.</summary>
/// <remarks>First version from MSDN Magazin 02/02</remarks>
/// <param name="szName">name of the command being added</param>
/// <param name="szButtonText">text displayed on menu or button</param>
/// <param name="szToolTip">text displayed in tool tip</param>
/// <param name="szKey">default key assignment, or empty string if none</param>
/// <param name="szMenuToAddTo">default menu to place on, or empty if none</param>
private Command AddCommand (String szName, int IconNr, String szButtonText, String szToolTip, String szKey, params CommandBar [] CmdBars) {
Command cmd = null;
object []GuidArray = new object[] { };
// The IDE identifies commands by their full name, which include the add-in name
try {
cmd = applicationObject.Commands.Item ("WebReports." + szName, -1);
cmd.Delete();
} catch(System.ArgumentException ex) {
ex = ex; // Thrown if command doesn't already exist.
}
try {
cmd = applicationObject.Commands.AddNamedCommand (addInInstance, szName, szButtonText, szToolTip,
false, IconNr, ref GuidArray,
(int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled);
} catch(System.ArgumentException ex) {
ex = ex; // Thrown if command already exist.
}
if ((szKey != null) && (szKey != "")) {
// a default keybinding specified
object [] bindings;
bindings = (object [])cmd.Bindings;
if (0 >= bindings.Length) {
// there is no preexisting key binding, so add the default
bindings = new object[1];
bindings[0] = (object)szKey;
cmd.Bindings = (object)bindings;
} // if
} // if
// Append Control at end of CommandBar
foreach (CommandBar c in CmdBars) {
if (c != null)
cmd.AddControl(c, c.Controls.Count+1);
} // foreach
return(cmd);
} // AddCommand
#endregion
}
}