private void ComponentRenamed(object sender, IComponentRenamedEventArgs e) { if (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 => stat.FilePath.Split('.')[0] == e.OldName); if (fileStatus != null) { var directory = Provider.CurrentRepository.LocalLocation; directory += directory.EndsWith("\\") ? string.Empty : "\\"; var fileExt = "." + fileStatus.FilePath.Split('.').Last(); _fileSystemWatcher.EnableRaisingEvents = false; File.Move(directory + fileStatus.FilePath, 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, IComponentRenamedEventArgs 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); }