[gnome-subtitles] Allow to set the input framerate when no document is loaded, as it may be used as a parameter when o



commit 71367c8ff84ff9479b281e33491fb34a58285d4d
Author: Pedro Castro <mail pedrocastro org>
Date:   Wed Nov 17 22:44:49 2010 +0000

    Allow to set the input framerate when no document is loaded, as it may be used as a parameter when opening files

 src/Glade/MainWindow.glade                         |   28 +++-------
 .../Core/Command/ChangeFrameRateCommand.cs         |    4 +-
 src/GnomeSubtitles/Core/EventHandlers.cs           |    8 ---
 src/GnomeSubtitles/Ui/Menus.cs                     |   56 +++++++++++++++----
 4 files changed, 55 insertions(+), 41 deletions(-)
---
diff --git a/src/Glade/MainWindow.glade b/src/Glade/MainWindow.glade
index 9bffa7a..b62086c 100644
--- a/src/Glade/MainWindow.glade
+++ b/src/Glade/MainWindow.glade
@@ -248,8 +248,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                         <signal name="activate" handler="OnEditRedo"/>
-                        <accelerator key="Z" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                         <accelerator key="Y" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="Z" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -532,8 +532,8 @@
                         <property name="label" translatable="yes">Find Ne_xt</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnSearchFindNext"/>
-                        <accelerator key="g" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="F3" signal="activate"/>
+                        <accelerator key="g" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -543,8 +543,8 @@
                         <property name="label" translatable="yes">Find Pre_vious</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnSearchFindPrevious"/>
-                        <accelerator key="g" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                         <accelerator key="F3" signal="activate" modifiers="GDK_SHIFT_MASK"/>
+                        <accelerator key="g" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -591,56 +591,46 @@
                             <child>
                               <widget class="GtkRadioMenuItem" id="timingsInputFrameRate23">
                                 <property name="visible">True</property>
-                                <property name="sensitive">False</property>
                                 <property name="label">23.976</property>
                                 <property name="use_underline">True</property>
                                 <property name="draw_as_radio">True</property>
-                                <signal name="toggled" handler="OnTimingsInputFrameRate"/>
                               </widget>
                             </child>
                             <child>
                               <widget class="GtkRadioMenuItem" id="timingsInputFrameRate24">
                                 <property name="visible">True</property>
-                                <property name="sensitive">False</property>
                                 <property name="label">24</property>
                                 <property name="use_underline">True</property>
                                 <property name="draw_as_radio">True</property>
                                 <property name="group">timingsInputFrameRate23</property>
-                                <signal name="toggled" handler="OnTimingsInputFrameRate"/>
                               </widget>
                             </child>
                             <child>
                               <widget class="GtkRadioMenuItem" id="timingsInputFrameRate25">
                                 <property name="visible">True</property>
-                                <property name="sensitive">False</property>
                                 <property name="label">25 (PAL)</property>
                                 <property name="use_underline">True</property>
                                 <property name="active">True</property>
                                 <property name="draw_as_radio">True</property>
                                 <property name="group">timingsInputFrameRate23</property>
-                                <signal name="toggled" handler="OnTimingsInputFrameRate"/>
                               </widget>
                             </child>
                             <child>
                               <widget class="GtkRadioMenuItem" id="timingsInputFrameRate29">
                                 <property name="visible">True</property>
-                                <property name="sensitive">False</property>
                                 <property name="label">29.97 (NTSC)</property>
                                 <property name="use_underline">True</property>
                                 <property name="draw_as_radio">True</property>
                                 <property name="group">timingsInputFrameRate23</property>
-                                <signal name="toggled" handler="OnTimingsInputFrameRate"/>
                               </widget>
                             </child>
                             <child>
                               <widget class="GtkRadioMenuItem" id="timingsInputFrameRate30">
                                 <property name="visible">True</property>
-                                <property name="sensitive">False</property>
                                 <property name="label">30</property>
                                 <property name="use_underline">True</property>
                                 <property name="draw_as_radio">True</property>
                                 <property name="group">timingsInputFrameRate23</property>
-                                <signal name="toggled" handler="OnTimingsInputFrameRate"/>
                               </widget>
                             </child>
                           </widget>
@@ -803,8 +793,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">False</property>
                         <signal name="activate" handler="OnVideoPlayPause"/>
-                        <accelerator key="p" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="F5" signal="activate"/>
+                        <accelerator key="p" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoPlayPauseImage">
                             <property name="visible">True</property>
@@ -831,8 +821,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">False</property>
                         <signal name="activate" handler="OnVideoRewind"/>
-                        <accelerator key="k" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="F6" signal="activate"/>
+                        <accelerator key="k" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoRewindImage">
                             <property name="visible">True</property>
@@ -850,8 +840,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">False</property>
                         <signal name="activate" handler="OnVideoForward"/>
-                        <accelerator key="l" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="F7" signal="activate"/>
+                        <accelerator key="l" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoForwardImage">
                             <property name="visible">True</property>
@@ -891,8 +881,8 @@
                         <property name="label" translatable="yes">Seek _to Selection</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoSeekToSelection"/>
-                        <accelerator key="r" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                         <accelerator key="F4" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
+                        <accelerator key="r" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -902,8 +892,8 @@
                         <property name="label" translatable="yes">Select Nearest Subtitle</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoSelectNearestSubtitle"/>
-                        <accelerator key="F4" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="r" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F4" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -912,8 +902,8 @@
                         <property name="label" translatable="yes">Auto Select Subtitle</property>
                         <property name="use_underline">True</property>
                         <signal name="toggled" handler="OnVideoAutoSelectSubtitles"/>
-                        <accelerator key="F3" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="j" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F3" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
diff --git a/src/GnomeSubtitles/Core/Command/ChangeFrameRateCommand.cs b/src/GnomeSubtitles/Core/Command/ChangeFrameRateCommand.cs
index f426443..3b815da 100644
--- a/src/GnomeSubtitles/Core/Command/ChangeFrameRateCommand.cs
+++ b/src/GnomeSubtitles/Core/Command/ChangeFrameRateCommand.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2009 Pedro Castro
+ * Copyright (C) 2006-2010 Pedro Castro
  *
  * Gnome Subtitles is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -60,7 +60,7 @@ public class ChangeInputFrameRateCommand : ChangeFrameRateCommand {
 	}
 	
 	protected override void UpdateMenuItem () {
-		Base.Ui.Menus.UpdateActiveInputFrameRateMenuItem();
+		Base.Ui.Menus.UpdateActiveInputFrameRateMenuItem(true);
 	}
 }
 
diff --git a/src/GnomeSubtitles/Core/EventHandlers.cs b/src/GnomeSubtitles/Core/EventHandlers.cs
index d428ea5..3da485f 100644
--- a/src/GnomeSubtitles/Core/EventHandlers.cs
+++ b/src/GnomeSubtitles/Core/EventHandlers.cs
@@ -205,14 +205,6 @@ public class EventHandlers {
 
 	/*	Timings Menu */
 	
-	public void OnTimingsInputFrameRate (object o, EventArgs args) {
-		RadioMenuItem menuItem = o as RadioMenuItem;
-		if (menuItem.Active) {
-			float frameRate = Menus.FrameRateFromMenuItem((menuItem.Child as Label).Text);
-			Base.CommandManager.Execute(new ChangeInputFrameRateCommand(frameRate));
-		}
-	}
-	
 	public void OnTimingsVideoFrameRate (object o, EventArgs args) {
 		RadioMenuItem menuItem = o as RadioMenuItem;
 		if (menuItem.Active) {
diff --git a/src/GnomeSubtitles/Ui/Menus.cs b/src/GnomeSubtitles/Ui/Menus.cs
index 3c8ed47..23623b7 100644
--- a/src/GnomeSubtitles/Ui/Menus.cs
+++ b/src/GnomeSubtitles/Ui/Menus.cs
@@ -54,9 +54,12 @@ public class Menus {
 		SetSensitivity(WidgetNames.PasteButton, sensitivity);
 	}
 	
-	public void UpdateActiveInputFrameRateMenuItem () {
+	public void UpdateActiveInputFrameRateMenuItem (bool toggleHandlers) {
 		float inputFrameRate = Base.Document.Subtitles.Properties.OriginalFrameRate;
-		SetCheckMenuItemActivity(InputFrameRateMenuItem(inputFrameRate), true, Base.Handlers.OnTimingsInputFrameRate);
+		if (toggleHandlers)
+			SetCheckMenuItemActivity(InputFrameRateMenuItem(inputFrameRate), true, OnTimingsInputFrameRateToggled);
+		else
+			SetCheckMenuItemActivity(InputFrameRateMenuItem(inputFrameRate), true);
 	}
 	
 	public void UpdateActiveVideoFrameRateMenuItem () {
@@ -218,18 +221,27 @@ public class Menus {
 		SetSensitivity(WidgetNames.ToolsAutocheckSpelling, sensitivity);
 	}
 	
-	private void SetFrameRateMenus () {
-		if (Base.TimingMode == TimingMode.Frames) {
-			SetMenuSensitivity(WidgetNames.TimingsInputFrameRateMenu, true);
-			SetMenuSensitivity(WidgetNames.TimingsVideoFrameRateMenu, true);
+	private void SetFrameRateMenus (bool documentLoaded) {
+		if (documentLoaded) {
+			if (Base.TimingMode == TimingMode.Frames) {
+				UpdateActiveInputFrameRateMenuItem(false);
+				SetMenuSensitivity(WidgetNames.TimingsInputFrameRateMenu, true);
+				SetInputFrameRateMenuHandlers(true);
+				
+				SetMenuSensitivity(WidgetNames.TimingsVideoFrameRateMenu, true);
+				UpdateActiveVideoFrameRateMenuItem();
+			}
+			else {
+				UpdateActiveInputFrameRateMenuItem(false);
+				SetMenuSensitivity(WidgetNames.TimingsInputFrameRateMenu, false);
+
+				SetMenuSensitivity(WidgetNames.TimingsVideoFrameRateMenu, true);
+				UpdateActiveVideoFrameRateMenuItem();
+			}
 		}
 		else {
-			SetMenuSensitivity(WidgetNames.TimingsInputFrameRateMenu, false);
-			SetMenuSensitivity(WidgetNames.TimingsVideoFrameRateMenu, true);
+			SetInputFrameRateMenuHandlers(false);
 		}
-		
-		UpdateActiveInputFrameRateMenuItem();
-		UpdateActiveVideoFrameRateMenuItem();
 	}
 	
 	private void SetStylesActivity (bool bold, bool italic, bool underline) {
@@ -471,13 +483,14 @@ public class Menus {
 	
 	private void OnBaseDocumentLoaded (Document document) {
 		SetDocumentSensitivity(true);
-		SetFrameRateMenus();
+		SetFrameRateMenus(true);
 		SetActiveTimingMode(Base.TimingMode);
 		SetCheckMenuItemActivity(WidgetNames.ToolsAutocheckSpelling, Base.SpellLanguages.Enabled);
 	}
 	
 	private void OnBaseDocumentUnloaded (Document document) {
 		SetDocumentSensitivity(false);
+		SetFrameRateMenus(false);
 	}
 	
 	private void OnBaseVideoLoaded (Uri videoUri) {
@@ -562,6 +575,25 @@ public class Menus {
     private void OnCommandManagerCommandActivated (object o, CommandActivatedArgs args) {
     	UpdateUndoRedoMessages();
     }
+    
+    	
+	private void OnTimingsInputFrameRateToggled (object o, EventArgs args) {
+		RadioMenuItem menuItem = o as RadioMenuItem;
+		if (menuItem.Active) {
+			float frameRate = Menus.FrameRateFromMenuItem((menuItem.Child as Label).Text);
+			Base.CommandManager.Execute(new ChangeInputFrameRateCommand(frameRate));
+		}
+	}
+
+	private void SetInputFrameRateMenuHandlers (bool activate) {
+		Menu menu = Base.GetWidget(WidgetNames.TimingsInputFrameRateMenu) as Menu;
+		foreach (RadioMenuItem menuItem in menu.Children) {
+			if (activate)
+				menuItem.Toggled += OnTimingsInputFrameRateToggled;
+			else 
+				menuItem.Toggled -= OnTimingsInputFrameRateToggled;
+		}
+	}
 
 }
 



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