/// <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)
        {
            Contract.Requires(entry != null);
            Contract.Requires(languages != null);

            return((new[] { entry.Key }).Concat(entry.GetLanguageDataColumns(languages, scope)));
        }
        internal void OnIndexChanged(ResourceTableEntry resourceTableEntry)
        {
            Contract.Requires(resourceTableEntry != null);

            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)
            {
                Contract.Assume(language != null);

                language.MoveNode(resourceTableEntry, previousEntries);
            }
        }
        private static IEnumerable <string> GetLanguageDataColumns(this ResourceTableEntry entry, IEnumerable <CultureKey> languages, IResourceScope scope)
        {
            Contract.Requires(entry != null);
            Contract.Requires(languages != null);

            return(languages.SelectMany(l => entry.GetLanguageDataColumns(l, scope)));
        }
        internal void MoveNode([NotNull] ResourceTableEntry resourceTableEntry, [NotNull][ItemNotNull] IEnumerable <ResourceTableEntry> previousEntries)
        {
            Contract.Requires(resourceTableEntry != null);
            Contract.Requires(previousEntries != null);

            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();
        }
Example #5
0
        /// <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 languages.</param>
        /// <returns>
        /// The columns of this line.
        /// </returns>
        private static IEnumerable <string> GetTableLine(this ResourceTableEntry entry, IEnumerable <ResourceLanguage> languages)
        {
            Contract.Requires(entry != null);
            Contract.Requires(languages != null);

            return((new[] { entry.Key }).Concat(languages.SelectMany(l => entry.GetTableDataColumns(l.CultureKey))));
        }
Example #6
0
        private static IEnumerable <string> GetTableLine([NotNull] this ResourceTableEntry entry, [NotNull] IEnumerable <CultureKey> languages)
        {
            Contract.Requires(entry != null);
            Contract.Requires(languages != null);
            Contract.Ensures(Contract.Result <IEnumerable <string> >() != null);

            return(new[] { entry.Key }.Concat(languages.SelectMany(entry.GetTableDataColumns)));
        }
Example #7
0
        private static IEnumerable <string> GetTableDataColumns([NotNull] this ResourceTableEntry entry, CultureKey cultureKey)
        {
            Contract.Requires(entry != null);

            yield return(entry.Comments.GetValue(cultureKey));

            yield return(entry.Values.GetValue(cultureKey));
        }
 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;
 }
        private static IEnumerable <string> GetLanguageDataColumns([NotNull] this ResourceTableEntry entry, [NotNull][ItemNotNull] IEnumerable <CultureKey> languages, [CanBeNull] IResourceScope scope)
        {
            Contract.Requires(entry != null);
            Contract.Requires(languages != null);
            Contract.Ensures(Contract.Result <IEnumerable <string> >() != null);

            return(languages.SelectMany(l => entry.GetLanguageDataColumns(l, scope)));
        }
        /// <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 #11
0
            public void FindCodeReferences([NotNull] ResourceTableEntry entry, [NotNull][ItemNotNull] ICollection <CodeReference> references, [NotNull] 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            = !string.IsNullOrEmpty(cfg.Expression) ? new Regex(cfg.Expression.Replace("$Key", key).Replace("$File", baseName)) : 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);
                }
            }
 public EntryChange(ResourceTableEntry entry, string text, CultureInfo culture, ColumnKind columnKind, string originalText)
 {
     Contract.Requires(entry != null);
     Entry        = entry;
     Text         = ProposedText = text;
     Culture      = culture;
     ColumnKind   = columnKind;
     OriginalText = originalText;
 }
        private static IEnumerable <string> GetLanguageDataColumns([NotNull] this ResourceTableEntry entry, [NotNull] CultureKey language, [CanBeNull] IResourceScope scope)
        {
            if ((scope == null) || scope.Comments.Contains(language))
            {
                yield return(entry.Comments.GetValue(language));
            }

            if ((scope == null) || scope.Languages.Contains(language))
            {
                yield return(entry.Values.GetValue(language));
            }
        }
        /// <summary>
        /// Removes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        public void Remove(ResourceTableEntry item)
        {
            Contract.Requires(item != null);

            foreach (var language in _languages.Values)
            {
                Contract.Assume(language != null);
                language.RemoveKey(item.Key);
            }

            _resourceTableEntries.Remove(item);
        }
Example #15
0
        public TranslationItem(ResourceTableEntry entry, string source, CultureKey targetCulture)
        {
            Contract.Requires(entry != null);
            Contract.Requires(source != null);
            Contract.Requires(targetCulture != null);

            Entry  = entry;
            Source = source;

            _targetCulture              = targetCulture;
            _results.CollectionChanged += (_, __) => OnPropertyChanged(() => Translation);
            _orderedResults             = new ListCollectionView(_results);
            _orderedResults.SortDescriptions.Add(new SortDescription("Rating", ListSortDirection.Descending));
            _orderedResults.SortDescriptions.Add(new SortDescription("Translator.DisplayName", ListSortDirection.Ascending));
        }
        private static IEnumerable <string> GetLanguageDataColumns(this ResourceTableEntry entry, CultureKey language, IResourceScope scope)
        {
            Contract.Requires(entry != null);
            Contract.Requires(language != null);

            if ((scope == null) || scope.Comments.Contains(language))
            {
                yield return(entry.Comments.GetValue(language));
            }

            if ((scope == null) || scope.Languages.Contains(language))
            {
                yield return(entry.Values.GetValue(language));
            }
        }
Example #17
0
        private static bool SetEntryData(this ResourceTableEntry entry, CultureInfo culture, ColumnKind columnKind, string text)
        {
            Contract.Requires(entry != null);

            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");
            }
        }
        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 #19
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");
            }
        }
Example #20
0
        private static string GetEntryData([NotNull] this ResourceTableEntry entry, [NotNull] CultureKey culture, ColumnKind columnKind)
        {
            Contract.Requires(entry != null);
            Contract.Requires(culture != null);

            var snapshot = entry.Snapshot;

            if (snapshot != null)
            {
                ResourceData data;
                if (!snapshot.TryGetValue(culture, out 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");
            }
        }
        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 #22
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 #23
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);
        }
Example #24
0
        private static IEnumerable <string> GetTableDataColumns(this ResourceTableEntry entry, CultureKey cultureKey)
        {
            yield return(entry.Comments.GetValue(cultureKey));

            yield return(entry.Values.GetValue(cultureKey));
        }
 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)));
 }
 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)));
 }
Example #27
0
 public ResourceTableEntryEventArgs([NotNull] ResourceTableEntry entry)
 {
     Entry = entry;
 }