[gnome-subtitles] Show line lengths in the subtitle list, option configurable in the View menu (related to bug #625485
- From: Pedro Daniel da Rocha Melo e Castro <pcastro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-subtitles] Show line lengths in the subtitle list, option configurable in the View menu (related to bug #625485
- Date: Tue, 28 Dec 2010 23:28:59 +0000 (UTC)
commit 119ea323570ccd49058f46cd6835054bacca601c
Author: Pedro Castro <mail pedrocastro org>
Date: Mon Dec 27 06:44:29 2010 -0800
Show line lengths in the subtitle list, option configurable in the View menu (related to bug #625485)
data/gnome-subtitles.schemas | 11 ++++
gnome-subtitles.mdp | 2 +-
m4/intltool.m4 | 2 +-
src/Glade/MainWindow.glade | 14 +++++-
src/GnomeSubtitles/Core/Config.cs | 7 +++
src/GnomeSubtitles/Core/EventHandlers.cs | 3 +-
src/GnomeSubtitles/Ui/Menus.cs | 24 +++++++++-
src/GnomeSubtitles/Ui/View/SubtitleView.cs | 71 ++++++++++++++++++----------
src/GnomeSubtitles/Ui/WidgetNames.cs | 1 +
src/SubLib/Core/Domain/SubtitleText.cs | 6 ++-
10 files changed, 109 insertions(+), 32 deletions(-)
---
diff --git a/data/gnome-subtitles.schemas b/data/gnome-subtitles.schemas
index 439dfa1..d7e3811 100644
--- a/data/gnome-subtitles.schemas
+++ b/data/gnome-subtitles.schemas
@@ -36,6 +36,17 @@
</locale>
</schema>
<schema>
+ <key>/schemas/apps/gnome-subtitles/preferences/view/line_lengths</key>
+ <applyto>/apps/gnome-subtitles/preferences/view/line_lengths</applyto>
+ <owner>gnome-subtitles</owner>
+ <type>bool</type>
+ <default>TRUE</default>
+ <locale name="C">
+ <short>View line lengths</short>
+ <long>Whether to view line lengths as characters counts in the subtitle list.</long>
+ </locale>
+ </schema>
+ <schema>
<key>/schemas/apps/gnome-subtitles/preferences/spellcheck/active_text_language</key>
<applyto>/apps/gnome-subtitles/preferences/spellcheck/active_text_language</applyto>
<owner>gnome-subtitles</owner>
diff --git a/gnome-subtitles.mdp b/gnome-subtitles.mdp
index cbade67..3c1c826 100644
--- a/gnome-subtitles.mdp
+++ b/gnome-subtitles.mdp
@@ -2,7 +2,6 @@
<Policies>
<TextStylePolicy FileWidth="120" TabWidth="4" RemoveTrailingWhitespace="True" EolMarker="Unix" inheritsSet="Mono" inheritsScope="text/plain" />
</Policies>
- <Deployment.LinuxDeployData generateScript="False" />
<Configurations active="Debug">
<Configuration name="Debug" ctype="DotNetProjectConfiguration">
<Output directory="build" assembly="gnome-subtitles" assemblyKeyFile="/home/noup/Workspace/gnome-subtitles/." />
@@ -262,5 +261,6 @@
<ProjectReference type="Gac" localcopy="True" refto="gconf-sharp, Version=2.24.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
</References>
<LanguageParameters StartupObject="GnomeSubtitles.Execution.Executable" ApplicationIcon="." ctype="CSharpProjectParameters" />
+ <Deployment.LinuxDeployData generateScript="False" />
<DeploymentInformation strategy="File" />
</Project>
\ No newline at end of file
diff --git a/m4/intltool.m4 b/m4/intltool.m4
index 839e855..122d773 100644
--- a/m4/intltool.m4
+++ b/m4/intltool.m4
@@ -172,7 +172,7 @@ IT_PO_SUBDIR([po])
AC_DEFUN([IT_PO_SUBDIR],
[AC_PREREQ([2.53])dnl We use ac_top_srcdir inside AC_CONFIG_COMMANDS.
dnl
-dnl The following CONFIG_COMMANDS should be executed at the very end
+dnl The following CONFIG_COMMANDS should be exetuted at the very end
dnl of config.status.
AC_CONFIG_COMMANDS_PRE([
AC_CONFIG_COMMANDS([$1/stamp-it], [
diff --git a/src/Glade/MainWindow.glade b/src/Glade/MainWindow.glade
index 2476873..545a245 100644
--- a/src/Glade/MainWindow.glade
+++ b/src/Glade/MainWindow.glade
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0"?>
<glade-interface>
<!-- interface-requires gtk+ 2.16 -->
<!-- interface-naming-policy toplevel-contextual -->
@@ -460,6 +460,18 @@
</widget>
</child>
<child>
+ <widget class="GtkCheckMenuItem" id="viewLineLengths">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Line Lengths</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkSeparatorMenuItem" id="viewSeparator2">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+ <child>
<widget class="GtkCheckMenuItem" id="viewVideo">
<property name="visible">True</property>
<property name="label" translatable="yes">_Video</property>
diff --git a/src/GnomeSubtitles/Core/Config.cs b/src/GnomeSubtitles/Core/Config.cs
index 9a59e90..bca87e6 100644
--- a/src/GnomeSubtitles/Core/Config.cs
+++ b/src/GnomeSubtitles/Core/Config.cs
@@ -42,6 +42,7 @@ public class Config {
private const string keyPrefsEncodings = keyPrefs + "encodings/";
private const string keyPrefsSpellCheck = keyPrefs + "spellcheck/";
private const string keyPrefsVideo = keyPrefs + "video/";
+ private const string keyPrefsView = keyPrefs + "view/";
private const string keyPrefsWindow = keyPrefs + "window/";
private const string keyPrefsDefaults = keyPrefs + "defaults/";
private const string keyPrefsTranslation = keyPrefs + "translation/";
@@ -51,6 +52,7 @@ public class Config {
private const string keyPrefsEncodingsShownInMenu = keyPrefsEncodings + "shown_in_menu";
private const string keyPrefsTranslationSaveAll = keyPrefsTranslation + "save_all";
private const string keyPrefsVideoAutoChooseFile = keyPrefsVideo + "auto_choose_file";
+ private const string keyPrefsViewLineLengths = keyPrefsView + "line_lengths";
private const string keyPrefsSpellCheckActiveTextLanguage = keyPrefsSpellCheck + "active_text_language";
private const string keyPrefsSpellCheckActiveTranslationLanguage = keyPrefsSpellCheck + "active_translation_language";
private const string keyPrefsSpellCheckAutocheck = keyPrefsSpellCheck + "autocheck";
@@ -103,6 +105,11 @@ public class Config {
set { Set(keyPrefsVideoAutoChooseFile, value); }
}
+ public bool PrefsViewLineLengths {
+ get { return GetBool(keyPrefsViewLineLengths, true); }
+ set { Set(keyPrefsViewLineLengths, value); }
+ }
+
public int PrefsWindowHeight {
get { return GetInt(keyPrefsWindowHeight, 600, 200, true, 0, false); }
set { Set(keyPrefsWindowHeight, value); }
diff --git a/src/GnomeSubtitles/Core/EventHandlers.cs b/src/GnomeSubtitles/Core/EventHandlers.cs
index 6da0a20..770c85d 100644
--- a/src/GnomeSubtitles/Core/EventHandlers.cs
+++ b/src/GnomeSubtitles/Core/EventHandlers.cs
@@ -170,8 +170,7 @@ public class EventHandlers {
Base.Ui.Video.Show();
else
Base.Ui.Video.Hide();
- }
-
+ }
public void OnViewVideoSubtitlesText (object o, EventArgs args) {
if ((o as RadioMenuItem).Active)
diff --git a/src/GnomeSubtitles/Ui/Menus.cs b/src/GnomeSubtitles/Ui/Menus.cs
index 5481c7d..7dbde8e 100644
--- a/src/GnomeSubtitles/Ui/Menus.cs
+++ b/src/GnomeSubtitles/Ui/Menus.cs
@@ -31,6 +31,9 @@ public class Menus {
/* Constant strings */
private string videoTagText = Catalog.GetString("Video");
+
+ /* Stored values */
+ private bool viewLineLengthsEnabled = false;
public Menus () {
SetToolbarHomogeneity(); //TODO needed until homogeneity definition in glade starts working
@@ -55,6 +58,10 @@ public class Menus {
}
}
+ public bool ViewLineLengthsEnabled {
+ get { return viewLineLengthsEnabled; }
+ }
+
/* Public methods */
@@ -151,9 +158,13 @@ public class Menus {
SetSensitivity(WidgetNames.TimingsShift, true);
}
}
-
+
private void SetBlankActivity () {
SetCheckMenuItemActivity(WidgetNames.ToolsAutocheckSpelling, Base.SpellLanguages.Enabled);
+
+ /* Set View Line Lengths */
+ this.viewLineLengthsEnabled = Base.Config.PrefsViewLineLengths;
+ SetCheckMenuItemActivity(WidgetNames.ViewLineLengths, this.viewLineLengthsEnabled);
}
private void SetViewVideoActivity (bool activity) {
@@ -501,6 +512,8 @@ public class Menus {
Base.CommandManager.UndoToggled += OnCommandManagerUndoToggled;
Base.CommandManager.RedoToggled += OnCommandManagerRedoToggled;
Base.CommandManager.CommandActivated += OnCommandManagerCommandActivated;
+
+ (Base.GetWidget(WidgetNames.ViewLineLengths) as CheckMenuItem).Toggled += OnViewLineLengthsToggled;
}
private void OnBaseDocumentLoaded (Document document) {
@@ -623,6 +636,15 @@ public class Menus {
menuItem.Toggled -= handler;
}
}
+
+ private void OnViewLineLengthsToggled (object o, EventArgs args) {
+ bool newValue = ((o as CheckMenuItem).Active);
+ if (newValue != viewLineLengthsEnabled) {
+ viewLineLengthsEnabled = newValue;
+ Base.Config.PrefsViewLineLengths = newValue;
+ Base.Ui.View.Refresh();
+ }
+ }
}
diff --git a/src/GnomeSubtitles/Ui/View/SubtitleView.cs b/src/GnomeSubtitles/Ui/View/SubtitleView.cs
index 28a35b8..b1d216b 100644
--- a/src/GnomeSubtitles/Ui/View/SubtitleView.cs
+++ b/src/GnomeSubtitles/Ui/View/SubtitleView.cs
@@ -234,12 +234,12 @@ public class SubtitleView {
int textWidth = Util.ColumnWidth(tree, "0123456789012345678901234567890123456789");
CellRendererText textCellRenderer = new CellRendererText();
textCellRenderer.Alignment = Pango.Alignment.Center;
- textCol = Util.CreateTreeViewColumn(Catalog.GetString("Text"), textWidth, textCellRenderer, RenderTextCell);
+ textCol = Util.CreateTreeViewColumn(Catalog.GetString("Text"), textWidth, textCellRenderer, RenderSubtitleTextCell);
/* Translation column */
CellRendererText translationCellRenderer = new CellRendererText();
translationCellRenderer.Alignment = Pango.Alignment.Center;
- translationCol = Util.CreateTreeViewColumn(Catalog.GetString("Translation"), textWidth, translationCellRenderer, RenderTranslationCell);
+ translationCol = Util.CreateTreeViewColumn(Catalog.GetString("Translation"), textWidth, translationCellRenderer, RenderTranslationTextCell);
SetTranslationVisible(false);
tree.AppendColumn(numberCol);
@@ -300,36 +300,57 @@ public class SubtitleView {
renderer.Text = Util.TimeSpanToText(subtitles[iter].Times.Duration);
}
- private void RenderTextCell (TreeViewColumn column, CellRenderer cell, TreeModel treeModel, TreeIter iter) {
+ private void RenderSubtitleTextCell (TreeViewColumn column, CellRenderer cell, TreeModel treeModel, TreeIter iter) {
Subtitle subtitle = subtitles[iter];
- CellRendererText renderer = cell as CellRendererText;
- renderer.Text = subtitle.Text.GetReplaceEmptyLines(" "); //Replace empty lines with a space so Pango doesn't complain
- SetRendererStyle(renderer, subtitle);
+ RenderTextCell(cell as CellRendererText, iter, subtitle.Text, subtitle.Style);
}
- private void RenderTranslationCell (TreeViewColumn column, CellRenderer cell, TreeModel treeModel, TreeIter iter) {
+ private void RenderTranslationTextCell (TreeViewColumn column, CellRenderer cell, TreeModel treeModel, TreeIter iter) {
Subtitle subtitle = subtitles[iter];
- CellRendererText renderer = cell as CellRendererText;
- renderer.Text = subtitle.Translation.GetReplaceEmptyLines(" "); //Replace empty lines with a space so Pango doesn't complain
- SetRendererStyle(renderer, subtitle);
+ RenderTextCell(cell as CellRendererText, iter, subtitle.Translation, subtitle.Style);
}
-
- private void SetRendererStyle (CellRendererText renderer, Subtitle subtitle) {
- if (subtitle.Style.Italic)
- renderer.Style = Pango.Style.Italic;
- else
- renderer.Style = Pango.Style.Normal;
-
- if (subtitle.Style.Bold)
- renderer.Weight = (int)Pango.Weight.Bold;
- else
- renderer.Weight = (int)Pango.Weight.Normal;
- if (subtitle.Style.Underline)
- renderer.Underline = Pango.Underline.Single;
- else
- renderer.Underline = Pango.Underline.None;
+ private void RenderTextCell (CellRendererText renderer, TreeIter iter, SubtitleText subtitleText, SubLib.Core.Domain.Style subtitleStyle) {
+
+ /* If there's no text, return empty text without line count */
+ if (subtitleText.IsEmpty) {
+ renderer.Text = String.Empty;
+ return;
+ }
+
+ string textMarkup = String.Empty;
+ string stylePrefix = String.Empty;
+ string styleSuffix = String.Empty;
+ GetStyleMarkup(subtitleStyle, ref stylePrefix, ref styleSuffix);
+
+ bool first = true;
+ bool viewLineLengths = Base.Ui.Menus.ViewLineLengthsEnabled;
+ foreach (string line in subtitleText) {
+ textMarkup += (first ? String.Empty : "\n") + stylePrefix + line + styleSuffix + (viewLineLengths ? " <span size=\"small\"><sup>(" + line.Length + ")</sup></span>" : String.Empty);
+ if (first)
+ first = false;
+ }
+
+ renderer.Markup = textMarkup;
}
+
+ private void GetStyleMarkup (SubLib.Core.Domain.Style subtitleStyle, ref string prefix, ref string suffix) {
+ if (subtitleStyle.Italic) {
+ prefix += "<i>";
+ suffix = "</i>" + suffix;
+ }
+
+ if (subtitleStyle.Bold) {
+ prefix += "<b>";
+ suffix = "</b>" + suffix;
+ }
+
+ if (subtitleStyle.Underline) {
+ prefix += "<u>";
+ suffix = "</u>" + suffix;
+ }
+ }
+
/* Event members */
diff --git a/src/GnomeSubtitles/Ui/WidgetNames.cs b/src/GnomeSubtitles/Ui/WidgetNames.cs
index 8647b06..2cb2fff 100644
--- a/src/GnomeSubtitles/Ui/WidgetNames.cs
+++ b/src/GnomeSubtitles/Ui/WidgetNames.cs
@@ -55,6 +55,7 @@ public class WidgetNames {
/* View Menu */
public const string ViewTimes = "viewTimes";
public const string ViewFrames = "viewFrames";
+ public const string ViewLineLengths = "viewLineLengths";
public const string ViewVideo = "viewVideo";
public const string ViewVideoSubtitlesText = "viewVideoSubtitlesText";
public const string ViewVideoSubtitlesTranslation = "viewVideoSubtitlesTranslation";
diff --git a/src/SubLib/Core/Domain/SubtitleText.cs b/src/SubLib/Core/Domain/SubtitleText.cs
index 69c70de..9e8712d 100644
--- a/src/SubLib/Core/Domain/SubtitleText.cs
+++ b/src/SubLib/Core/Domain/SubtitleText.cs
@@ -54,7 +54,11 @@ public class SubtitleText : ICloneable {
/// <summary>Whether there is no text.</summary>
public bool IsEmpty {
- get { return (lines.Count == 0); }
+ get { return ((lines.Count == 0) || ((lines.Count == 1) && ((lines[0] as string).Length == 0))); }
+ }
+
+ public IEnumerator GetEnumerator () {
+ return lines.GetEnumerator();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]