protected override void Dispose(bool disposing) { if (disposing && !_disposed) { _disposed = true; if (_docEvents != null) { _docEvents.DocumentSaved -= DocEventsOnDocumentSaved; _docEvents = null; } if (_buildEvents != null) { _buildEvents.OnBuildBegin += BuildEventsOnOnBuildBegin; _buildEvents.OnBuildDone += BuildEventsOnOnBuildDone; _buildEvents = null; } if (_solutionEvents != null) { _solutionEvents.BeforeClosing -= SolutionEventsOnBeforeClosing; _solutionEvents = null; } } base.Dispose(disposing); }
/// <summary> /// Subscribes to the DocumentSaved event. /// </summary> private void InitializeAddIn() { Command[] availableResharperCleanupCommands = this.dte.Commands.Cast <Command>().Where(x => ReSharperSilentCleanupCodeCommandsNames.Contains(x.Name)).ToArray(); if (!availableResharperCleanupCommands.Any()) { return; } this.resharperCommandToUse = availableResharperCleanupCommands.First().Name; var events2 = this.dte.Events; this.DisconnectFromVsEvents(); this.documentEvents = events2.DocumentEvents[null]; this.documentEvents.DocumentSaved += this.OnDocumentSaved; this.documentEvents.DocumentClosing += this.OnDocumentClosing; this.buildEvents = events2.BuildEvents; this.buildEvents.OnBuildBegin += this.OnBuildBegin; this.buildEvents.OnBuildDone += this.OnBuildDone; this.solutionEvents = events2.SolutionEvents; this.solutionEvents.Opened += this.OnOpenedSolution; this.solutionEvents.BeforeClosing += this.OnBeforeClosingSolution; this.timer.Start(); }
protected override void Initialize() { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); // Add our command handlers for menu (commands must exist in the .vsct file) OleMenuCommandService mcs = this.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { // Create the command for the menu item. var editProjMenuItem = new MenuCommand(ProjMenuItemCallback, new CommandID(GuidList.EditProjCmdSetId, (int)PkgCmdIDList.editProjFile)); var editSlnMenuItem = new MenuCommand(SlnMenuItemCallback, new CommandID(GuidList.EditSlnCmdSetId, (int)PkgCmdIDList.editSlnFile)); this.dte = this.GetService(typeof(DTE)) as DTE; // need to keep a strong reference to CommandEvents so that it's not GC'ed this.saveFileCommand = this.dte.Events.CommandEvents[VSConstants.CMDSETID.StandardCommandSet97_string, (int)VSConstants.VSStd97CmdID.SaveProjectItem]; this.saveAllCommand = this.dte.Events.CommandEvents[VSConstants.CMDSETID.StandardCommandSet97_string, (int)VSConstants.VSStd97CmdID.SaveSolution]; this.exitCommand = this.dte.Events.CommandEvents[VSConstants.CMDSETID.StandardCommandSet97_string, (int)VSConstants.VSStd97CmdID.Exit]; this.saveFileCommand.AfterExecute += saveCommands_AfterExecute; documentEvents = this.dte.Events.DocumentEvents; documentEvents.DocumentClosing += documentClosing; this.saveAllCommand.AfterExecute += saveCommands_AfterExecute; this.exitCommand.BeforeExecute += exitCommand_BeforeExecute; mcs.AddCommand(editProjMenuItem); mcs.AddCommand(editSlnMenuItem); } }
private void WireUpEvents() { _dteEvents = Dte.Events; _solutionEvents = _dteEvents.SolutionEvents; _solutionEvents.ProjectAdded += project => _templateController.ResetTemplates(); _solutionEvents.ProjectRemoved += project => _templateController.ResetTemplates(); _solutionEvents.ProjectRenamed += (project, oldName) => _templateController.ResetTemplates(); _solutionMonitor.AdviseTrackProjectDocumentsEvents(); _solutionMonitor.TemplateAdded += (sender, args) => _templateController.ResetTemplates(); _solutionMonitor.TemplateDeleted += (sender, args) => _templateController.ResetTemplates(); _solutionMonitor.TemplateRenamed += (sender, args) => _templateController.ResetTemplates(); _solutionMonitor.CsFileAdded += (sender, args) => _generationController.OnCsFileChanged(args.Paths); _solutionMonitor.CsFileDeleted += (sender, args) => _generationController.OnCsFileDeleted(args.Paths); _solutionMonitor.CsFileRenamed += (sender, args) => _generationController.OnCsFileRenamed(args.Paths, args.OldPaths); _documentEvents = _dteEvents.DocumentEvents; _documentEvents.DocumentSaved += document => { if (document.FullName.EndsWith(Constants.CsExtension, StringComparison.InvariantCultureIgnoreCase)) { _generationController.OnCsFileChanged(new[] { document.FullName }); } else if (document.FullName.EndsWith(Constants.TemplateExtension, StringComparison.InvariantCultureIgnoreCase)) { _generationController.OnTemplateChanged(document.FullName); } }; RenderTemplate.Instance.RenderTemplateClicked += (sender, args) => _generationController.OnTemplateChanged(args.Path, true); }
/// <summary> /// Setups the event handlers. /// </summary> internal void SetupEventHandlers() { TraceService.WriteLine("NugetService::SetupEventHandlers"); this.documentEvents = this.visualStudioService.DTEService.GetDocumentEvents(); this.documentEvents.DocumentOpened += this.DocumentEventsDocumentOpened; }
public FormsPlayerViewModel([Import(typeof(SVsServiceProvider))] IServiceProvider services) { ConnectCommand = new DelegateCommand(Connect, () => !isConnected); DisconnectCommand = new DelegateCommand(Disconnect, () => isConnected); events = services.GetService <DTE>().Events.DocumentEvents; events.DocumentSaved += document => Publish(document.FullName); var manager = new ShellSettingsManager(services); settings = manager.GetWritableSettingsStore(SettingsScope.UserSettings); if (!settings.CollectionExists(SettingsPath)) { settings.CreateCollection(SettingsPath); } if (settings.PropertyExists(SettingsPath, SettingsKey)) { SessionId = settings.GetString(SettingsPath, SettingsKey, ""); } if (string.IsNullOrEmpty(SessionId)) { // Initialize SessionId from MAC address. var mac = NetworkInterface.GetAllNetworkInterfaces() .Where(nic => nic.NetworkInterfaceType != NetworkInterfaceType.Loopback) .Select(nic => nic.GetPhysicalAddress().ToString()) .First(); SessionId = NaiveBijective.Encode(NaiveBijective.Decode(mac)); } TaskScheduler.UnobservedTaskException += OnTaskException; }
public async Task StopPulseTrackingAsync() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); this.StopTimer(); if (await GetServiceAsync(typeof(DTE)) is DTE dte) { Events events = dte.Events; WindowEvents windowEvents = events.WindowEvents; windowEvents.WindowActivated -= this.OnActiveDocumentChanged; this.dteEvents = events.DTEEvents; this.dteEvents.OnBeginShutdown -= this.OnBeginShutdown; this.textEditorEvents = events.TextEditorEvents; this.textEditorEvents.LineChanged -= this.OnLineChanged; this.buildEvents = events.BuildEvents; this.buildEvents.OnBuildDone -= this.OnBuildDone; this.documentEvents = events.DocumentEvents; this.documentEvents.DocumentSaved -= this.OnDocumentSaved; } }
public DTEHelper(DTE dte) { this.DTE = dte; Current = this; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; //System.Windows.Input.Keyboard.AddPreviewKeyDownHandler(System.Windows.Application.Current.MainWindow, new System.Windows.Input.KeyEventHandler(App_KeyDown)); System.Windows.Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException; System.Windows.Forms.Application.ThreadException += Application_ThreadException; docEvents = DTE.Events.DocumentEvents; //docEvents.DocumentOpening += DocumentEvents_DocumentOpening; //docEvents.DocumentClosing += VSPackage1Package_DocumentClosing; //VS关闭命令事件 //cmdEvents = DTE.Events.CommandEvents["{5EFC7975-14BC-11CF-9B2B-00AA00573819}", 229]; //cmdEvents.BeforeExecute += cmdEvents_BeforeExecute; //solEvents = DTE.Events.SolutionEvents; //solEvents.Opened += solEvents_Opened; wndEvents = DTE.Events.WindowEvents; wndEvents.WindowActivated += wndEvents_WindowActivated; dteEvents = DTE.Events.DTEEvents; dteEvents.OnStartupComplete += dteEvents_OnStartupComplete; TextViewCreationListener.FileContentChanged += TextViewCreationListener_FileContentChanged; UploadLog(); }
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); await Command.InitializeAsync(this); ObjDte = (DTE) await GetServiceAsync(typeof(DTE)); InitTrackFile(); try { // VisualStudio Object _docEvents = ObjDte.Events.DocumentEvents; _windowEvents = ObjDte.Events.WindowEvents; _solutionEvents = ObjDte.Events.SolutionEvents; _buildEvents = ObjDte.Events.BuildEvents; // setup event handlers _solutionEvents.BeforeClosing += SolutionEventsBeforeClosing; _buildEvents.OnBuildBegin += BuildEventsOnBuildBegin; _buildEvents.OnBuildDone += BuildEventsOnBuildDone; StartTrack(); } catch (Exception) { throw; } }
public void InitializeAsync() { try { Logger.Info(string.Format("Initializing WakaTime v{0}", WakaTimeConstants.PluginVersion)); // VisualStudio Object _docEvents = ObjDte.Events.DocumentEvents; _windowEvents = ObjDte.Events.WindowEvents; _solutionEvents = ObjDte.Events.SolutionEvents; // Settings Form _settingsForm = new SettingsForm(); _settingsForm.ConfigSaved += SettingsFormOnConfigSaved; try { // Make sure python is installed if (!PythonManager.IsPythonInstalled()) { Downloader.DownloadAndInstallPython(); } if (!DoesCliExist() || !IsCliLatestVersion()) { Downloader.DownloadAndInstallCli(); } } catch (WebException ex) { Logger.Error("Are you behind a proxy? Try setting a proxy in iTimeTrack Settings with format https://user:pass@host:port. Exception Traceback:", ex); } catch (Exception ex) { Logger.Error("Error detecting dependencies. Exception Traceback:", ex); } // Add our command handlers for menu (commands must exist in the .vsct file) var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (mcs != null) { // Create the command for the menu item. var menuCommandId = new CommandID(GuidList.GuidWakaTimeCmdSet, (int)PkgCmdIdList.UpdateWakaTimeSettings); var menuItem = new MenuCommand(MenuItemCallback, menuCommandId); mcs.AddCommand(menuItem); } // setup event handlers _docEvents.DocumentOpened += DocEventsOnDocumentOpened; _docEvents.DocumentSaved += DocEventsOnDocumentSaved; _windowEvents.WindowActivated += WindowEventsOnWindowActivated; _solutionEvents.Opened += SolutionEventsOnOpened; Logger.Info(string.Format("Finished initializing WakaTime v{0}", WakaTimeConstants.PluginVersion)); } catch (Exception ex) { Logger.Error("Error initializing Wakatime", ex); } }
public StepTaggerProvider() { if (_events2 != null) { return; } _events2 = GaugePackage.DTE.Events as Events2; _codeModelEvents = _events2.CodeModelEvents; _projectItemsEvents = _events2.ProjectItemsEvents; _documentEvents = _events2.DocumentEvents; _codeModelEvents.ElementAdded += element => RefreshUsages(); _codeModelEvents.ElementChanged += (element, change) => RefreshUsages(); _codeModelEvents.ElementDeleted += (parent, element) => RefreshUsages(); _projectItemsEvents.ItemAdded += item => RefreshUsages(); _projectItemsEvents.ItemRemoved += item => RefreshUsages(); _projectItemsEvents.ItemRenamed += (item, name) => RefreshUsages(); _documentEvents.DocumentSaved += document => { if (document.IsGaugeConceptFile() || document.IsGaugeSpecFile()) { RefreshUsages(); } }; }
/// <summary> /// Subscribes to the DocumentSaved event. /// </summary> private void InitializeAddIn() { if (this.dte.Commands.Cast <Command>().All(x => x.Name != ReSharperSilentCleanupCodeCommandName)) { return; } var events2 = (EnvDTE80.Events2) this.dte.Events; this.DisconnectFromVsEvents(); this.documentEvents = events2.DocumentEvents[null]; this.documentEvents.DocumentSaved += this.OnDocumentSaved; this.documentEvents.DocumentClosing += this.OnDocumentClosing; this.buildEvents = events2.BuildEvents; this.buildEvents.OnBuildBegin += this.OnBuildBegin; this.buildEvents.OnBuildDone += this.OnBuildDone; this.solutionEvents = events2.SolutionEvents; this.solutionEvents.Opened += this.OnOpenedSolution; this.solutionEvents.BeforeClosing += this.OnBeforeClosingSolution; this.timer.Start(); }
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { Debug.WriteLine("Entering Initialize() of: {0}", this); await base.InitializeAsync(cancellationToken, progress); _dte = (DTE)(await GetServiceAsync(typeof(DTE))); _events = _dte.Events; _documentEvents = _events.DocumentEvents; _documentEvents.DocumentSaved += DocumentEvents_DocumentSaved; var window = _dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput); var outputWindow = (OutputWindow)window.Object; _outputPane = outputWindow.OutputWindowPanes .Cast <OutputWindowPane>() .FirstOrDefault(p => p.Name == "AutoRunCustomTool") ?? outputWindow.OutputWindowPanes.Add("AutoRunCustomTool"); _errorListProvider = new ErrorListProvider(this) { ProviderName = "AutoRunCustomTool", ProviderGuid = Guid.NewGuid() }; RegisterExtenderProvider(); }
private void InitializeAsync() { try { // VisualStudio Object _docEvents = ObjDte.Events.DocumentEvents; _windowEvents = ObjDte.Events.WindowEvents; _solutionEvents = ObjDte.Events.SolutionEvents; // Settings Form _settingsForm = new SettingsForm(ref WakaTime); _settingsForm.ConfigSaved += SettingsFormOnConfigSaved; // Add our command handlers for menu (commands must exist in the .vsct file) if (GetService(typeof(IMenuCommandService)) is OleMenuCommandService mcs) { // Create the command for the menu item. var menuCommandId = new CommandID(GuidList.GuidWakaTimeCmdSet, (int)PkgCmdIdList.UpdateWakaTimeSettings); var menuItem = new MenuCommand(MenuItemCallback, menuCommandId); mcs.AddCommand(menuItem); } // setup event handlers _docEvents.DocumentOpened += DocEventsOnDocumentOpened; _docEvents.DocumentSaved += DocEventsOnDocumentSaved; _windowEvents.WindowActivated += WindowEventsOnWindowActivated; _solutionEvents.Opened += SolutionEventsOnOpened; WakaTime.InitializeAsync(); } catch (Exception ex) { WakaTime.Logger.Error("Error Initializing WakaTime", ex); } }
public async Task InitializeListenersAsync() { string MethodName = "InitializeListenersAsync"; try { await JoinableTaskFactory.SwitchToMainThreadAsync(); string PluginVersion = GetVersion(); Logger.Info(string.Format("Initializing Code Time v{0}", PluginVersion)); Logger.FileLog("Initializing Code Time", MethodName); _statusBarButton = new StatusBarButton(); await this.InitializeUserInfoAsync(); // VisualStudio Object Events2 events = (Events2)ObjDte.Events; _textDocKeyEvent = events.TextDocumentKeyPressEvents; _docEvents = events.DocumentEvents; _solutionEvents = events.SolutionEvents; // _solutionEvents.Opened += this.SolutionEventOpenedAsync; Task.Delay(3000).ContinueWith((task) => { SolutionEventOpenedAsync(); }); } catch (Exception ex) { Logger.Error("Error Initializing SoftwareCo", ex); } }
/// <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 initialization code that rely on services provided by VisualStudio. /// </summary> /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param> /// <param name="progress">A provider for progress updates.</param> /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns> protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var dte = await GetServiceAsync(typeof(DTE)) as DTE; Assumes.Present(dte); // trigger scaffold when RAML document gets saved events = dte.Events; documentEvents = events.DocumentEvents; documentEvents.DocumentSaved += DocumentEventsOnDocumentSaved; await AddContractCommand.InitializeAsync(this, dte); await ExtractRAMLCommand.InitializeAsync(this, dte); await AddReferenceCommand.InitializeAsync(this); await EditPropertiesCommand.InitializeAsync(this); Tracking.Init(); }
public DocumentEventsTrackerTest() { _solutionEventsMock = Substitute.For <SolutionEvents>(); _solutionEventsMock.Opened += Arg.Any <_dispSolutionEvents_OpenedEventHandler>(); _solutionEventsMock.BeforeClosing += Arg.Any <_dispSolutionEvents_BeforeClosingEventHandler>(); _solutionEventsMock.AfterClosing += Arg.Any <_dispSolutionEvents_AfterClosingEventHandler>(); _documentEventsMock = Substitute.For <DocumentEvents>(); _documentEventsMock.DocumentClosing += Arg.Any <_dispDocumentEvents_DocumentClosingEventHandler>(); _eventsMock = new Mock <Events>(); _eventsMock.SetupGet(g => g.SolutionEvents).Returns(_solutionEventsMock); _eventsMock.Setup(g => g.get_DocumentEvents(It.IsAny <EnvDTE.Document>())).Returns(_documentEventsMock); _solutionMock = new Mock <Solution>(); _solutionMock.SetupGet(g => g.FullName).Returns("c:\\test.sln"); _dteMock = new Mock <_DTE>(); _dteMock.SetupGet(g => g.Events).Returns(_eventsMock.Object); _dteMock.SetupGet(g => g.Solution).Returns(_solutionMock.Object); _documentHistoryManagerMock = new Mock <IDocumentHistoryManager>(); _documentHistoryManagerMock.Setup(s => s.Initialize(It.IsAny <IEnumerable <IClosedDocument> >())); _historyRepositoryFactoryMock = new Mock <IHistoryRepositoryFactory>(); _historyRepositoryMock = new Mock <IHistoryRepository>(); _messageBoxMock = new Mock <IMessageBox>(); _messageBoxMock.Setup(s => s.ShowError(It.IsAny <string>(), It.IsAny <string>())); _documentEventsTracker = new DocumentEventsTracker(_dteMock.Object, _documentHistoryManagerMock.Object, _historyRepositoryFactoryMock.Object, _messageBoxMock.Object); }
/// <summary> /// Initializes the package environment by hooking into the VS IDE. /// </summary> /// <returns>If the environment was successfully initialized, the return value is true. Otherwise, the return value is false.</returns> private bool InitializeEnvironment() { try { // Cache the environment _dte = GetService(typeof(DTE)) as DTE; if (_dte == null) { return(false); } // Cache the options page. _generalOptions = GetAutomationObject("UncrustifyVS.General") as OptionsPageGeneral; if (_generalOptions == null) { return(false); } // Save the environment events so they don't get GC'd. _dteEvents = _dte.Events; _dteDocEvents = _dteEvents.DocumentEvents; // Register the document callbacks for event-driven formatting _dteDocEvents.DocumentSaved += DocEvents_Saved; _dteDocEvents.DocumentOpened += DocEvents_Opened; return(true); } catch { return(false); } }
public void SolutionLoaded() { _dte = (DTE)GetService(typeof(DTE)); if (_dte == null) { Debug.WriteLine("Unable to get the EnvDTE.DTE service."); return; } var events = _dte.Events as Events2; if (events == null) { Debug.WriteLine("Unable to get the Events2."); return; } _documentEvents = events.get_DocumentEvents(); _documentEvents.DocumentSaved += BundlerSaveOnLoadPackage_DocumentSaved; _projectItemEvents = events.ProjectItemsEvents; _projectItemEvents.ItemAdded += BundlerSaveOnLoadPackage_ItemAdded; _projectItemEvents.ItemRenamed += BundlerSaveOnLoadPackage_ItemRenamed; Debug.WriteLine("Solution loaded and listener document event save listener set up."); }
protected override void Initialize() { Debug.WriteLine ("Entering Initialize() of: {0}", this); base.Initialize(); _dte = (DTE)GetService(typeof(DTE)); _events = _dte.Events; _documentEvents = _events.DocumentEvents; _documentEvents.DocumentSaved += DocumentEvents_DocumentSaved; var window = _dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput); var outputWindow = (OutputWindow)window.Object; _outputPane = outputWindow.OutputWindowPanes .Cast<OutputWindowPane>() .FirstOrDefault(p => p.Name == "AutoRunCustomTool") ?? outputWindow.OutputWindowPanes.Add("AutoRunCustomTool"); _errorListProvider = new ErrorListProvider(this) { ProviderName = "AutoRunCustomTool", ProviderGuid = Guid.NewGuid() }; RegisterExtenderProvider(); }
public async override void Initialize(object sender, SectionInitializeEventArgs e) { base.Initialize(sender, e); _buildService = GetService <IVsTeamFoundationBuild>(); _dte = GetService <DTE>(); _dteEvents = _dte.Events; _dteDocumentEvents = _dte.Events.DocumentEvents; _dteDocumentEvents.DocumentSaved += _dteDocumentEvents_DocumentSaved; _optionsViewModel.OptionsModel.Initialize(this.ServiceProvider); var sectionContext = e.Context as BuildsSectionContext; if (sectionContext != null) { Builds = sectionContext.Builds; } else { await RefreshAsync(); } }
/// <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 initialization code that rely on services provided by VisualStudio. /// </summary> /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param> /// <param name="progress">A provider for progress updates.</param> /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns> protected override async Task InitializeAsync( CancellationToken cancellationToken, IProgress <ServiceProgressData> progress ) { // When initialized asynchronously, the current thread may be a background thread at this point. // Do any initialization that requires the UI thread after switching to the UI thread. ShowDebugMessage("InitializeAsync - enter"); await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _dte = ( DTE )GetGlobalService(typeof(DTE)); _docEvents = _dte.Events.DocumentEvents; _docEvents.DocumentSaved += DocEventsOnDocumentSaved; _buildEvents = _dte.Events.BuildEvents; _buildEvents.OnBuildBegin += BuildEventsOnOnBuildBegin; _buildEvents.OnBuildDone += BuildEventsOnOnBuildDone; _solutionEvents = _dte.Events.SolutionEvents; _solutionEvents.BeforeClosing += SolutionEventsOnBeforeClosing; _cleanupCommand = _dte.Commands.Cast <Command>().FirstOrDefault(x => ReSharperSilentCleanupCodeCommandsNames.Contains(x.Name)); ShowDebugMessage($"Command: {_cleanupCommand?.Name}"); ShowDebugMessage("InitializeAsync - exit"); }
/// <summary> /// Initializes a new instance of the <see cref="VsEvents"/> class. /// </summary> /// <param name="environment"> /// The environment. /// </param> /// <param name="dte2"> /// The dte 2. /// </param> /// <param name="vsSonarExtensionPackage"></param> public VsEvents(IVsEnvironmentHelper environment, DTE2 dte2, VsSonarExtensionPackage vsSonarExtensionPackage) { this.dte2 = dte2; this.package = vsSonarExtensionPackage; this.environment = environment; this.SolutionEvents = dte2.Events; this.visualStudioEvents = dte2.Events.DTEEvents; this.buildEvents = dte2.Events.BuildEvents; this.DocumentsEvents = this.SolutionEvents.DocumentEvents; this.SolutionEvents.SolutionEvents.Opened += this.SolutionOpened; this.SolutionEvents.SolutionEvents.AfterClosing += this.SolutionClosed; this.SolutionEvents.WindowEvents.WindowActivated += this.WindowActivated; this.SolutionEvents.WindowEvents.WindowClosing += this.WindowClosed; this.DocumentsEvents.DocumentSaved += this.DoumentSaved; this.visualStudioEvents.OnStartupComplete += this.CloseToolWindows; this.buildEvents.OnBuildProjConfigDone += this.ProjectHasBuild; VSColorTheme.ThemeChanged += this.VSColorTheme_ThemeChanged; var extensionRunningPath = Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").ToString(); var uniqueId = this.dte2.Version; if (extensionRunningPath.ToLower().Contains(this.dte2.Version + "exp")) { uniqueId += "Exp"; } SonarQubeViewModelFactory.StartupModelWithVsVersion(uniqueId, this.package).AnalysisModeHasChange += this.AnalysisModeHasChange; SonarQubeViewModelFactory.SQViewModel.VSonarQubeOptionsViewData.GeneralConfigurationViewModel.ConfigurationHasChanged += this.AnalysisModeHasChange; }
public void OnConnect(DTE2 applicationObject) { ApplicationObject = applicationObject; DocumentManager.BeforeKeyPress = OnBeforeKeyPress; DocumentManager.AfterKeyPress = OnAfterKeyPress; DocumentManager.Setup(applicationObject); var events = (Events2)applicationObject.Events; solutionEvents = events.SolutionEvents; projectItemEvents = events.ProjectItemsEvents; textEditorEvents = events.get_TextEditorEvents(null); documentEvents = events.DocumentEvents; dteEvents = events.DTEEvents; dteEvents.OnBeginShutdown += OnBeginShutdown; solutionEvents.Opened += OnSolutionOpened; solutionEvents.BeforeClosing += OnSolutionClosing; projectItemEvents.ItemAdded += OnSolutionItemAdded; projectItemEvents.ItemRenamed += OnSolutionItemRenamed; projectItemEvents.ItemRemoved += OnSolutionItemRemoved; textEditorEvents.LineChanged += OnTextEditorLineChanged; documentEvents.DocumentSaved += DocumentEvents_DocumentSaved; Command cmd = ApplicationObject.Commands.Item("Edit.CompleteWord", -1); commandEvents = ApplicationObject.Events.get_CommandEvents(cmd.Guid, cmd.ID); commandEvents.BeforeExecute += OnBeforeCompleteWordRequested; }
void VsShellPropertyEvents_AfterShellPropertyChanged(object sender, VsShellPropertyEventsHandler.ShellPropertyChangeEventArgs e) { SafeExecute(() => { // when zombie state changes to false, finish package initialization //! DO NOT USE CODE WHICH MAY EXECUTE FOR LONG TIME HERE if ((int)__VSSPROPID.VSSPROPID_Zombie == e.PropId) { if ((bool)e.Var == false) { var dte2 = ServiceProvider.GetDte2(); Events = dte2.Events as Events2; DTEEvents = Events.DTEEvents; SolutionEvents = Events.SolutionEvents; DocumentEvents = Events.DocumentEvents; WindowEvents = Events.WindowEvents; DebuggerEvents = Events.DebuggerEvents; CommandEvents = Events.CommandEvents; SelectionEvents = Events.SelectionEvents; DelayedInitialise(); } } }); }
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _application = (DTE2)application; _addInInstance = (AddIn)addInInst; // Core var name = _addInInstance.Name; var outputPane = _application.ToolWindows.OutputWindow.OutputWindowPanes.GetPane(name); var feedback = new FeedbackManager(name, outputPane); _core = new Core(feedback); // Events _events = (Events2)_application.Events; _projectsEvents = _events.ProjectsEvents; _projectItemsEvents = _events.ProjectItemsEvents; _documentEvents = _events.DocumentEvents; _buildEvents = _events.BuildEvents; AttachEvents(); // If being connected when Solution is already loaded - try to load all projects if (_application.Solution != null) { _core.Load(_application.Solution); } }
public void Initialize() { _uiTaskScheduler = TTasks.TaskScheduler.FromCurrentSynchronizationContext(); _taskProvider = new VulnerabilityTaskProvider(this._serviceProvider); _markerProvider = new PackageReferenceMarkerProvider(_taskProvider); _refreshTimer = new Timer(new TimerCallback(RefreshTimer), null, Timeout.Infinite, Timeout.Infinite); _selectionEvents = new EventSinks.VsSelectionEvents(VSPackage.Instance.MonitorSelection); _selectionEvents.SolutionOpened += SelectionEvents_SolutionOpened; _packageInstallerEvents = ServiceLocator.GetInstance <IVsPackageInstallerEvents>(); if (_packageInstallerEvents == null) { throw new InvalidOperationException(string.Format(Resources.Culture, Resources.General_MissingService, typeof(IVsPackageInstallerEvents).FullName)); } _packageInstallerEvents.PackageInstalled += InstallerEvents_PackageInstalled; _packageInstallerEvents.PackageUninstalled += InstallerEvents_PackageUninstalled; _packageInstallerEvents.PackageReferenceAdded += InstallerEvents_PackageReferenceAdded; _packageInstallerEvents.PackageReferenceRemoved += InstallerEvents_PackageReferenceRemoved; _dte = ServiceLocator.GetInstance <DTE>(); if (_dte == null) { throw new InvalidOperationException(string.Format(Resources.Culture, Resources.General_MissingService, typeof(DTE).FullName)); } _documentEvents = _dte.Events.DocumentEvents; _documentEvents.DocumentOpened += OnDocumentOpened; _documentEvents.DocumentClosing += OnDocumentClosing; }
protected override void Initialize() { Debug.WriteLine("Entering Initialize() of: {0}", this); base.Initialize(); _dte = (DTE)GetService(typeof(DTE)); _events = _dte.Events; _documentEvents = _events.DocumentEvents; _documentEvents.DocumentSaved += DocumentEvents_DocumentSaved; var window = _dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput); var outputWindow = (OutputWindow)window.Object; _outputPane = outputWindow.OutputWindowPanes .Cast <OutputWindowPane>() .FirstOrDefault(p => p.Name == "AutoRunCustomTool") ?? outputWindow.OutputWindowPanes.Add("AutoRunCustomTool"); _errorListProvider = new ErrorListProvider(this) { ProviderName = "AutoRunCustomTool", ProviderGuid = Guid.NewGuid() }; RegisterExtenderProvider(); }
///////////////////////////////////////////////////////////////////////////// // 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())); //System.Diagnostics.Debugger.Break(); // Add our command handlers for menu (commands must exist in the .vsct file) var mcs = (IMenuCommandService)GetService(typeof(IMenuCommandService)); if (mcs != null) { // Create the command for the tool window var toolwndCommandID = new CommandID(GuidList.guidJsParserPackageCmdSet, (int)PkgCmdIDList.cmdJsParser); var menuToolWin = new MenuCommand(JsParserMenuCmd, toolwndCommandID); mcs.AddCommand(menuToolWin); // Create the command for the tool window toolwndCommandID = new CommandID(GuidList.guidJsParserPackageCmdSet, (int)PkgCmdIDList.cmdJsParserFind); menuToolWin = new MenuCommand(JsParserMenuFindCmd, toolwndCommandID); mcs.AddCommand(menuToolWin); } _jsParserService = new JsParserService(Settings.Default); var dte = (DTE)GetService(typeof(DTE)); Events events = dte.Events; _documentEvents = events.get_DocumentEvents(null); _solutionEvents = events.SolutionEvents; _windowEvents = events.get_WindowEvents(null); _documentEvents.DocumentSaved += documentEvents_DocumentSaved; _documentEvents.DocumentOpened += documentEvents_DocumentOpened; _windowEvents.WindowActivated += windowEvents_WindowActivated; if (VSVersionDetector.IsVs2012(dte.Version)) { //load .Net4.5 assembly dynamically because current project targeted as 4.0 for VS2010 compability var asm = Assembly.Load("JsParser.Package.2012"); var type = asm.GetType("JsParser.Package._2012.VS2012UIThemeProvider"); object serviceDelegate = new Func <Type, object>(GetService); _uiThemeProvider = (IUIThemeProvider)Activator.CreateInstance(type, serviceDelegate); } else { _uiThemeProvider = new VS2010UIThemeProvider(GetService); } _jsParserToolWindowManager = new JsParserToolWindowManager(_jsParserService, _uiThemeProvider, () => { return(FindToolWindow <JsParserToolWindow>()); }); _uiThemeProvider.SubscribeToThemeChanged(() => { _jsParserToolWindowManager.NotifyColorChangeToToolWindow(); }); base.Initialize(); }
// -------------------------------------------------------------------------------------------- /// <summary> /// Initializes the event listener. /// </summary> // -------------------------------------------------------------------------------------------- static VsDocumentEvents() { _Events = VsIde.GetObject <DocumentEvents>("DocumentEvents"); _ClosingEventCounter = 0; _OpenedEventCounter = 0; _OpeningEventCounter = 0; _SavedEventCounter = 0; }
/// <summary>Implements the OnStartupComplete method of the IDTExtensibility2 interface. Receives notification that the host application has completed loading.</summary> /// <param term='custom'>Array of parameters that are host application specific.</param> /// <seealso class='IDTExtensibility2' /> public void OnStartupComplete(ref Array custom) { this.eventsOnDocs = this.events.get_DocumentEvents(); this.eventsOnDocs.DocumentSaved += DocumentEvents_DocumentSaved; windc = new ScriptConvertor(); minc = new MinCompiler(); }
public void Dispose() { if (_documentEvents != null) { _documentEvents.DocumentOpened -= DocumentEventsOnDocumentOpened; _documentEvents = null; } }
protected override void Dispose(bool disposing) { UnadviseSolutionEvents(); Cache.Instance.Dispose(); _buildEvents = null; _documentEvents = null; _solutionEvents = null; base.Dispose(disposing); }
public DteWithEvents(DTE dte) { DTE = dte; SolutionEvents = dte.Events.SolutionEvents; ProjectItemsEvents = ((Events2)dte.Events).ProjectItemsEvents; DocumentEvents = ((Events2) dte.Events).DocumentEvents; BuildEvents = ((Events2) dte.Events).BuildEvents; CodeModelEvents = ((Events2)dte.Events).CodeModelEvents; }
/// <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 initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); var dte = GetService(typeof(DTE)) as DTE2; documentEvents = dte.Events.DocumentEvents; documentEvents.DocumentSaved += documentEvents_DocumentSaved; }
public static void BindEvents(DTE2 applicationObject) { if (_events != null) return; _application = applicationObject; _events = _application.Events.DocumentEvents; _documentSaved = new _dispDocumentEvents_DocumentSavedEventHandler(documentSaved); _events.DocumentSaved += _documentSaved; }
// ReSharper restore EmptyConstructor /// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; _documentEvents = _applicationObject.Events.DocumentEvents; _documentEvents.DocumentSaved += DocumentSaved; _CSSPrefixer = new CSSPrefixes(_applicationObject); }
public EncourageIntellisenseController( ITextView textView, DTE dte, EncourageIntellisenseControllerProvider provider) { this.textView = textView; this.provider = provider; this.documentEvents = dte.Events.DocumentEvents; documentEvents.DocumentSaved += OnSaved; }
DocumentEvents saveEvent;//DocumentEvents object used for saving events /// <summary> /// Initialization of UI and editing related events and members /// </summary> /// <param name="textView"></param> /// <param name="mcb"></param> /// <param name="cs"></param> public CoProCommandFilter(IWpfTextView textView, CoProNetwork mcb, GraphicObjects cs) { m_textView = textView; m_adornmentLayer = m_textView.GetAdornmentLayer("MultiEditLayer"); m_added = false; m_textView.LayoutChanged += m_textView_LayoutChanged; cb = mcb; gobj = cs; //crts.DTE2.Events.TextEditorEvents.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler(); events = gobj.DTE2.Events; saveEvent = events.DocumentEvents; saveEvent.DocumentSaved += new _dispDocumentEvents_DocumentSavedEventHandler(my_DocWasSaved); cb.NewCaret += new NewCaretEventHandler(my_NewCaret); cb.ChangeCaret += new ChangeCaretEventHandler(my_ChangedCaret); cb.EditorDisc += new EditorDisconnectedEventHandler(my_EditorDisc); cb.NewText += new NewTextEventHandler(my_AddedText); cb.RemovedText += new RemovedTextEventHandler(my_RemovedText); cb.SaveEvent += new SaveEventHandler(my_Save); cb.AddAllEditors += new AddCurrentEditorsEventHandler(my_AddEditors); cb.ItemRemoved += new ItemRemovedEventHandler(my_RemovedItem); cb.ItemAdded += new NewItemAddedEventHandler(my_ItemAdded); textView.Caret.PositionChanged += new EventHandler<CaretPositionChangedEventArgs>(my_PositionChanged); textView.TextBuffer.Changed += TextBuffer_Changed; InitBrushes(); uiDisp = Dispatcher.CurrentDispatcher; ITextDocument textDoc; var rc = m_textView.TextBuffer.Properties.TryGetProperty<ITextDocument>( typeof(ITextDocument), out textDoc); filename = gobj.DTE2.Solution.FullName; filename = filename.Substring(filename.LastIndexOf('\\') + 1); filename = filename.Split('.')[0]; filename = textDoc.FilePath.Substring(textDoc.FilePath.IndexOf(filename)); if (cb.IsAdmin) { cb.AdminEvent += my_AdminCallback; } if (isFirstTime) { isFirstTime = false; } else { if (!cb.IsAdmin) { cb.UpdateSpecificFile(filename); } } filename = filename.Substring(filename.LastIndexOf('\\') + 1); cb.IntializePosition(filename, m_textView.Caret.Position.BufferPosition.Position, cb.Name); currBufferSize = m_textView.TextSnapshot.Length; }
public static void Initialize(IServiceProvider provider, DTE _dte) { dte = _dte; if (errorListProvider != null) return; errorListProvider = new ErrorListProvider(provider); errorListProvider.ProviderGuid = Guid.Parse("7C2C89EC-D368-4B15-B93A-E506EEA449E4"); errorListProvider.ProviderName = "Naggy.DiagnosticsProvider"; documentEvents = dte.Events.DocumentEvents; documentEvents.DocumentClosing += new _dispDocumentEvents_DocumentClosingEventHandler(documentEvents_DocumentClosing); }
public DteWithEvents(DTE dte, IIdeTracer tracer) { DTE = dte; SolutionEvents = dte.Events.SolutionEvents; ProjectItemsEvents = ((Events2)dte.Events).ProjectItemsEvents; DocumentEvents = ((Events2) dte.Events).DocumentEvents; BuildEvents = ((Events2) dte.Events).BuildEvents; CodeModelEvents = ((Events2)dte.Events).CodeModelEvents; SolutionEventsListener = new SolutionEventsListener(); FileChangeEventsListener = new FileChangeEventsListener(tracer); SolutionEvents.BeforeClosing += FileChangeEventsListener.StopListening; }
public MDView() { InitializeComponent(); dte = Package.GetGlobalService(typeof(DTE)) as DTE2; events = dte.Events; docEvents = events.DocumentEvents; dte.Events.WindowEvents.WindowActivated += OnWindowActivated; docEvents.DocumentSaved += OnDocumentSaved; browser.LoadCompleted += OnBrowserLoadCompleted; var properties = dte.get_Properties("FontsAndColors", "TextEditor"); var fontsAndColorsItems = (EnvDTE.FontsAndColorsItems)properties.Item("FontsAndColorsItems").Object; colorableItems = fontsAndColorsItems.Item("Plain Text") as ColorableItems; UpdateMarkdown(""); Unloaded += (s, o) => (formatter as IDisposable).Dispose(); }
public static void Initialize(DTE d) { if (dte != null) return; dte = d; documentEvents = dte.Events.DocumentEvents; windowEvents = dte.Events.WindowEvents; documentEvents.DocumentSaved += DocumentEventsOnDocumentSaved; documentEvents.DocumentClosing += DocumentEventsOnDocumentClosing; windowEvents.WindowActivated += windowEvents_WindowActivated; solutionEventsHandler = new SolutionEventsHandler(); solutionEventsHandler.ActiveProjectConfigurationChanged += ActiveProjectConfigurationChanged; DiagnosticsFinder.Toggled += new EventHandler<EventArgs>(DiagnosticsFinder_Toggled); }
protected override void Initialize() { lock (_s_applicationLock) { Application = (DTE2)GetService(typeof(SDTE)); _events = Application.Application.Events; _dteEvents = _events.DTEEvents; _documentEvents = _events.DocumentEvents; var win = Application.Windows.Item(EnvDTE.Constants.vsWindowKindOutput); _outputWindow = win.Object as OutputWindow; if (_outputWindow != null) { _karmaOutputWindowPane = _outputWindow.OutputWindowPanes.Add("Karma"); } _dteEvents.OnBeginShutdown += ShutdownKarma; _events.SolutionEvents.Opened += SolutionEventsOpened; } base.Initialize(); // Add our command handlers for menu (commands must exist in .vsct file) var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null == mcs) return; // Create the command for the menu item. var menuCommandId1 = new CommandID( GuidList.guidToggleKarmaVsUnitCmdSet, (int)PkgCmdIDList.cmdidToggleKarmaVsUnit ); var menuItem1 = new MenuCommand(KarmaVsUnit, menuCommandId1); mcs.AddCommand(menuItem1); // Create the command for the menu item. var menuCommandId2 = new CommandID( GuidList.guidToggleKarmaVsE2eCmdSet, (int)PkgCmdIDList.cmdidToggleKarmaVsE2e ); var menuItem2 = new MenuCommand(KarmaVsE2e, menuCommandId2); mcs.AddCommand(menuItem2); }
public BuildOnSave(Package package) { IServiceProvider serviceProvider = package; _dte = serviceProvider.GetService(typeof(DTE)) as DTE; _events = _dte.Events; _documentEvents = _events.DocumentEvents; _buildEvents = _events.BuildEvents; var guid = typeof(VSConstants.VSStd97CmdID).GUID.ToString("B"); _buildSolutionEvent = _dte.Events.CommandEvents[guid, (int)VSConstants.VSStd97CmdID.BuildSln]; var commandService = serviceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; _topMenu = new MenuCommand(delegate { }, new CommandID(CommandSet, TopMenuCommandId)); _menuItem = new MenuCommand(enableDisableBuildOnSave, new CommandID(CommandSet, CommandId)); _buildTypeSolution = new MenuCommand(setBuildTypeToSolution, new CommandID(CommandSet, BuildTypeSolutionCommandId)); _buildTypeStartupProject = new MenuCommand(setBuildTypeToStartupProject, new CommandID(CommandSet, BuildTypeStartupProjectCommandId)); _buildTypeProjectsOfSavedFiles = new MenuCommand(setBuildTypeToProjectsOfSavedFiles, new CommandID(CommandSet, BuildTypeProjectsOfSavedFilesCommandId)); _buildTypeAffectedProjectsOfSavedFiles = new MenuCommand(setBuildTypeToAffectedProjectsOfSavedFiels, new CommandID(CommandSet, BuildTypeAffectedProjectsOfSavedFilesCommandId)); commandService.AddCommand(_topMenu); commandService.AddCommand(_menuItem); commandService.AddCommand(_buildTypeSolution); commandService.AddCommand(_buildTypeStartupProject); commandService.AddCommand(_buildTypeProjectsOfSavedFiles); commandService.AddCommand(_buildTypeAffectedProjectsOfSavedFiles); // create the output pane. _outputWindow = _dte.Windows.Item(Constants.vsWindowKindOutput); _outputPane = ((OutputWindow)_outputWindow.Object).OutputWindowPanes.Add("BuildOnSave"); _topMenu.Visible = true; _solutionOptions = DefaultOptions; Log.I("BuildOnSave initialized"); syncOptions(); }
public OpenFileTracker([Import]SVsServiceProvider serviceProvider) { var dte = (EnvDTE.DTE)serviceProvider.GetService(typeof(EnvDTE.DTE)); // Subscribe to document events. documentEvents = dte.Events.DocumentEvents; documentEvents.DocumentOpened += TrackDocument; documentEvents.DocumentClosing += UntrackDocument; // When a solution is closed, VS calls DocumentClosing with NULLS (ARGH!!! WTF?!), so we'll have to skip over // them and manually empty tracked documents when this happens :( solutionEvents = dte.Events.SolutionEvents; solutionEvents.BeforeClosing += UntrackAllDocuments; // Subscribe for existing projects already open when we were triggered. foreach (Document document in dte.Documents) TrackDocument(document); }
public override void OnToolWindowCreated() { var tsvnPackage = Package as TSVNPackage; var dte = (DTE)tsvnPackage.GetServiceHelper(typeof(DTE)); _tsvnToolWindowControl.SetDTE(dte); _fileHelper = new FileHelper(dte); _commandHelper = new CommandHelper(dte); _documentEvents = dte.Events.DocumentEvents; _documentEvents.DocumentSaved += DocumentEvents_DocumentSaved; _solutionEvents = dte.Events.SolutionEvents; _solutionEvents.Opened += SolutionEvents_Opened; _tsvnToolWindowControl.GotFocus += _tsvnToolWindowControl_GotFocus; _tsvnToolWindowControl.HideUnversionedButton.IsChecked = Settings.Default.HideUnversioned; _tsvnToolWindowControl.Update(_commandHelper.GetPendingChanges(), _fileHelper.GetSolutionDir()); }
/// <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 initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { UnityRefactorHelperSettingsCommand.Initialize(this); base.Initialize(); Cache.Instance.OleMenuCommandService = GetService(typeof (IMenuCommandService)) as OleMenuCommandService; Cache.Instance.Dte = (DTE) GetService(typeof (SDTE)); var events = Cache.Instance.Dte.Events; _documentEvents = events.DocumentEvents; _buildEvents = events.BuildEvents; Cache.Instance.SolutionService = GetService(typeof (IVsSolution)) as IVsSolution; _solutionEvents = new SolutionEvents(); _solution = GetService(typeof (SVsSolution)) as IVsSolution; _solution.AdviseSolutionEvents(_solutionEvents, out _solutionEventsCookie); _documentEvents.DocumentSaved += DocumentEventsOnDocumentSaved; _buildEvents.OnBuildProjConfigDone += BuildEventsOnOnBuildProjConfigDone; }
public override void OnEnable() { try { base.OnEnable(); this.ApplicationObject.Events.SolutionItemsEvents.ItemAdded += new _dispProjectItemsEvents_ItemAddedEventHandler(SolutionItemsEvents_ItemAdded); //appObject.Events.MiscFilesEvents.ItemAdded += null; //windowEvents = appObject.Events.get_WindowEvents(null); //windowEvents.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(windowEvents_WindowActivated); //windowEvents.WindowCreated += new _dispWindowEvents_WindowCreatedEventHandler(windowEvents_WindowCreated); docEvents = this.ApplicationObject.Events.get_DocumentEvents(null); docEvents.DocumentOpened += new _dispDocumentEvents_DocumentOpenedEventHandler(docEvents_DocumentOpened); t.Tick += new EventHandler(t_Tick); t.Interval = 500; } catch (Exception exception) { MessageBox.Show(exception.Message + "\r\n" + exception.StackTrace); } }
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary> /// <param term='application'>Root object of the host application.</param> /// <param term='connectMode'>Describes how the Add-in is being loaded.</param> /// <param term='addInInst'>Object representing this Add-in.</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _application = (DTE2)application; _addIn = (EnvDTE.AddIn)addInInst; // Events _events = (Events2)_application.Events; _projectsEvents = _events.ProjectsEvents; _projectItemsEvents = _events.ProjectItemsEvents; _documentEvents = _events.DocumentEvents; _buildEvents = _events.BuildEvents; AttachEvents(); _core = new Core(); // If being connected when Solution is already loaded - try to load all projects if (_application.Solution != null) { _core.Load(_application.Solution); } }
protected override void Initialize() { base.Initialize(); _dte = GetService(typeof (SDTE)) as DTE; if (_dte == null) return; _controller = new Controller(); _buildEvents = _dte.Events.BuildEvents; _buildEvents.OnBuildBegin += OnBuildBegin; _documentEvents = _dte.Events.DocumentEvents; _documentEvents.DocumentSaved += DocumentSaved; var events2 = _dte.Events as Events2; if (events2 == null) return; _projectItemsEvents = events2.ProjectItemsEvents; _projectItemsEvents.ItemAdded += ItemAdded; _projectItemsEvents.ItemRemoved += ItemRemoved; _projectItemsEvents.ItemRenamed += ItemRenamed; _solutionEvents = _dte.Events.SolutionEvents; _solutionEvents.ProjectRemoved += ProjectRemoved; var menuCommandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != menuCommandService) { var showOptionsCommandId = new CommandID(GuidList.guidAutoT4MVCCmdSet, (int) PkgCmdIDList.cmdidShowOptions); var showOptionsMenuCommand = new OleMenuCommand(ShowOptions, showOptionsCommandId); menuCommandService.AddCommand(showOptionsMenuCommand); showOptionsMenuCommand.BeforeQueryStatus += ShowOptionsMenuCommandOnBeforeQueryStatus; } }
private void BrowserForm_Load(object sender, EventArgs e) { //��ü����ĵ���������һ���ĵ����� Inventor.Document doc; doc = m_inventorApplication.ActiveDocument; //���ӵ��ĵ��¼���������Ӧ�ĵ��ر� docEvents = doc.DocumentEvents; //ʹ�������ؼ������µ���������� browserPane = doc.BrowserPanes.Add("Calendar", "MSCAL.Calendar"); //���õ������ؼ������� calCtrl = (MSACAL.Calendar)browserPane.Control; //���������ؼ���ʾ��ǰ���� calCtrl.Today(); //ʹ�´����Ϊ����� browserPane.Activate(); calCtrl.Click += new MSACAL.DCalendarEvents_ClickEventHandler(calCtrl_Click); }
protected override void Initialize() { base.Initialize(); documentEvents = IDE.Events.DocumentEvents; documentEvents.DocumentSaved += documentEvents_DocumentSaved; var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if ( null != mcs ) { var menuCommandID = new CommandID(GuidList.guidLine_Endings_UnifierCmdSet_File, (int)PkgCmdIDList.cmdidUnifyLineEndings_File); var menuItem = new MenuCommand(new EventHandler(UnifyLineEndingsInFileEventHandler), menuCommandID); menuItem.Visible = true; menuItem.Enabled = true; mcs.AddCommand(menuItem); menuCommandID = new CommandID(GuidList.guidLine_Endings_UnifierCmdSet_Folder, (int)PkgCmdIDList.cmdidUnifyLineEndings_Folder); menuItem = new MenuCommand(new EventHandler(UnifyLineEndingsInFolderEventHandler), menuCommandID); menuItem.Visible = true; menuItem.Enabled = true; mcs.AddCommand(menuItem); menuCommandID = new CommandID(GuidList.guidLine_Endings_UnifierCmdSet_Project, (int)PkgCmdIDList.cmdidUnifyLineEndings_Project); menuItem = new MenuCommand(new EventHandler(UnifyLineEndingsInProjectEventHandler), menuCommandID); menuItem.Visible = true; menuItem.Enabled = true; mcs.AddCommand(menuItem); menuCommandID = new CommandID(GuidList.guidLine_Endings_UnifierCmdSet_Solution, (int)PkgCmdIDList.cmdidUnifyLineEndings_Solution); menuItem = new MenuCommand(new EventHandler(UnifyLineEndingsInSolutionEventHandler), menuCommandID); menuItem.Visible = true; menuItem.Enabled = true; mcs.AddCommand(menuItem); } SetupOutputWindow(); }
/// <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 initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { base.Initialize(); DTE dte = GetService(typeof(SDTE)) as DTE; if (dte != null) { _documentEvents = dte.Events.DocumentEvents; _documentEvents.DocumentSaved += OnDocumentSaved; } _extensionGroups = new FileExtensionGroup[] { new FileExtensionGroup { Name = ".NET", Extensions = new[]{".cs", ".vb"} , Enabled = true }, new FileExtensionGroup { Name = "C/C++", Extensions = new[]{".cpp", ".c", ".h", ".hpp"} , Enabled = true }, new FileExtensionGroup { Name = "SQL", Extensions = new[]{".sql"} , Enabled = true }, new FileExtensionGroup { Name = "XML", Extensions = new[]{".xml", ".xsd", ".xaml", ".resx", ".wsdl"} , Enabled = true }, new FileExtensionGroup { Name = "ASP.NET", Extensions = new[]{".aspx", ".ascx", ".asax", ".ashx", ".asmx", ".css", ".js", ".htm", ".html", ".cshtml"}, Enabled = true }, new FileExtensionGroup { Name = "Command files", Extensions = new[]{".ps1", ".psm1", ".cmd", ".bat"} , Enabled = true }, new FileExtensionGroup { Name = "T4", Extensions = new[]{".tt"} , Enabled = true }, new FileExtensionGroup { Name = "Other text files", Extensions = new[]{".txt", ".nuspec", ".build", ".config", ".manifest"} , Enabled = true } }; _fileExtensions = GetEnabledFileExtensions(_extensionGroups); }
/// <summary> /// Initializes a new instance of the <see cref="FileLinkCommand"/> 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 FileLinkCommand(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); var menuItem = new OleMenuCommand(this.MenuItemCallback, menuCommandID); menuItem.BeforeQueryStatus += OnBeforeQueryStatus; commandService.AddCommand(menuItem); } _dte = (DTE2)this.ServiceProvider.GetService(typeof(SDTE)); _dteEvents = _dte.Events; _documentEvents = _dteEvents.DocumentEvents; base.GetDte2(_dte); }
public static void Initialize(DocumentEvents events) { Instance = new DocumentOpenListener(events); }
protected override void Initialize() { Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); base.Initialize(); _dte = (EnvDTE.DTE)GetService(typeof(SDTE)); _eventsHandlers = _dte.Events.DocumentEvents; _eventsHandlers.DocumentSaved += documentSaved; _outputPane = _dte.AddOutputWindowPane("cppcheck analysis output"); AnalyzerCppcheck cppcheckAnalayzer = new AnalyzerCppcheck(); cppcheckAnalayzer.ProgressUpdated += checkProgressUpdated; _analyzers.Add(cppcheckAnalayzer); if (String.IsNullOrEmpty(Properties.Settings.Default.DefaultArguments)) Properties.Settings.Default.DefaultArguments = CppcheckSettings.DefaultArguments; // 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(GuidList.guidCPPCheckPluginCmdSet, (int)PkgCmdIDList.cmdidCheckProjectCppcheck); MenuCommand menuItem = new MenuCommand(onCheckCurrentProjectRequested, menuCommandID); mcs.AddCommand( menuItem ); CommandID solutionMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginCmdSet, (int)PkgCmdIDList.cmdidCheckSolutionCppcheck); MenuCommand solutionMenuItem = new MenuCommand(onCheckSolution, solutionMenuCommandID); mcs.AddCommand(solutionMenuItem); // Create the command for the settings window CommandID settingsWndCmdId = new CommandID(GuidList.guidCPPCheckPluginCmdSet, (int)PkgCmdIDList.cmdidSettings); MenuCommand menuSettings = new MenuCommand(onSettingsWindowRequested, settingsWndCmdId); mcs.AddCommand(menuSettings); CommandID projectMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginProjectCmdSet, (int)PkgCmdIDList.cmdidCheckProjectCppcheck1); MenuCommand projectMenuItem = new MenuCommand(onCheckCurrentProjectRequested, projectMenuCommandID); mcs.AddCommand(projectMenuItem); CommandID projectsMenuCommandID = new CommandID(GuidList.guidCPPCheckPluginMultiProjectCmdSet, (int)PkgCmdIDList.cmdidCheckProjectsCppcheck); MenuCommand projectsMenuItem = new MenuCommand(onCheckAllProjectsRequested, projectsMenuCommandID); mcs.AddCommand(projectsMenuItem); } // Creating the tool window FindToolWindow(typeof(MainToolWindow), 0, true); }
private DocumentOpenListener(DocumentEvents events) { _events = events; _events.DocumentOpened += DocumentOpened; }