1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
// Copyright © 2008, 2010, Oracle and/or its affiliates. All rights reserved.
//
// MySQL Connector/NET is licensed under the terms of the GPLv2
// <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
// MySQL Connectors. There are special exceptions to the terms and
// conditions of the GPLv2 as it is applied to this software, see the
// FLOSS License Exception
// <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
using System;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.ComponentModel.Design;
using Microsoft.Win32;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio;
using MySql.Data.VisualStudio.Properties;
using System.Reflection;
using EnvDTE;
using Microsoft.VisualStudio.CommandBars;
using MySql.Data.VisualStudio.Editors;
namespace MySql.Data.VisualStudio
{
/// <summary>
/// This is the class that implements the package exposed by this assembly.
///
/// The minimum requirement for a class to be considered a valid package for Visual Studio
/// is to implement the IVsPackage interface and register itself with the shell.
/// This package uses the helper classes defined inside the Managed Package Framework (MPF)
/// to do it: it derives from the Package class that provides the implementation of the
/// IVsPackage interface and uses the registration attributes defined in the framework to
/// register itself and its components with the shell.
/// </summary>
[ComVisible(true)]
// This attribute tells the registration utility (regpkg.exe) that this class needs
// to be registered as package.
[PackageRegistration(UseManagedResourcesOnly = true)]
// A Visual Studio component can be registered under different regitry roots; for instance
// when you debug your package you want to register it in the experimental hive. This
// attribute specifies the registry root to use if no one is provided to regpkg.exe with
// the /root switch.
[DefaultRegistryRoot("Software\\Microsoft\\VisualStudio\\9.0Exp")]
// This attribute is used to register the informations needed to show the this package
// in the Help/About dialog of Visual Studio.
[InstalledProductRegistration(true, null, null, null)]
[ProvideEditorFactory(typeof(SqlEditorFactory), 200,
TrustLevel = __VSEDITORTRUSTLEVEL.ETL_AlwaysTrusted)]
[ProvideEditorExtension(typeof(SqlEditorFactory), ".mysql", 32,
ProjectGuid = "{A2FE74E1-B743-11D0-AE1A-00A0C90FFFC3}",
TemplateDir = @"..\..\Templates",
NameResourceID = 105,
DefaultName = "MySQL SQL Editor")]
[ProvideEditorLogicalView(typeof(SqlEditorFactory), "{7651a703-06e5-11d1-8ebd-00a0c90f26ea}")]
[ProvideService(typeof(MySqlProviderObjectFactory), ServiceName = "MySQL Provider Object Factory")]
[ProvideService(typeof(MySqlLanguageService))]
[ProvideLanguageService(typeof(MySqlLanguageService), MySqlLanguageService.LanguageName, 101,
RequestStockColors = true)]
// In order be loaded inside Visual Studio in a machine that has not the VS SDK installed,
// package needs to have a valid load key (it can be requested at
// http://msdn.microsoft.com/vstudio/extend/). This attributes tells the shell that this
// package has a load key embedded in its resources.
[ProvideLoadKey("Standard", "1.0", "MySQL Tools for Visual Studio", "MySQL AB c/o MySQL, Inc.", 100)]
// This attribute is needed to let the shell know that this package exposes some menus.
[ProvideMenuResource(1000, 1)]
// This attribute registers a tool window exposed by this package.
[Guid(GuidStrings.Package)]
public sealed class MySqlDataProviderPackage : Package, IVsInstalledProduct
{
private MySqlLanguageService languageService;
public static MySqlDataProviderPackage Instance;
/// <summary>
/// Default constructor of the package.
/// Inside this method you can place any initialization code that does not require
/// any Visual Studio service because at this point the package object is created but
/// not sited yet inside Visual Studio environment. The place to do all the other
/// initialization is the Initialize method.
/// </summary>
public MySqlDataProviderPackage() : base()
{
if (Instance != null)
throw new Exception("Creating second instance of package");
Instance = this;
Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
}
/////////////////////////////////////////////////////////////////////////////
// Overriden Package Implementation
#region Package Members
/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initilaization code that rely on services provided by VisualStudio.
/// </summary>
protected override void Initialize()
{
Trace.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
MySqlProviderObjectFactory factory = new MySqlProviderObjectFactory();
((IServiceContainer)this).AddService(
typeof(MySqlProviderObjectFactory), factory, true);
base.Initialize();
RegisterEditorFactory(new SqlEditorFactory());
// Add our command handlers for menu (commands must exist in the .vsct file)
OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (null != mcs)
{
// Create the command for the menu item.
CommandID menuCommandID = new CommandID(Guids.CmdSet, (int)PkgCmdIDList.cmdidConfig);
OleMenuCommand menuItem = new OleMenuCommand(ConfigCallback, menuCommandID);
menuItem.BeforeQueryStatus += new EventHandler(configWizard_BeforeQueryStatus);
mcs.AddCommand(menuItem);
}
languageService = new MySqlLanguageService();
languageService.SetSite(this);
IServiceContainer serviceContainer = (IServiceContainer)this;
serviceContainer.AddService(typeof(MySqlLanguageService), languageService, true);
}
#endregion
void configWizard_BeforeQueryStatus(object sender, EventArgs e)
{
OleMenuCommand configButton = sender as OleMenuCommand;
configButton.Visible = false;
DTE dte = GetService(typeof(DTE)) as DTE;
Array a = (Array)dte.ActiveSolutionProjects;
if (a.Length != 1) return;
Project p = (Project)a.GetValue(0);
configButton.Visible = false;
foreach (Property prop in p.Properties)
{
if (prop.Name == "WebSiteType" || prop.Name.StartsWith("WebApplication"))
{
configButton.Visible = true;
break;
}
}
}
private void ConfigCallback(object sender, EventArgs e)
{
WebConfig.WebConfigDlg w = new WebConfig.WebConfigDlg();
w.ShowDialog();
}
#region IVsInstalledProduct Members
int IVsInstalledProduct.IdBmpSplash(out uint pIdBmp)
{
pIdBmp = 400;
return VSConstants.S_OK;
}
int IVsInstalledProduct.IdIcoLogoForAboutbox(out uint pIdIco)
{
pIdIco = 400;
return VSConstants.S_OK;
}
int IVsInstalledProduct.OfficialName(out string pbstrName)
{
pbstrName = Resources.ProductName;
return VSConstants.S_OK;
}
int IVsInstalledProduct.ProductDetails(out string pbstrProductDetails)
{
pbstrProductDetails = Resources.ProductDetails;
return VSConstants.S_OK;
}
int IVsInstalledProduct.ProductID(out string pbstrPID)
{
string fullname = Assembly.GetExecutingAssembly().FullName;
string[] parts = fullname.Split(new char[] { '=' });
string[] versionParts = parts[1].Split(new char[] { '.' });
pbstrPID = String.Format("{0}.{1}.{2}", versionParts[0], versionParts[1], versionParts[2]);
return VSConstants.S_OK;
}
#endregion
}
}
|