/// <summary>Creates a new instance of the <see cref="SubtitleSearchResults" /> class.</summary> /// <param name="subtitle">The zero-based number of the subtitle where the text was found.</param> /// <param name="textType">The type of text content where the text was found.</param> /// <param name="index">The zero-based position where the text was found, within a subtitle.</param> /// <param name="length">The length of the found text.</param> public SubtitleSearchResults(int subtitle, SubtitleTextType textType, int index, int length) { this.subtitle = subtitle; this.textType = textType; this.index = index; this.length = length; }
public void SetActiveLanguageIndex(SubtitleTextType textType, int index) { bool isEmpty = ((index < 0) || (index >= languages.Length)); SpellLanguage activeLanguage = null; if (isEmpty) { index = -1; } else { activeLanguage = languages[index] as SpellLanguage; } Logger.Info("[Spellcheck] Setting active {0} language: {1}", textType, (activeLanguage == null ? "none." : activeLanguage.ID)); /* Set index variable */ if (textType == SubtitleTextType.Text) { activeTextLanguageIndex = index; } else { activeTranslationLanguageIndex = index; } string activeLanguageID = (isEmpty ? String.Empty : activeLanguage.ID); SetActiveLanguageInConfig(textType, activeLanguageID); EmitLanguageChanged(textType); }
protected SetLanguageDialog (SubtitleTextType textType) : base(gladeFilename) { this.textType = textType; SetDialogTitle(textType); SetIntroLabel(textType); FillAvailableLanguages(); SelectActiveLanguage(textType); }
private int GetActiveLanguageIndex (SubtitleTextType textType, int count) { int activeLanguageIndex = Base.SpellLanguages.GetActiveLanguageIndex(textType); /* Set active language to the first if invalid */ if ((activeLanguageIndex == -1) || (activeLanguageIndex >= count)) activeLanguageIndex = 0; return activeLanguageIndex; }
/// <summary>Creates a new instance of the <see cref="SubtitleSearchOptions" /> class.</summary> /// <param name="regex">The regular expression to use when searching. It must be created with /// <see cref="RegexOptions.IgnoreCase" /> to perform a case-insensitive search.</param> /// <param name="textType">The type of text content the search is started at.</param> /// <param name="lineBreak">The line break to use between multiple lines of text in each subtitle.</param> /// <param name="startSubtitle">The zero-based number of the subtitle to start the search at.</param> /// <param name="startIndex">The zero-based position within the startSubtitle to start the search at.</param> /// <param name="wrap">Whether to continue the search from the beginning when it reaches the end of the subtitles.</param> /// <param name="backwards">Whether to search backwards. Note that regex must be constructed with the /// <see cref="RegexOptions.RightToLeft" /> option for backwards search to work.</param> public SubtitleSearchOptions (Regex regex, SubtitleTextType textType, string lineBreak, int startSubtitle, int startIndex, bool wrap, bool backwards) { this.regex = regex; this.textType = textType; this.lineBreak = lineBreak; this.startSubtitle = startSubtitle; this.startIndex = startIndex; this.wrap = wrap; this.backwards = backwards; }
/* Public methods */ /// <summary>Saves subtitles to the file with the specified properties.</summary> /// <param name="subtitles">The subtitles to save.</param> /// <param name="properties">The properties of the file to save the subtitles to. Its <see cref="TimingMode" /> property is used to /// choose the timing mode for subtitle formats that support both time and frame modes.</param> /// <param name="textType">The type of text content to save.</param> /// <remarks>An updated <see cref="SubLib.FileProperties" /> object can be accessed with <see cref="FileProperties" /> after saving.</remarks> public void Save (Subtitles subtitles, FileProperties properties, SubtitleTextType textType) { SubtitleFormat format = BuiltInSubtitleFormats.GetFormat(properties.SubtitleType); SubtitleOutput output = new SubtitleOutput(format, textType); string text = output.Build(subtitles.Collection, subtitles.Properties, properties); FileInputOutput.WriteFile(properties.Path, text, properties.Encoding); fileProperties = GetUpdatedFileProperties(properties); VerboseConsole.WriteLine("[*] Saved " + textType + " \"" + properties.Path + "\" with encoding \"" + properties.Encoding + "\", format \"" + format.Name + "\" and frame rate \"" + subtitles.Properties.CurrentFrameRate + "\""); }
/// <summary>Creates a new instance of the <see cref="SubtitleSearchOptions" /> class.</summary> /// <param name="regex">The regular expression to use when searching. It must be created with /// <see cref="RegexOptions.IgnoreCase" /> to perform a case-insensitive search.</param> /// <param name="textType">The type of text content the search is started at.</param> /// <param name="lineBreak">The line break to use between multiple lines of text in each subtitle.</param> /// <param name="startSubtitle">The zero-based number of the subtitle to start the search at.</param> /// <param name="startIndex">The zero-based position within the startSubtitle to start the search at.</param> /// <param name="wrap">Whether to continue the search from the beginning when it reaches the end of the subtitles.</param> /// <param name="backwards">Whether to search backwards. Note that regex must be constructed with the /// <see cref="RegexOptions.RightToLeft" /> option for backwards search to work.</param> public SubtitleSearchOptions(Regex regex, SubtitleTextType textType, string lineBreak, int startSubtitle, int startIndex, bool wrap, bool backwards) { this.regex = regex; this.textType = textType; this.lineBreak = lineBreak; this.startSubtitle = startSubtitle; this.startIndex = startIndex; this.wrap = wrap; this.backwards = backwards; }
public int GetActiveLanguageIndex(SubtitleTextType textType) { if (textType == SubtitleTextType.Text) { return(activeTextLanguageIndex); } else { return(activeTranslationLanguageIndex); } }
private void SetActiveLanguageInConfig(SubtitleTextType textType, string activeLanguage) { if (textType == SubtitleTextType.Text) { Base.Config.SpellCheckTextLanguage = activeLanguage; } else { Base.Config.SpellCheckTranslationLanguage = activeLanguage; } }
private void SelectActiveLanguage (SubtitleTextType textType) { int count = store.IterNChildren(); if (count == 0) return; int activeLanguageIndex = GetActiveLanguageIndex(textType, count); TreePath path = Core.Util.IntToPath(activeLanguageIndex); languagesTreeView.ScrollToCell(path, null, true, 0.5f, 0.5f); languagesTreeView.SetCursor(path, null, false); }
private void EmitLanguageChanged(SubtitleTextType textType) { if (textType == SubtitleTextType.Text) { EmitTextLanguageChanged(); } else { EmitTranslationLanguageChanged(); } }
private SubtitleSearchResults MatchValues(Match match, int subtitleNumber, SubtitleTextType textType, int charsBeforeMatchInput) { if (match.Success) { return(new SubtitleSearchResults(subtitleNumber, textType, match.Index + charsBeforeMatchInput, match.Length)); } else { return(null); } }
public void TextFocusOnSelection(int startIndex, int endIndex, SubtitleTextType textType) { if (textType == SubtitleTextType.Text) { textEdit.FocusOnSelection(startIndex, endIndex); } else { translationEdit.FocusOnSelection(startIndex, endIndex); } }
private int GetActiveLanguageIndex(SubtitleTextType textType, int count) { int activeLanguageIndex = Base.SpellLanguages.GetActiveLanguageIndex(textType); /* Set active language to the first if invalid */ if ((activeLanguageIndex == -1) || (activeLanguageIndex >= count)) { activeLanguageIndex = 0; } return(activeLanguageIndex); }
internal SubtitleText GetSubtitleText(int subtitleNumber, SubtitleTextType textType) { Subtitle subtitle = collection[subtitleNumber]; if (textType == SubtitleTextType.Text) { return(subtitle.Text); } else { return(subtitle.Translation); } }
/// <summary>Gets the indexes of the current text selection.</summary> /// <param name="start">The start of the selection.</param> /// <param name="end">The end of the selection.</param> /// <param name="textType">The type of text content selected.</param> /// <remarks>If no subtitle is being edited, both indexes are set to zero. /// If no text is selected, both indexes are set to the position of the cursor.</remarks> private void GetTextContentSelectionIndexes(out int start, out int end, out SubtitleTextType textType) { if (Base.Ui.Edit.Enabled && Base.Ui.Edit.TextOrTranslationIsFocus) { Base.Ui.Edit.GetTextSelectionBounds(out start, out end, out textType); } else { start = 0; end = 0; textType = SubtitleTextType.Text; } }
protected SubtitleFileSaveAsDialog (SubtitleTextType textType) : base(gladeFilename) { dialog = GetDialog() as FileChooserDialog; this.textType = textType; SetTitle(); InitEncodingComboBox(); InitFormatComboBox(); InitNewlineComboBox(); SetDialogFromFileProperties(); ConnectHandlers(); }
/* Public methods */ /// <summary>Saves subtitles to the file with the specified properties.</summary> /// <param name="subtitles">The subtitles to save.</param> /// <param name="properties">The properties of the file to save the subtitles to. Its <see cref="TimingMode" /> property is used to /// choose the timing mode for subtitle formats that support both time and frame modes.</param> /// <param name="textType">The type of text content to save.</param> /// <remarks>An updated <see cref="SubLib.FileProperties" /> object can be accessed with <see cref="FileProperties" /> after saving.</remarks> public void Save(Subtitles subtitles, FileProperties properties, SubtitleTextType textType) { SubtitleFormat format = BuiltInSubtitleFormats.GetFormat(properties.SubtitleType); SubtitleOutput output = new SubtitleOutput(format, textType); string text = output.Build(subtitles.Collection, subtitles.Properties, properties); FileInputOutput.WriteFile(properties.Path, text, properties.Encoding); fileProperties = GetUpdatedFileProperties(properties); Logger.Info("[SubtitleSaver] Saved {0} \"{1}\" with encoding \"{2}\", format \"{3}\" and frame rate \"{4}\"", textType, properties.Path, properties.Encoding, format.Name, subtitles.Properties.CurrentFrameRate); }
public void SetPosition(SubtitleTextType textType, int lineNumber, int columnNumber) { //To translators: Trans corresponds to Translation (used here to denote whether text or translation is being edited). string type = (textType == SubtitleTextType.Text ? Catalog.GetString("Text") : Catalog.GetString("Trans")); //To translators: Ln corresponds to Line string line = Catalog.GetString("Ln"); //To translators: Col corresponds to Column string column = Catalog.GetString("Col"); string message = type + " " + line + " " + lineNumber + ", " + column + " " + columnNumber; ClearStatus(positionStatus); positionStatus.Push(0, message); }
private void SelectActiveLanguage(TreeView treeView, SubtitleTextType textType) { int count = treeView.Model.IterNChildren(); if (count == 0) { return; } int activeLanguageIndex = GetActiveLanguageIndex(textType, count); TreePath path = Core.Util.IntToPath(activeLanguageIndex); treeView.ScrollToCell(path, null, true, 0.5f, 0.5f); treeView.SetCursor(path, null, false); }
public bool GetTextSelectionBounds(out int start, out int end, out SubtitleTextType textType) { if (textEdit.IsFocus) { textType = SubtitleTextType.Text; return(textEdit.GetTextSelectionBounds(out start, out end)); } else if (translationEdit.IsFocus) { textType = SubtitleTextType.Translation; return(translationEdit.GetTextSelectionBounds(out start, out end)); } else { textType = SubtitleTextType.Text; start = -1; end = -1; return(false); } }
public SaveConfirmationDialog(string primaryText, SubtitleTextType textType) : base() { this.textType = textType; string filename = String.Empty; if (textType == SubtitleTextType.Text) { filename = Base.Document.TextFile.Filename; } else if (Base.Document.HasTranslationFileProperties) { filename = Base.Document.TranslationFile.Filename; } else { filename = Base.Document.UnsavedTranslationFilename; } SetText(primaryText, secondaryText, filename); }
internal SubtitleOutput(SubtitleFormat format, SubtitleTextType textType) { this.format = format; this.textType = textType; }
private void SetIntroLabel (SubtitleTextType textType) { introLabel.TextWithMnemonic = (textType == SubtitleTextType.Text ? introLabelText : introLabelTranslation); }
internal SubtitleOutput (SubtitleFormat format, SubtitleTextType textType) { this.format = format; this.textType = textType; }
public SpellLanguage GetActiveLanguage(SubtitleTextType textType) { int index = GetActiveLanguageIndex(textType); return(GetLanguage(index)); }
/// <summary>Selects a <see cref="TreePath" />, activates it and selects text in the subtitle it refers to.</summary> /// <param name="path">The path to select. If it's null, all paths will be unselected.</param> /// <param name="align">Whether to align the selected path to the center if the path isn't visible and scrolling is needed.</param> /// <param name="reselect">Whether to reselect the path if it's already the only selected path.</param> /// <param name="start">The index to start the text selection with. This is also where the cursor is positioned.</param> /// <param name="end">The index to start the text selection with. This is also where the cursor is positioned.</param> /// <param name="textType">The type of text content to select.</param> public void Select(TreePath path, bool align, bool reselect, int start, int end, SubtitleTextType textType) { if (path == null) { UnselectAll(); return; } Select(path, align, reselect); Core.Base.Ui.Edit.TextFocusOnSelection(start, end, textType); }
private SubtitleSearchResults MatchValues (Match match, int subtitleNumber, SubtitleTextType textType, int charsBeforeMatchInput) { if (match.Success) { return new SubtitleSearchResults(subtitleNumber, textType, match.Index + charsBeforeMatchInput, match.Length); } else return null; }
private SubtitleSearchResults FindInTextContentFromIndex (int subtitleNumber, string lineBreak, Regex regex, int startIndex, SubtitleTextType textType) { SubtitleText text = subtitles.GetSubtitleText(subtitleNumber, textType); return MatchValues(regex.Match(text.Get(lineBreak), startIndex), subtitleNumber, textType, 0); }
/// <returns>The <see cref="SubtitleSearchResults" />, or null if the text was not found.</returns> private SubtitleSearchResults FindInSubtitleTillIndex(int subtitleNumber, string lineBreak, Regex regex, int endIndex, SubtitleTextType textType, bool backwards) { if (backwards) { if (textType == SubtitleTextType.Text) { /* Find first in the translation */ SubtitleSearchResults results = FindInTextContent(subtitleNumber, lineBreak, regex, SubtitleTextType.Translation); if (results != null) { return(results); } /* Not found in the text, finding in the text till the specified index */ return(FindInTextContentTillIndex(subtitleNumber, lineBreak, regex, endIndex, SubtitleTextType.Text, backwards)); } else { /* Find in the translation till specified index */ return(FindInTextContentTillIndex(subtitleNumber, lineBreak, regex, endIndex, SubtitleTextType.Translation, backwards)); } } else { if (textType == SubtitleTextType.Text) { /* Find in the text ending at the specified index */ return(FindInTextContentTillIndex(subtitleNumber, lineBreak, regex, endIndex, SubtitleTextType.Text, backwards)); } else { /* Find first in the text */ SubtitleSearchResults results = FindInTextContent(subtitleNumber, lineBreak, regex, SubtitleTextType.Text); if (results != null) { return(results); } /* Not found in the text, finding in the translation till the specified index */ return(FindInTextContentTillIndex(subtitleNumber, lineBreak, regex, endIndex, SubtitleTextType.Translation, backwards)); } } }
private SubtitleSearchResults FindInTextContentTillIndex (int subtitleNumber, string lineBreak, Regex regex, int endIndex, SubtitleTextType textType, bool backwards) { SubtitleText text = subtitles.GetSubtitleText(subtitleNumber, textType); string subtitleText = text.Get(lineBreak); if (backwards) { string subtitleTextSubstring = subtitleText.Substring(endIndex); return MatchValues(regex.Match(subtitleTextSubstring), subtitleNumber, textType, endIndex); } else { string subtitleTextSubstring = subtitleText.Substring(0, endIndex); return MatchValues(regex.Match(subtitleTextSubstring), subtitleNumber, textType, 0); } }
/// <returns>The <see cref="SubtitleSearchResults" />, or null if the text was not found.</returns> private SubtitleSearchResults FindInSubtitleTillIndex (int subtitleNumber, string lineBreak, Regex regex, int endIndex, SubtitleTextType textType, bool backwards) { if (backwards) { if (textType == SubtitleTextType.Text) { /* Find first in the translation */ SubtitleSearchResults results = FindInTextContent(subtitleNumber, lineBreak, regex, SubtitleTextType.Translation); if (results != null) return results; /* Not found in the text, finding in the text till the specified index */ return FindInTextContentTillIndex(subtitleNumber, lineBreak, regex, endIndex, SubtitleTextType.Text, backwards); } else { /* Find in the translation till specified index */ return FindInTextContentTillIndex(subtitleNumber, lineBreak, regex, endIndex, SubtitleTextType.Translation, backwards); } } else { if (textType == SubtitleTextType.Text) { /* Find in the text ending at the specified index */ return FindInTextContentTillIndex(subtitleNumber, lineBreak, regex, endIndex, SubtitleTextType.Text, backwards); } else { /* Find first in the text */ SubtitleSearchResults results = FindInTextContent(subtitleNumber, lineBreak, regex, SubtitleTextType.Text); if (results != null) return results; /* Not found in the text, finding in the translation till the specified index */ return FindInTextContentTillIndex(subtitleNumber, lineBreak, regex, endIndex, SubtitleTextType.Translation, backwards); } } }
public void SetActiveLanguage(SubtitleTextType textType, string languageID) { int index = GetLanguageIndex(languageID); SetActiveLanguageIndex(textType, index); }
private void SetDialogTitle (SubtitleTextType textType) { GetDialog().Title = (textType == SubtitleTextType.Text ? dialogTitleText : dialogTitleTranslation); }
private bool SaveFile (SubLib.Core.Domain.Subtitles subtitles, FileProperties properties, SubtitleTextType textType) { try { SubtitleSaver saver = new SubtitleSaver(); saver.Save(subtitles, properties, textType); return true; } catch (Exception e) { Console.Error.WriteLine("Caught exception saving backup file: " + e); return false; } }
public SaveSubtitlesOnCloseFileConfirmationDialog(string primaryText, SubtitleTextType textType) : base(primaryText, textType) { }
private SubtitleSearchResults FindInTextContentFromIndex(int subtitleNumber, string lineBreak, Regex regex, int startIndex, SubtitleTextType textType) { SubtitleText text = subtitles.GetSubtitleText(subtitleNumber, textType); return(MatchValues(regex.Match(text.Get(lineBreak), startIndex), subtitleNumber, textType, 0)); }
/// <summary>Creates a new instance of the <see cref="SubtitleSearchOptions" /> class.</summary> /// <param name="regex">The regular expression to use when searching. It must be created with /// <see cref="RegexOptions.IgnoreCase" /> to perform a case-insensitive search.</param> /// <param name="textType">The type of text content the search is started at.</param> /// <param name="startSubtitle">The zero-based number of the subtitle to start the search at.</param> /// <param name="startIndex">The zero-based position within the startSubtitle to start the search at.</param> /// <param name="wrap">Whether to continue the search from the beginning when it reaches the end of the subtitles.</param> /// <param name="backwards">Whether to search backwards. Note that regex must be constructed with the /// <see cref="RegexOptions.RightToLeft" /> option for backwards search to work.</param> /// <remarks>The newline character (\n) is used as lineBreak.</remarks> public SubtitleSearchOptions(Regex regex, SubtitleTextType textType, int startSubtitle, int startIndex, bool wrap, bool backwards) : this(regex, textType, "\n", startSubtitle, startIndex, wrap, backwards) { }
private bool SaveFile(SubLib.Core.Domain.Subtitles subtitles, FileProperties properties, SubtitleTextType textType) { try { SubtitleSaver saver = new SubtitleSaver(); saver.Save(subtitles, properties, textType); return(true); } catch (Exception e) { Logger.Error(e, "Caught an exception while saving backup file"); return(false); } }
/// <summary>Creates a new instance of the <see cref="SubtitleSearchOptions" /> class.</summary> /// <param name="regex">The regular expression to use when searching. It must be created with /// <see cref="RegexOptions.IgnoreCase" /> to perform a case-insensitive search.</param> /// <param name="textType">The type of text content the search is started at.</param> /// <param name="startSubtitle">The zero-based number of the subtitle to start the search at.</param> /// <param name="startIndex">The zero-based position within the startSubtitle to start the search at.</param> /// <param name="wrap">Whether to continue the search from the beginning when it reaches the end of the subtitles.</param> /// <param name="backwards">Whether to search backwards. Note that regex must be constructed with the /// <see cref="RegexOptions.RightToLeft" /> option for backwards search to work.</param> /// <remarks>The newline character (\n) is used as lineBreak.</remarks> public SubtitleSearchOptions (Regex regex, SubtitleTextType textType, int startSubtitle, int startIndex, bool wrap, bool backwards) : this(regex, textType, "\n", startSubtitle, startIndex, wrap, backwards) { }
private SubtitleSearchResults FindInTextContentTillIndex(int subtitleNumber, string lineBreak, Regex regex, int endIndex, SubtitleTextType textType, bool backwards) { SubtitleText text = subtitles.GetSubtitleText(subtitleNumber, textType); string subtitleText = text.Get(lineBreak); if (backwards) { string subtitleTextSubstring = subtitleText.Substring(endIndex); return(MatchValues(regex.Match(subtitleTextSubstring), subtitleNumber, textType, endIndex)); } else { string subtitleTextSubstring = subtitleText.Substring(0, endIndex); return(MatchValues(regex.Match(subtitleTextSubstring), subtitleNumber, textType, 0)); } }
internal SubtitleText GetSubtitleText (int subtitleNumber, SubtitleTextType textType) { Subtitle subtitle = collection[subtitleNumber]; if (textType == SubtitleTextType.Text) return subtitle.Text; else return subtitle.Translation; }
/// <summary>Creates a new instance of the <see cref="SubtitleSearchResults" /> class.</summary> /// <param name="subtitle">The zero-based number of the subtitle where the text was found.</param> /// <param name="textType">The type of text content where the text was found.</param> /// <param name="index">The zero-based position where the text was found, within a subtitle.</param> /// <param name="length">The length of the found text.</param> public SubtitleSearchResults (int subtitle, SubtitleTextType textType, int index, int length) { this.subtitle = subtitle; this.textType = textType; this.index = index; this.length = length; }