[gnome-subtitles] Fix bug #601195 - Subtitle loop. If Subtitle Loop and Auto Select Subtitle are both selected, for mu



commit 2d0ff216daae97bdf9e31ed4210c3c28994f2a2e
Author: Pedro Castro <mail pedrocastro org>
Date:   Sun Jul 25 11:43:28 2010 +0100

    Fix bug #601195 - Subtitle loop.
    If Subtitle Loop and Auto Select Subtitle are both selected, for multiple selection
    Subtitle Loop will prevail as the subtitle will already be selected. It won't be in editing
    state, though, due to multiple selection.

 src/Glade/MainWindow.glade                      |    4 +-
 src/GnomeSubtitles/Core/EventHandlers.cs        |    4 +-
 src/GnomeSubtitles/Ui/Menus.cs                  |    2 -
 src/GnomeSubtitles/Ui/VideoPreview/Video.cs     |   38 +++++++++++------------
 src/GnomeSubtitles/Ui/View/SubtitleSelection.cs |   19 +++++++++--
 src/GnomeSubtitles/Ui/View/SubtitleView.cs      |    9 ++---
 6 files changed, 41 insertions(+), 35 deletions(-)
---
diff --git a/src/Glade/MainWindow.glade b/src/Glade/MainWindow.glade
index 8916684..0484fa8 100644
--- a/src/Glade/MainWindow.glade
+++ b/src/Glade/MainWindow.glade
@@ -817,7 +817,7 @@
                     <child>
                       <widget class="GtkCheckMenuItem" id="videoLoopSelectionPlayback">
                         <property name="visible">True</property>
-                        <property name="label" translatable="yes">Loop Selection Playback</property>
+                        <property name="label" translatable="yes">_Loop Selection</property>
                         <property name="use_underline">True</property>
                         <signal name="toggled" handler="OnVideoLoopSelectionPlayback"/>
                         <accelerator key="F11" signal="activate" modifiers="GDK_CONTROL_MASK"/>
@@ -909,7 +909,7 @@
                     <child>
                       <widget class="GtkCheckMenuItem" id="videoAutoSelectSubtitles">
                         <property name="visible">True</property>
-                        <property name="label" translatable="yes">Auto Select Subtitles</property>
+                        <property name="label" translatable="yes">Auto Select Subtitle</property>
                         <property name="use_underline">True</property>
                         <signal name="toggled" handler="OnVideoAutoSelectSubtitles"/>
                         <accelerator key="j" signal="activate" modifiers="GDK_CONTROL_MASK"/>
diff --git a/src/GnomeSubtitles/Core/EventHandlers.cs b/src/GnomeSubtitles/Core/EventHandlers.cs
index e63a64d..d428ea5 100644
--- a/src/GnomeSubtitles/Core/EventHandlers.cs
+++ b/src/GnomeSubtitles/Core/EventHandlers.cs
@@ -271,11 +271,11 @@ public class EventHandlers {
 	}
 		
 	public void OnVideoAutoSelectSubtitles (object o, EventArgs args) {
-		Base.Ui.View.SetAutoSelectSubtitles();
+		Base.Ui.View.SetAutoSelectSubtitles((o as CheckMenuItem).Active);
  	}
 		
 	public void OnVideoLoopSelectionPlayback (object o, EventArgs args) {
-		Base.Ui.Video.SetLoopSelectionPlayback();
+		Base.Ui.Video.SetLoopSelectionPlayback((o as CheckMenuItem).Active);
  	}
 		
 	public void OnVideoSetSubtitleStart (object o, EventArgs args) {
diff --git a/src/GnomeSubtitles/Ui/Menus.cs b/src/GnomeSubtitles/Ui/Menus.cs
index 1d78ae1..3c8ed47 100644
--- a/src/GnomeSubtitles/Ui/Menus.cs
+++ b/src/GnomeSubtitles/Ui/Menus.cs
@@ -289,13 +289,11 @@ public class Menus {
 			SetSensitivity(WidgetNames.VideoSeekToSelection, true);
 			SetSensitivity(WidgetNames.VideoSetSubtitleStart, true);
 			SetSensitivity(WidgetNames.VideoSetSubtitleEnd, true);
-			SetSensitivity(WidgetNames.VideoAutoSelectSubtitles, true);
 		}
 		else {
 			SetSensitivity(WidgetNames.VideoSeekToSelection, false);
 			SetSensitivity(WidgetNames.VideoSetSubtitleStart, false);
 			SetSensitivity(WidgetNames.VideoSetSubtitleEnd, false);
-			SetSensitivity(WidgetNames.VideoAutoSelectSubtitles, false);
 		}
 	}
 	
diff --git a/src/GnomeSubtitles/Ui/VideoPreview/Video.cs b/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
index b3ffc70..23bac39 100644
--- a/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
+++ b/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
@@ -139,12 +139,11 @@ public class Video {
 		player.Close();
 	}
 		
-	public void SetLoopSelectionPlayback(){
-			CheckMenuItem loopSelectionPlayback = Base.GetWidget(WidgetNames.VideoLoopSelectionPlayback) as CheckMenuItem;
-		if (loopSelectionPlayback.Active)
-			Base.Ui.Video.Position.Changed += OnVideoPositionChanged;
+	public void SetLoopSelectionPlayback (bool enabled){
+		if (enabled)
+			Base.Ui.Video.Position.Changed += OnVideoPositionChangedLoopPlayback;
 		else
-			Base.Ui.Video.Position.Changed -= OnVideoPositionChanged;
+			Base.Ui.Video.Position.Changed -= OnVideoPositionChangedLoopPlayback;
 	}
 	
 	public void Rewind () {
@@ -187,7 +186,7 @@ public class Video {
 	
 	public void SelectNearestSubtitle () {		
 		int indexToSelect = tracker.FindSubtitleNearPosition(position.CurrentTime);
-		Base.Ui.View.Selection.Select(indexToSelect, false, false);
+		Base.Ui.View.Selection.Select(indexToSelect, true, true);
 	}
 	
 	/* Private methods */
@@ -335,20 +334,19 @@ public class Video {
 			SetSelectionDependentControlsSensitivity(false);
 	}
 	
-	private void OnVideoPositionChanged (TimeSpan position) {
-			
-			
-			Subtitle firstSubtitle = Core.Base.Ui.View.Selection.FirstSubtitle;
-			Subtitle lastSubtitle = Core.Base.Ui.View.Selection.LastSubtitle;
-			
-			if( firstSubtitle != null ){
-				
-				double startTime = firstSubtitle.Times.Start.TotalSeconds;
-				double endTime = lastSubtitle.Times.End.TotalSeconds;
-				
-				if( position.TotalSeconds < startTime || position.TotalSeconds > endTime )
-					SeekToSelection();
-			}
+	/// <summary>Do loop playback when it's enabled, seeking to current selection on video position change.</summary>
+	private void OnVideoPositionChangedLoopPlayback (TimeSpan position) {
+		if (!(Base.IsDocumentLoaded))
+			return;
+
+		Subtitle firstSubtitle = Core.Base.Ui.View.Selection.FirstSubtitle;
+		if (firstSubtitle == null)
+			return;
+
+		Subtitle lastSubtitle = Core.Base.Ui.View.Selection.LastSubtitle;
+
+		if ((position < firstSubtitle.Times.Start) || (position > lastSubtitle.Times.End))
+			SeekToSelection();
 	}
 
 }
diff --git a/src/GnomeSubtitles/Ui/View/SubtitleSelection.cs b/src/GnomeSubtitles/Ui/View/SubtitleSelection.cs
index a28e2b8..1c1a6be 100644
--- a/src/GnomeSubtitles/Ui/View/SubtitleSelection.cs
+++ b/src/GnomeSubtitles/Ui/View/SubtitleSelection.cs
@@ -225,26 +225,37 @@ public class SubtitleSelection {
     /// <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="checkAllPaths">If multiple paths are selected and reselect isn't required, check if the current path is contained in the selection.
+    /// If the subtitle is within the selection but we want to guarantee that only that single subtitle is selected, set this to false.</param>
     /// <remarks>The input focus will be placed on the path.</remarks>
-    public void Select (TreePath path, bool align, bool reselect) {
+    public void Select (TreePath path, bool align, bool reselect, bool checkAllPaths) {
    		if (path == null) {
    			UnselectAll();
    			return;
    		}
-   		if ((!reselect) && (Count == 1) && (selection.PathIsSelected(path))) //No reselection is required and path is already the only selected path
+   		
+   		if ((!reselect) && (checkAllPaths || (Count == 1)) && (selection.PathIsSelected(path))) //No reselection is required and path is already the only selected path
    			return;
 
 		SetFocus(path, align);
 	}
 	
+	public void Select (TreePath path, bool align, bool reselect) {
+		Select(path, align, reselect, false);
+	}
+	
 	/// <summary>Selects the specified index, possibly aligning it to the center and/or reselecting it.</summary>
 	/// <param name="index">The index of the subtitle to select.</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>
     /// <remarks>The subtitle is only selected if it exists. The input focus will be placed on the path.</remarks>
-    public void Select (int index, bool align, bool reselect) {
+    public void Select (int index, bool align, bool reselect, bool checkAllPaths) {
     	if ((index >= 0) && (index < Base.Document.Subtitles.Count))
-    		Select(Util.IntToPath(index), align, reselect);
+    		Select(Util.IntToPath(index), align, reselect, checkAllPaths);
+	}
+	
+	public void Select (int index, bool align, bool reselect) {
+		Select(index, align, reselect, false);
 	}
 	
 	/// <summary>Selects a <see cref="TreePath" />, activates it and selects text in the subtitle it refers to.</summary>
diff --git a/src/GnomeSubtitles/Ui/View/SubtitleView.cs b/src/GnomeSubtitles/Ui/View/SubtitleView.cs
index 392f09e..28a35b8 100644
--- a/src/GnomeSubtitles/Ui/View/SubtitleView.cs
+++ b/src/GnomeSubtitles/Ui/View/SubtitleView.cs
@@ -71,9 +71,8 @@ public class SubtitleView {
     
     /* Public methods */ 
 	
-	public void SetAutoSelectSubtitles(){
-		CheckMenuItem autoSelectSubtitles = Base.GetWidget(WidgetNames.VideoAutoSelectSubtitles) as CheckMenuItem;
-		if (autoSelectSubtitles.Active)
+	public void SetAutoSelectSubtitles (bool active) {
+		if (active)
 			Base.Ui.Video.Tracker.SubtitleChanged += OnCurrentSubtitleChanged;
 		else
 			Base.Ui.Video.Tracker.SubtitleChanged -= OnCurrentSubtitleChanged;
@@ -388,8 +387,8 @@ public class SubtitleView {
 			SubtitleCountChanged(subtitles.Count);
 	}
 	
-	private void OnCurrentSubtitleChanged (int subtitleIndex) {			
-		selection.Select(subtitleIndex, false, false);
+	private void OnCurrentSubtitleChanged (int subtitleIndex) {		
+		selection.Select(subtitleIndex, false, false, true);
 	}
 
     private void SetEmptyModel () {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]