/* Private members */ private bool Merge() { 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(subtitles); if (!mergeOperator.Merge(firstPathInt, lastPathInt)) { return(false); } 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); return(true); }
/* Used in the object construction */ private void Open(string path, Encoding encoding) { SubtitleFactory factory = new SubtitleFactory(); factory.Encoding = encoding; factory.FallbackEncoding = GetFallbackEncoding(); factory.InputFrameRate = Base.Ui.Menus.TimingsInputFrameRateActive; SubLib.Core.Domain.Subtitles openedSubtitles = null; try { openedSubtitles = factory.Open(path); } catch (FileNotFoundException) { New(path); return; } subtitles = new Ui.View.Subtitles(openedSubtitles); textFile = factory.FileProperties; if (textFile.SubtitleType != SubtitleType.Unknown) { canTextBeSaved = true; } }
private ArrayList GetOutOfRangeIntervals() { Ui.View.Subtitles subtitles = Base.Document.Subtitles; ArrayList intervals = new ArrayList(); if (syncPoints.Collection.Count == 0) { return(intervals); } SyncPoint first = syncPoints.Collection.Get(0); if (first.SubtitleNumber > 0) { string firstInterval = "1" + (first.SubtitleNumber > 1 ? "-" + first.SubtitleNumber : String.Empty); intervals.Add(firstInterval); } SyncPoint last = syncPoints.Collection.Get(syncPoints.Collection.Count - 1); int lastSubtitleNumber = subtitles.Count - 1; if (last.SubtitleNumber < lastSubtitleNumber) { string lastInterval = (last.SubtitleNumber < lastSubtitleNumber - 1 ? (last.SubtitleNumber + 2) + "-" : String.Empty) + (lastSubtitleNumber + 1); intervals.Add(lastInterval); } return(intervals); }
/* 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); }
private Times[] GetCurrentTimes(int[] subtitleRange, Ui.View.Subtitles subtitles) { int subtitleFrom = subtitleRange[0]; int subtitleTo = subtitleRange[1]; Times[] currentTimes = new Times[subtitleTo - subtitleFrom + 1]; for (int index = subtitleFrom; index <= subtitleTo; index++) { Subtitle subtitle = subtitles[index]; currentTimes[index - subtitleFrom] = subtitle.Times.Clone(); } return(currentTimes); }
private int[] GetSubtitleRange(Ui.View.Subtitles subtitles) { if (SelectionType == SelectionType.Range) { TreePath[] paths = Paths; int pathFrom = Util.PathToInt(paths[0]); int pathTo = Util.PathToInt(paths[1]); return(new int[] { pathFrom, pathTo }); } else if (SelectionType == SelectionType.All) { if (subtitles.Count < 2) { return(null); } int pathFrom = 0; int pathTo = subtitles.Count - 1; return(new int[] { pathFrom, pathTo }); } return(null); }
protected override bool ChangeValues() { Ui.View.Subtitles subtitles = Base.Document.Subtitles; if (lastTimes == null) { int[] subtitleRange = GetSubtitleRange(subtitles); Times[] timesToStore = GetCurrentTimes(subtitleRange, subtitles); SynchronizeOperator syncOp = new SynchronizeOperator(subtitles); if (!syncOp.Sync(syncPoints.Collection, toSyncAll)) { return(false); } lastTimes = timesToStore; } else { int[] subtitleRange = GetSubtitleRange(subtitles); Times[] timesToStore = GetCurrentTimes(subtitleRange, subtitles); if (subtitleRange == null) { return(false); } int subtitleFrom = subtitleRange[0]; int subtitleTo = subtitleRange[1]; for (int index = subtitleFrom; index <= subtitleTo; index++) { Subtitle subtitle = subtitles[index]; Times timesToUse = lastTimes[index - subtitleFrom]; subtitle.Times.Start = timesToUse.Start; subtitle.Times.End = timesToUse.End; } lastTimes = timesToStore; } return(true); }
private void GetGlobalStyles(TreePath[] paths, out bool bold, out bool italic, out bool underline) { Ui.View.Subtitles subtitles = Base.Document.Subtitles; bold = true; italic = true; underline = true; foreach (TreePath path in paths) { Subtitle subtitle = subtitles[path]; if ((bold == true) && !subtitle.Style.Bold) //bold hasn't been unset { bold = false; } if ((italic == true) && !subtitle.Style.Italic) { italic = false; } if ((underline == true) && !subtitle.Style.Underline) { underline = false; } } }
/* Used in the object construction */ private void New() { SubtitleFactory factory = new SubtitleFactory(); subtitles = new Ui.View.Subtitles(factory.New()); }
/* Used in the object construction */ private void Open (string path, Encoding encoding) { SubtitleFactory factory = new SubtitleFactory(); factory.Verbose = true; factory.Encoding = encoding; factory.FallbackEncoding = GetFallbackEncoding(); factory.InputFrameRate = Base.Ui.Menus.TimingsInputFrameRateActive; SubLib.Core.Domain.Subtitles openedSubtitles = null; try { openedSubtitles = factory.Open(path); } catch (FileNotFoundException) { New(path); return; } subtitles = new Ui.View.Subtitles(openedSubtitles); textFile = factory.FileProperties; if (textFile.SubtitleType != SubtitleType.Unknown) canTextBeSaved = true; }
/* Used in the object construction */ private void New () { SubtitleFactory factory = new SubtitleFactory(); factory.Verbose = true; subtitles = new Ui.View.Subtitles(factory.New()); }