示例#1
0
        /// <summary>
        /// sets the objects that would be accessed later by other classes
        /// </summary>
        /// <param name="h">iwpftextviewhost of the textview</param>
        /// <param name="cb">the client network object</param>
        /// <param name="cpe">the explorer management object</param>
        public GraphicObjects(IWpfTextViewHost h, CoProNetwork cb, CoProExplorer cpe)
        {
            coproExplorer = cpe;
            if (DTE2.ActiveWindow != null)
            {
                iwpf    = h;
                we      = ((Events2)DTE2.Events).WindowEvents;
                this.cb = cb;
                //pie.ItemAdded += ItemAdded;
                //((Events2)DTE2.Events).WindowEvents.WindowClosing += new _dispWindowEvents_WindowClosingEventHandler(ClosedWindow);
                //cb = new MyCallBack();
                //cb.ChangeCaret += new ChangeCaretEventHandler(my_CaretChange);
                //twice = false;
                //TODO: register to cb's events
                //TODO: add a different handler function for each of the events
                // examples: http://www.codeproject.com/Articles/20550/C-Event-Implementation-Fundamentals-Best-Practices

                //ts.NewLine();
                //ts.Insert("a");
                //tde = ((Events2)DTE2.Events).TextDocumentKeyPressEvents;
                //tde.BeforeKeyPress += new _dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler(KeyPress_EventHandler);

                //te.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler(EnterFix);
                //DTE2.Events.CommandEvents.BeforeExecute+= new _dispCommandEvents_BeforeExecuteEventHandler()
                //te.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler(IntelisenseFix);
            }
        }
示例#2
0
 /// <summary>
 /// Registers handlers for the Activated and Closing events from the text window.
 /// </summary>
 public void AddWindowEvents()
 {
     events        = dte.Events;
     windowsEvents = events.get_WindowEvents(null);
     windowsEvents.WindowActivated += windowsEvents_WindowActivated;
     windowsEvents.WindowClosing   += windowsEvents_WindowClosing;
 }
示例#3
0
        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;
            }
        }
示例#4
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();
        }
        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);
            }
        }
示例#6
0
        /// <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(DTE2 application, ext_ConnectMode connectMode, AddIn addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;
            ViewBase.ResetToolWindowList();
            OutputWindow.Initialize(_applicationObject);

            try
            {
                CreateMenu();

                try
                {
                    Events events = _applicationObject.Events;
                    _windowsEvents = events.get_WindowEvents(null);
                    _windowsEvents.WindowActivated += OnWindowActivated;
                    _eve = _applicationObject.Events.DTEEvents;
                }
                catch (Exception oEx)
                {
                    LoggingHelper.HandleException(oEx);
                }
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);
            }
        }
        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;
            }
        }
示例#8
0
        public EventHelper(DTE dte)
        {
            _dte          = dte;
            _windowEvents = dte.Events.WindowEvents;

            _windowEvents.WindowActivated += _windowEvents_WindowActivated;
        }
示例#9
0
 public GoToTestedClassCommand(DTE2 dte)
     : base(dte)
 {
     _events    = Dte.Events;
     _winEvents = _events.get_WindowEvents();
     _winEvents.WindowActivated += WindowActivated;
 }
        /// <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()
        {
            //按钮事件加载
            GetTKKCommand.Initialize(this);
            TranslateCommand.Initialize(this);
            ToggleAutoTranslateCommand.Initialize(this);
            base.Initialize();

            //加载配置项
            Settings.ReloadSetting((OptionPageGrid)GetDialogPage(typeof(OptionPageGrid)));


            //创建连接返回翻译内容
            if (Settings.RequestMode == RequestMode.Api)
            {
                TranslateClient = new TranslateClient(Settings);//new TranslateClient(Settings);
            }
            else
            {
                TranslateClient = new HtmlAnalysisTranslateClient(Settings);
            }

            DTE            = (DTE2)GetService(typeof(DTE));
            Events         = DTE.Events;
            DocumentEvents = Events.DocumentEvents;
            WindowEvents   = Events.WindowEvents;

            DocumentEvents.DocumentOpened += DocumentEvents_DocumentOpened;
            DocumentEvents.DocumentSaved  += DocumentEvents_DocumentSaved;
            WindowEvents.WindowActivated  += WindowEvents_WindowActivated;
        }
        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();
                    }
                }
            });
        }
        private void OnStartupComplete()
        {
            CreateOutputWindow();
            CreateStatusBarIcon();

            solutionEvents = events.SolutionEvents;
            buildEvents    = events.BuildEvents;
            windowEvents   = events.WindowEvents;

            solutionEvents.Opened += OnSolutionOpened;

            solutionEvents.AfterClosing += OnSolutionClosed;

            buildEvents.OnBuildBegin += OnBuildBegin;
            buildEvents.OnBuildDone  += OnBuildDone;

            debugService = (IVsDebugger)GetGlobalService(typeof(SVsShellDebugger));
            debugService.AdviseDebuggerEvents(this, out debugCookie);

            var componentModel = (IComponentModel)GetGlobalService(typeof(SComponentModel));

            operationState = componentModel.GetService <IOperationState>();
            operationState.StateChanged += OperationStateOnStateChanged;

            application                   = Application.Current;
            application.Activated        += OnApplicationActivated;
            application.Deactivated      += OnApplicationDeactivated;
            windowEvents.WindowActivated += OnWindowActivated;

            SystemEvents.SessionSwitch    += OnSessionSwitch;
            SystemEvents.PowerModeChanged += OnPowerModeChanged;

            VSColorTheme.ThemeChanged += OnThemeChanged;

            chart.Loaded += (s, a) =>
            {
                Window window = Window.GetWindow(chart);
                new Lid(window).StatusChanged += OnLidStatusChanged;
            };

            ListenToScreenSaver();

            sm = new VSStateMachine();

            if (application.Windows.OfType <Window>()
                .All(w => !w.IsActive))
            {
                sm.On(VSStateMachine.Events.LostFocus);
            }

            if (dte.Solution.Count > 0)
            {
                sm.On(VSStateMachine.Events.SolutionOpened);
            }

            sm.StateChanged += s => Output("Current state: {0}", s.ToString());

            Output("Startup complete");
            Output("Current state: {0}", sm.CurrentState.ToString());
        }
示例#13
0
        /// <summary>
        /// Initialisation of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the Initialisation code that rely on services provided by VisualStudio.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token to monitor for Initialisation 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 Initialisation, 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)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            // When Initialised asynchronously, the current thread may be a background thread at this point.
            // Do any Initialisation that requires the UI thread after switching to the UI thread.
            //await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            GetLogger().LogInformation(GetPackageName(), "Initialising.");
            await base.InitializeAsync(cancellationToken, progress);

            try
            {
                var dte = (DTE)await this.GetServiceAsync(typeof(DTE));

                var _dteEvents = dte.Events;

                _dteEditorEvents = _dteEvents.TextEditorEvents;
                _dteWindowEvents = _dteEvents.WindowEvents;

                _dteEditorEvents.LineChanged     += OnLineChanged;
                _dteWindowEvents.WindowActivated += OnWindowActivated;

                _stack = new Stack <CancellationTokenSource>();

                GetLogger().LogInformation(GetPackageName(), "Initialised.");
            }
            catch (Exception exception)
            {
                GetLogger().LogError(GetPackageName(), "Exception during initialisation", exception);
            }
        }
示例#14
0
 public WindowImpl(IAvaloniaNativeFactory factory)
 {
     using (var e = new WindowEvents(this))
     {
         Init(_native = factory.CreateWindow(e), factory.CreateScreens());
     }
 }
示例#15
0
        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();
        }
示例#16
0
 public WindowImpl(IAvaloniaNativeFactory factory, AvaloniaNativePlatformOptions opts) : base(opts)
 {
     using (var e = new WindowEvents(this))
     {
         Init(_native = factory.CreateWindow(e), factory.CreateScreens());
     }
 }
示例#17
0
        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();
        }
        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);
            }
        }
示例#19
0
        /////////////////////////////////////////////////////////////////////////////
        // 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();
        }
        public StackTraceExplorerToolWindow() : base(null)
        {
            Caption = _caption;
            Content = new StackTraceExplorerToolWindowControl();

            _windowEvents = EnvDteHelper.Dte.Events.WindowEvents;
            _windowEvents.WindowActivated += _windowEvents_WindowActivated;
        }
 public BookmarksController(IDialControllerHost host, IVsTextManager textManager)
     : base(host, textManager)
 {
     _host     = host;
     _commands = host.DTE.Commands;
     _events   = host.DTE.Events.WindowEvents;
     _events.WindowActivated += WindowActivated;
 }
        public DexterFileAnalysisCommand(Package package, int commandId, Guid commandSet, ConfigurationProvider configurationProvider)
            : base(package, commandId, commandSet, configurationProvider)
        {
            WindowEvents events = ((Events2)Dte.Events).WindowEvents;

            events.WindowActivated += OnDocumentWindowActivated;
            events.WindowClosing   += OnDocumentWindowClosed;
        }
 public ErrorsController(IDialControllerHost host)
 {
     _host      = host;
     _dte       = host.DTE;
     _errorList = _dte.ToolWindows.ErrorList as IErrorList;
     _events    = _dte.Events.WindowEvents;
     _events.WindowActivated += WindowActivated;
 }
示例#24
0
        public WindowManager(DTE2 applicationObject, EnvDTE.AddIn addInInstance)
        {
            this.addInInstance     = addInInstance;
            this.applicationObject = applicationObject;

            this.events = this.applicationObject.DTE.Events.get_WindowEvents(null);

            this.events.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(WindowManager_WindowActivated);
        }
        public BookmarksController(RadialControllerMenuItem menuItem, DTE2 dte) : base(menuItem)
        {
            _commands = dte.Commands;
            // Switched in provider
#pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
            _events = dte.Events.WindowEvents;
            _events.WindowActivated += OnToolWindowActivated;
#pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread
        }
示例#26
0
        public SolutionEvents(DTE2 applicationObject)
        {
            _applicationObject = applicationObject;

            _documentEvents = _applicationObject.Events.DocumentEvents;
            _windowsEvents  = _applicationObject.Events.WindowEvents;

            _documentEvents.DocumentOpened += DocumentEvents_DocumentOpened;
            _windowsEvents.WindowActivated += WindowEvents_WindowActivated;
        }
示例#27
0
        private void SetUpLifeCycleEvents()
        {
            var dte = ServiceLocator.Resolve <DTE2>();

            _dteEvents = dte.Events.DTEEvents;
            _dteEvents.OnBeginShutdown   += DteEventsOnOnBeginShutdown;
            _dteEvents.OnStartupComplete += StartupCompleted;
            _windowEvents = dte.Events.WindowEvents;
            _windowEvents.WindowActivated += SandoWindowActivated;
        }
示例#28
0
 private void WindowEvents_WindowActivated(Window gotFocus, Window lostFocus)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     if (dte.MainWindow?.Visible == true)
     {
         windowEvents.WindowActivated -= WindowEvents_WindowActivated;
         windowEvents = null;
         QtVsToolsPackage.Instance.VsMainWindowActivated();
     }
 }
 public void HookWindowActivation()
 {
     windowEvents = base.GetWindowEvents();
     if (ShouldHookWindowActivated)
         windowEvents.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(windowEvents_WindowActivated);
     if (ShouldHookWindowCreated)
         windowEvents.WindowCreated += new _dispWindowEvents_WindowCreatedEventHandler(windowEvents_WindowCreated);
     if (ShouldHookWindowClosing)
         windowEvents.WindowClosing += new _dispWindowEvents_WindowClosingEventHandler(windowEvents_WindowClosing);
 }
        public ErrorsController(RadialControllerMenuItem menuItem, DTE2 dte) : base(menuItem)
        {
            _dte = dte;
            // Switched in provider
#pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
            _errorList = _dte.ToolWindows.ErrorList as IErrorList;
            _events    = _dte.Events.WindowEvents;
            _events.WindowActivated += OnToolWindowActivated;
#pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread
        }
示例#31
0
        private void Initialize(IRSEnv env)
        {
            var dte = env.IDESession.DTE;

            if (dte.ActiveWindow != null)
            {
                OnWindowActivated(dte.ActiveWindow, null);
            }
            _windowEvents = dte.Events.WindowEvents;
            _windowEvents.WindowActivated += OnWindowActivated;
        }
示例#32
0
        /// <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)
        {
            _applicationObject = (DTE2)application;
            _addInInstance = (AddIn)addInInst;

            _windowEvents = _applicationObject.Events.WindowEvents;
            _windowEvents.WindowCreated += OnWindowCreated;

            _solutionEvents = _applicationObject.Events.SolutionEvents;
            _solutionEvents.Opened += OnSolutionOpened;
        }
示例#33
0
        public WindowImpl(IAvaloniaNativeFactory factory, AvaloniaNativePlatformOptions opts) : base(opts)
        {
            _factory = factory;
            _opts    = opts;
            using (var e = new WindowEvents(this))
            {
                Init(_native = factory.CreateWindow(e), factory.CreateScreens());
            }

            //NativeMenuExporter = new AvaloniaNativeMenuExporter(_native, factory);
        }
        private void SetupDocumentEvents()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            IVsTrackProjectDocuments2 tpdService = (IVsTrackProjectDocuments2)_sccProvider.GetService(typeof(SVsTrackProjectDocuments));
            tpdService.AdviseTrackProjectDocumentsEvents(this, out _tpdTrackProjectDocumentsCookie);
            Debug.Assert(VSConstants.VSCOOKIE_NIL != _tpdTrackProjectDocumentsCookie);

            var activeIde = SolutionExtensions.GetActiveIDE();
            //var activeIde = BasicSccProvider.GetServiceEx<EnvDTE80.DTE2>();
            //activeIde.Events.SolutionItemsEvents.
            _windowEvents = activeIde.Events.WindowEvents;
            _solutionEvents = activeIde.Events.SolutionEvents;
            _solutionEvents.ProjectAdded += _solutionEvents_ProjectAdded;
            _windowEvents.WindowActivated += _windowEvents_WindowActivated;

        }
示例#35
0
        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()
        {
            base.Initialize();

            _commandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            if (_commandService != null) {
                _commandService.AddCommand(InsertGuidCommand.Instance.MenuCommand);
            }

            var dte = GetService(typeof(DTE)) as DTE;
            if (dte != null) {
                _windowEvents = dte.Events.WindowEvents;
                if (_windowEvents != null) {
                    _windowEvents.WindowActivated += WindowEvents_WindowActivated;
                    _windowEvents.WindowClosing += WindowEvents_WindowClosing;
                }
            }
        }
示例#37
0
        public void Init()
        {
            DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;

            IVsTextView view;
            manager.GetActiveView( 1, null, out view);

            docEvent = dte.Events.get_DocumentEvents(null);

            winEvent = dte.Events.get_WindowEvents(null);
        }
示例#38
0
        private void InitEvents()
        {
            if (solutionEvents == null)
            {
                solutionEvents = m_dte.Events.SolutionEvents;
                solutionEvents.Opened += new _dispSolutionEvents_OpenedEventHandler(SolutionOpened);
                solutionEvents.AfterClosing += new _dispSolutionEvents_AfterClosingEventHandler(SolutionClosed);
                solutionEvents.ProjectAdded += new _dispSolutionEvents_ProjectAddedEventHandler(ProjectAdded);
                solutionEvents.ProjectRemoved += new _dispSolutionEvents_ProjectRemovedEventHandler(ProjectRemoved);
                solutionEvents.ProjectRenamed += new _dispSolutionEvents_ProjectRenamedEventHandler(ProjectRenamed);
            }

            if (windowEvents == null)
            {
                windowEvents = m_dte.Events.get_WindowEvents(null);
                windowEvents.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(WindowActivated);
                windowEvents.WindowClosing += new _dispWindowEvents_WindowClosingEventHandler(WindowClosing);
            }

            if( textEditorEvents == null )
            {
                textEditorEvents = m_dte.Events.get_TextEditorEvents(null);
                textEditorEvents.LineChanged += new _dispTextEditorEvents_LineChangedEventHandler(LineChanged);
            }
        }
示例#39
0
文件: Connect.cs 项目: hxhlb/jsparser
        /// <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)
        {
            _applicationObject = (DTE2)application;
            _addInInstance = (EnvDTE.AddIn)addInInst;
            if(connectMode == ext_ConnectMode.ext_cm_UISetup)
            {
                object []contextGUIDS = new object[] { };
                Commands2 commands = (Commands2)_applicationObject.Commands;
                string toolsMenuName;

                try
                {
                    //If you would like to move the command to a different menu, change the word "Tools" to the
                    //  English version of the menu. This code will take the culture, append on the name of the menu
                    //  then add the command to that menu. You can find a list of all the top-level menus in the file
                    //  CommandBar.resx.
                    string resourceName;
                    ResourceManager resourceManager = new ResourceManager("JsParser_AddIn.CommandBar", Assembly.GetExecutingAssembly());
                    CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID);

                    if(cultureInfo.TwoLetterISOLanguageName == "zh")
                    {
                        System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                        resourceName = String.Concat(parentCultureInfo.Name, "Tools");
                    }
                    else
                    {
                        resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools");
                    }
                    toolsMenuName = resourceManager.GetString(resourceName);
                }
                catch
                {
                    //We tried to find a localized version of the word Tools, but one was not found.
                    //  Default to the en-US word, which may work for the current culture.
                    toolsMenuName = "Tools";
                }

                //Place the command on the tools menu.
                //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
                Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"];

                //Find the Tools command bar on the MenuBar command bar:
                CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName];
                CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl;

                //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
                //  just make sure you also update the QueryStatus/Exec method to include the new command names.
                try
                {
                    //Add a command to the Commands collection:
                    var comShow = commands.AddNamedCommand2(_addInInstance,
                        "Show",
                        "Javascript Parser",
                        "Javascript Parser AddIn Show",
                        true,
                        629,
                        ref contextGUIDS,
                        (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                        (int)vsCommandStyle.vsCommandStylePictAndText,
                        vsCommandControlType.vsCommandControlTypeButton
                    );

                    //Add a command to the Commands collection:
                    var comFind = commands.AddNamedCommand2(_addInInstance,
                        "Find",
                        "Javascript Parser Find",
                        "Javascript Parser AddIn 'Find' Feature",
                        true,
                        0,
                        ref contextGUIDS,
                        (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
                        (int)vsCommandStyle.vsCommandStylePictAndText,
                        vsCommandControlType.vsCommandControlTypeButton
                    );

                    //Add a control for the command to the tools menu:
                    if(toolsPopup != null)
                    {
                        if (comShow != null)
                        {
                            comShow.AddControl(toolsPopup.CommandBar, 1);
                        }

                        if (comFind != null)
                        {
                            comFind.Bindings = "Text Editor::SHIFT+ALT+J";
                            comFind.AddControl(toolsPopup.CommandBar, 2);
                        }
                    }
                }
                catch(System.ArgumentException)
                {
                    //If we are here, then the exception is probably because a command with that name
                    //  already exists. If so there is no need to recreate the command and we can
                    //  safely ignore the exception.
                }
            }

            //Subscribe to IDE events
            Events events = _applicationObject.Events;
            _documentEvents = events.get_DocumentEvents(null);
            _windowEvents = events.get_WindowEvents(null);
            _documentEvents.DocumentSaved += documentEvents_DocumentSaved;
            _documentEvents.DocumentOpened += documentEvents_DocumentOpened;
            _windowEvents.WindowActivated += windowEvents_WindowActivated;

            _uiThemeProvider = new DefaultUIThemeProvider();
            _jsParserService = new JsParserService(Settings.Default);
            _jsParserToolWindowManager = new JsParserToolWindowManager(_jsParserService, _uiThemeProvider, () =>
            {
                return EnsureWindowCreated();
            });
        }
        /// <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();

            try
            {
                if (VisualStudio.Solution != null)
                {
                    Log.Message("Starting Tidy Tabs inside Visual Studio {0} {1} for solution {2}", VisualStudio.Edition, VisualStudio.Version, VisualStudio.Solution.FullName);
                }

                windowEvents = VisualStudio.Events.WindowEvents;
                documentEvents = VisualStudio.Events.DocumentEvents;
                textEditorEvents = VisualStudio.Events.TextEditorEvents;
                solutionEvents = VisualStudio.Events.SolutionEvents;
                buildEvents = VisualStudio.Events.BuildEvents;

                windowEvents.WindowActivated += WindowEventsWindowActivated;
                documentEvents.DocumentClosing += DocumentEventsOnDocumentClosing;
                documentEvents.DocumentSaved += DocumentEventsOnDocumentSaved;
                textEditorEvents.LineChanged += TextEditorEventsOnLineChanged;
                solutionEvents.Opened += SolutionEventsOnOpened;
                buildEvents.OnBuildBegin += BuildEventsOnOnBuildBegin;

                shell = (IVsShell)GetService(typeof(SVsShell));

                if (shell != null)
                {
                    shell.AdviseBroadcastMessages(this, out shellCookie);
                }

                OleMenuCommandService menuCommandService = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

                if (menuCommandService != null)
                {
                    CommandID menuCommandId = new CommandID(GuidList.guidTidyTabsCmdSet, (int)PkgCmdIDList.cmdidTidyTabs);
                    MenuCommand menuItem = new MenuCommand(TidyTabsMenuItemCommandActivated, menuCommandId);
                    menuCommandService.AddCommand(menuItem);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
示例#41
0
		/// <summary>
		/// Load Event of Query Builder
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void QueryBuilder_Load(object sender, EventArgs e)
		{
			try
			{
				
				//Initialization of Queries tablelayour where the QueryGridGrup will be added
				InitializeQueriesTableLayoutPanel();
				//Initialization of Attribute List
				InitializeAttributesDataGrid();
				InitializeRecentQueries();
				defaultGroup = AddDataGridViewToPanel();
				OMETrace.WriteFunctionStart();
				Events events = ApplicationObject.Events;
				_windowsEvents = events.get_WindowEvents(null);
				_windowsEvents.WindowActivated += _windowsEvents_WindowActivated;
				OMETrace.WriteFunctionEnd();

				SetLiterals();
				recentQueriesToolTip = new ToolTip();
			}
			catch (Exception oEx)
			{
				LoggingHelper.ShowMessage(oEx);
			}
		}
示例#42
0
        /// <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)
        {
            Logger.Info(string.Format("Initializing WakaTime v{0}", _version));

            try
            {
                _applicationObject = (DTE2)application;
                _addInInstance = (AddIn)addInInst;

                _editorVersion = _applicationObject.Version;
                _docEvents = _applicationObject.Events.DocumentEvents;
                _docEvents.DocumentOpened += DocEventsOnDocumentOpened;
                _docEvents.DocumentSaved += DocEventsOnDocumentSaved;
                _windowsEvents = _applicationObject.Events.WindowEvents;
                _windowsEvents.WindowActivated += WindowsEventsOnWindowActivated;

                if (connectMode == ext_ConnectMode.ext_cm_UISetup)
                {
                    var contextGuids = new object[] { };
                    var commands = (Commands2)_applicationObject.Commands;
                    const string toolsMenuName = "Tools";

                    //Place the command on the tools menu.
                    //Find the MenuBar command bar, which is the top-level command bar holding all the main menu items:
                    var menuBarCommandBar = ((CommandBars)_applicationObject.CommandBars)["MenuBar"];

                    //Find the Tools command bar on the MenuBar command bar:
                    var toolsControl = menuBarCommandBar.Controls[toolsMenuName];
                    var toolsPopup = (CommandBarPopup)toolsControl;

                    //This try/catch block can be duplicated if you wish to add multiple commands to be handled by your Add-in,
                    //  just make sure you also update the QueryStatus/Exec method to include the new command names.
                    try
                    {
                        //Add a command to the Commands collection:
                        var command = commands.AddNamedCommand2(_addInInstance, "WakaTime", "WakaTime", "WakaTime Settings", true, 59, ref contextGuids, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

                        //Add a control for the command to the tools menu:
                        if ((command != null) && (toolsPopup != null))
                        {
                            command.AddControl(toolsPopup.CommandBar, 1);
                        }
                    }
                    catch (ArgumentException)
                    {
                        //If we are here, then the exception is probably because a command with that name
                        //  already exists. If so there is no need to recreate the command and we can
                        //  safely ignore the exception.
                    }
                }

                // Make sure python is installed
                if (!PythonManager.IsPythonInstalled())
                {
                    var dialogResult = MessageBox.Show(@"Let's download and install Python now?", @"WakaTime requires Python", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dialogResult == DialogResult.Yes)
                    {
                        var url = PythonManager.PythonDownloadUrl;
                        Downloader.DownloadPython(url, WakaTimeConstants.UserConfigDir);
                    }
                    else
                        MessageBox.Show(
                            @"Please install Python (https://www.python.org/downloads/) and restart SQL Server Management Studio to enable the WakaTime plugin.",
                            @"WakaTime", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                if (!DoesCliExist() || !IsCliLatestVersion())
                {
                    try
                    {
                        Directory.Delete(string.Format("{0}\\wakatime-master", WakaTimeConstants.UserConfigDir), true);
                    }
                    catch { /* ignored */ }

                    Downloader.DownloadCli(WakaTimeConstants.CliUrl, WakaTimeConstants.UserConfigDir);
                }

                GetSettings();

                if (string.IsNullOrEmpty(ApiKey))
                    PromptApiKey();

                Logger.Info(string.Format("Finished initializing WakaTime v{0}", _version));
            }
            catch (Exception ex)
            {
                Logger.Error("Error initializing Wakatime", ex);
            }
        }
        public void InitializeAsync()
        {
            try
            {
                Logger.Info(string.Format("Initializing WakaTime v{0}", Constants.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 (!Dependencies.IsPythonInstalled())
                    {
                        Dependencies.DownloadAndInstallPython();
                    }

                    if (!Dependencies.DoesCliExist() || !Dependencies.IsCliUpToDate())
                    {
                        Dependencies.DownloadAndInstallCli();
                    }
                }
                catch (WebException ex)
                {
                    Logger.Error("Are you behind a proxy? Try setting a proxy in WakaTime 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;

                // setup timer to process queued heartbeats every 8 seconds
                timer.Interval = 1000 * 8;
                timer.Elapsed += ProcessHeartbeats;
                timer.Start();

                Logger.Info(string.Format("Finished initializing WakaTime v{0}", Constants.PluginVersion));
            }
            catch (Exception ex)
            {
                Logger.Error("Error Initializing WakaTime", ex);
            }
        }
        protected override void Initialize()
        {
            var log = GetService(typeof(SVsActivityLog)) as IVsActivityLog;
            Logger.Instance.Initialize(log);
            try
            {
                base.Initialize();

                _objDte = (DTE2)GetService(typeof(DTE));
                _docEvents = _objDte.Events.DocumentEvents;
                _windowEvents = _objDte.Events.WindowEvents;
                _solutionEvents = _objDte.Events.SolutionEvents;
                _version = string.Format("{0}.{1}.{2}", CoreAssembly.Version.Major, CoreAssembly.Version.Minor, CoreAssembly.Version.Build);
                _editorVersion = _objDte.Version;
                Logger.Instance.Info("Initializing WakaTime v" + _version);
                _wakaTimeConfigFile = new WakaTimeConfigFile();

                // Make sure python is installed
                if (!PythonManager.IsPythonInstalled())
                {
                    var url = PythonManager.GetPythonDownloadUrl();
                    Downloader.DownloadPython(url, ConfigDir);
                }

                if (!DoesCliExist() || !IsCliLatestVersion())
                {
                    try
                    {
                        Directory.Delete(ConfigDir + "\\wakatime-master", true);
                    }
                    catch { /* ignored */ }

                    Downloader.DownloadCli(WakaTimeConstants.CliUrl, ConfigDir);
                }

                ApiKey = _wakaTimeConfigFile.ApiKey;
                DEBUG = _wakaTimeConfigFile.Debug;

                if (string.IsNullOrEmpty(ApiKey))
                    PromptApiKey();

                // 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.Instance.Info("Finished initializing WakaTime v" + _version);
            }
            catch (Exception ex)
            {
                Logger.Instance.Error(ex.Message);
            }
        }
        public void InitializeAsync()
        {
            _version = string.Format("{0}.{1}.{2}", CoreAssembly.Version.Major, CoreAssembly.Version.Minor, CoreAssembly.Version.Build);

            try
            {
                Logger.Info(string.Format("Initializing WakaTime v{0}", _version));

                base.Initialize();

                _objDte = (DTE2)GetService(typeof(DTE));
                _docEvents = _objDte.Events.DocumentEvents;
                _windowEvents = _objDte.Events.WindowEvents;
                _solutionEvents = _objDte.Events.SolutionEvents;
                _editorVersion = _objDte.Version;
                _settingsForm = new SettingsForm();
                _settingsForm.ConfigSaved += SettingsFormOnConfigSaved;
                _wakaTimeConfigFile = new WakaTimeConfigFile();

                // Make sure python is installed
                if (!PythonManager.IsPythonInstalled())
                {
                    var dialogResult = MessageBox.Show(@"Let's download and install Python now?",
                        @"WakaTime requires Python", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dialogResult == DialogResult.Yes)
                    {
                        var url = PythonManager.PythonDownloadUrl;
                        Downloader.DownloadPython(url, WakaTimeConstants.UserConfigDir);
                    }
                    else
                        MessageBox.Show(
                            @"Please install Python (https://www.python.org/downloads/) and restart Visual Studio to enable the WakaTime plugin.",
                            @"WakaTime", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                if (!DoesCliExist() || !IsCliLatestVersion())
                {
                    try
                    {
                        Directory.Delete(string.Format("{0}\\wakatime-master", WakaTimeConstants.UserConfigDir), true);
                    }
                    catch { /* ignored */ }

                    Downloader.DownloadCli(WakaTimeConstants.CliUrl, WakaTimeConstants.UserConfigDir);
                }

                GetSettings();

                if (string.IsNullOrEmpty(ApiKey))
                    PromptApiKey();

                // 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}", _version));
            }
            catch (Exception ex)
            {
                Logger.Error("Error initializing Wakatime", ex);
            }
        }
示例#46
0
        /// <summary>
        /// Sets the Visual Studio IDE object.
        /// </summary>
        private DTE InitializeDTE()
        {
            // Store the dte so that it can be used later.
            var dte = Package.GetService<DTE>();

            _events = dte.Events;

            // Registers handlers for the Activated and Closing events from the text window.
            _windowsEvents = _events.get_WindowEvents(null);
            _windowsEvents.WindowActivated += windowsEvents_WindowActivated;
            _windowsEvents.WindowClosing += windowsEvents_WindowClosing;

            // Registers handlers for certain solution events.
            _solnEvents = _events.SolutionEvents;
            _solnEvents.Opened += solnEvents_Opened;
            _solnEvents.QueryCloseSolution += solnEvents_QueryCloseSolution;

            // Get the code model data.
            _codeCache = new CodeOutlineCache(_control, dte);
            return dte;
        }
        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();
                    }
                }
            });
        }
示例#48
0
 /// <summary>
 /// Registers handlers for the Activated and Closing events from the text window.
 /// </summary>
 public void AddWindowEvents()
 {
     events = dte.Events;
     windowsEvents = events.get_WindowEvents(null);
     windowsEvents.WindowActivated += windowsEvents_WindowActivated;
     windowsEvents.WindowClosing += windowsEvents_WindowClosing;
 }
示例#49
0
文件: Connect.cs 项目: erdincay/db4o
		/// <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)
		{
			_applicationObject = (DTE2)application;
			_addInInstance = (AddIn)addInInst;
			ViewBase.ResetToolWindowList();
			OutputWindow.Initialize(_applicationObject);

			try
			{
				if (connectMode == ext_ConnectMode.ext_cm_AfterStartup || connectMode == ext_ConnectMode.ext_cm_Startup)
				{
					CreateMenu();
					


					try
					{
						CommandBars toolBarCommandBars = ((CommandBars)_applicationObject.CommandBars);
						string toolbarName = Helper.GetResourceString(OMControlLibrary.Common.Constants.PRODUCT_CAPTION);
						try
						{
							omToolbar = toolBarCommandBars.Add(toolbarName, MsoBarPosition.msoBarTop, Type.Missing, false);
						}
						catch (ArgumentException)
						{
							omToolbar = toolBarCommandBars[toolbarName];
						}
						CreateToolBar();
						omToolbar.Visible = true;
					
					}
					catch (Exception oEx)
					{
						LoggingHelper.HandleException(oEx);
					}

					try
					{
						Events events = _applicationObject.Events;
						_windowsEvents = events.get_WindowEvents(null);
						
						_windowsEvents.WindowActivated += OnWindowActivated;

						_eve = _applicationObject.Events.DTEEvents;
						_eve.ModeChanged += DesignDebugModeChanged;
						
						
					}
					catch (Exception oEx)
					{
						LoggingHelper.HandleException(oEx);
					}
					
					try
					{
						//This function checks whether user already logged in.

						ViewBase.ApplicationObject = _applicationObject;
						//enable disable connect button while checking cfredentials
						connectDatabaseMenu.Enabled = false;
						connectDatabaseButton.Enabled = false;
						Cursor.Current = Cursors.WaitCursor;
						Cursor.Current = Cursors.Default;
						connectDatabaseMenu.Enabled = true;
						connectDatabaseButton.Enabled = true;
					}
					catch (Exception oEx)
					{
						LoggingHelper.HandleException(oEx);
					}
				}
			}
			catch (Exception oEx)
			{
				LoggingHelper.HandleException(oEx);
			}

		}
        public void InitializeAsync()
        {
            _version = string.Format("{0}.{1}.{2}", CoreAssembly.Version.Major, CoreAssembly.Version.Minor, CoreAssembly.Version.Build);

            try
            {
                Logger.Info(string.Format("Initializing WakaTime v{0}", _version));

                // VisualStudio Object
                _objDte = (DTE2)GetService(typeof(DTE));
                _docEvents = _objDte.Events.DocumentEvents;
                _windowEvents = _objDte.Events.WindowEvents;
                _solutionEvents = _objDte.Events.SolutionEvents;
                _editorVersion = _objDte.Version;

                // Settings Form
                _settingsForm = new SettingsForm();
                _settingsForm.ConfigSaved += SettingsFormOnConfigSaved;

                // Load config file
                _wakaTimeConfigFile = new WakaTimeConfigFile();
                GetSettings();

                if (!DoesCliExist() || !IsCliLatestVersion())
                {
                    try
                    {
                        Directory.Delete(string.Format("{0}\\wakatime-master", WakaTimeConstants.UserConfigDir), true);
                    }
                    catch { /* ignored */ }

                    Downloader.DownloadCli(WakaTimeConstants.CliUrl, WakaTimeConstants.UserConfigDir);
                }

                if (string.IsNullOrEmpty(ApiKey))
                    PromptApiKey();

                // 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}", _version));
            }
            catch (Exception ex)
            {
                Logger.Error("Error initializing Wakatime", ex);
            }
        }
示例#51
0
        public BuildContext(IPackageContext packageContext, FindProjectItemDelegate findProjectItem)
        {
            _buildedProjects = new BuildedProjectsCollection();
            _buildingProjects = new List<ProjectItem>();
            _buildingProjectsLockObject = ((ICollection)_buildingProjects).SyncRoot;

            _packageContext = packageContext;
            _findProjectItem = findProjectItem;

            Events dteEvents = packageContext.GetDTE().Events;
            _buildEvents = dteEvents.BuildEvents;
            _windowEvents = dteEvents.WindowEvents;
            _commandEvents = dteEvents.CommandEvents;

            _buildEvents.OnBuildBegin += BuildEvents_OnBuildBegin;
            _buildEvents.OnBuildDone += (s, e) => BuildEvents_OnBuildDone();
            _buildEvents.OnBuildProjConfigBegin += BuildEvents_OnBuildProjectBegin;
            _buildEvents.OnBuildProjConfigDone += BuildEvents_OnBuildProjectDone;

            _windowEvents.WindowActivated += WindowEvents_WindowActivated;

            _commandEvents.AfterExecute += CommandEvents_AfterExecute;
        }
示例#52
0
		public QueryResult()
		{
			strstoreTreeValue = string.Empty;
			strstoreValue = string.Empty;
			try
			{
				SetStyle(ControlStyles.CacheText | ControlStyles.OptimizedDoubleBuffer, true);

				InitializeComponent();
				Events events = ApplicationObject.Events;
				_windowsEvents = events.get_WindowEvents(null);
				_windowsEvents.WindowActivated += _windowsEvents_WindowActivated;
				


				Events2 eventsSource = (Events2)ApplicationObject.Events;
				_events = eventsSource.get_WindowVisibilityEvents(Helper.QueryResultToolWindow);
				_events.WindowHiding += WindowHiding;
				InitializeResultDataGridView();
				InitializeTabControl();
			}
			catch (Exception oEx)
			{
				LoggingHelper.ShowMessage(oEx);
			}
		}
        public void InitializeAsync()
        {

            try
            {
                Logger.Info(string.Format("Initializing WakaTime v{0}", WakaTimeConstants.PluginVersion));

                // VisualStudio Object
                objDte = (DTE2)GetService(typeof(DTE));
                _docEvents = objDte.Events.DocumentEvents;
                _windowEvents = objDte.Events.WindowEvents;
                _solutionEvents = objDte.Events.SolutionEvents;

                // Settings Form
                _settingsForm = new SettingsForm();
                _settingsForm.ConfigSaved += SettingsFormOnConfigSaved;

                // Load config file
                _wakaTimeConfigFile = new WakaTimeConfigFile();
                GetSettings();

                try
                {

                    // Make sure python is installed
                    if (!PythonManager.IsPythonInstalled())
                    {
                        Downloader.DownloadAndInstallPython();
                    }

                    if (!DoesCliExist() || !IsCliLatestVersion())
                    {
                        Downloader.DownloadAndInstallCli();
                    }
                }
                catch (System.Net.WebException ex)
                {
                    Logger.Error("Are you behind a proxy? Try setting a proxy in WakaTime Settings with format https://user:pass@host:port. Exception Traceback:", ex);
                }
                catch (Exception ex)
                {
                    Logger.Error("Error detecting dependencies. Exception Traceback:", ex);
                }

                if (string.IsNullOrEmpty(ApiKey))
                    PromptApiKey();

                // 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);
            }
        }