/// <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) { Dte = await GetServiceAsync(typeof(SDTE)) as DTE2; _serviceProvider = new ServiceProvider((IServiceProvider)Dte); var componentModel = (IComponentModel)GetGlobalService(typeof(SComponentModel)); _undoHistoryRegistry = componentModel.DefaultExportProvider.GetExportedValue <ITextUndoHistoryRegistry>(); var plugin = new VsRunningDocTableEventsHandler(this); MenuCommandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); _runningDocumentTable = new RunningDocumentTable(this); _runningDocumentTable.Advise(plugin); OptionsPage = (OptionsPage)GetDialogPage(typeof(OptionsPage)); _solutionExplorerContextMenu = new SolutionExplorerContextMenu(this); await EnableDisableFormatOnSaveCommand.InitializeAsync(this); }
internal DocumentMonitorService(SVsServiceProvider vsServiceProvider, ICompletionBroker completionBroker) { _vsServiceProvider = vsServiceProvider; _runningDocumentTable = new RunningDocumentTable(vsServiceProvider); _runningDocumentTable.Advise(this); _completionBroker = completionBroker; _dte = (DTE)vsServiceProvider.GetService(typeof(_DTE)); // NB: Resharper somehow f***s with this event, we need to do as // little as possible in the event handler itself var documentChanged = _changed .ObserveOn(RxApp.TaskpoolScheduler) .Throttle(TimeSpan.FromSeconds(2.0), RxApp.TaskpoolScheduler) .Where(_ => !isCompletionActive()) .Select(_ => Unit.Default) .ObserveOn(RxApp.MainThreadScheduler); documentChanged.Subscribe(_ => SaveAll()); // NB: We use the message bus here, because we want to effectively // merge all of the text change notifications from any document MessageBus.Current.RegisterMessageSource(documentChanged, "AnyDocumentChanged"); checkAlreadyOpenDocuments(vsServiceProvider); _dte.Events.WindowEvents.WindowActivated += (o, e) => _changed.OnNext(Unit.Default); }
/// <summary> /// The event explorer user control constructor. /// </summary> public VSEventHandler() { // Advise the RDT of this event sink. DTEObj = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2; ServiceProvider sp = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)DTEObj); //IOleServiceProvider sp = // Package.GetGlobalService(typeof(IOleServiceProvider)) as IOleServiceProvider; if (sp == null) { return; } rdt = new RunningDocumentTable(sp); if (rdt == null) { return; } rdtCookie = rdt.Advise(this); DTEObj.Events.BuildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(BuildEvents_OnBuildDone); DTEObj.Events.SolutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened); }
public TextDocumentTable( [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, IFileSystem fileSystem, ITextDocumentFactoryService textDocumentFactoryService, IVsEditorAdaptersFactoryService vsEditorAdaptersFactoryService) { _fileSystem = fileSystem; _textDocumentFactoryService = textDocumentFactoryService; _vsEditorAdaptersFactoryService = vsEditorAdaptersFactoryService; _firstRun = new Lazy <bool>(FetchRunningDocumentTable); _runningDocumentTable = new RunningDocumentTable(serviceProvider); var vsDocTable = serviceProvider.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable4; if (vsDocTable != null) { var runningDocTableEvents = new VsRunningDocTableEvents(vsDocTable, vsEditorAdaptersFactoryService); runningDocTableEvents.DocumentOpened += RunningDocTableEventsOnDocumentOpened; runningDocTableEvents.DocumentClosed += RunningDocTableEventsOnDocumentClosed; runningDocTableEvents.DocumentRenamed += RunningDocTableEventsOnDocumentRenamed; _runningDocTableEventsCookie = _runningDocumentTable.Advise(runningDocTableEvents); } else { Logger.LogWarn("Error getting {0} from Service Provider", typeof(IVsRunningDocumentTable4).FullName); } }
internal DocumentMonitorService(SVsServiceProvider vsServiceProvider, ICompletionBroker completionBroker) { _vsServiceProvider = vsServiceProvider; _runningDocumentTable = new RunningDocumentTable(vsServiceProvider); _runningDocumentTable.Advise(this); _completionBroker = completionBroker; _dte = (DTE)vsServiceProvider.GetService(typeof(_DTE)); // NB: Resharper somehow f***s with this event, we need to do as // little as possible in the event handler itself var documentChanged = _changed .ObserveOn(RxApp.TaskpoolScheduler) .Throttle(TimeSpan.FromSeconds(2.0), RxApp.TaskpoolScheduler) .Where(_ => !isCompletionActive()) .Select(_ => Unit.Default) .ObserveOn(RxApp.MainThreadScheduler); documentChanged.Subscribe(_ => SaveAll()); // NB: We use the message bus here, because we want to effectively // merge all of the text change notifications from any document MessageBus.Current.RegisterMessageSource(documentChanged, "AnyDocumentChanged"); checkAlreadyOpenDocuments(vsServiceProvider); _dte.Events.WindowEvents.WindowActivated += (o,e) => _changed.OnNext(Unit.Default); }
private async Task SetUpRunningDocumentTableEventsAsync(CancellationToken cancellationToken) { await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var runningDocumentTable = new RunningDocumentTable(this); runningDocumentTable.Advise(MyRunningDocTableEvents.Instance); }
/// <summary> /// Initializes a new instance of the <see cref="RunningDocumentTableEventListener" /> class. /// </summary> /// <param name="package">The package hosting the event listener.</param> internal RunningDocumentTableEventListener(CodeMaidPackage package) : base(package) { // Create and store a reference to the running document table. RunningDocumentTable = new RunningDocumentTable(package); // Register with the running document table for events. EventCookie = RunningDocumentTable.Advise(this); }
/// <summary> /// Initializes a new instance of the <see cref="RunningDocumentTableEventListener"/> class. /// </summary> /// <param name="package">The package hosting the event listener.</param> internal RunningDocumentTableEventListener(EditorConfigPackage package) : base(package) { // Create and store a reference to the running document table. RunningDocumentTable = new RunningDocumentTable(package); // Register with the running document table for events. EventCookie = RunningDocumentTable.Advise(this); }
public RunningDocTableEvents(IServiceProvider serviceProvider, Action <uint> OnAfterSave = null, Action OnAfterSaveAll = null) { rdt = new RunningDocumentTable(serviceProvider); cookie = rdt.Advise(this); OnAfterSaveFn = OnAfterSave; OnAfterSaveAllFn = OnAfterSaveAll; }
private async Task SetUpRunningDocumentTableEventsAsync(CancellationToken cancellationToken) { await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var runningDocumentTable = new RunningDocumentTable(this); var plugin = new RapidXamlRunningDocTableEvents(this, runningDocumentTable); runningDocumentTable.Advise(plugin); }
/// <summary> /// Initializes a new instance of the <see cref="RunningDocumentTableEventListener"/> class. /// </summary> /// <param name="package">The package hosting the event listener.</param> internal RunningDocumentTableEventListener(EditorConfigPackage package) : base(package) { _editorAdaptersFactory = Package.ComponentModel.GetService<IVsEditorAdaptersFactoryService>(); // Create and store a reference to the running document table. RunningDocumentTable = new RunningDocumentTable(package); // Register with the running document table for events. EventCookie = RunningDocumentTable.Advise(this); }
/// <summary> /// Initializes a new instance of the <see cref="RunningDocumentTableEventListener"/> class. /// </summary> /// <param name="package">The package hosting the event listener.</param> internal RunningDocumentTableEventListener(EditorConfigPackage package) : base(package) { _editorAdaptersFactory = Package.ComponentModel.GetService <IVsEditorAdaptersFactoryService>(); // Create and store a reference to the running document table. RunningDocumentTable = new RunningDocumentTable(package); // Register with the running document table for events. EventCookie = RunningDocumentTable.Advise(this); }
public RunningDocTableEvents(Package aPackage) { try { mRunningDocumentTable = new RunningDocumentTable(aPackage); mRunningDocumentTable.Advise(this); } catch (Exception) { } }
protected override void Initialize() { var dte = (DTE)GetService(typeof(DTE)); var runningDocumentTable = new RunningDocumentTable(this); var onSaveEventHandler = new OnSaveEventHandler(runningDocumentTable, dte); var plugin = new VsRunningDocTableEventHandler(onSaveEventHandler); runningDocumentTable.Advise(plugin); base.Initialize(); }
public RunningDocTableEvents(Package aPackage) { try { mDte = (DTE)Package.GetGlobalService(typeof(DTE)); mRunningDocumentTable = new RunningDocumentTable(aPackage); mRunningDocumentTable.Advise(this); } catch (Exception) { } }
public RunningDocTableEvents(Commands commands, DTE dte) { ThreadHelper.ThrowIfNotOnUIThread(); _commands = commands; _dte = dte; IOleServiceProvider ServiceProvider = Package.GetGlobalService(typeof(IOleServiceProvider)) as IOleServiceProvider ?? throw new ArgumentNullException(nameof(ServiceProvider)); _runningDocumentTable = new RunningDocumentTable(new ServiceProvider(ServiceProvider)) ?? throw new ArgumentNullException(nameof(_runningDocumentTable)); _rdtCookie = _runningDocumentTable.Advise(this); }
/// <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() { var dte = (DTE)GetService(typeof(DTE)); var txtMgr = (IVsTextManager)GetService(typeof(SVsTextManager)); var runningDocumentTable = new RunningDocumentTable(this); var documentFormatter = new DocumentFormatter(txtMgr, dte); plugin = new FormatDocumentOnBeforeSave(dte, runningDocumentTable, documentFormatter); runningDocumentTable.Advise(plugin); base.Initialize(); }
///////////////////////////////////////////////////////////////////////////// // Overridden 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 initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { var dte = (DTE)GetService(typeof(DTE)); var txtMgr = (IVsTextManager)GetService(typeof(SVsTextManager)); var runningDocumentTable = new RunningDocumentTable(this); SettingsPage options = (SettingsPage)GetDialogPage(typeof(SettingsPage)); var plugin = new FormatDocumentOnBeforeSave(dte, runningDocumentTable, txtMgr, options); runningDocumentTable.Advise(plugin); base.Initialize(); }
/// <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 async void Initialize() { var dte = (DTE)GetService(typeof(DTE)); var runningDocumentTable = new RunningDocumentTable(this); var documentFormatService = new BeautifierFormatService(dte); plugin = new FormatDocumentOnBeforeSave(dte, runningDocumentTable, documentFormatService); runningDocumentTable.Advise(plugin); base.Initialize(); }
public RunningDocTableEvents(Package aPackage) { try { mRunningDocumentTable = new RunningDocumentTable(aPackage); mRunningDocumentTable.Advise(this); } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await JoinableTaskFactory.SwitchToMainThreadAsync(); _dte = ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE)) as DTE2; _serviceProvider = new ServiceProvider((IServiceProvider)_dte); _runningDocTable = new RunningDocumentTable(_serviceProvider); _runningDocTable.Advise(new RunningDocTableEventsHandler(this)); optionPage = (OptionPageGrid)GetDialogPage(typeof(OptionPageGrid)); await base.InitializeAsync(cancellationToken, progress); }
private void InitializePackage() { rdt = new RunningDocumentTable(this); rdt.Advise(new RunningDocTableEvents(this)); if (GetService(typeof(IMenuCommandService)) is OleMenuCommandService mcs) { // Create the command for the menu item. CommandID menuCommandID = new CommandID( GuidList.guidRemoveTrailingWhitespacesCmdSet, (int)PkgCmdIDList.cmdIdRemoveTrailingWhitespaces); OleMenuCommand menuItem = new OleMenuCommand(OnRemoveTrailingWhitespacesPressed, menuCommandID); menuItem.BeforeQueryStatus += OnBeforeQueryStatus; mcs.AddCommand(menuItem); } }
/// <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() { var dte = (DTE)GetService(typeof(DTE)); var runningDocumentTable = new RunningDocumentTable(this); var defaultConfig = (VisualStudioConfiguration)GetDialogPage(typeof(VisualStudioConfiguration)); var documentFormatService = new DocumentFormatService(dte, (doc) => new FormatDocumentConfiguration(doc, defaultConfig)); plugin = new FormatDocumentOnBeforeSave(dte, runningDocumentTable, documentFormatService); runningDocumentTable.Advise(plugin); base.Initialize(); }
/// <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 this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var dte = (await GetServiceAsync(typeof(DTE))) as DTE; var runningDocumentTable = new RunningDocumentTable(this); var runningDocumentTableEvents = new TextFormatterRunningDocumentTableEvents(dte, runningDocumentTable, new Dictionary <string, ITextFormatter>(StringComparer.OrdinalIgnoreCase) { { ".bim", CreateBimTextFormatter() } }); runningDocumentTable.Advise(runningDocumentTableEvents); }
public SassWatcher(VSPackage package, IVsOutputWindowPane pane) { if (package == null) { throw new ArgumentNullException(nameof(package)); } _vsOutWindow = pane ?? throw new ArgumentNullException(nameof(pane)); _runningDocumentTable = new RunningDocumentTable(package); _runningDocumentTable.Advise(this); _errorList = new ErrorListProvider(package) { ProviderName = $"{Metadata.ProductName} Error List", ProviderGuid = new Guid("6e63fa03-9f4e-47da-9cf9-5efd22799c28") }; }
public TypescriptWatcher(VSPackage package, IVsOutputWindowPane pane) { if (package == null) { throw new ArgumentNullException(nameof(package)); } _vsOutWindow = pane ?? throw new ArgumentNullException(nameof(pane)); _runningDocumentTable = new RunningDocumentTable(package); _runningDocumentTable.Advise(this); _errorList = new ErrorListProvider(package) { ProviderName = $"{Symbol.Name} Error List", ProviderGuid = new Guid("e18abe6a-7968-4bd6-9266-0684b1d50e7a") }; }
public FileChangeListener() { IOleServiceProvider sp = Package.GetGlobalService(typeof(IOleServiceProvider)) as IOleServiceProvider; if (sp == null) { return; } _rdt = new RunningDocumentTable(new ServiceProvider(sp)); if (_rdt == null) { return; } _rdtCookie = _rdt.Advise(this); }
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 CollapseCommand.InitializeAsync(this); await ExpandCommand.InitializeAsync(this); var runningDocumentTable = new RunningDocumentTable(this); var dte = await this.GetServiceAsync(typeof(DTE)) as DTE2; MyRunningDocTableEvents.Instance.Initialize(this, runningDocumentTable, dte); runningDocumentTable.Advise(MyRunningDocTableEvents.Instance); }
/// <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() { isAsyncLoadSupported = this.IsAsyncPackageSupported(); // Only perform initialization if async package framework is not supported if (!isAsyncLoadSupported) { var dte = (DTE)GetService(typeof(DTE)); var runningDocumentTable = new RunningDocumentTable(this); var defaultConfig = (VisualStudioConfiguration)GetDialogPage(typeof(VisualStudioConfiguration)); var documentFormatService = new DocumentFormatService(dte, (doc) => new FormatDocumentConfiguration(doc, defaultConfig)); plugin = new FormatDocumentOnBeforeSave(dte, runningDocumentTable, documentFormatService); runningDocumentTable.Advise(plugin); } base.Initialize(); }
/// <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(); dte = GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; _props = dte.get_Properties("Remove Trailing Whitespaces", "Options"); rdt = new RunningDocumentTable(this); rdt.Advise(new RunningDocTableEvents(this)); var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (mcs != null) { // Create the command for the menu item. CommandID menuCommandID = new CommandID( GuidList.guidRemoveTrailingWhitespacesCmdSet, (int)PkgCmdIDList.cmdIdRemoveTrailingWhitespaces); OleMenuCommand menuItem = new OleMenuCommand(onRemoveTrailingWhitespacesPressed, menuCommandID); menuItem.BeforeQueryStatus += onBeforeQueryStatus; mcs.AddCommand(menuItem); } }
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await JoinableTaskFactory.SwitchToMainThreadAsync(); _dte = ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE)) as DTE2; _serviceProvider = new ServiceProvider((IServiceProvider)_dte); _runningDocTable = new RunningDocumentTable(_serviceProvider); _runningDocTable.Advise(new RunningDocTableEventsHandler(this)); optionPage = (OptionPageGrid)GetDialogPage(typeof(OptionPageGrid)); _node = new NodeProcess(this); if (!_node.IsReadyToExecute()) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed _node.EnsurePackageInstalledAsync().ConfigureAwait(false); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } await base.InitializeAsync(cancellationToken, progress); }
public IVsTask Initialize(IAsyncServiceProvider pServiceProvider, IProfferAsyncService pProfferService, IAsyncProgressCallback pProgressCallback) { if (!isAsyncLoadSupported) { throw new InvalidOperationException("Async Initialize method should not be called when async load is not supported."); } return(ThreadHelper.JoinableTaskFactory.RunAsync <object>(async() => { var dte = await pServiceProvider.GetServiceAsync <DTE>(typeof(DTE)); var runningDocumentTable = new RunningDocumentTable(this); var defaultConfig = (VisualStudioConfiguration)GetDialogPage(typeof(VisualStudioConfiguration)); var documentFormatService = new DocumentFormatService(dte, (doc) => new FormatDocumentConfiguration(doc, defaultConfig)); plugin = new FormatDocumentOnBeforeSave(dte, runningDocumentTable, documentFormatService); runningDocumentTable.Advise(plugin); return null; }).AsVsTask()); }
internal DocumentMonitorService(SVsServiceProvider vsServiceProvider, ICompletionBroker completionBroker) { _runningDocumentTable = new RunningDocumentTable(vsServiceProvider); _runningDocumentTable.Advise(this); _completionBroker = completionBroker; _dte = (DTE)vsServiceProvider.GetService(typeof(_DTE)); var documentChanged = Observable.FromEventPattern(x => _changed += x, x => _changed -= x) .Throttle(TimeSpan.FromSeconds(2.0), RxApp.MainThreadScheduler) .Where(_ => !IsCompletionActive()) .Select(_ => Unit.Default); var dispatcher = Dispatcher.CurrentDispatcher; documentChanged.Subscribe(_ => dispatcher.BeginInvoke(new Action(() => SaveAll()))); // NB: We use the message bus here, because we want to effectively // merge all of the text change notifications from any document MessageBus.Current.RegisterMessageSource(documentChanged, "AnyDocumentChanged"); CheckAlreadyOpenDocuments(vsServiceProvider); }
/// <summary> /// The event explorer user control constructor. /// </summary> public RdtEventControl() { InitializeComponent(); // Create a selection container for tracking selected RDT events. selectionContainer = new MsVsShell.SelectionContainer(); // Advise the RDT of this event sink. IOleServiceProvider sp = Package.GetGlobalService(typeof(IOleServiceProvider)) as IOleServiceProvider; if (sp == null) return; rdt = new RunningDocumentTable(new ServiceProvider(sp)); if (rdt == null) return; rdtCookie = rdt.Advise(this); // Obtain the single instance of the options via automation. try { DTE dte = (DTE)Package.GetGlobalService(typeof(DTE)); EnvDTE.Properties props = dte.get_Properties("RDT Event Explorer", "Explorer Options"); IOptions o = props.Item("ContainedOptions").Object as IOptions; options = (Options)o; } catch { IVsActivityLog log = Package.GetGlobalService( typeof(SVsActivityLog)) as IVsActivityLog; if (log != null) { log.LogEntry( (UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, this.ToString(), string.Format(CultureInfo.CurrentCulture, "RdtEventExplorer could not obtain properties via automation: {0}", this.ToString()) ); } options = new Options(); } // Prepare the event grid. eventGrid.AutoGenerateColumns = false; eventGrid.AllowUserToAddRows = false; eventGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; eventGrid.Columns.Add("Event", Resources.EventHeader); eventGrid.Columns.Add("Moniker", Resources.MonikerHeader); eventGrid.Columns["Event"].ReadOnly = true; eventGrid.Columns["Moniker"].ReadOnly = true; eventGrid.AllowUserToResizeRows = false; eventGrid.AllowUserToResizeColumns = true; eventGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; int x = Screen.PrimaryScreen.Bounds.Size.Width; int y = Screen.PrimaryScreen.Bounds.Size.Height; Size = new Size(x / 3, y / 3); }
/// <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(); // 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 Refresh Command and its handler CommandID refreshCommandID = new CommandID(GuidList.guidVSPackageGDBACmdSet, (int)PkgCmdIDList.cmdidRefreshContextMenu); MenuCommand menuRefresh = new MenuCommand(RefreshCommandCallBack, refreshCommandID); mcs.AddCommand(menuRefresh); // Create the command for the tool window for the RDT Event List CommandID toolwndCommandID = new CommandID(GuidList.guidRdtEventExplorerCmdSet, (int)PkgCmdIDList.cmdidMyTool); MenuCommand menuToolWin = new MenuCommand(new EventHandler(ShowToolWindow), toolwndCommandID); mcs.AddCommand(menuToolWin); } //Alternative method //uint dwCookie = 0; //IVsRunningDocumentTable rdt2 = (IVsRunningDocumentTable)Package.GetGlobalService(typeof(SVsRunningDocumentTable)); //rdt2.AdviseRunningDocTableEvents(this, out dwCookie); // Create a selection container for tracking selected RDT events. selectionContainer = new Microsoft.VisualStudio.Shell.SelectionContainer(); // Advise the RDT of this event sink. Microsoft.VisualStudio.OLE.Interop.IServiceProvider sp = Package.GetGlobalService(typeof(Microsoft.VisualStudio.OLE.Interop.IServiceProvider)) as Microsoft.VisualStudio.OLE.Interop.IServiceProvider; if (sp == null) return; rdt = new RunningDocumentTable(new ServiceProvider(sp)); if (rdt == null) return; rdtCookie = rdt.Advise(this); }
/// <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() { var dte = (DTE)GetService(typeof(DTE)); var runningDocumentTable = new RunningDocumentTable(this); var documentFormatService = new DocumentFormatService(dte, () => (ExtensionsCfg)GetDialogPage(typeof(ExtensionsCfg))); plugin = new FormatDocumentOnBeforeSave(dte, runningDocumentTable, documentFormatService); runningDocumentTable.Advise(plugin); base.Initialize(); }
public RunningDocTableEvents() { _runningDocumentTable = new RunningDocumentTable(); _coockie = _runningDocumentTable.Advise(this); }
/// <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 = Package.GetGlobalService(typeof(DTE)) as EnvDTE80.DTE2; var shellSettingsManager = new ShellSettingsManager(this); var writableSettingsStore = shellSettingsManager.GetWritableSettingsStore(SettingsScope.UserSettings); var settings = new SettingsHelper (CollectionPath, writableSettingsStore); clangStyle = new ClangFormatStyle(); styleDb = new StyleDatabase(settings); dte.Events.SolutionEvents.Opened += onSolutionOpened; dte.Events.SolutionEvents.AfterClosing += onSolutionClosed; dte.Events.SolutionEvents.Renamed += onSolutionRenamed; appEvents = dte.Events; solutionEvents = appEvents.SolutionEvents; rdt = new RunningDocumentTable (this); rdt.Advise(new RunningDocTableEvents(this)); // 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.GuidCmdSet, (int)PkgCmdIDList.cmdIdOptions); OleMenuCommand menuItem = new OleMenuCommand(optionsDialogCallback, menuCommandID); mcs.AddCommand(menuItem); menuCommandID = new CommandID( GuidList.GuidCmdSet, (int)PkgCmdIDList.cmdIdFormatDocument); menuItem = new OleMenuCommand(formatDocumentCallback, menuCommandID); menuItem.BeforeQueryStatus += onBeforeQueryStatus; mcs.AddCommand(menuItem); menuCommandID = new CommandID( GuidList.GuidCmdSet, (int)PkgCmdIDList.cmdIdFormatFunction); menuItem = new OleMenuCommand(formatFunctionCallback, menuCommandID); menuItem.BeforeQueryStatus += onBeforeQueryStatus; mcs.AddCommand(menuItem); menuCommandID = new CommandID( GuidList.GuidCmdSet, (int)PkgCmdIDList.cmdIdFormatSelection); menuItem = new OleMenuCommand(formatSelectionCallback, menuCommandID); menuItem.BeforeQueryStatus += onBeforeQueryStatus; mcs.AddCommand(menuItem); } }
public DocumentEventListener(IServiceProvider package) { _table = new RunningDocumentTable(package); _cookie = _table.Advise(this); }
/// <summary> /// The event explorer user control constructor. /// </summary> public RdtEventControl() { InitializeComponent(); // Create a selection container for tracking selected RDT events. selectionContainer = new MsVsShell.SelectionContainer(); // Advise the RDT of this event sink. IOleServiceProvider sp = Package.GetGlobalService(typeof(IOleServiceProvider)) as IOleServiceProvider; if (sp == null) { return; } rdt = new RunningDocumentTable(new ServiceProvider(sp)); if (rdt == null) { return; } rdtCookie = rdt.Advise(this); // Obtain the single instance of the options via automation. try { DTE dte = (DTE)Package.GetGlobalService(typeof(DTE)); EnvDTE.Properties props = dte.get_Properties("RDT Event Explorer", "Explorer Options"); IOptions o = props.Item("ContainedOptions").Object as IOptions; options = (Options)o; } catch { IVsActivityLog log = Package.GetGlobalService( typeof(SVsActivityLog)) as IVsActivityLog; if (log != null) { log.LogEntry( (UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION, this.ToString(), string.Format(CultureInfo.CurrentCulture, "RdtEventExplorer could not obtain properties via automation: {0}", this.ToString()) ); } options = new Options(); } // Prepare the event grid. eventGrid.AutoGenerateColumns = false; eventGrid.AllowUserToAddRows = false; eventGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; eventGrid.Columns.Add("Event", Resources.EventHeader); eventGrid.Columns.Add("Moniker", Resources.MonikerHeader); eventGrid.Columns["Event"].ReadOnly = true; eventGrid.Columns["Moniker"].ReadOnly = true; eventGrid.AllowUserToResizeRows = false; eventGrid.AllowUserToResizeColumns = true; eventGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; int x = Screen.PrimaryScreen.Bounds.Size.Width; int y = Screen.PrimaryScreen.Bounds.Size.Height; Size = new Size(x / 3, y / 3); }
//#region IVsRunningDocTableEvents4 Members //public int OnAfterLastDocumentUnlock(IVsHierarchy pHier, uint itemid, string pszMkDocument, int fClosedWithoutSaving) //{ // return VSConstants.S_OK; //} //public int OnAfterSaveAll() //{ // return VSConstants.S_OK; //} //public int OnBeforeFirstDocumentLock(IVsHierarchy pHier, uint itemid, string pszMkDocument) //{ // return VSConstants.S_OK; //} //#endregion //-------------------------------------------------------------------------------- // SccProvider Service initialization/unitialization //-------------------------------------------------------------------------------- #region SccProvider Service initialization/unitialization public SccProviderService(SccProvider sccProvider) { Debug.Assert(null != sccProvider); _sccProvider = sccProvider; // Subscribe to solution events IVsSolution sol = (IVsSolution)_sccProvider.GetService(typeof(SVsSolution)); sol.AdviseSolutionEvents(this, out _vsSolutionEventsCookie); Debug.Assert(VSConstants.VSCOOKIE_NIL != _vsSolutionEventsCookie); // Subscribe to project documents IVsTrackProjectDocuments2 tpdService = (IVsTrackProjectDocuments2)_sccProvider.GetService(typeof(SVsTrackProjectDocuments)); tpdService.AdviseTrackProjectDocumentsEvents(this, out _tpdTrackProjectDocumentsCookie); Debug.Assert(VSConstants.VSCOOKIE_NIL != _tpdTrackProjectDocumentsCookie); //add doc save envent // Advise the RDT of this event sink. IOleServiceProvider sp = Package.GetGlobalService(typeof(IOleServiceProvider)) as IOleServiceProvider; if (sp == null) return; m_oRdTVSFrame = new RunningDocumentTable(new ServiceProvider(sp)); if (m_oRdTVSFrame == null) return; m_nRdtCookie = m_oRdTVSFrame.Advise(this); }