Add() public method

Appends a subtitle to the end of the list.
public Add ( Subtitle subtitle ) : void
subtitle SubLib.Core.Domain.Subtitle
return void
示例#1
0
        /// <summary>Inserts a subtitle in the specified path.</summary>
        public void Insert(Subtitle subtitle, TreePath path)
        {
            int index = Util.PathToInt(path);

            subtitles.Add(subtitle, index);
            selection.Select(path, true, true);
        }
        public override bool Execute()
        {
            GnomeSubtitles.Ui.View.Subtitles subtitles = Base.Document.Subtitles;
            ArrayList pathsBefore     = new ArrayList();
            ArrayList subtitlesBefore = new ArrayList();
            ArrayList pathsAfter      = new ArrayList();

            SplitOperator splitOperator = new SplitOperator(subtitles, Base.Config.TimingsTimeBetweenSubtitles);

            foreach (TreePath path in Paths)
            {
                int      subtitleIndex = Util.PathToInt(path) + subtitlesBefore.Count;    //need to account for subtitles already added in this loop
                Subtitle subtitle      = subtitles[subtitleIndex];
                Subtitle subtitleClone = subtitle.Clone(subtitles.Properties);
                Subtitle subtitle2     = splitOperator.Split(subtitle);
                if (subtitle2 != null)
                {
                    pathsAfter.Add(Util.IntToPath(subtitleIndex));
                    pathsAfter.Add(Util.IntToPath(subtitleIndex + 1));

                    pathsBefore.Add(path);
                    subtitlesBefore.Add(subtitleClone);

                    subtitles.Add(subtitle2, subtitleIndex + 1);
                }
            }

            /* If any subtitle was changed, the command was successful */
            if (subtitlesBefore.Count == 0)
            {
                return(false);
            }
            else
            {
                this.subtitlesBefore = (Subtitle[])subtitlesBefore.ToArray(typeof(Subtitle));
                this.Paths           = (TreePath[])pathsBefore.ToArray(typeof(TreePath));
                this.pathsAfter      = (TreePath[])pathsAfter.ToArray(typeof(TreePath));
                Base.Ui.View.RedrawPaths(this.pathsAfter);
                Base.Ui.View.Selection.Select(this.pathsAfter, this.pathsAfter[0], true);
                PostProcess();
                return(true);
            }
        }