/// <summary> /// Returns true if given node's type matches the type of items this control holds /// </summary> public override bool CanContainItem(ResXDataNode node) { if (node == null) { throw new ArgumentNullException("node"); } return(node.HasValue <Icon>()); // only Icons are allowed }
/// <summary> /// Returns true if given node's type matches the type of items this control holds /// </summary> public override bool CanContainItem(ResXDataNode node) { if (node == null) { throw new ArgumentNullException("node"); } return(node.HasValue <string>() && !node.HasLinkedFileContent()); }
/// <summary> /// Returns true if given node's type matches the type of items this control holds /// </summary> public override bool CanContainItem(ResXDataNode node) { if (node == null) { throw new ArgumentNullException("node"); } // memory streams are considered to be sounds return(node.HasValue <MemoryStream>() && (node.FileRef == null || node.FileRef.FileName.ToLower().EndsWith(".wav"))); }
/// <summary> /// Saves given node's content into random file in specified directory and returns the file path /// </summary> protected override string SaveIntoTmpFile(ResXDataNode node, string name, string directory) { byte[] bytes; string path; if (node.HasValue <string>()) // contains text file { string value = node.GetValue <string>(); string filename = name + ".txt"; path = Path.Combine(directory, filename); bytes = Encoding.UTF8.GetBytes(value); } else { bytes = node.GetValue <byte[]>(); string filename = node.Name + ".bin"; path = Path.Combine(directory, filename); } FileStream fs = null; try { fs = new FileStream(path, FileMode.Create); fs.Write(bytes, 0, bytes.Length); } finally { if (fs != null) { fs.Close(); } } return(path); }
/// <summary> /// Add string data from given ResX file to the list of data for translation /// </summary> private void AddDataForTranslation(GlobalTranslateProjectItem item, List <AbstractTranslateInfoItem> data) { string path = item.ProjectItem.GetFullPath(); if (RDTManager.IsFileOpen(path)) // file is open { object docData = VLDocumentViewsManager.GetDocData(path); // get document buffer if (docData is ResXEditor) // document is opened in ResX editor -> use custom method to get string data { ResXEditor editor = (ResXEditor)docData; editor.UIControl.AddForTranslation(data); } else // document is opened in original VS editor { IVsTextLines lines = VLDocumentViewsManager.GetTextLinesForFile(path, false); string text = VLDocumentViewsManager.GetTextFrom(lines); // get plain text of ResX file ResXResourceReader reader = null; BufferTranslateInfoItem prev = null; BufferTranslateInfoItem first = null; try { reader = ResXResourceReader.FromFileContents(text); reader.UseResXDataNodes = true; // add all string resources to the list // items are linked like a linked-list, allowing ApplyTranslation to work foreach (DictionaryEntry entry in reader) { ResXDataNode node = (entry.Value as ResXDataNode); if (node.HasValue <string>()) { BufferTranslateInfoItem translateItem = new BufferTranslateInfoItem(); translateItem.ResourceKey = entry.Key.ToString(); translateItem.Value = node.GetValue <string>(); translateItem.Filename = path; translateItem.Applied = false; translateItem.GlobalTranslateItem = item; translateItem.Prev = prev; translateItem.IVsTextLines = lines; data.Add(translateItem); prev = translateItem; if (first == null) { first = translateItem; } } else { item.NonStringData.Add(node); } } if (first != null) { first.Prev = prev; } } finally { if (reader != null) { reader.Close(); } } } } else // file is closed { ResXProjectItem resxItem = ResXProjectItem.ConvertToResXItem(item.ProjectItem, item.ProjectItem.ContainingProject); resxItem.Load(); loadedResxItems.Add(resxItem); // add string data from ResX file resxItem.AddAllStringReferencesUnique(data); } }