Exemplo n.º 1
0
        protected override void Initialize()
        {
            base.Initialize();

            // Prepare event
            DTE dte = GetService(typeof(DTE)) as DTE;

            if (dte != null)
            {
                CommandVisible = false;
                WindowEvents   = dte.Events.WindowEvents;
                WindowEvents.WindowActivated += WindowEvents_WindowActivated;
                WindowEvents.WindowClosing   += WindowEvents_WindowClosing;
            }

            // 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 tool window
                CommandID      viewIndentCommandID = new CommandID(guidIndentGuideCmdSet, cmdidViewIndentGuides);
                OleMenuCommand menuCmd             = new OleMenuCommand(ToggleVisibility, viewIndentCommandID);
                menuCmd.BeforeQueryStatus += BeforeQueryStatus;

                mcs.AddCommand(menuCmd);
            }

            Service = new IndentGuideService(this);
            (this as IServiceContainer).AddService(typeof(SIndentGuide), Service, true);
            Service.Upgrade();
            Service.Load();
        }
Exemplo n.º 2
0
        protected override void Initialize()
        {
            base.Initialize();

            JoinableTaskFactory = ThreadHelper.JoinableTaskFactory;

            // Prepare event
            var dte = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

            if (dte != null)
            {
                CommandVisible = false;
                WindowEvents   = dte.Events.WindowEvents;
                WindowEvents.WindowActivated += WindowEvents_WindowActivated;
                WindowEvents.WindowClosing   += WindowEvents_WindowClosing;
            }

            // 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 tool window
                CommandID viewIndentCommandID = new CommandID(guidIndentGuideCmdSet, cmdidViewIndentGuides);
                var       menuCmd             = new OleMenuCommand(ToggleVisibility, viewIndentCommandID);
                menuCmd.BeforeQueryStatus += new EventHandler(BeforeQueryStatus);

                mcs.AddCommand(menuCmd);
            }

            Service = new IndentGuideService(this);
            ((IServiceContainer)this).AddService(typeof(SIndentGuide), Service, true);
            Service.Upgrade();
            Service.Load();
        }
        protected async override Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            // Prepare event
            var dte = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

            if (dte != null)
            {
                CommandVisible = false;
                WindowEvents   = dte.Events.WindowEvents;
                WindowEvents.WindowActivated += WindowEvents_WindowActivated;
                WindowEvents.WindowClosing   += WindowEvents_WindowClosing;
            }

            // 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 tool window
                CommandID viewIndentCommandID = new CommandID(guidIndentGuideCmdSet, cmdidViewIndentGuides);
                var       menuCmd             = new OleMenuCommand(ToggleVisibility, viewIndentCommandID);
                menuCmd.BeforeQueryStatus += new EventHandler(BeforeQueryStatus);

                mcs.AddCommand(menuCmd);
            }

            Service = new IndentGuideService(this);
            AddService(typeof(SIndentGuide), async(container, ct, type) => Service, true);
            Service.Upgrade();
            Service.Load();
        }
Exemplo n.º 4
0
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            JoinableTaskFactory = ThreadHelper.JoinableTaskFactory;

            // Switches to the UI thread in order to consume some services used in command initialization
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            // Prepare event
            var dte = await GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

            if (dte != null)
            {
                CommandVisible = false;
                WindowEvents   = dte.Events.WindowEvents;
                WindowEvents.WindowActivated += WindowEvents_WindowActivated;
                WindowEvents.WindowClosing   += WindowEvents_WindowClosing;
            }

            // Add our command handlers for menu (commands must exist in the .vsct file)
            var mcs = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (mcs != null)
            {
                // Create the command for the tool window
                CommandID viewIndentCommandID = new CommandID(guidIndentGuideCmdSet, cmdidViewIndentGuides);
                var       menuCmd             = new OleMenuCommand(ToggleVisibility, viewIndentCommandID);
                menuCmd.BeforeQueryStatus += new EventHandler(BeforeQueryStatus);

                mcs.AddCommand(menuCmd);
            }

            Service = new IndentGuideService(this);
            // Adds a service on the background thread
            AddService(typeof(SIndentGuide), async(container, ct, type) => await System.Threading.Tasks.Task.FromResult(Service), true);

            Service.Upgrade();
            Service.Load();
        }
        protected override void Initialize()
        {
            base.Initialize();

            // Prepare event
            var dte = GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
            if (dte != null) {
                CommandVisible = false;
                WindowEvents = dte.Events.WindowEvents;
                WindowEvents.WindowActivated += WindowEvents_WindowActivated;
                WindowEvents.WindowClosing += WindowEvents_WindowClosing;
            }

            // 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 tool window
                CommandID viewIndentCommandID = new CommandID(guidIndentGuideCmdSet, cmdidViewIndentGuides);
                var menuCmd = new OleMenuCommand(ToggleVisibility, viewIndentCommandID);
                menuCmd.BeforeQueryStatus += new EventHandler(BeforeQueryStatus);

                mcs.AddCommand(menuCmd);
            }

            Service = new IndentGuideService(this);
            ((IServiceContainer)this).AddService(typeof(SIndentGuide), Service, true);
            Service.Upgrade();
            Service.Load();
        }