Inheritance: SubLib.Core.Domain.Subtitles
        public override bool Execute()
        {
            GnomeSubtitles.Ui.View.Subtitles subtitles = Base.Document.Subtitles;
            int firstPathInt = Util.PathToInt(this.FirstPath);
            int lastPathInt  = Util.PathToInt(this.LastPath);

            /* Store selected subtitles */
            int subtitleCount = lastPathInt - firstPathInt + 1;

            this.subtitlesBefore    = new Subtitle[subtitleCount];
            this.subtitlesBefore[0] = subtitles[firstPathInt].Clone(subtitles.Properties);     //only the first needs to be cloned, the rest won't be changed
            for (int index = 1, currentPath = firstPathInt + 1; index < subtitleCount; index++, currentPath++)
            {
                this.subtitlesBefore[index] = subtitles[currentPath];
            }

            /* Merge subtitles */
            MergeOperator mergeOperator = new MergeOperator(Base.Document.Subtitles);

            if (!mergeOperator.Merge(firstPathInt, lastPathInt))
            {
                return(false);
            }
            else
            {
                TreePath secondPath = Util.IntToPath(firstPathInt + 1);
                subtitles.RemoveRange(secondPath, this.LastPath);
                Base.Ui.View.RedrawPath(this.FirstPath);
                Base.Ui.View.Selection.Select(this.FirstPath, true, true);
                PostProcess();
                return(true);
            }
        }
Exemple #2
0
        /* Private members */

        /// <summary>Loads the subtitles</summary>
        private void Load(Subtitles subtitles)
        {
            this.subtitles = subtitles;
            tree.Model     = subtitles.Model;
            Refresh();

            tree.Model.RowInserted += OnModelRowInserted;
            tree.Model.RowDeleted  += OnModelRowDeleted;

            EmitSubtitleCountChangedEvent();
        }
        /* Private members */

        private Subtitle[] GetSubtitlesAfter(GnomeSubtitles.Ui.View.Subtitles subtitles, TreePath[] pathsAfter)
        {
            Subtitle[] subtitlesAfter = new Subtitle[pathsAfter.Length];
            for (int index = 0; index < pathsAfter.Length; index++)
            {
                TreePath path          = pathsAfter[index];
                int      subtitleIndex = Util.PathToInt(path);
                subtitlesAfter[index] = subtitles[subtitleIndex];
            }
            return(subtitlesAfter);
        }
        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);
            }
        }