internal string Build (SubtitleCollection collection, SubtitleProperties subtitleProperties, FileProperties fileProperties) { this.subtitleProperties = subtitleProperties; StringBuilder output = new StringBuilder(); if (format.HasHeaders) output.Append(format.HeadersToString(subtitleProperties, fileProperties)); if (format.HasBodyBegin) output.Append(format.BodyBeginOut); string subtitleExpression = GetSubtitleExpression(format, subtitleProperties, fileProperties); Regex fieldExpression = new Regex(@"<<(?<Field>\w+)(,(?<Width>\d+))?>>"); MatchEvaluator matchEvaluator = new MatchEvaluator(this.FieldEvaluator); foreach (Subtitle currentSubtitle in collection) { subtitle = currentSubtitle; string outputSubtitle = fieldExpression.Replace(subtitleExpression, matchEvaluator); output.Append(outputSubtitle); output.Append("\n"); subtitleNumber++; previousSubtitle = subtitle; } if (format.HasBodyEnd) output.Append(format.BodyEndOut); subtitle = null; previousSubtitle = null; subtitleNumber = 1; ConvertNewlines(output, fileProperties); return output.ToString(); }
public override void Undo () { if (this.subtitleAfter == null) { this.subtitleAfter = Base.Document.Subtitles[this.FirstPath]; } Base.Document.Subtitles.Remove(this.FirstPath); Base.Ui.View.Insert(this.subtitlesBefore, this.FirstPath, this.FirstPath); PostProcess(); }
// can be optimized internal override void SubtitleInputPostProcess (Subtitle subtitle) { string subtitleText = subtitle.Text.Get(lineBreak); string styleText = String.Empty; MatchCollection matches = styleExpression.Matches(subtitleText); foreach (Match match in matches) { styleText += match.Value; } Style style = StringToStyle(styleText); subtitle.Style = style; subtitleText = styleExpression.Replace(subtitleText, String.Empty); subtitle.Text.Set(subtitleText, lineBreak, true); }
private void ReadSubtitles (Encoding encoding, ParsingProperties properties, SubtitleCollection collection) { string[] lines = text.Split(new char[] {'\n'}); for (int i = 0; i < lines.Length; i++) { SubtitleText stext = ParseSubtitleText(lines[i]); Style style = new Style(); if(!stext.IsEmpty) { Subtitle subtitle = new Subtitle(null, stext, style); collection.Add(subtitle); } } }
protected override string GetSubtitleTextContent (Subtitle subtitle) { return subtitle.Text.Get(); }
protected override void ChangeSubtitleTextContent (Subtitle subtitle, string text) { subtitle.Text.Set(text); }
protected void OnSubtitleSelectionChanged (TreePath[] paths, Subtitle subtitle) { if (subtitle != null) LoadSubtitle(subtitle); else ClearFields(); }
private void OnSubtitleSelectionChanged (TreePath[] paths, Subtitle subtitle) { if ((subtitle != null) && IsLoaded) SetSelectionDependentControlsSensitivity(true); else SetSelectionDependentControlsSensitivity(false); }
/// <summary>Creates a subtitle based on the subtitle at the specified index and adds it to the /// collection, inserting it right after that index.</summary> /// <remarks>The newly created subtitle's times will be based on the specified subtitle. /// Its duration will be <see cref="SubtitleConstants.MaxSingleLineSubtitleDuration" />.</remarks> /// <param name="index">The zero-based index after which the subtitle should be inserted.</param> /// <param name="subtitleProperties">The SubtitleProperties of the subtitles.</param> /// <param name="timeBetweenSubtitles">The gap to keep after the existing subtitle, in milliseconds.</param> /// <returns>True if the subtitle could be added, false otherwise.</returns> public bool AddNewAfter (int index, SubtitleProperties subtitleProperties, int timeBetweenSubtitles) { Subtitle existing = Get(index); if (existing == null) return false; TimeSpan subtitleStart = existing.Times.End + TimeSpan.FromMilliseconds(timeBetweenSubtitles); TimeSpan subtitleEnd = subtitleStart + TimeSpan.FromSeconds(SubtitleConstants.AverageSubtitleDuration); Subtitle subtitle = new Subtitle(subtitleProperties, subtitleStart, subtitleEnd); Add(subtitle, index + 1); return true; }
protected abstract void ChangeSubtitleTextContent (Subtitle subtitle, string text);
private void LoadDurationTiming (Subtitle subtitle) { durationSpinButton.ValueChanged -= OnDurationValueChanged; if (timingMode == TimingMode.Frames) durationSpinButton.Value = subtitle.Frames.Duration; else durationSpinButton.Value = subtitle.Times.Duration.TotalMilliseconds; durationSpinButton.ValueChanged += OnDurationValueChanged; }
private void OnSubtitleViewSelectionChanged (TreePath[] paths, Subtitle subtitle) { if (subtitle != null) { /* One subtitle selected */ SetStylesActivity(subtitle.Style.Bold, subtitle.Style.Italic, subtitle.Style.Underline); SetNonZeroSelectionDependentSensitivity(1, true); SetOneSelectionDependentSensitivity(true); } else { SetOneSelectionDependentSensitivity(false); int selectionCount = paths.Length; if (selectionCount == 0) { /* No selection */ SetNonZeroSelectionDependentSensitivity(selectionCount, false); SetStylesActivity(false, false, false); } else { /* Multiple paths selected */ SetNonZeroSelectionDependentSensitivity(selectionCount, true); bool bold, italic, underline; GetGlobalStyles(paths, out bold, out italic, out underline); SetStylesActivity(bold, italic, underline); } } }
/* Public methods */ /// <summary></summary> /// <remarks>SubtitleProperties is not cloned and should be set afterwards.</remarks> public Subtitle Clone (SubtitleProperties propertiesClone) { Subtitle subtitleClone = new Subtitle(); Times timesClone = this.times.Clone(subtitleClone); Frames framesClone = this.frames.Clone(subtitleClone); SubtitleText textClone = this.text.Clone() as SubtitleText; SubtitleText translationClone = (this.translation != null ? this.translation.Clone() as SubtitleText : null); Style styleClone = this.style.Clone() as Style; subtitleClone.SetFieldsForDeepClone(propertiesClone, timesClone, framesClone, textClone, translationClone, styleClone); return subtitleClone; }
public void Insert (Subtitle[] subtitles, TreePath firstPath, TreePath focus) { for (int index = 0, pathIndex = Util.PathToInt(firstPath) ; index < subtitles.Length ; index++, pathIndex++) { Subtitle subtitle = subtitles[index]; this.subtitles.Add(subtitle, pathIndex); } TreePath lastPath = Util.IntToPath(Util.PathToInt(firstPath) + subtitles.Length - 1); TreePath[] pathRange = new TreePath[]{firstPath, lastPath}; selection.SelectRange(pathRange, focus, true); }
/// <summary>Inserts a collection of subtitles in the specified paths.</summary> /// <param name="subtitles">The subtitles to insert.</param> /// <param name="paths">The paths corresponding to each of the subtitles. There must be the same number of paths as there are for subtitles.</param> /// <param name="focus">The path that should be given the focus.</param> public void Insert (Subtitle[] subtitles, TreePath[] paths, TreePath focus) { for (int index = 0 ; index < subtitles.Length ; index++) { Subtitle subtitle = subtitles[index]; TreePath path = paths[index]; int pathIndex = Util.PathToInt(path); this.subtitles.Add(subtitle, pathIndex); } selection.Select(paths, focus, true); }
/// <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); }
private void LoadStartTiming (Subtitle subtitle) { startSpinButton.ValueChanged -= OnStartValueChanged; if (timingMode == TimingMode.Frames) startSpinButton.Value = subtitle.Frames.Start; else startSpinButton.Value = subtitle.Times.Start.TotalMilliseconds; startSpinButton.ValueChanged += OnStartValueChanged; }
public ChangeTimingCommand (int frames, string description, bool seekAfterChange): base(description, true, true) { this.subtitle = Base.Document.Subtitles[Path]; this.storedFrames = frames; this.seekAfterChange = seekAfterChange; }
private void LoadEndTiming (Subtitle subtitle) { endSpinButton.ValueChanged -= OnEndValueChanged; if (timingMode == TimingMode.Frames) endSpinButton.Value = subtitle.Frames.End; else endSpinButton.Value = subtitle.Times.End.TotalMilliseconds; endSpinButton.ValueChanged += OnEndValueChanged; }
public ChangeTimingCommand (TimeSpan time, string description, bool seekAfterChange): base(description, true, true) { this.subtitle = Base.Document.Subtitles[Path]; this.storedTime = time; this.seekAfterChange = seekAfterChange; }
private void OnSubtitleSelectionChanged (TreePath[] paths, Subtitle subtitle) { if (subtitle != null) LoadTimings(); else ClearFields(); }
/// <summary>Adds a subtitle to the end of the collection.</summary> /// <param name="subtitle">The subtitle to add.</param> public void Add (Subtitle subtitle){ subtitles.Add(subtitle); }
/// <summary>Creates a subtitle based on the subtitle at the specified index and adds it to the /// collection, inserting it right before that index.</summary> /// <remarks>The newly created subtitle's times will be based on the specified subtitle. Its duration /// will be <see cref="SubtitleConstants.MaxSingleLineSubtitleDuration" />. Both the start and end times /// times will be wrapped to zero if they are negative.</remarks> /// <param name="index">The zero-based index before which the subtitle should be inserted.</param> /// <param name="subtitleProperties">The SubtitleProperties of the subtitles.</param> /// <param name="timeBetweenSubtitles">The gap to keep before the existing subtitle, in milliseconds.</param> /// <returns>True if the subtitle could be added, false otherwise.</returns> public bool AddNewBefore (int index, SubtitleProperties subtitleProperties, int timeBetweenSubtitles) { Subtitle existing = Get(index); if (existing == null) return false; TimeSpan subtitleEnd = existing.Times.Start - TimeSpan.FromMilliseconds(timeBetweenSubtitles); if (subtitleEnd < TimeSpan.Zero) subtitleEnd = TimeSpan.FromSeconds(0); TimeSpan subtitleStart = subtitleEnd - TimeSpan.FromSeconds(SubtitleConstants.AverageSubtitleDuration); if (subtitleStart < TimeSpan.Zero) subtitleStart = TimeSpan.FromSeconds(0); Subtitle subtitle = new Subtitle(subtitleProperties, subtitleStart, subtitleEnd); Add(subtitle, index); return true; }
internal virtual void SubtitleInputPostProcess (Subtitle subtitle) { return; }
/// <summary>Creates a subtitle and adds it to the collection, inserting it at the specified index /// and with the specified start time.</summary> /// <remarks>The newly created subtitle's duration will be /// <see cref="SubtitleConstants.MaxSingleLineSubtitleDuration" />.</remarks> /// <param name="index">The zero-based index at which the subtitle should be inserted.</param> /// <param name="subtitleProperties">The SubtitleProperties of the subtitles.</param> /// <param name="start">The time at which the new subtitle will start</para> /// <returns>True if the subtitle could be added, false otherwise.</returns> public bool AddNewAt (int index, SubtitleProperties subtitleProperties, TimeSpan start) { if ((index < 0) || (index > Count)) return false; TimeSpan subtitleStart = start; TimeSpan subtitleEnd = subtitleStart + TimeSpan.FromSeconds(SubtitleConstants.AverageSubtitleDuration); Subtitle subtitle = new Subtitle(subtitleProperties, subtitleStart, subtitleEnd); Add(subtitle, index); return true; }
protected abstract string GetSubtitleTextContent (Subtitle subtitle);
/// <summary>Adds a subtitle to the collection, inserting it at the specified index.</summary> /// <param name="subtitle">The subtitle to add.</param> /// <param name="index">The zero-based index at which the subtitle should be inserted.</param> public void Add (Subtitle subtitle, int index){ subtitles.Insert(index, subtitle); }
/// <summary>Appends a subtitle to the end of the list.</summary> public void Add (Subtitle subtitle) { Collection.Add(subtitle); model.AppendValues(subtitle); }
/* Public members */ public override bool Execute () { InsertNew(); subtitle = Base.Document.Subtitles[newPath]; return true; }
/// <summary>Adds a subtitle to the specified position on the list.</summary> public void Add (Subtitle subtitle, int index) { Collection.Add(subtitle, index); model.SetValue(model.Insert(index), 0, subtitle); }