/* Private members */ private bool Split() { Ui.View.Subtitles subtitles = Base.Document.Subtitles; ArrayList pathsBefore = new ArrayList(); ArrayList subtitlesBefore = new ArrayList(); ArrayList pathsAfter = new ArrayList(); Dictionary <int, int[]> mapping = new Dictionary <int, int[]>(); SplitOperator splitOperator = new SplitOperator(subtitles, Base.Config.TimingsTimeBetweenSubtitles); foreach (TreePath path in Paths) { int originalSubtitleIndex = Util.PathToInt(path); int subtitlesThatHaveBeenAdded = pathsAfter.Count - pathsBefore.Count; //number of subtitles that have been added ever since, in this loop int subtitleIndex = originalSubtitleIndex + subtitlesThatHaveBeenAdded; Subtitle subtitle = subtitles[subtitleIndex]; Subtitle[] newSubtitles = splitOperator.Split(subtitle); if (newSubtitles != null) { pathsBefore.Add(path); subtitlesBefore.Add(subtitle); subtitles.Remove(subtitleIndex); int[] newSubtitleIndices = new int[newSubtitles.Length]; for (int i = 0; i < newSubtitles.Length; i++) { int newSubtitleIndex = subtitleIndex + i; pathsAfter.Add(Util.IntToPath(newSubtitleIndex)); subtitles.Add(newSubtitles[i], newSubtitleIndex); newSubtitleIndices[i] = newSubtitleIndex; } mapping.Add(originalSubtitleIndex, newSubtitleIndices); } } if (subtitlesBefore.Count == 0) { return(false); } this.subtitlesBefore = (Subtitle [])subtitlesBefore.ToArray(typeof(Subtitle)); this.Paths = (TreePath [])pathsBefore.ToArray(typeof(TreePath)); this.pathsAfter = (TreePath [])pathsAfter.ToArray(typeof(TreePath)); this.mapping = mapping; Base.Ui.View.RedrawPaths(this.pathsAfter); Base.Ui.View.Selection.Select(this.pathsAfter, this.pathsAfter[0], true); PostProcess(); return(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); } }