internal void MoveNode([NotNull] ResourceTableEntry resourceTableEntry, [NotNull][ItemNotNull] IEnumerable <ResourceTableEntry> previousEntries)
        {
            if (!CanEdit())
            {
                return;
            }

            var node = _nodes.GetValueOrDefault(resourceTableEntry.Key);

            if (node == null)
            {
                return;
            }

            var prevousNode = previousEntries
                              .Select(entry => _nodes.GetValueOrDefault(entry.Key))
                              .FirstOrDefault(item => item != null);

            if (prevousNode == null)
            {
                return;
            }

            var element = node.Element;

            element.Remove();
            prevousNode.Element.AddAfterSelf(element);

            OnChanged();
        }
 public EntryChange(ResourceTableEntry entry, string?text, CultureInfo?culture, ColumnKind columnKind, string?originalText)
 {
     Entry        = entry;
     Text         = text;
     Culture      = culture;
     ColumnKind   = columnKind;
     OriginalText = originalText;
 }
 public EntryChange([NotNull] ResourceTableEntry entry, [CanBeNull] string text, [CanBeNull] CultureInfo culture, ColumnKind columnKind, [CanBeNull] string originalText)
 {
     Entry        = entry;
     Text         = text;
     Culture      = culture;
     ColumnKind   = columnKind;
     OriginalText = originalText;
 }
        /// <summary>
        /// Removes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        public void Remove([NotNull] ResourceTableEntry item)
        {
            foreach (var language in _languages.Values)
            {
                language.RemoveKey(item.Key);
            }

            _resourceTableEntries.Remove(item);
        }
Example #5
0
            public void FindCodeReferences(ResourceTableEntry entry, ICollection <CodeReference> references, ITracer tracer)
            {
                var baseName = entry.Container.BaseName;

                try
                {
                    if (_lines == null)
                    {
                        return;
                    }

                    var key = entry.Key;

                    var lineIndices = _keyLinesLookup.GetValueOrDefault(key);
                    if (lineIndices == null)
                    {
                        return;
                    }

                    var parameters = _configurations.Select(cfg => new
                    {
                        StringComparison = cfg.IsCaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase,
                        Regex            = cfg.Expression != null && !string.IsNullOrEmpty(cfg.Expression) ? new Regex(cfg.Expression.Replace("$Key", key, StringComparison.Ordinal).Replace("$File", baseName, StringComparison.Ordinal)) : null,
                        cfg.SingleLineComment
                    }).ToArray();


                    foreach (var index in lineIndices)
                    {
                        var line       = _lines[index];
                        var lineNumber = index + 1;

                        foreach (var parameter in parameters)
                        {
                            try
                            {
                                var match = new CodeMatch(line, key, parameter.Regex, parameter.StringComparison, parameter.SingleLineComment);
                                if (!match.Success)
                                {
                                    continue;
                                }

                                references.Add(new CodeReference(_projectFile, lineNumber, match.Segments));
                                break;
                            }
                            catch (Exception ex) // Should not happen, but was reported by someone.
                            {
                                tracer.TraceError("Error detecting code reference in file {0}, line {1} for {2}.{3}\n{4}", _projectFile.FilePath, lineNumber, baseName, key, ex);
                            }
                        }
                    }
                }
                catch (Exception ex) // Should not happen, but was reported by someone.
                {
                    tracer.TraceError("Error detecting code reference in file {0} for {1}\n{2}", _projectFile.FilePath, baseName, ex);
                }
            }
        private static IEnumerable <string>?GetLanguageDataColumns(this ResourceTableEntry entry, CultureKey language, IResourceScope?scope)
        {
            if ((scope == null) || scope.Comments.Contains(language))
            {
                yield return(entry.Comments.GetValue(language) ?? string.Empty);
            }

            if ((scope == null) || scope.Languages.Contains(language))
            {
                yield return(entry.Values.GetValue(language) ?? string.Empty);
            }
        }
        public ResourceTableEntry Add([NotNull] string key)
        {
            if (!_languages.Any() || !_languages.Values.Any())
            {
                return(null);
            }

            var firstLanguage = _languages.Values.First();

            firstLanguage.ForceValue(key, string.Empty); // force an entry in the neutral language resource file.
            var index = Math.Floor(_resourceTableEntries.Select(entry => entry.Index).DefaultIfEmpty().Max()) + 1;
            var resourceTableEntry = new ResourceTableEntry(this, key, index, _languages);

            _resourceTableEntries.Add(resourceTableEntry);

            return(resourceTableEntry);
        }
Example #8
0
        private static string?GetEntryData(this ResourceTableEntry entry, CultureKey culture, ColumnKind columnKind)
        {
            var snapshot = entry.Snapshot;

            if (snapshot != null)
            {
                if (!snapshot.TryGetValue(culture, out var data) || (data == null))
                {
                    return(null);
                }

                return(columnKind switch
                {
                    ColumnKind.Text => data.Text,
                    ColumnKind.Comment => data.Comment,
                    _ => throw new InvalidOperationException("Invalid Column Kind")
                });
Example #9
0
        private static bool SetEntryData([NotNull] this ResourceTableEntry entry, [CanBeNull] CultureInfo culture, ColumnKind columnKind, [CanBeNull] string text)
        {
            if (!entry.CanEdit(culture))
            {
                return(false);
            }

            switch (columnKind)
            {
            case ColumnKind.Text:
                return(entry.Values.SetValue(culture, text));

            case ColumnKind.Comment:
                return(entry.Comments.SetValue(culture, text));

            default:
                throw new InvalidOperationException("Invalid Column Kind");
            }
        }
        internal void OnIndexChanged([NotNull] ResourceTableEntry resourceTableEntry)
        {
            var previousEntries = _resourceTableEntries
                                  .Where(entry => entry.Index < resourceTableEntry.Index)
                                  .Reverse()
                                  .ToArray();

            if (!previousEntries.Any())
            {
                return;
            }

            if (!_languages.Values.All(l => l.CanEdit()))
            {
                return;
            }

            foreach (var language in _languages.Values)
            {
                language.MoveNode(resourceTableEntry, previousEntries);
            }
        }
Example #11
0
        private static string GetEntryData([NotNull] this ResourceTableEntry entry, [NotNull] CultureKey culture, ColumnKind columnKind)
        {
            var snapshot = entry.Snapshot;

            if (snapshot != null)
            {
                if (!snapshot.TryGetValue(culture, out var data) || (data == null))
                {
                    return(null);
                }

                switch (columnKind)
                {
                case ColumnKind.Text:
                    return(data.Text);

                case ColumnKind.Comment:
                    return(data.Comment);

                default:
                    throw new InvalidOperationException("Invalid Column Kind");
                }
            }

            switch (columnKind)
            {
            case ColumnKind.Text:
                return(entry.Values.GetValue(culture));

            case ColumnKind.Comment:
                return(entry.Comments.GetValue(culture));

            default:
                throw new InvalidOperationException("Invalid Column Kind");
            }
        }
Example #12
0
 public ResourceTableEntryEventArgs([NotNull] ResourceTableEntry entry)
 {
     Entry = entry;
 }
Example #13
0
 public ResourceTableEntryEventArgs(ResourceTableEntry entry)
 {
     Entry = entry;
 }
 private static IEnumerable <string> GetLanguageDataColumns(this ResourceTableEntry entry, IEnumerable <CultureKey> languages, IResourceScope?scope)
 {
     return(languages.SelectMany(l => entry.GetLanguageDataColumns(l, scope)));
 }
 /// <summary>
 /// Gets one text tables line as an array of columns.
 /// </summary>
 /// <param name="entry">The entry for which to generate the line.</param>
 /// <param name="languages">The resource languages.</param>
 /// <param name="scope">The scope.</param>
 /// <returns>
 /// The columns of this line.
 /// </returns>
 private static IEnumerable <string> GetDataRow(this ResourceTableEntry entry, IEnumerable <CultureKey> languages, IResourceScope?scope)
 {
     return(new[] { entry.Key }.Concat(entry.GetLanguageDataColumns(languages, scope)));
 }
 private static IEnumerable <string> GetDataRow([NotNull] this ResourceTableEntry entry, [NotNull][ItemNotNull] IEnumerable <CultureKey> languages, [CanBeNull] IResourceScope scope)
 {
     return(new[] { entry.Key }.Concat(entry.GetLanguageDataColumns(languages, scope)));
 }
Example #17
0
 private static IEnumerable <string> GetTableLine([NotNull] this ResourceTableEntry entry, [NotNull][ItemNotNull] IEnumerable <CultureKey> languages)
 {
     return(new[] { entry.Key }.Concat(languages.SelectMany(entry.GetTableDataColumns)));
 }
Example #18
0
        private static IEnumerable <string> GetTableDataColumns([NotNull] this ResourceTableEntry entry, [CanBeNull] CultureKey cultureKey)
        {
            yield return(entry.Comments.GetValue(cultureKey) ?? string.Empty);

            yield return(entry.Values.GetValue(cultureKey) ?? string.Empty);
        }
 private static IEnumerable <string> GetLanguageDataColumns([NotNull] this ResourceTableEntry entry, [NotNull][ItemNotNull] IEnumerable <CultureKey> languages, [CanBeNull] IResourceScope scope)
 {
     return(languages.SelectMany(l => entry.GetLanguageDataColumns(l, scope)));
 }