コード例 #1
0
ファイル: CodeOutlineCache.cs プロジェクト: ugurak/nemerle
        /// <summary>
        /// Registers for code model events.
        /// </summary>
        private void AdviseCodeModelEvents()
        {
            try
            {
                EnvDTE80.DTE2 dte2 = _dte as EnvDTE80.DTE2;
                if (dte2 == null)
                {
                    throw new NullReferenceException("dte2 is NULL");
                }

                EnvDTE80.Events2 events2 = dte2.Events as EnvDTE80.Events2;
                if (events2 == null)
                {
                    throw new NullReferenceException("events2 is NULL");
                }

                _codeModelEvents = events2.get_CodeModelEvents(null);
                if (_codeModelEvents != null)
                {
                    _codeModelEvents.ElementAdded   += new _dispCodeModelEvents_ElementAddedEventHandler(codeModelEvents_Added);
                    _codeModelEvents.ElementChanged += new _dispCodeModelEvents_ElementChangedEventHandler(codeModelEvents_Changed);
                    _codeModelEvents.ElementDeleted += new _dispCodeModelEvents_ElementDeletedEventHandler(codeModelEvents_Deleted);
                }
            }
            catch (System.ArgumentException)
            {                // Failed to get CodeModelEvents, this should not occur.
                Utils.DisplayMessage(Resources.ErrorPrefix, "Failed to get Code Model events.");
                throw;
            }
        }
コード例 #2
0
        void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (string.IsNullOrEmpty(Dte2?.Solution?.FullName))
            {
                IsDteFounded = false;
                InitializeDTE();
                return;
            }
            else
            {
                IsDteFounded = true;
            }


            if (IsDteFounded == false)
            {
                return;
            }

            try
            {
                Extensions.LogToOutputWindow(Dte2, $"Package has been sited by DTE @ {e.SignalTime}");
            }
            catch (System.Exception exp)
            {
                Extensions.LogToOutputWindow(Dte2, $"Error: {exp.Message}");
            }

            try
            {
                // Project events handlers
                if (DteProjectsEvents == null)
                {
                    DteEvents                    = Dte2.Events as EnvDTE80.Events2;
                    DteProjectsEvents            = DteEvents.ProjectItemsEvents;
                    DteProjectsEvents.ItemAdded += PrjItemEvents_ItemAdded;
                    Extensions.LogToOutputWindow(Dte2, $"");
                }
            }
            catch (System.Exception exp)
            {
                Extensions.LogToOutputWindow(Dte2, $"Exception on project event handler: {exp.Message}");
            }

            if (Timer.Interval == TimerToFindDte && Dte2 != null)
            {
                Timer.Interval = TimerToReviewRootDirectory;
                Timer.Enabled  = false;
                Timer.Enabled  = true;
            }
        }
コード例 #3
0
        public CodeBeautifierEventHandler(IServiceProvider serviceProvider)
        {
            m_serviceProvider    = serviceProvider;
            m_hApplicationObject = serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2;

            m_settings.onOptionsChanged += new EventHandler(onConfigurationChanged);
            onConfigurationChanged(this, null);

            Command hCmdBuildSolution      = m_hApplicationObject.Commands.Item("Build.BuildSolution", 0);
            Command hCmdRebuildSolution    = m_hApplicationObject.Commands.Item("Build.RebuildSolution", 0);
            Command hCmdBuildOnlyProject   = m_hApplicationObject.Commands.Item("Build.BuildOnlyProject", 0);
            Command hCmdRebuildOnlyProject = m_hApplicationObject.Commands.Item("Build.RebuildOnlyProject", 0);

            Command hCmdBuildSelection   = m_hApplicationObject.Commands.Item("Build.BuildSelection", 886);
            Command hCmdRebuildSelection = m_hApplicationObject.Commands.Item("Build.RebuildSelection", 887);

            // BuildSolution
            m_hEventOnBuildSolution = m_hApplicationObject.Events.CommandEvents[hCmdBuildSolution.Guid, hCmdBuildSolution.ID] as CommandEvents;
            m_hEventOnBuildSolution.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnBuildSolution);

            m_hEventOnRebuildSolution = m_hApplicationObject.Events.CommandEvents[hCmdRebuildSolution.Guid, hCmdRebuildSolution.ID] as CommandEvents;
            m_hEventOnRebuildSolution.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnReBuildSolution);

            m_hEventOnBuildOnlyProject = m_hApplicationObject.Events.CommandEvents[hCmdBuildOnlyProject.Guid, hCmdBuildOnlyProject.ID] as CommandEvents;
            m_hEventOnBuildOnlyProject.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnBuildProject);

            m_hEventOnRebuildOnlyProject = m_hApplicationObject.Events.CommandEvents[hCmdRebuildOnlyProject.Guid, hCmdRebuildOnlyProject.ID] as CommandEvents;
            m_hEventOnRebuildOnlyProject.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnReBuildProject);


            m_hEventOnBuildSelected = m_hApplicationObject.Events.CommandEvents[hCmdBuildSelection.Guid, hCmdBuildSelection.ID] as CommandEvents;
            m_hEventOnBuildSelected.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnBuildProject);

            m_hEventOnRebuildSelected = m_hApplicationObject.Events.CommandEvents[hCmdRebuildSelection.Guid, hCmdRebuildSelection.ID] as CommandEvents;
            m_hEventOnRebuildSelected.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler(OnReBuildProject);

            EnvDTE80.Events2 dteEvents2 = m_hApplicationObject.Events as EnvDTE80.Events2;
            m_textDocumentEvents = dteEvents2.get_TextDocumentKeyPressEvents();
            m_textDocumentEvents.AfterKeyPress += onTextDocumentKeyPressed;

            m_documentEvents = dteEvents2.get_DocumentEvents();
            m_documentEvents.DocumentSaved += onDocumentSaved;
        }
コード例 #4
0
        /// <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()
        {
            _instance = this;
            _dte      = GetService(typeof(DTE)) as DTE2;
            Package   = this;
            EnvDTE80.Events2 events = _dte.Events as Events2;
            Helper.Logger.Initialize(this, "NFinalCompiler");
            _documentEvents = events.DocumentEvents;
            _solutionEvents = events.SolutionEvents;
            events.BuildEvents.OnBuildBegin          += BuildEvents_OnBuildBegin;
            events.BuildEvents.OnBuildDone           += BuildEvents_OnBuildDone;
            events.BuildEvents.OnBuildProjConfigDone += BuildEvents_OnBuildProjConfigDone;
            _documentEvents.DocumentSaved            += DocumentEvents_DocumentSaved;
            _solutionEvents.AfterClosing             += _solutionEvents_AfterClosing;
            _solutionEvents.ProjectRemoved           += _solutionEvents_ProjectRemoved;

            componentModel =
                (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel));

            base.Initialize();
        }
コード例 #5
0
        private void WindowEvents_WindowActivated(EnvDTE.Window gotFocus, EnvDTE.Window lostFocus)
        {
            //Trace.WriteLine(string.Format("\n>>>> WindowEvents_WindowActivated() - '{0}' <- '{1}' ({2})\n", gotFocus.Caption, lostFocus.Caption, (m_Dte2.ActiveDocument == null) ? "null" : m_Dte2.ActiveDocument.Name));
            Debug.Print("\n>>>> WindowEvents_WindowActivated() - '{0}' <- '{1}' ({2})\n", (gotFocus == null) ? "null" : gotFocus.Caption, (lostFocus == null) ? "null" : lostFocus.Caption, (m_Dte2.ActiveDocument == null) ? "null" : m_Dte2.ActiveDocument.Name);

            if (m_StringResourceBuilder.IsBrowsing)
            {
                return;
            }

            if (!m_IsVisible)
            {
                return;
            }

            if (m_Dte2.ActiveDocument == null)
            {
                if (m_StringResourceBuilder.Window != null)
                {
                    WindowEvents_WindowClosing(m_StringResourceBuilder.Window);
                }

                return;
            } //if

            Trace.WriteLine("WindowEvents_WindowActivated()");

            if (m_TextEditorEvents != null)
            {
                m_TextEditorEvents.LineChanged -= m_TextEditorEvents_LineChanged;
                m_TextEditorEvents              = null;
            } //if

            //if (m_TextDocumentKeyPressEvents != null)
            //{
            //  m_TextDocumentKeyPressEvents.AfterKeyPress -= m_TextDocumentKeyPressEvents_AfterKeyPress;
            //  m_TextDocumentKeyPressEvents.AfterKeyPress += m_TextDocumentKeyPressEvents_AfterKeyPress;
            //  m_TextDocumentKeyPressEvents = null;
            //} //if

            EnvDTE.Window window = m_Dte2.ActiveDocument.ActiveWindow;

            bool isGotDocument  = (gotFocus != null) && (gotFocus.Document != null),
                 isLostDocument = (lostFocus != null) && (lostFocus.Document != null),
                 isGotCode      = isGotDocument && (gotFocus.Caption.EndsWith(".cs") || gotFocus.Caption.EndsWith(".vb")),
                 isLostCode     = isLostDocument && (lostFocus.Caption.EndsWith(".cs") || lostFocus.Caption.EndsWith(".vb"));

            if (!isGotDocument /*&& !isLostDocument*/ && (m_StringResourceBuilder.Window != null))
            {
                window = m_StringResourceBuilder.Window;
            }
            if (isGotCode)
            {
                window = gotFocus;
            }
            else if (!isGotDocument && isLostCode)
            {
                window = lostFocus;
            }

            if ((window != null) && (window.Document != null) && (window.Caption.EndsWith(".cs") || window.Caption.EndsWith(".vb")))
            {
                TextDocument txtDoc = window.Document.Object("TextDocument") as TextDocument;
                if (txtDoc != null)
                {
                    EnvDTE80.Events2 events = (EnvDTE80.Events2)m_Dte2.Events;

                    m_TextEditorEvents              = events.TextEditorEvents[txtDoc];
                    m_TextEditorEvents.LineChanged -= m_TextEditorEvents_LineChanged;
                    m_TextEditorEvents.LineChanged += m_TextEditorEvents_LineChanged;

                    //m_TextDocumentKeyPressEvents = events.TextDocumentKeyPressEvents[txtDoc];
                    //m_TextDocumentKeyPressEvents.AfterKeyPress -= m_TextDocumentKeyPressEvents_AfterKeyPress;
                    //m_TextDocumentKeyPressEvents.AfterKeyPress += m_TextDocumentKeyPressEvents_AfterKeyPress;

                    if (m_FocusedTextDocumentWindowHash != window.GetHashCode())
                    {
                        m_FocusedTextDocumentWindowHash = window.GetHashCode();
                        m_StringResourceBuilder.FocusedTextDocumentWindow = window;
                        this.Dispatcher.BeginInvoke(new Action(m_StringResourceBuilder.DoBrowse));
                    } //if
                }     //if
            }
            //else if (m_StringResourceBuilder.Window != null)
            //  WindowEvents_WindowClosing(m_StringResourceBuilder.Window);
        }