private void OpenStringDictEditor() { if (m_stringDictLoad) { return; } guiStringDictEditor = new ResXEditor(NFileSystem.DefaultFileSystemRoot + GUISystem.Instance.DefauleStringDictFilePath); guiStringDictEditor.Show(); m_stringDictLoad = true; guiStringDictEditor.FormClosed += new FormClosedEventHandler(guiStringDictEditor_FormClosed); guiStringDictEditor.ResXFileSaved += new EventHandler <EventArgs>(guiStringDictEditor_ResXFileSaved); }
/// <summary> /// Replaces opened file's buffer with given data /// </summary> public static void SaveDataToBuffer(Dictionary <string, ResXDataNode> data, string file) { if (data == null) { throw new ArgumentNullException("data"); } if (file == null) { throw new ArgumentNullException("file"); } object docData = GetDocData(file); // get document buffer if (docData is ResXEditor) // opened in VL editor { ResXEditor editor = docData as ResXEditor; editor.UIControl.SetData(data); editor.IsDirty = true; } else // opened in default VS editor { IVsTextLines textLines = GetTextLinesFrom(docData); // get document line buffer ResXResourceWriter writer = null; MemoryStream stream = null; try { // create new memory stream and fill it with new ResX content stream = new MemoryStream(); writer = new ResXResourceWriter(stream); writer.BasePath = Path.GetDirectoryName(file); foreach (var pair in data) { writer.AddResource(pair.Key, pair.Value); } writer.Generate(); writer.Close(); // replace current buffer with the memory stream content, leaving no undo units SaveStreamToBuffer(stream, textLines, true); } finally { if (stream != null) { stream.Close(); } } } }
/// <summary> /// Runs this command, filling Results with references to resources in given file /// </summary> /// <param name="editorInstance">Instance of the ResX editor issuing the search</param> /// <param name="projects">List of referenced projects (are included in the search)</param> /// <param name="trie">Trie created from resource names</param> /// <param name="prefferedResXItem">Original ResX project item - used when culture-neutral vs. culture-specific differences are handled</param> /// <param name="isInitial">True if this search is the first after opening the resource file and therefore files with no code-model should be force opened</param> public void Process(ResXEditor editorInstance, List <Project> projects, Trie <CodeReferenceTrieElement> trie, ResXProjectItem prefferedResXItem, bool isInitial) { this.trie = trie; this.prefferedResXItem = prefferedResXItem; this.isInitial = isInitial; this.editorInstance = editorInstance; searchedProjectItems.Clear(); generatedProjectItems.Clear(); Results = new List <CodeReferenceResultItem>(); foreach (Project project in projects) { Process(project, false); } codeUsingsCache.Clear(); }
/// <summary> /// Returns content of opened ResX file's buffer /// </summary> /// <param name="data">Content of the buffer</param> /// <param name="file">File path</param> public static void LoadDataFromBuffer(ref Dictionary <string, ResXDataNode> data, string file) { if (file == null) { throw new ArgumentNullException("file"); } object docData = GetDocData(file); // get document's buffer if (docData is ResXEditor) { ResXEditor editor = docData as ResXEditor; data = editor.UIControl.GetData(false); } else { IVsTextLines textLines = GetTextLinesFrom(docData); // get text buffer string textBuffer = GetTextFrom(textLines); // get plain text ResXResourceReader reader = null; try { data = new Dictionary <string, ResXDataNode>(); // use reader to parse given ResX text reader = ResXResourceReader.FromFileContents(textBuffer); reader.BasePath = Path.GetDirectoryName(file); reader.UseResXDataNodes = true; foreach (DictionaryEntry entry in reader) { data.Add(entry.Key.ToString().ToLower(), entry.Value as ResXDataNode); } } finally { if (reader != null) { reader.Close(); } } } }
void guiStringDictEditor_FormClosed(object sender, FormClosedEventArgs e) { guiStringDictEditor = null; m_stringDictLoad = false; }
/// <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); } }