Esempio n. 1
0
 private void ChangedEventHandler(CodeElement Element, vsCMChangeKind Change)
 {
     if (Change == vsCMChangeKind.vsCMChangeKindRename || Change == vsCMChangeKind.vsCMChangeKindUnknown)
     {
         SolutionNavigator.AddElement(Element);
     }
 }
        // ------------------------------------------------------
        /// <summary>
        /// Called when an element is changed in the code model.
        /// </summary>
        /// <param name="element">
        /// The element that was changed.
        /// </param>
        /// <param name="changeKind">
        /// The kind of change that occurred.
        /// </param>
        private void CodeModel_ElementChanged(CodeElement element,
                                              vsCMChangeKind changeKind)
        {
            // Disabled until can be made more stable.

            // TryToChangeElementToTestSuitesView(element, changeKind);
        }
Esempio n. 3
0
 private void CodeModelEvents_ElementChanged(CodeElement element, vsCMChangeKind change)
 {
     if ((element != null) && (
             (change == vsCMChangeKind.vsCMChangeKindUnknown) ||
             (change == vsCMChangeKind.vsCMChangeKindRename) ||
             (change == vsCMChangeKind.vsCMChangeKindSignatureChange)))
     {
         _codeModelEventSubscribers.For(s => s.ElementChanged(element));
     }
 }
        // ------------------------------------------------------
        /// <summary>
        /// Tries to change the specified element in the CxxTest Suites
        /// window. Does nothing if the window is not yet created.
        /// </summary>
        /// <param name="element">
        /// The element that was changed.
        /// </param>
        /// <param name="changeKind">
        /// The kind of change that occurred.
        /// </param>
        public void TryToChangeElementToTestSuitesWindow(CodeElement element,
                                                         vsCMChangeKind changeKind)
        {
            CxxTestSuitesToolWindow window =
                FindToolWindow(typeof(CxxTestSuitesToolWindow), 0, false)
                as CxxTestSuitesToolWindow;

            if (window != null)
            {
                window.ChangeElement(element, changeKind);
            }
        }
Esempio n. 5
0
 public void ChangeElement(CodeElement element, vsCMChangeKind changeKind)
 {
     try
     {
         control.ChangeElement(element, changeKind);
     }
     catch (Exception)
     {
         // To protect against unforeseen problems, we'll just do a
         // global refresh if anything bad happens during the update.
         control.RefreshFromSolution();
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Raised when a CodeElement object has been changed.
        /// </summary>
        /// <param name="modifiedElement">The CodeElement that was changed.</param>
        /// <param name="iChangeType">The type of change event that was fired.</param>
        private void codeModelEvents_Changed(CodeElement modifiedElement, vsCMChangeKind iChangeType)
        {
            try
            {
                if (CurrentFileManager == null)
                {
                    return;
                }

                ForceReload();
            }
            catch (Exception ex)
            {
                SourceOutlineToolWindow.DisplayMessage(Resources.ErrorPrefix, "codeModelEvents_Changed exception: " + ex);
            }
        }
        public void ChangeElement(CodeElement element, vsCMChangeKind changeKind)
        {
            if (testsTreeView.Nodes.Count == 0)
            {
                return;
            }

            if (element is VCCodeClass || element is VCCodeStruct)
            {
                testsTreeView.BeginUpdate();

                VCCodeModel model = ((VCCodeElement)element).CodeModel;

                TestSuiteCollector collector = new TestSuiteCollector();
                collector.Process(model);
                List <TestSuite> suitesInModel = new List <TestSuite>(collector.Suites);

                // Iterate through the current suites in the view and pull out any
                // that are no longer in the model.

                TreeNode solutionNode = testsTreeView.Nodes[0];

                for (int i = 0; i < solutionNode.Nodes.Count;)
                {
                    TreeNode viewNode = solutionNode.Nodes[i];
                    int      index    = suitesInModel.FindIndex(
                        new Predicate <TestSuite>(delegate(TestSuite suite)
                    {
                        return(suite.Name == viewNode.Text);
                    }));

                    if (index == -1)
                    {
                        viewNode.Remove();
                    }
                    else
                    {
                        // The suites that are left over will be those in the
                        // model that aren't yet in the tree, so they need to
                        // be added.

                        suitesInModel.RemoveAt(index);
                        i++;
                    }
                }

                // Make sure a suite with the same name isn't already in the
                // view (this could happen if the name changes and then quickly
                // changes back before the event fires. If it's not there, add
                // it.

                foreach (TestSuite suite in suitesInModel)
                {
                    AddTestSuiteToNode(suite, solutionNode, null).Expand();
                }

                testsTreeView.Sort();
                testsTreeView.EndUpdate();
            }
            else if (element is VCCodeFunction)
            {
                testsTreeView.BeginUpdate();

                VCCodeElement parent = (VCCodeElement)((VCCodeElement)element).Parent;

                TestCaseCollector collector = new TestCaseCollector();
                collector.Process(parent.Children);
                List <TestCase> casesInModel = new List <TestCase>(collector.TestCases);

                // Iterate through the current test cases for this suite in the
                // view and pull out any that are no longer in the model.

                TreeNode suiteNode = FindNodeForTestSuite(parent);

                if (suiteNode == null)
                {
                    return;
                }

                for (int i = 0; i < suiteNode.Nodes.Count;)
                {
                    TreeNode viewNode = suiteNode.Nodes[i];
                    int      index    = casesInModel.FindIndex(
                        new Predicate <TestCase>(delegate(TestCase testCase)
                    {
                        return(testCase.Name == viewNode.Text);
                    }));

                    if (index == -1)
                    {
                        viewNode.Remove();
                    }
                    else
                    {
                        // The test cases that are left over will be those in
                        // the model that aren't yet in the tree, so they need
                        // to be added.

                        casesInModel.RemoveAt(index);
                        i++;
                    }
                }

                foreach (TestCase testCase in casesInModel)
                {
                    AddTestCaseToNode((TestSuite)suiteNode.Tag, testCase, suiteNode, null);
                }

                testsTreeView.Sort();
                testsTreeView.EndUpdate();
            }
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="FileCodeModelChangedEventArgs"/> class.
		/// </summary>
		/// <param name="element">The changed <see cref="CodeElement"/>.</param>
		/// <param name="changeKind">The kind of change.</param>
		public FileCodeModelChangedEventArgs(CodeElement element, vsCMChangeKind changeKind)
		{
			ChangeKind = changeKind;
			Element = element;
		}
        public void ChangeElement(CodeElement element, vsCMChangeKind changeKind)
        {
            if (testsTreeView.Nodes.Count == 0)
                return;

            if (element is VCCodeClass || element is VCCodeStruct)
            {
                testsTreeView.BeginUpdate();

                VCCodeModel model = ((VCCodeElement)element).CodeModel;

                TestSuiteCollector collector = new TestSuiteCollector();
                collector.Process(model);
                List<TestSuite> suitesInModel = new List<TestSuite>(collector.Suites);

                // Iterate through the current suites in the view and pull out any
                // that are no longer in the model.

                TreeNode solutionNode = testsTreeView.Nodes[0];

                for (int i = 0; i < solutionNode.Nodes.Count; )
                {
                    TreeNode viewNode = solutionNode.Nodes[i];
                    int index = suitesInModel.FindIndex(
                        new Predicate<TestSuite>(delegate(TestSuite suite)
                        {
                            return suite.Name == viewNode.Text;
                        }));

                    if (index == -1)
                        viewNode.Remove();
                    else
                    {
                        // The suites that are left over will be those in the
                        // model that aren't yet in the tree, so they need to
                        // be added.

                        suitesInModel.RemoveAt(index);
                        i++;
                    }
                }

                // Make sure a suite with the same name isn't already in the
                // view (this could happen if the name changes and then quickly
                // changes back before the event fires. If it's not there, add
                // it.

                foreach(TestSuite suite in suitesInModel)
                    AddTestSuiteToNode(suite, solutionNode, null).Expand();

                testsTreeView.Sort();
                testsTreeView.EndUpdate();
            }
            else if (element is VCCodeFunction)
            {
                testsTreeView.BeginUpdate();

                VCCodeElement parent = (VCCodeElement)((VCCodeElement)element).Parent;

                TestCaseCollector collector = new TestCaseCollector();
                collector.Process(parent.Children);
                List<TestCase> casesInModel = new List<TestCase>(collector.TestCases);

                // Iterate through the current test cases for this suite in the
                // view and pull out any that are no longer in the model.

                TreeNode suiteNode = FindNodeForTestSuite(parent);

                if (suiteNode == null)
                    return;

                for (int i = 0; i < suiteNode.Nodes.Count; )
                {
                    TreeNode viewNode = suiteNode.Nodes[i];
                    int index = casesInModel.FindIndex(
                        new Predicate<TestCase>(delegate(TestCase testCase)
                        {
                            return testCase.Name == viewNode.Text;
                        }));

                    if (index == -1)
                        viewNode.Remove();
                    else
                    {
                        // The test cases that are left over will be those in
                        // the model that aren't yet in the tree, so they need
                        // to be added.

                        casesInModel.RemoveAt(index);
                        i++;
                    }
                }

                foreach (TestCase testCase in casesInModel)
                    AddTestCaseToNode((TestSuite)suiteNode.Tag, testCase, suiteNode, null);

                testsTreeView.Sort();
                testsTreeView.EndUpdate();
            }
        }
        // ------------------------------------------------------
        /// <summary>
        /// Called when an element is changed in the code model.
        /// </summary>
        /// <param name="element">
        /// The element that was changed.
        /// </param>
        /// <param name="changeKind">
        /// The kind of change that occurred.
        /// </param>
        private void CodeModel_ElementChanged(CodeElement element,
			vsCMChangeKind changeKind)
        {
            // Disabled until can be made more stable.

            // TryToChangeElementToTestSuitesView(element, changeKind);
        }
        // ------------------------------------------------------
        /// <summary>
        /// Tries to change the specified element in the CxxTest Suites
        /// window. Does nothing if the window is not yet created.
        /// </summary>
        /// <param name="element">
        /// The element that was changed.
        /// </param>
        /// <param name="changeKind">
        /// The kind of change that occurred.
        /// </param>
        public void TryToChangeElementToTestSuitesWindow(CodeElement element,
			vsCMChangeKind changeKind)
        {
            CxxTestSuitesToolWindow window =
                FindToolWindow(typeof(CxxTestSuitesToolWindow), 0, false)
                as CxxTestSuitesToolWindow;

            if (window != null)
                window.ChangeElement(element, changeKind);
        }
Esempio n. 12
0
        /// <summary>
        /// Raised when a CodeElement object has been changed.
        /// </summary>
        /// <param name="modifiedElement">The CodeElement that was changed.</param>
        /// <param name="iChangeType">The type of change event that was fired.</param>
        private void codeModelEvents_Changed(CodeElement modifiedElement, vsCMChangeKind iChangeType)
        {
            try
            {
                if (CurrentFileManager == null)
                    return;

                ForceReload();
            }
            catch (Exception ex)
            {
                SourceOutlineToolWindow.DisplayMessage(Resources.ErrorPrefix, "codeModelEvents_Changed exception: " + ex);
            }
        }
        /*
          /// <summary>
          /// Last change kind (protected agains multi-calls)
          /// </summary>
          vsCMChangeKind lastChange = (vsCMChangeKind)(-1);
        */
        /// <summary>
        /// Processes code element changes
        /// </summary>
        /// <param name="element"></param>
        /// <param name="Change"></param>
        void events_ElementChanged(CodeElement element, vsCMChangeKind Change)
        {
            /*
               if ((lastAction == LastAction.Change) && (lastChange == Change) && (lastElement == element))
                return;
               else
               {
                lastChange = Change;
                lastElement = element;
                lastAction = LastAction.Change;
               }
             */
            switch (Change)
            {
                case vsCMChangeKind.vsCMChangeKindArgumentChange:
                    if (element is CodeAttribute2)
                    {
                        CodeAttribute2 attribute = element as CodeAttribute2;
                        if (OnAttributeChanged != null)
                            OnAttributeChanged(attribute);
                    }
                    break;
                case vsCMChangeKind.vsCMChangeKindBaseChange:
                    if (element is CodeType)
                    {
                        CodeType codeType = element as CodeType;

                        // Only fire event when a valid base changed
                        if ((codeType.Bases.Count > 0) && (codeType.Bases.Item(1) is CodeType))
                            if (OnBaseTypeChanged != null)
                                OnBaseTypeChanged(element as CodeType);
                    }
                    break;

                case vsCMChangeKind.vsCMChangeKindRename:
                    // Change type name
                    if (element is CodeType)
                    {
                        CodeType codeType = element as CodeType;

                        foreach (string fullTypeName in typesByFullName.Keys)
                        {
                            CodeType type = typesByFullName[fullTypeName];
                            try
                            {
                                string name = type.Name; // will have an exception for renamed type
                            }
                            catch (Exception)
                            {
                                string name = GetTypeName(fullTypeName);
                                typesByName.Remove(name, codeType);
                                typesByFullName.Remove(fullTypeName);
                                typesByFullName.Add(codeType.FullName, codeType);
                                typesByName.Add(codeType.Name, codeType);
                                if (OnTypeRenamed != null)
                                    OnTypeRenamed(fullTypeName, codeType);
                                break; // Must be the last instruction ! (no loop otherwise modified collection !)
                            }
                        }
                    }
                    else if (element is CodeParameter)
                    {
                        CodeParameter parameter = element as CodeParameter;
                        CodeFunction2 function = parameter.Parent as CodeFunction2;
                        int index = 0;
                        foreach (CodeParameter p in function.Parameters)
                            if (p == parameter)
                            {
                                if (OnParameterRenamed != null)
                                    OnParameterRenamed(function, index, parameter);
                                break;
                            }
                    }
                    else if (element is CodeNamespace)
                    {
                        CodeNamespace ns = element as CodeNamespace;
                        List<string> toReplace = new List<string>();

                        // Find obsolete types
                        foreach (string fullTypeName in typesByFullName.Keys)
                        {
                            CodeType type = typesByFullName[fullTypeName];
                            try
                            {
                                string oldNs = type.Namespace.FullName;
                            }
                            catch (Exception)
                            {
                                toReplace.Add(fullTypeName);
                            }
                        }

                        // And replace them
                        foreach (string fullTypeName in toReplace)
                        {
                            // Removes obsolete types
                            string name = GetTypeName(fullTypeName);
                            CodeType type = typesByFullName[fullTypeName];
                            typesByName.Remove(name, type);
                            typesByFullName.Remove(fullTypeName);

                            // Find new one
                            type = ns.Members.Item(name) as CodeType;

                            // And add-it
                            typesByFullName.Add(type.FullName, type);
                            typesByName.Add(type.Name, type);

                            // Notify renaming
                            if (OnTypeRenamed != null)
                                OnTypeRenamed(fullTypeName, type);
                        }
                    }
                    else if (element is CodeVariable)
                    {
                        CodeVariable field = element as CodeVariable;
                        CodeType type = field.Parent as CodeType;
                        if (OnFieldRenamed != null)
                            OnFieldRenamed(type, field);
                    }
                    else if (element is CodeFunction2)
                    {
                        CodeFunction2 m = element as CodeFunction2;
                        CodeType type = m.Parent as CodeType;
                        if (OnMethodRenamed != null)
                            OnMethodRenamed(type, m);
                    }
                    break;

                case vsCMChangeKind.vsCMChangeKindSignatureChange:
                case vsCMChangeKind.vsCMChangeKindTypeRefChange:
                case vsCMChangeKind.vsCMChangeKindUnknown:
                    if (OnElementPropertiesChanged != null)
                        OnElementPropertiesChanged(element);
                    break;
                default:
                    if (OnElementPropertiesChanged != null)
                        OnElementPropertiesChanged(element);
                    break;
            }
        }
Esempio n. 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FileCodeModelChangedEventArgs"/> class.
 /// </summary>
 /// <param name="element">The changed <see cref="CodeElement"/>.</param>
 /// <param name="changeKind">The kind of change.</param>
 public FileCodeModelChangedEventArgs(CodeElement element, vsCMChangeKind changeKind)
 {
     ChangeKind = changeKind;
     Element    = element;
 }
Esempio n. 15
0
        /// <summary>
        /// Raised when a CodeElement object has been changed.
        /// </summary>
        /// <param name="modifiedElement">The CodeElement that was changed.</param>
        /// <param name="iChangeType">The type of change event that was fired.</param>
        private void codeModelEvents_Changed(CodeElement modifiedElement, vsCMChangeKind iChangeType)
        {
            try
            {
                if (CurrentFileManager == null)
                {
                    return;
                }

                ForceReload();
            }
            catch (Exception ex)
            {
                Utils.DisplayMessage(Resources.ErrorPrefix, "codeModelEvents_Changed exception: " + ex.ToString());
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Occurs when a code element is changed in the text window,
        /// and finds the element's parent in the outline and reloads it.
        /// </summary>
        /// <param name="modifiedElement">The changed code element.</param>
        /// <param name="iChangeType">The type of change.</param>
        public void OnCodeModelElementChanged(CodeElement modifiedElement, vsCMChangeKind iChangeType)
        {
            if (modifiedElement == null || !CodeModelHelpers.IsInterestingKind(modifiedElement.Kind))
            {
                return;
            }

            Debug.Assert(_dte.ActiveDocument == _currentDocument);

            FindBestMatchCodeElementToRefreshFrom(modifiedElement);
        }
Esempio n. 17
0
 public void OnElementChanged(CodeElement element, vsCMChangeKind change)
 {
     ;
 }