public static void CheckReference(ResourceResolveResult result, string expectedResourceSetName, string expectedKey, string expectedCallingClassFullName, string expectedCallingMemberFullName) { Assert.IsNotNull(result, "Resource reference should be detected."); if (expectedResourceSetName == null) { Assert.IsNull(result.ResourceSetReference, "Resource set reference should not be detected."); } else { Assert.IsNotNull(result.ResourceSetReference, "Resource set reference should be detected."); Assert.IsNotNull(result.ResourceSetReference.ResourceSetName, "Resource set name must not be null."); Assert.AreEqual(expectedResourceSetName, result.ResourceSetReference.ResourceSetName, "Incorrect resource set name."); } if (expectedKey == null) { Assert.IsNull(result.Key, "Resource key should not be detected."); } else { Assert.IsNotNull(result.Key, "Resource key should be detected."); Assert.AreEqual(expectedKey, result.Key, "Incorrect resource key."); } if (expectedCallingClassFullName == null) { Assert.IsNull(result.CallingClass, "Calling class should not be detected."); } else { Assert.IsNotNull(result.CallingClass, "Calling class should be detected."); Assert.AreEqual(expectedCallingClassFullName, result.CallingClass.FullyQualifiedName, "Incorrect calling class."); } if (expectedCallingMemberFullName == null) { Assert.IsNull(result.CallingMember, "Calling member should not be detected."); } else { Assert.IsNotNull(result.CallingMember, "Calling member should be detected."); Assert.AreEqual(expectedCallingMemberFullName, result.CallingMember.FullyQualifiedName, "Incorrect calling member."); } }
public static void CheckNoReference(ResourceResolveResult result) { Assert.IsNull(result, "Resource reference should not be detected."); }
/// <summary> /// Renames all references to a resource including the definition. /// </summary> /// <param name="rrr">The resource to be renamed.</param> /// <param name="newKey">The new name of the resource key.</param> /// <param name="monitor">An object implementing <see cref="IProgressMonitor"/> to report the progress of the operation. Can be <c>null</c>.</param> public static void Rename(ResourceResolveResult rrr, string newKey, IProgressMonitor monitor) { // Prevent duplicate key names if (rrr.ResourceFileContent.ContainsKey(newKey)) { if (monitor != null) monitor.ShowingDialog = true; MessageService.ShowWarning("${res:Hornung.ResourceToolkit.EditStringResourceDialog.DuplicateKey}"); if (monitor != null) monitor.ShowingDialog = false; return; } List<Reference> references = FindReferences(rrr.FileName, rrr.Key, monitor); if (references == null) { return; } try { // rename definition (if present) if (rrr.ResourceFileContent.ContainsKey(rrr.Key)) { rrr.ResourceFileContent.RenameKey(rrr.Key, newKey); } else { if (monitor != null) monitor.ShowingDialog = true; MessageService.ShowWarning("${res:Hornung.ResourceToolkit.RenameKeyDefinitionNotFoundWarning}"); if (monitor != null) monitor.ShowingDialog = false; } } catch (Exception ex) { if (monitor != null) monitor.ShowingDialog = true; MessageService.ShowWarningFormatted("${res:Hornung.ResourceToolkit.ErrorProcessingResourceFile}" + Environment.NewLine + ex.Message, rrr.ResourceFileContent.FileName); if (monitor != null) monitor.ShowingDialog = false; // Do not rename the references when renaming the definition failed. return; } // rename references // FIXME: RenameReferences does not enforce escaping rules. May be a problem if someone uses double-quotes in the new resource key name. FindReferencesAndRenameHelper.RenameReferences(references, newKey); // rename definitions in localized resource files foreach (KeyValuePair<string, IResourceFileContent> entry in ResourceFileContentRegistry.GetLocalizedContents(rrr.FileName)) { try { if (entry.Value.ContainsKey(rrr.Key)) { entry.Value.RenameKey(rrr.Key, newKey); } } catch (Exception ex) { if (monitor != null) monitor.ShowingDialog = true; MessageService.ShowWarningFormatted("${res:Hornung.ResourceToolkit.ErrorProcessingResourceFile}" + Environment.NewLine + ex.Message, entry.Value.FileName); if (monitor != null) monitor.ShowingDialog = false; } } }
public static void Rename(ResourceResolveResult rrr) { string newKey = MessageService.ShowInputBox("${res:SharpDevelop.Refactoring.Rename}", "${res:Hornung.ResourceToolkit.RenameResourceText}", rrr.Key); if (!String.IsNullOrEmpty(newKey) && !newKey.Equals(rrr.Key)) { using(AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("${res:SharpDevelop.Refactoring.Rename}")) { Rename(rrr, newKey, monitor); } } }
/// <summary> /// Determines whether the specified ResourceResolveResult describes /// a resource that should be included in the search result. /// </summary> public bool IsReferenceToResource(ResourceResolveResult result) { return FileUtility.IsEqualFileName(this.ResourceFileName, result.FileName) && this.Key.Equals(result.Key, StringComparison.OrdinalIgnoreCase); }
/// <summary> /// Determines whether the specified ResourceResolveResult describes /// a resource that should be included in the search result. /// </summary> public bool IsReferenceToResource(ResourceResolveResult result) { return true; }