コード例 #1
0
ファイル: BilingualRowData.cs プロジェクト: StHillmann/disfr
 public BilingualRowData(PairRenderer renderer, AssetData asset, ITransPair pair, int seq)
 {
     TransPair = pair;
     AssetData = asset;
     Renderer  = renderer;
     Seq       = seq;
 }
コード例 #2
0
        /// <summary>
        /// Load a set of <see cref="IAsset"/>s from a bilingual file into a new TableController.
        /// </summary>
        /// <param name="bundle">Asset bundle that contains entries to show on this table.</param>
        /// <returns>
        /// A newly created and loaded <see cref="ITableController"/> instance.
        /// </returns>
        public static ITableController LoadBilingualAssets(IAssetBundle bundle)
        {
            var renderer = new PairRenderer();
            var instance = new TableController(renderer, bundle);

            instance.ReloadBilingualAssets();
            return(instance);
        }
コード例 #3
0
ファイル: TableController.cs プロジェクト: StHillmann/disfr
        /// <summary>
        /// Creates an unloaded instance of TableController.
        /// </summary>
        /// <param name="renderer">A pair renderer to render the rows in this table.</param>
        /// <remarks>
        /// Use <see cref="LoadBilingualAssets"/> to create a usable instance.
        /// </remarks>
        protected TableController(PairRenderer renderer)
        {
            Renderer = renderer;

            // The following are the default settings whose values are different from default(T).
            // BTW, the default settings should be user configurable. FIXME.
            TagShowing   = TagShowing.Disp;
            ShowSpecials = true;

            UpdateFilter();
        }
コード例 #4
0
        /// <summary>
        /// Creates an unloaded instance of TableController.
        /// </summary>
        /// <param name="renderer">A pair renderer to render the rows in this table.</param>
        /// <remarks>
        /// Use <see cref="LoadBilingualAssets"/> to create a usable instance.
        /// </remarks>
        protected TableController(PairRenderer renderer, IAssetBundle bundle)
        {
            DelegateCommandHelper.GetHelp(this);

            Renderer = renderer;
            Bundle   = bundle;

            // The following are the default settings whose values are different from default(T).
            // BTW, the default settings should be user configurable. FIXME.
            TagShowing   = TagShowing.Disp;
            ShowSpecials = true;

            UpdateFilter();
        }
コード例 #5
0
ファイル: TableController.cs プロジェクト: StHillmann/disfr
        /// <summary>
        /// Load a set of <see cref="IAsset"/>s from a bilingual file into a new TableController.
        /// </summary>
        /// <param name="bundle">Asset bundle that contains entries to show on this table.</param>
        /// <returns>
        /// A newly created and loaded <see cref="ITableController"/> instance.
        /// </returns>
        public static ITableController LoadBilingualAssets(IAssetBundle bundle)
        {
            var name   = bundle.Name;
            var assets = bundle.Assets;

            var renderer    = new PairRenderer();
            var asset_array = assets.ToArray();

            // Build an instance.
            var new_instance = new TableController(renderer);

            new_instance.LoadBilingualRowData(asset_array, a => a.TransPairs, renderer);
            new_instance.Name = name;

            // Take care of Alt.
            if (asset_array.Any(a => a.AltPairs.Any()))
            {
                new_instance.AltLoader = delegate(string[] origins)
                {
                    var alt_instance = new TableController(renderer);
                    alt_instance.LoadBilingualRowData(asset_array, FilteredAltPairs(origins), renderer);
                    alt_instance.Name = string.Format("Alt TM {0}", name);
                    return(alt_instance);
                };

                new_instance.AltOriginsLoader = delegate()
                {
                    var origins = new HashSet <string>();
                    foreach (var asset in asset_array)
                    {
                        var origin = asset.Properties.ToList().FindIndex(prop => prop.Key == "origin");
                        if (origin >= 0)
                        {
                            origins.UnionWith(asset.AltPairs.Select(pair => pair[origin]));
                        }
                    }
                    origins.Remove(null); // XXX
                    return(origins.AsEnumerable());
                };
            }

            return(new_instance);
        }
コード例 #6
0
ファイル: TableController.cs プロジェクト: StHillmann/disfr
        private void LoadBilingualRowData(IAsset[] assets, Func <IAsset, IEnumerable <ITransPair> > pairs, PairRenderer renderer)
        {
            var props         = new List <AdditionalPropertiesInfo>();
            var props_indexes = new Dictionary <string, int>();

            foreach (var prop in assets.SelectMany(a => a.Properties))
            {
                int index;
                if (!props_indexes.TryGetValue(prop.Key, out index))
                {
                    index = props_indexes[prop.Key] = props.Count;
                    props.Add(new AdditionalPropertiesInfo(index, prop.Key, prop.Visible));
                }
                else if (prop.Visible && !props[index].Visible)
                {
                    props[index] = new AdditionalPropertiesInfo(index, prop.Key, prop.Visible);
                }
            }

            var rows   = new List <IRowData>();
            var seq    = 0;
            var serial = 0;

            foreach (var asset in assets)
            {
                var mapper = new int[props.Count];
                for (int i = 0; i < mapper.Length; i++)
                {
                    mapper[i] = int.MaxValue;
                }
                for (int j = 0; j < asset.Properties.Count; j++)
                {
                    mapper[props_indexes[asset.Properties[j].Key]] = j;
                }

                var ad = new AssetData()
                {
                    LongAssetName = asset.Original,
                    BaseSerial    = serial,
                    SourceLang    = asset.SourceLang,
                    TargetLang    = asset.TargetLang,
                    PropMapper    = mapper,
                };

                foreach (var pair in pairs(asset))
                {
                    rows.Add(new BilingualRowData(renderer, ad, pair, seq++));
                    if (pair.Serial > 0)
                    {
                        serial++;
                    }
                }
            }

            _AdditionalProps = props;
            _Rows.Rows       = rows;
        }