private bool ComponentIsWorksheet(ComponentRenamedEventArgs e)
        {
            var componentIsWorksheet = false;

            foreach (var declaration in AllUserDeclarations)
            {
                if (declaration.ProjectId == e.ProjectId &&
                    declaration.DeclarationType == DeclarationType.ClassModule &&
                    declaration.IdentifierName == e.OldName)
                {
                    foreach (var superType in ((ClassModuleDeclaration)declaration).Supertypes)
                    {
                        if (superType.IdentifierName == "Worksheet")
                        {
                            componentIsWorksheet = true;
                            break;
                        }
                    }

                    break;
                }
            }

            return(componentIsWorksheet);
        }
        private void ComponentRenamed(object sender, ComponentRenamedEventArgs e)
        {
            if (!_listening || Provider == null || !Provider.HandleVbeSinkEvents)
            {
                return;
            }

            if (e.ProjectId != Provider.CurrentRepository.Id)
            {
                return;
            }

            Logger.Trace("Component {0} renamed to {1}", e.OldName, e.Component.Name);
            var fileStatus = Provider.LastKnownStatus().SingleOrDefault(stat => Path.GetFileNameWithoutExtension(stat.FilePath) == e.OldName);

            if (fileStatus != null)
            {
                var directory = Provider.CurrentRepository.LocalLocation;
                var fileExt   = "." + Path.GetExtension(fileStatus.FilePath);

                _fileSystemWatcher.EnableRaisingEvents = false;
                File.Move(Path.Combine(directory, fileStatus.FilePath), Path.Combine(directory, e.Component.Name + fileExt));
                _fileSystemWatcher.EnableRaisingEvents = true;

                Provider.RemoveFile(e.OldName + fileExt, false);
                Provider.AddFile(e.Component.Name + fileExt);
            }
        }
        private void Sinks_ComponentRenamed(object sender, ComponentRenamedEventArgs e)
        {
            if (!e.Project.VBE.IsInDesignMode)
            {
                return;
            }

            if (AllDeclarations.Count == 0)
            {
                return;
            }

            Logger.Debug("Component '{0}' was renamed to '{1}'.", e.OldName, e.Component.Name);

            var componentIsWorksheet = false;

            foreach (var declaration in AllUserDeclarations)
            {
                if (declaration.ProjectId == e.ProjectId &&
                    declaration.DeclarationType == DeclarationType.ClassModule &&
                    declaration.IdentifierName == e.OldName)
                {
                    foreach (var superType in ((ClassModuleDeclaration)declaration).Supertypes)
                    {
                        if (superType.IdentifierName == "Worksheet")
                        {
                            componentIsWorksheet = true;
                            break;
                        }
                    }

                    break;
                }
            }

            if (componentIsWorksheet)
            {
                RemoveProject(e.ProjectId);
                Logger.Debug("Project '{0}' was removed.", e.Component.Name);

                RefreshProjects(e.Project.VBE);
            }
            else
            {
                RemoveRenamedComponent(e.ProjectId, e.OldName);
            }

            OnParseRequested(sender);
        }
        private void Sinks_ComponentRenamed(object sender, ComponentRenamedEventArgs e)
        {
            if (!_vbe.IsInDesignMode || !ThereAreDeclarations())
            {
                return;
            }

            Logger.Debug("Component '{0}' was renamed to '{1}'.", e.OldName, e.QualifiedModuleName.ComponentName);

            //todo: Find out for which situation this drastic (and problematic) cache invalidation has been introduced.
            if (ComponentIsWorksheet(e))
            {
                RefreshProject(e.ProjectId);
                Logger.Debug("Project '{0}' was removed.", e.QualifiedModuleName.ComponentName);
            }
            OnParseRequested(sender);
        }