本文整理汇总了C#中Microsoft.VisualStudio.Shell.Package类的典型用法代码示例。如果您正苦于以下问题:C# Package类的具体用法?C# Package怎么用?C# Package使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Package类属于Microsoft.VisualStudio.Shell命名空间,在下文中一共展示了Package类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
protected override void Initialize()
{
_dte = GetService(typeof(DTE)) as DTE2;
Package = this;
Telemetry.SetDeviceName(_dte.Edition);
Logger.Initialize(this, Constants.VSIX_NAME);
Events2 events = (Events2)_dte.Events;
_solutionEvents = events.SolutionEvents;
_solutionEvents.AfterClosing += () => { TableDataSource.Instance.CleanAllErrors(); };
_solutionEvents.ProjectRemoved += (project) => { TableDataSource.Instance.CleanAllErrors(); };
_buildEvents = events.BuildEvents;
_buildEvents.OnBuildBegin += OnBuildBegin;
CreateConfig.Initialize(this);
Recompile.Initialize(this);
CompileOnBuild.Initialize(this);
RemoveConfig.Initialize(this);
CompileAllFiles.Initialize(this);
CleanOutputFiles.Initialize(this);
base.Initialize();
}
示例2: AddInheritDocCommand
private AddInheritDocCommand(Package package)
{
this.package = package;
OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandId = new CommandID(CommandSet, CommandId);
var menuItem = new OleMenuCommand(MenuItemCallback, menuCommandId);
commandService.AddCommand(menuItem);
menuItem.BeforeQueryStatus += (sender, e) =>
{
bool visible = false;
var dte = (DTE)Package.GetGlobalService(typeof(SDTE));
var classElem = SearchService.FindClass(dte);
if (classElem != null)
{
List<CodeElement> codeElements = SearchService.FindCodeElements(dte);
if (classElem.ImplementedInterfaces.Count > 0)
{
visible = true;
}
else
{
visible = codeElements.Any(elem => elem.IsInherited() || elem.OverridesSomething());
}
}
((OleMenuCommand)sender).Visible = visible;
};
}
}
示例3: LocatorWindowCommand
/// <summary>
/// Initializes a new instance of the <see cref="LocatorWindowCommand"/> class.
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
/// <param name="package">Owner package, not null.</param>
private LocatorWindowCommand(Package package)
{
if (package == null)
{
throw new ArgumentNullException("package");
}
this.package = package;
OleMenuCommandService commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, CommandId);
var menuItem = new MenuCommand(this.ShowToolWindow, menuCommandID);
commandService.AddCommand(menuItem);
}
// Get the instance number 0 of this tool window. This window is single instance so this instance
// is actually the only one.
// The last flag is set to true so that if the tool window does not exists it will be created.
_locatorWindow = package.FindToolWindow(typeof(LocatorWindow), 0, true) as LocatorWindow;
if ((null == _locatorWindow) || (null == _locatorWindow.Frame))
{
throw new NotSupportedException("Cannot create tool window");
}
_locator = new Locator();
_solution = ServiceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
_solution.AdviseSolutionEvents(_locator, out _cookie);
_locatorWindow.SetLocator(_locator);
_locator.StartWorkerThread();
}
示例4: BuildStartProject
/// <summary>
/// Initializes a new instance of the <see cref="BuildStartProject"/> class.
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
/// <param name="package">Owner package, not null.</param>
private BuildStartProject(Package package)
{
if (package == null)
{
throw new ArgumentNullException("package");
}
this.package = package;
// Add a menu item.
OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, CommandId);
var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
commandService.AddCommand(menuItem);
}
// Register as an advisory interface.
var solutionService = ServiceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
if (solutionService != null)
{
solutionService.AdviseSolutionEvents(this, out m_EventSinkCookie);
}
}
示例5: CommandWithArguments
private CommandWithArguments(Package package)
{
if (package == null)
{
throw new ArgumentNullException("package");
}
this.package = package;
OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, CommandId);
// Step 1: Add the <CommandFlag>AllowParams</CommandFlag> in the .vsct file for the command
// Step 2: Use an OleMenuCommand, not a MenuCommand
var oleMenuCommand = new OleMenuCommand(this.MenuItemCallback, menuCommandID);
// Step 3: Initialize the ParametersDescription property to the "$" value.
// That magical value means that the command accepts any kind of values
oleMenuCommand.ParametersDescription = "$";
commandService.AddCommand(oleMenuCommand);
}
}
示例6: EditorFactory
public EditorFactory(Package package, IComponentContext context)
{
Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering {0} constructor", this));
this.editorPackage = package;
this.context = context;
}
示例7: IntegrationTestServiceCommands
private IntegrationTestServiceCommands(Package package)
{
if (package == null)
{
throw new ArgumentNullException(nameof(package));
}
_package = package;
var commandService = ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var startServiceMenuCmdId = new CommandID(GrpIdIntegrationTestServiceCommands, CmdIdStartIntegrationTestService);
_startServiceMenuCmd = new MenuCommand(StartServiceCallback, startServiceMenuCmdId) {
Enabled = true,
Supported = true,
Visible = true
};
commandService.AddCommand(_startServiceMenuCmd);
var stopServiceMenuCmdId = new CommandID(GrpIdIntegrationTestServiceCommands, CmdIdStopIntegrationTestService);
_stopServiceMenuCmd = new MenuCommand(StopServiceCallback, stopServiceMenuCmdId) {
Enabled = false,
Supported = true,
Visible = false
};
commandService.AddCommand(_stopServiceMenuCmd);
}
}
示例8: PoorMansTSqlFormatterCommand
/// <summary>
/// Initializes a new instance of the <see cref="PoorMansTSqlFormatterCommand"/> class.
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
/// <param name="package">Owner package, not null.</param>
private PoorMansTSqlFormatterCommand(Package package)
{
if (package == null)
{
throw new ArgumentNullException("package");
}
this.package = package;
OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
_applicationObject = Package.GetGlobalService(typeof(DTE)) as DTE;
_formattingManager = PoorMansTSqlFormatterPluginShared.Utils.GetFormattingManager(Properties.Settings.Default);
//Command cmd = _applicationObject.Commands.Item("Tools.FormatTSQLCode", -1);
//cmd.Bindings = "Text Editor::Ctrl+Shift+D";
var menuFormatCommandID = new CommandID(CommandSet, FormatCommandId);
var menuFormatItem = new MenuCommand(this.MenuFormatCallback, menuFormatCommandID);
commandService.AddCommand(menuFormatItem);
var menuOptionsCommandID = new CommandID(CommandSet, OptionsCommandId);
var menuOptionsItem = new MenuCommand(this.MenuOptionsCallback, menuOptionsCommandID);
commandService.AddCommand(menuOptionsItem);
_formatCommand = _applicationObject.Commands.Item("Tools.FormatTSQLCode", -1);
SetFormatHotkey();
}
}
示例9: Factory
public Factory(Package package)
: base()
{
this.package = package;
var solution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution));
ErrorHandler.ThrowOnFailure(solution.AdviseSolutionEvents(this, out solutionCookie));
}
示例10: AliaserCommand
/// <summary>
/// Initializes a new instance of the <see cref="AliaserCommand"/> class.
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
/// <param name="package">Owner package, not null.</param>
private AliaserCommand(Package package)
{
if (package == null)
{
throw new ArgumentNullException("package");
}
this.package = package;
this.MainService = new AliaserService();
OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
CommandID menuToAliasCommandID = new CommandID(MenuGroup, ALIASER_TO_ALIAS_COMMAND_ID);
CommandID menuToInstanceCommandID = new CommandID(MenuGroup, ALIASER_TO_INSTANCE_COMMAND_ID);
EventHandler transformAliasToInstace = this.TransformAliasToInstace;
EventHandler transformInstaceToAlias = this.TransformInstaceToAlias;
MenuCommand menuItemToInstace = new MenuCommand(transformAliasToInstace, menuToInstanceCommandID);
MenuCommand menuItemToAlias = new MenuCommand(transformInstaceToAlias, menuToAliasCommandID);
commandService.AddCommand(menuItemToInstace);
commandService.AddCommand(menuItemToAlias);
}
}
示例11: ProjectFactory
protected ProjectFactory(Package package)
{
Package = package;
Site = package;
// Please be aware that this methods needs that ServiceProvider is valid, thus the ordering of calls in the ctor matters.
buildEngine = Utilities.InitializeMsBuildEngine(buildEngine, Site);
}
示例12: SolutionEventsListener
private SolutionEventsListener(Package package)
{
if (package == null)
throw new ArgumentNullException(nameof(package));
this.package = package;
}
示例13: VisualStudioConnection
public VisualStudioConnection(Package package)
{
_package = package;
_dte = (DTE2)Package.GetGlobalService(typeof(DTE));
_solutionEvents = ((Events2)_dte.Events).SolutionEvents;
_buildEvents = ((Events2)_dte.Events).BuildEvents;
_subject = new Subject<EventType>();
}
示例14: BooLangProjectFactory
public BooLangProjectFactory(Package package)
: base(package)
{
string booBinPath = (string)Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VisualStudio\9.0Exp\Configuration\Packages\{55663be2-a969-4279-82c5-a6f27936f4f7}").GetValue("BooBinPath");
this.package = (ProjectPackage)package;
this.BuildEngine.GlobalProperties["BoocToolPath"] = new BuildProperty("BoocToolPath", booBinPath);
this.BuildEngine.GlobalProperties["BooBinPath"] = new BuildProperty("BooBinPath",booBinPath);
}
示例15: ProjectFactory
protected ProjectFactory(Microsoft.VisualStudio.Shell.Package package)
{
this.package = package;
this.site = package;
// Please be aware that this methods needs that ServiceProvider is valid, thus the ordering of calls in the ctor matters.
this.buildEngine = Utilities.InitializeMsBuildEngine(this.buildEngine, this.site);
}