[gnome-subtitles/gtk3] Timings Adjust dialog improvements



commit c76dc7d9cb49193a70202187e764f9286a0e963b
Author: Pedro Castro <pedro gnomesubtitles org>
Date:   Sat May 12 21:04:40 2018 +0100

    Timings Adjust dialog improvements
    
    This dialog now supports the same Apply To options as the Shift
    dialog. It also is no longer modal, so can be used multiple times
    without closing. Code cleanup.

 gnome-subtitles.csproj                             |   1 +
 .../{ => old.glade}/TimingsAdjustDialog.glade      |   0
 src/Glade/old.glade/TimingsAdjustDialog.ui         | 429 +++++++++++++++++++++
 src/GnomeSubtitles/Core/EventHandlers.cs           |   4 +-
 src/GnomeSubtitles/Core/Util.cs                    |  37 +-
 src/GnomeSubtitles/Dialog/DialogStrings.cs         |  33 ++
 src/GnomeSubtitles/Dialog/Dialogs.cs               |   3 +-
 src/GnomeSubtitles/Dialog/TimingsAdjustDialog.cs   | 418 ++++++++++++++++----
 src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs    |  49 ++-
 src/GnomeSubtitles/Ui/Menus.cs                     |  13 +-
 10 files changed, 865 insertions(+), 122 deletions(-)
---
diff --git a/gnome-subtitles.csproj b/gnome-subtitles.csproj
index 5e29274..01edded 100644
--- a/gnome-subtitles.csproj
+++ b/gnome-subtitles.csproj
@@ -283,6 +283,7 @@
     <Compile Include="src\GnomeSubtitles\Dialog\SetLanguagesDialog.cs" />
     <Compile Include="src\GnomeSubtitles\Ui\WidgetStyles.cs" />
     <Compile Include="src\GnomeSubtitles\Dialog\FileHeadersDialog.cs" />
+    <Compile Include="src\GnomeSubtitles\Dialog\DialogStrings.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <ItemGroup>
diff --git a/src/Glade/TimingsAdjustDialog.glade b/src/Glade/old.glade/TimingsAdjustDialog.glade
similarity index 100%
rename from src/Glade/TimingsAdjustDialog.glade
rename to src/Glade/old.glade/TimingsAdjustDialog.glade
diff --git a/src/Glade/old.glade/TimingsAdjustDialog.ui b/src/Glade/old.glade/TimingsAdjustDialog.ui
new file mode 100644
index 0000000..2415a7f
--- /dev/null
+++ b/src/Glade/old.glade/TimingsAdjustDialog.ui
@@ -0,0 +1,429 @@
+<?xml version="1.0"?>
+<interface>
+  <object class="GtkAdjustment" id="adjustment1">
+    <property name="upper">100</property>
+    <property name="lower">0</property>
+    <property name="page_increment">10</property>
+    <property name="step_increment">1</property>
+    <property name="page_size">0</property>
+    <property name="value">1</property>
+  </object>
+  <object class="GtkAdjustment" id="adjustment2">
+    <property name="upper">100</property>
+    <property name="lower">0</property>
+    <property name="page_increment">10</property>
+    <property name="step_increment">1</property>
+    <property name="page_size">0</property>
+    <property name="value">1</property>
+  </object>
+  <!-- interface-requires gtk+ 2.16 -->
+  <!-- interface-naming-policy toplevel-contextual -->
+  <object class="GtkDialog" id="dialog">
+    <property name="title" translatable="yes">Adjust Timings</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="window_position">center-on-parent</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="type_hint">dialog</property>
+    <property name="skip_taskbar_hint">True</property>
+    <property name="skip_pager_hint">True</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="dialogVBox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">10</property>
+        <child>
+          <object class="GtkHBox" id="hBox">
+            <property name="visible">True</property>
+            <property name="border_width">2</property>
+            <property name="spacing">10</property>
+            <child>
+              <object class="GtkFrame" id="firstSubtitleFrame">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="firstSubtitleAlignment">
+                    <property name="visible">True</property>
+                    <property name="border_width">4</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkTable" id="firstSubtitleTable">
+                        <property name="visible">True</property>
+                        <property name="n_rows">3</property>
+                        <property name="n_columns">2</property>
+                        <property name="column_spacing">10</property>
+                        <property name="row_spacing">8</property>
+                        <child>
+                          <object class="GtkLabel" id="firstSubtitleNoInputLabel">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="xpad">5</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"/>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkSpinButton" id="firstSubtitleNewStartSpinButton">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="adjustment">adjustment1</property>
+                            <property name="climb_rate">1</property>
+                            <property name="numeric">True</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">2</property>
+                            <property name="bottom_attach">3</property>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"/>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="firstSubtitleStartInputLabel">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="xpad">5</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">1</property>
+                            <property name="bottom_attach">2</property>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"/>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="firstSubtitleNewStartLabel">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">New Start:</property>
+                          </object>
+                          <packing>
+                            <property name="top_attach">2</property>
+                            <property name="bottom_attach">3</property>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"/>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="firstSubtitleStartLabel">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">Start Frame:</property>
+                          </object>
+                          <packing>
+                            <property name="top_attach">1</property>
+                            <property name="bottom_attach">2</property>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"/>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="firstSubtitleNoLabel">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">No.:</property>
+                          </object>
+                          <packing>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"/>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="firstSubtitleFrameLabel">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">&lt;b&gt;First Subtitle&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkFrame" id="lastSubtitleFrame">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="lastSubtitleAlignment">
+                    <property name="visible">True</property>
+                    <property name="border_width">4</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkTable" id="lastSubtitleTable">
+                        <property name="visible">True</property>
+                        <property name="n_rows">3</property>
+                        <property name="n_columns">2</property>
+                        <property name="column_spacing">10</property>
+                        <property name="row_spacing">8</property>
+                        <child>
+                          <object class="GtkSpinButton" id="lastSubtitleNewStartSpinButton">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="adjustment">adjustment2</property>
+                            <property name="climb_rate">1</property>
+                            <property name="numeric">True</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">2</property>
+                            <property name="bottom_attach">3</property>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"/>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="lastSubtitleStartInputLabel">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="xpad">5</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">1</property>
+                            <property name="bottom_attach">2</property>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"/>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="lastSubtitleNoInputLabel">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="xpad">5</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"/>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="lastSubtitleNewStartLabel">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">New Start:</property>
+                          </object>
+                          <packing>
+                            <property name="top_attach">2</property>
+                            <property name="bottom_attach">3</property>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"/>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="lastSubtitleStartLabel">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">Start Frame:</property>
+                          </object>
+                          <packing>
+                            <property name="top_attach">1</property>
+                            <property name="bottom_attach">2</property>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"/>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="lastSubtitleNoLabel">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">No.:</property>
+                          </object>
+                          <packing>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"/>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="lastSubtitleFrameLabel">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">&lt;b&gt;Last Subtitle&lt;/b&gt;</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkFrame" id="applyToFrame">
+            <property name="visible">True</property>
+            <property name="border_width">2</property>
+            <property name="label_xalign">0</property>
+            <property name="shadow_type">none</property>
+            <child>
+              <object class="GtkAlignment" id="applyToAlignment">
+                <property name="visible">True</property>
+                <property name="border_width">4</property>
+                <property name="left_padding">12</property>
+                <child>
+                  <object class="GtkVBox" id="applyToVBox">
+                    <property name="visible">True</property>
+                    <property name="orientation">vertical</property>
+                    <property name="spacing">4</property>
+                    <child>
+                      <object class="GtkRadioButton" id="allSubtitlesRadioButton">
+                        <property name="label" translatable="yes">All Subtitles</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_indicator">True</property>
+                        <property name="group">selectedRangeRadioButton</property>
+                        <signal handler="OnToggleAllSubtitles" name="toggled"/>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkRadioButton" id="selectedRangeRadioButton">
+                        <property name="label" translatable="yes">Selected Range</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="active">True</property>
+                        <property name="draw_indicator">True</property>
+                        <signal handler="OnToggleSelectedSubtitles" name="toggled"/>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child type="label">
+              <object class="GtkLabel" id="applyToLabel">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">&lt;b&gt;Apply to&lt;/b&gt;</property>
+                <property name="use_markup">True</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialogActionArea">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="buttonCancel">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="buttonAdjust">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">False</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment3">
+                    <property name="visible">True</property>
+                    <property name="xscale">0</property>
+                    <property name="yscale">0</property>
+                    <child>
+                      <object class="GtkHBox" id="hbox7">
+                        <property name="visible">True</property>
+                        <property name="spacing">2</property>
+                        <child>
+                          <object class="GtkImage" id="image83">
+                            <property name="visible">True</property>
+                            <property name="stock">gtk-ok</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label9">
+                            <property name="visible">True</property>
+                            <property name="label" translatable="yes">Adjust</property>
+                            <property name="use_underline">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">buttonCancel</action-widget>
+      <action-widget response="-5">buttonAdjust</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/src/GnomeSubtitles/Core/EventHandlers.cs b/src/GnomeSubtitles/Core/EventHandlers.cs
index 14897f6..74b979e 100644
--- a/src/GnomeSubtitles/Core/EventHandlers.cs
+++ b/src/GnomeSubtitles/Core/EventHandlers.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2017 Pedro Castro
+ * Copyright (C) 2006-2018 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
@@ -19,11 +19,9 @@
 
 using GnomeSubtitles.Core.Command;
 using GnomeSubtitles.Dialog;
-using GnomeSubtitles.Dialog.Unmanaged;
 using GnomeSubtitles.Ui;
 using GnomeSubtitles.Ui.View;
 using Gtk;
-using Mono.Unix;
 using SubLib.Core.Domain;
 using SubLib.Core.Timing;
 using System;
diff --git a/src/GnomeSubtitles/Core/Util.cs b/src/GnomeSubtitles/Core/Util.cs
index 1d28e76..d50475b 100644
--- a/src/GnomeSubtitles/Core/Util.cs
+++ b/src/GnomeSubtitles/Core/Util.cs
@@ -19,11 +19,11 @@
 
 using Gtk;
 using SubLib.Core.Domain;
+using SubLib.Core.Timing;
 using SubLib.Util;
 using System;
 using System.Diagnostics;
 using System.Globalization;
-using System.Threading;
 
 namespace GnomeSubtitles.Core {
 
@@ -103,16 +103,41 @@ public class Util {
        }
 
        public static void SetSpinButtonTimingMode (SpinButton spinButton, TimingMode timingMode) {
+               SetSpinButtonTimingMode(spinButton, timingMode, 0);
+       }
+
+       /// <summary>
+       /// Note: Should be either used to set the first timing mode or to switch between modes.
+       /// Should not be used if the timing mode is unchanged, as events will be assigned again.
+       /// </summary>
+       /// <param name="spinButton">Spin button.</param>
+       /// <param name="timingMode">Timing mode.</param>
+       /// <param name="frameRateForConversion">Frame rate for conversion if the spin button has a value. 
Use 0 for no conversion.</param>
+       public static void SetSpinButtonTimingMode (SpinButton spinButton, TimingMode timingMode, float 
frameRateForConversion) {
+               bool convertValue = (spinButton.ValueAsInt > 0) && (frameRateForConversion > float.Epsilon);
+               int oldValue = spinButton.ValueAsInt;
+               
+               //Switching to Frames mode
+               
                if (timingMode == TimingMode.Frames) {
                        spinButton.Numeric = true;
                        spinButton.Input -= OnTimeInput;
                        spinButton.Output -= OnTimeOutput;
+                       
+                       //Even if the value isn't converted, we need to set the old one in order for the 
input to be shown with the new format
+                       spinButton.Value = (convertValue ? TimingUtil.TimeMillisecondsToFrames(oldValue, 
frameRateForConversion) : oldValue);
+                       
+                       return;
                }
-               else {
-                       spinButton.Numeric = false;
-                       spinButton.Input += OnTimeInput;
-                       spinButton.Output += OnTimeOutput;
-               }
+               
+               //Switching to Times mode
+               
+               spinButton.Numeric = false;
+               spinButton.Input += OnTimeInput;
+               spinButton.Output += OnTimeOutput;
+               
+               //Even if the value isn't converted, we need to set the old one in order for the input to be 
shown with the new format
+               spinButton.Value = (convertValue ? TimingUtil.FramesToTime(oldValue, 
frameRateForConversion).TotalMilliseconds : oldValue);
        }
 
        public static void SetSpinButtonAdjustment (SpinButton spinButton, TimeSpan upperLimit, bool 
canNegate) {
diff --git a/src/GnomeSubtitles/Dialog/DialogStrings.cs b/src/GnomeSubtitles/Dialog/DialogStrings.cs
new file mode 100644
index 0000000..e564e78
--- /dev/null
+++ b/src/GnomeSubtitles/Dialog/DialogStrings.cs
@@ -0,0 +1,33 @@
+/*
+ * This file is part of Gnome Subtitles.
+ * Copyright (C) 2018 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Gnome Subtitles is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+using Mono.Unix;
+
+namespace GnomeSubtitles.Dialog {
+
+public class DialogStrings {
+
+       public static readonly string ApplyToAllSubtitles = Catalog.GetString("_All subtitles");
+       public static readonly string ApplyToSelection = Catalog.GetString("_Selected subtitles");
+       public static readonly string ApplyToFirstToSelection = Catalog.GetString("Subtitles between those 
selected and the _first");
+       public static readonly string ApplyToSelectionToLast = Catalog.GetString("Subtitles between those 
selected and the _last");
+
+}
+
+}
\ No newline at end of file
diff --git a/src/GnomeSubtitles/Dialog/Dialogs.cs b/src/GnomeSubtitles/Dialog/Dialogs.cs
index fa9b84f..bbf128a 100644
--- a/src/GnomeSubtitles/Dialog/Dialogs.cs
+++ b/src/GnomeSubtitles/Dialog/Dialogs.cs
@@ -36,8 +36,9 @@ public class Dialogs {
                BaseDialog dialog = dialogs[dialogType] as BaseDialog;
                if (dialog == null) {
                        object newDialog = Activator.CreateInstance(dialogType, args);
-                       if (!(newDialog is BaseDialog))
+                       if (!(newDialog is BaseDialog)) {
                                return null;
+                       }
 
                        dialog = newDialog as BaseDialog;
                        if (dialog.Scope != DialogScope.Singleton) {
diff --git a/src/GnomeSubtitles/Dialog/TimingsAdjustDialog.cs 
b/src/GnomeSubtitles/Dialog/TimingsAdjustDialog.cs
index c4444f0..23688e0 100644
--- a/src/GnomeSubtitles/Dialog/TimingsAdjustDialog.cs
+++ b/src/GnomeSubtitles/Dialog/TimingsAdjustDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2017 Pedro Castro
+ * Copyright (C) 2006-2018 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
@@ -19,8 +19,8 @@
 
 using GnomeSubtitles.Core;
 using GnomeSubtitles.Core.Command;
+using GnomeSubtitles.Ui;
 using GnomeSubtitles.Ui.View;
-//using Glade;
 using Gtk;
 using Mono.Unix;
 using SubLib.Core.Domain;
@@ -29,112 +29,376 @@ using System;
 namespace GnomeSubtitles.Dialog {
 
 
-public class TimingsAdjustDialog : BuilderDialog {
+public class TimingsAdjustDialog : BaseDialog {
        private TimingMode timingMode;
 
-       /* Constant strings */
-       private const string gladeFilename = "TimingsAdjustDialog.glade";
-
        /* Widgets */
 
-       [Builder.Object] private Label firstSubtitleStartLabel = null;
-       [Builder.Object] private Label firstSubtitleNoInputLabel = null;
-       [Builder.Object] private Label firstSubtitleStartInputLabel = null;
-       [Builder.Object] private SpinButton firstSubtitleNewStartSpinButton = null;
-       [Builder.Object] private Label lastSubtitleStartLabel = null;
-       [Builder.Object] private Label lastSubtitleNoInputLabel = null;
-       [Builder.Object] private Label lastSubtitleStartInputLabel = null;
-       [Builder.Object] private SpinButton lastSubtitleNewStartSpinButton = null;
-       [Builder.Object] private RadioButton allSubtitlesRadioButton = null;
-       [Builder.Object] private RadioButton selectedRangeRadioButton = null;
+       private Label firstSubtitleStartLabel = null;
+       private Label firstSubtitleStartInputLabel = null;
+       private Label firstSubtitleNoInputLabel = null;
+       private Label firstSubtitleNewStartLabel = null;
+       private SpinButton firstSubtitleNewStartSpinButton = null;
+       
+       private Label lastSubtitleStartLabel = null;
+       private Label lastSubtitleStartInputLabel = null;
+       private Label lastSubtitleNoInputLabel = null;
+       private Label lastSubtitleNewStartLabel = null;
+       private SpinButton lastSubtitleNewStartSpinButton = null;
+       
+       private RadioButton allSubtitlesRadioButton = null;
+       private RadioButton selectedSubtitlesRadioButton = null;
+       private RadioButton fromFirstSubtitleToSelectionRadioButton = null;
+       private RadioButton fromSelectionToLastSubtitleRadioButton = null;
 
 
-       public TimingsAdjustDialog () : base(gladeFilename){
+       public TimingsAdjustDialog () : base(){
                timingMode = Base.TimingMode;
-               SetSpinButtons();
-               UpdateForTimingMode();
-               SetApplyToSelectionSensitivity();
-               SetSelectionType();
+               
+               Init(BuildDialog());
+               
+               UpdateFromTimingMode();
+               UpdateApplyToOptionFromSubtitleSelection();
+               ConnectEventHandlers();
+       }
+       
+       /* Overriden members */
+
+       public override DialogScope Scope {
+               get { return DialogScope.Document; }
        }
 
-       private void SetSpinButtons () {
+       public override void Show () {
+               UpdateApplyToOptionFromSubtitleSelection();
+               base.Show();
+       }
+       
+       public override void Destroy () {
+               DisconnectEventHandlers();
+               base.Destroy();
+       }
+       
+       
+       /* Private members */
+       
+       private Gtk.Dialog BuildDialog () {
+               Gtk.Dialog dialog = new Gtk.Dialog(Catalog.GetString("Adjust Timings Between 2 Points"), 
Base.Ui.Window, DialogFlags.DestroyWithParent,
+                       Util.GetStockLabel("gtk-close"), ResponseType.Cancel, Catalog.GetString("_Apply"), 
ResponseType.Ok);
+
+               dialog.DefaultResponse = ResponseType.Ok;
+
+               Grid grid = new Grid();
+               grid.BorderWidth = WidgetStyles.BorderWidthMedium;
+               grid.RowSpacing = WidgetStyles.RowSpacingLarge;
+               grid.ColumnSpacing = WidgetStyles.ColumnSpacingLarge;
+               
+               
+               //First Subtitle frame
+               
+               Frame firstSubtitleFrame = new Frame();
+               firstSubtitleFrame.ShadowType = ShadowType.None;
+               Label firstSubtitleFrameLabel = new Label();
+               firstSubtitleFrameLabel.Markup = "<b>" + Catalog.GetString("First Point") + "</b>";
+               firstSubtitleFrame.LabelWidget = firstSubtitleFrameLabel;
+               
+               Grid firstSubtitleGrid = new Grid();
+               firstSubtitleGrid.BorderWidth = WidgetStyles.BorderWidthMedium;
+               firstSubtitleGrid.RowSpacing = WidgetStyles.RowSpacingMedium;
+               firstSubtitleGrid.ColumnSpacing = WidgetStyles.ColumnSpacingMedium;
+               firstSubtitleGrid.MarginLeft = WidgetStyles.FrameContentSpacingMedium;
+               Label firstSubtitleNoLabel = CreateAlignedLabel(Catalog.GetString("Subtitle No.:"));
+               firstSubtitleGrid.Attach(firstSubtitleNoLabel, 0, 0, 1, 1);
+               firstSubtitleNoInputLabel = CreateAlignedLabel();
+               firstSubtitleGrid.Attach(firstSubtitleNoInputLabel, 1, 0, 1, 1);
+               firstSubtitleStartLabel = CreateAlignedLabel();
+               firstSubtitleGrid.Attach(firstSubtitleStartLabel, 0, 1, 1, 1);
+               firstSubtitleStartInputLabel = CreateAlignedLabel();
+               firstSubtitleGrid.Attach(firstSubtitleStartInputLabel, 1, 1, 1, 1);
+               firstSubtitleNewStartLabel = CreateAlignedLabel();
+               firstSubtitleNewStartLabel.SetAlignment(0, 0.5f);
+               firstSubtitleGrid.Attach(firstSubtitleNewStartLabel, 0, 2, 1, 1);
+               firstSubtitleNewStartSpinButton = new SpinButton(new Adjustment(0, 0, 0, 1, 10, 0), 0, 0);
                firstSubtitleNewStartSpinButton.WidthChars = Core.Util.SpinButtonTimeWidthChars;
+               firstSubtitleNewStartSpinButton.Alignment = 0.5f;
+               firstSubtitleGrid.Attach(firstSubtitleNewStartSpinButton, 1, 2, 1, 1);
+               
+               firstSubtitleFrame.Add(firstSubtitleGrid);
+               grid.Attach(firstSubtitleFrame, 0, 0, 1, 1);
+
+       
+               //Second Subtitle frame
+               
+               Frame lastSubtitleFrame = new Frame();
+               lastSubtitleFrame.ShadowType = ShadowType.None;
+               Label lastSubtitleFrameLabel = new Label();
+               lastSubtitleFrameLabel.Markup = "<b>" + Catalog.GetString("Second Point") + "</b>";
+               lastSubtitleFrame.LabelWidget = lastSubtitleFrameLabel;
+
+               Grid lastSubtitleGrid = new Grid();
+               lastSubtitleGrid.BorderWidth = WidgetStyles.BorderWidthMedium;
+               lastSubtitleGrid.RowSpacing = WidgetStyles.RowSpacingMedium;
+               lastSubtitleGrid.ColumnSpacing = WidgetStyles.ColumnSpacingMedium;
+               lastSubtitleGrid.MarginLeft = WidgetStyles.FrameContentSpacingMedium;
+               Label lastSubtitleNoLabel = CreateAlignedLabel(Catalog.GetString("Subtitle No.:"));
+               lastSubtitleGrid.Attach(lastSubtitleNoLabel, 0, 0, 1, 1);
+               lastSubtitleNoInputLabel = CreateAlignedLabel();
+               lastSubtitleGrid.Attach(lastSubtitleNoInputLabel, 1, 0, 1, 1);
+               lastSubtitleStartLabel = CreateAlignedLabel();
+               lastSubtitleGrid.Attach(lastSubtitleStartLabel, 0, 1, 1, 1);
+               lastSubtitleStartInputLabel = CreateAlignedLabel();
+               lastSubtitleGrid.Attach(lastSubtitleStartInputLabel, 1, 1, 1, 1);
+               lastSubtitleNewStartLabel = CreateAlignedLabel();
+               lastSubtitleGrid.Attach(lastSubtitleNewStartLabel, 0, 2, 1, 1);
+               lastSubtitleNewStartSpinButton = new SpinButton(new Adjustment(0, 0, 0, 1, 10, 0), 0, 0);
                lastSubtitleNewStartSpinButton.WidthChars = Core.Util.SpinButtonTimeWidthChars;
+               lastSubtitleNewStartSpinButton.Alignment = 0.5f;
+               lastSubtitleGrid.Attach(lastSubtitleNewStartSpinButton, 1, 2, 1, 1);
+               
+               lastSubtitleFrame.Add(lastSubtitleGrid);
+               grid.Attach(lastSubtitleFrame, 1, 0, 1, 1);
+               
+
+               //Apply To frame
+               
+               Frame applyToFrame = new Frame();
+               applyToFrame.ShadowType = ShadowType.None;
+               Label applyToFrameLabel = new Label();
+               applyToFrameLabel.Markup = "<b>" + Catalog.GetString("Apply to") + "</b>";
+               applyToFrame.LabelWidget = applyToFrameLabel;
+
+
+               allSubtitlesRadioButton = new RadioButton(DialogStrings.ApplyToAllSubtitles);
+               selectedSubtitlesRadioButton = new RadioButton(allSubtitlesRadioButton, 
DialogStrings.ApplyToSelection);
+               fromFirstSubtitleToSelectionRadioButton = new RadioButton(allSubtitlesRadioButton, 
DialogStrings.ApplyToFirstToSelection);
+               fromSelectionToLastSubtitleRadioButton = new RadioButton(allSubtitlesRadioButton, 
DialogStrings.ApplyToSelectionToLast);
+
+               allSubtitlesRadioButton.Toggled += OnToggleRadioButton;
+               selectedSubtitlesRadioButton.Toggled += OnToggleRadioButton;
+               fromFirstSubtitleToSelectionRadioButton.Toggled += OnToggleRadioButton;
+               fromSelectionToLastSubtitleRadioButton.Toggled += OnToggleRadioButton;
+               
+               Box applyToFrameVBox = new Box(Orientation.Vertical, WidgetStyles.BoxSpacingMedium);
+               applyToFrameVBox.BorderWidth = WidgetStyles.BorderWidthMedium;
+               applyToFrameVBox.MarginLeft = WidgetStyles.FrameContentSpacingMedium;
+               applyToFrameVBox.Add(allSubtitlesRadioButton);
+               applyToFrameVBox.Add(selectedSubtitlesRadioButton);
+               applyToFrameVBox.Add(fromFirstSubtitleToSelectionRadioButton);
+               applyToFrameVBox.Add(fromSelectionToLastSubtitleRadioButton);
+               
+               applyToFrame.Add(applyToFrameVBox);
+               grid.Attach(applyToFrame, 0, 1, 2, 2);
+               
+               dialog.ContentArea.Add(grid);
+               dialog.ContentArea.ShowAll();
+               
+               return dialog;
+       }
+       
+       private Label CreateAlignedLabel () {
+               Label label = new Label();
+               label.SetAlignment(0, 0.5f);
+               return label;
+       }
+       
+       private Label CreateAlignedLabel (string text) {
+               Label label = CreateAlignedLabel();
+               label.Text = text;
+               return label;
        }
 
-       private void UpdateForTimingMode () {
-               if (timingMode == TimingMode.Times) {
-                       string startLabel = Catalog.GetString("Start Time:");
-                       firstSubtitleStartLabel.Text = startLabel;
-                       lastSubtitleStartLabel.Text = startLabel;
-               }
+       private void UpdateFromTimingMode () {
+               string startLabel = (timingMode == TimingMode.Times ? Catalog.GetString("Current Time:") : 
Catalog.GetString("Current Frame:"));
+               string newStartLabel = (timingMode == TimingMode.Times ? Catalog.GetString("New Time:") : 
Catalog.GetString("New Frame:"));
+       
+               firstSubtitleStartLabel.Text = startLabel;
+               lastSubtitleStartLabel.Text = startLabel;
+               firstSubtitleNewStartLabel.Text = newStartLabel;
+               lastSubtitleNewStartLabel.Text = newStartLabel;
+
                Core.Util.SetSpinButtonTimingMode(firstSubtitleNewStartSpinButton, timingMode);
                Core.Util.SetSpinButtonMaxAdjustment(firstSubtitleNewStartSpinButton, timingMode, false);
                Core.Util.SetSpinButtonTimingMode(lastSubtitleNewStartSpinButton, timingMode);
                Core.Util.SetSpinButtonMaxAdjustment(lastSubtitleNewStartSpinButton, timingMode, false);
+               
+               UpdateInputValuesAccordingToApplyToOption();
        }
-
-       private void SetSelectionType () {
-               if (Core.Base.Ui.View.Selection.Count < 2)
-                       allSubtitlesRadioButton.Active = true;
-               else
-                       SetApplyToSelection(); //It's already selected by default, only need to set values
+       
+       private void UpdateApplyToOptionFromSubtitleSelection () {
+               int selectionCount = Core.Base.Ui.View.Selection.Count;
+               if (selectionCount > 1) {
+                       if (selectedSubtitlesRadioButton.Active) {
+                               UpdateInputValuesAccordingToApplyToOption(); //It's already selected, need to 
call update directly
+                       } else {
+                               selectedSubtitlesRadioButton.Active = true;
+                       }
+               } else {
+                       if (allSubtitlesRadioButton.Active) {
+                               UpdateInputValuesAccordingToApplyToOption(); //It's already selected, need to 
call update directly
+                       } else {
+                               allSubtitlesRadioButton.Active = true;
+                       }
+               }
+       }
+       
+       private void UpdateInputValuesAccordingToApplyToOption () {
+               if (allSubtitlesRadioButton.Active) {
+                       UpdateInputValuesForApplyToAll();
+               } else if (selectedSubtitlesRadioButton.Active) {
+                       UpdateInputValuesForApplyToSelection();
+               } else if (fromFirstSubtitleToSelectionRadioButton.Active) {
+                       UpdateInputValuesForApplyToFirstToSelection();
+               } else if (fromSelectionToLastSubtitleRadioButton.Active) {
+                       UpdateInputValuesForApplyToSelectionToLast();
+               }
        }
 
-       private void SetApplyToAll () {
-               SubtitleCollection collection = Base.Document.Subtitles.Collection;
+       private void UpdateInputValuesForApplyToAll () {
+               int subtitleCount = Base.Document.Subtitles.Collection.Count;
 
-               int firstNo = 1;
-               int lastNo = collection.Count;
+               int firstNo = (subtitleCount > 0 ? 1 : -1);
+               int lastNo = (subtitleCount > 1 ? subtitleCount : -1);
                UpdateInputValues(firstNo, lastNo);
        }
 
-       private void SetApplyToSelection () {
-               TreePath firstPath = Core.Base.Ui.View.Selection.FirstPath;
-               TreePath lastPath = Core.Base.Ui.View.Selection.LastPath;
-
-               int firstNo = firstPath.Indices[0] + 1;
-               int lastNo = lastPath.Indices[0] + 1;
-
-               UpdateInputValues (firstNo, lastNo);
+       private void UpdateInputValuesForApplyToSelection () {
+               int selectionCount = Core.Base.Ui.View.Selection.Count;
+       
+               int firstNo = (selectionCount > 0 ? Core.Base.Ui.View.Selection.FirstPath.Indices[0] + 1 : 
-1);
+               int lastNo = (selectionCount > 1 ? Core.Base.Ui.View.Selection.LastPath.Indices[0] + 1 : -1);
+               UpdateInputValues(firstNo, lastNo);
        }
+       
+       private void UpdateInputValuesForApplyToFirstToSelection () {
+               int subtitleCount = Base.Document.Subtitles.Collection.Count;
+               int firstNo = (subtitleCount > 0 ? 1 : -1);
 
-       private void SetApplyToSelectionSensitivity () {
-               int selectionCount = Core.Base.Ui.View.Selection.Count;
-               if (selectionCount < 2)
-                       selectedRangeRadioButton.Sensitive = false;
+               int lastNo = -1;
+               if (subtitleCount > 1) {
+                       TreePath path = Core.Base.Ui.View.Selection.LastPath;
+                       if (path != null) {
+                               int lastIndex = path.Indices[0];
+                               if (lastIndex > 0) {
+                                       lastNo = lastIndex + 1;
+                               }
+                       }
+               }
+               
+               UpdateInputValues(firstNo, lastNo);
+       }
+       
+       private void UpdateInputValuesForApplyToSelectionToLast () {
+               int subtitleCount = Base.Document.Subtitles.Collection.Count;
+               int lastNo = (subtitleCount > 0 ? subtitleCount : -1);
+               
+               int firstNo = -1;
+               if (subtitleCount > 1) {
+                       TreePath path = Core.Base.Ui.View.Selection.FirstPath;
+                       if (path != null) {
+                               int firstIndex = path.Indices[0];
+                               if (firstIndex < subtitleCount - 1) {
+                                       firstNo = firstIndex + 1;
+                               }
+                       }
+               }
+               
+               UpdateInputValues(firstNo, lastNo);
        }
 
        private void UpdateInputValues (int firstNo, int lastNo) {
-               SubtitleCollection collection = Base.Document.Subtitles.Collection;
-               Subtitle firstSubtitle = collection.Get(firstNo - 1);
-               Subtitle lastSubtitle = collection.Get(lastNo - 1);
-
-               firstSubtitleNoInputLabel.Text = firstNo.ToString();
-               lastSubtitleNoInputLabel.Text = lastNo.ToString();
-
-               if (timingMode == TimingMode.Frames) {
-                       firstSubtitleStartInputLabel.Text = firstSubtitle.Frames.Start.ToString();
-                       firstSubtitleNewStartSpinButton.Value = firstSubtitle.Frames.Start;
-                       lastSubtitleStartInputLabel.Text = lastSubtitle.Frames.Start.ToString();
-                       lastSubtitleNewStartSpinButton.Value = lastSubtitle.Frames.Start;
+       
+               //Handle the first subtitle
+               if (firstNo == -1) {
+                       firstSubtitleNoInputLabel.Text = "-";
+                       firstSubtitleStartInputLabel.Text = "-";
+                       firstSubtitleNewStartSpinButton.Value = 0;
+               } else {
+                       Subtitle firstSubtitle = Base.Document.Subtitles.Collection.Get(firstNo - 1);
+                       firstSubtitleNoInputLabel.Text = firstNo.ToString();
+
+                       if (timingMode == TimingMode.Frames) {                  
+                               firstSubtitleStartInputLabel.Text = firstSubtitle.Frames.Start.ToString();
+                               firstSubtitleNewStartSpinButton.Value = firstSubtitle.Frames.Start;
+                       } else {
+                               firstSubtitleStartInputLabel.Text = 
Core.Util.TimeSpanToText(firstSubtitle.Times.Start);
+                               firstSubtitleNewStartSpinButton.Value = 
firstSubtitle.Times.Start.TotalMilliseconds;
+                       }
                }
-               else {
-                       firstSubtitleStartInputLabel.Text = 
Core.Util.TimeSpanToText(firstSubtitle.Times.Start);
-                       firstSubtitleNewStartSpinButton.Value = firstSubtitle.Times.Start.TotalMilliseconds;
-                       lastSubtitleStartInputLabel.Text = Core.Util.TimeSpanToText(lastSubtitle.Times.Start);
-                       lastSubtitleNewStartSpinButton.Value = lastSubtitle.Times.Start.TotalMilliseconds;
+               
+               //Handle the last subtitle
+               if (lastNo == -1) {
+                       lastSubtitleNoInputLabel.Text = "-";
+                       lastSubtitleStartInputLabel.Text = "-";
+                       lastSubtitleNewStartSpinButton.Value = 0;
+               } else {
+                       Subtitle lastSubtitle = Base.Document.Subtitles.Collection.Get(lastNo - 1);
+                       lastSubtitleNoInputLabel.Text = lastNo.ToString();
+
+                       if (timingMode == TimingMode.Frames) {                  
+                               lastSubtitleStartInputLabel.Text = lastSubtitle.Frames.Start.ToString();
+                               lastSubtitleNewStartSpinButton.Value = lastSubtitle.Frames.Start;
+                       } else {
+                               lastSubtitleStartInputLabel.Text = 
Core.Util.TimeSpanToText(lastSubtitle.Times.Start);
+                               lastSubtitleNewStartSpinButton.Value = 
lastSubtitle.Times.Start.TotalMilliseconds;
+                       }
                }
+               
+               //Update spin buttons sensitivity
+               bool hasBothPoints = (firstNo != -1) && (lastNo != -1);
+               firstSubtitleNewStartSpinButton.Sensitive = hasBothPoints;
+               lastSubtitleNewStartSpinButton.Sensitive = hasBothPoints;
+               
+               //Update apply button sensitivity
+               Button applyButton = Dialog.GetWidgetForResponse((int)ResponseType.Ok) as Button;
+               applyButton.Sensitive = hasBothPoints;
+       }
+       
+       private SelectionIntended GetSelectionIntended () {
+               if (allSubtitlesRadioButton.Active)
+                       return SelectionIntended.All;
+               else if (selectedSubtitlesRadioButton.Active)
+                       return SelectionIntended.Simple;
+               else if (fromFirstSubtitleToSelectionRadioButton.Active)
+                       return SelectionIntended.SimpleToFirst;
+               else
+                       return SelectionIntended.SimpleToLast;
        }
 
+
        /* Event members */
 
-       #pragma warning disable 169             //Disables warning about handlers not being used
+       private void OnToggleRadioButton (object o, EventArgs args) {
+               if ((o as RadioButton).Active) {
+                       UpdateInputValuesAccordingToApplyToOption();
+               }
+       }
+
+       private void ConnectEventHandlers () {
+               Base.TimingModeChanged += OnBaseTimingModeChanged;
+               Base.Ui.View.Selection.Changed += OnSubtitleViewSelectionChanged;
+       }
+       
+       private void DisconnectEventHandlers () {
+               Base.TimingModeChanged -= OnBaseTimingModeChanged;
+               Base.Ui.View.Selection.Changed -= OnSubtitleViewSelectionChanged;
+       }
+       
+       private void OnBaseTimingModeChanged (TimingMode newTimingMode) {
+       if (timingMode == newTimingMode) {
+                       return;
+               }
+
+               timingMode = newTimingMode;
+               UpdateFromTimingMode();
+    }
+    
+    private void OnSubtitleViewSelectionChanged (TreePath[] paths, Subtitle subtitle) {
+       UpdateInputValuesAccordingToApplyToOption();
+    }
 
        protected override bool ProcessResponse (ResponseType response) {
                if (response == ResponseType.Ok) {
-                       SelectionIntended selectionIntended = (allSubtitlesRadioButton.Active ? 
SelectionIntended.All : SelectionIntended.Range);
-
+                       SelectionIntended selectionIntended = GetSelectionIntended();
+               
                        if (timingMode == TimingMode.Times) {
                                TimeSpan firstTime = TimeSpan.Parse(firstSubtitleNewStartSpinButton.Text);
                                TimeSpan lastTime = TimeSpan.Parse(lastSubtitleNewStartSpinButton.Text);
@@ -145,20 +409,14 @@ public class TimingsAdjustDialog : BuilderDialog {
                                int lastFrame = (int)lastSubtitleNewStartSpinButton.Value;
                                Base.CommandManager.Execute(new AdjustTimingsCommand(firstFrame, lastFrame, 
selectionIntended));
                        }
+                       
+                       return true;
                }
+               
                return false;
        }
 
-       private void OnToggleAllSubtitles (object o, EventArgs args) {
-               if ((o as RadioButton).Active)
-                       SetApplyToAll();
-       }
-
-       private void OnToggleSelectedSubtitles (object o, EventArgs args) {
-               if ((o as RadioButton).Active)
-                       SetApplyToSelection();
-       }
-
+    
 }
 
 }
diff --git a/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs b/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs
index c82fe0f..f6983b2 100644
--- a/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs
+++ b/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs
@@ -24,13 +24,11 @@ using GnomeSubtitles.Ui.View;
 using Gtk;
 using Mono.Unix;
 using SubLib.Core.Domain;
-using SubLib.Core.Timing;
 using System;
 
 namespace GnomeSubtitles.Dialog {
 
-//TODO set spinButton limits according to selection type
-//TODO show informative message about the Ctrl+Shift++ shortcuts
+//TODO show informative message about the Ctrl+Shift++ shortcuts?
 public class TimingsShiftDialog : BaseDialog {
        private TimingMode timingMode;
 
@@ -57,6 +55,11 @@ public class TimingsShiftDialog : BaseDialog {
                UpdateFromSelection();
                base.Show();
        }
+       
+       public override void Destroy () {
+               DisconnectEventHandlers();
+               base.Destroy();
+       }
 
 
        /* Methods */
@@ -106,10 +109,10 @@ public class TimingsShiftDialog : BaseDialog {
                applyToFrameLabel.Markup = "<b>" + Catalog.GetString("Apply to") + "</b>";
                applyToFrame.LabelWidget = applyToFrameLabel;
                
-               allSubtitlesRadioButton = new RadioButton(Catalog.GetString("_All subtitles"));
-               selectedSubtitlesRadioButton = new RadioButton(allSubtitlesRadioButton, 
Catalog.GetString("_Selected subtitles"));
-               fromFirstSubtitleToSelectionRadioButton = new RadioButton(allSubtitlesRadioButton, 
Catalog.GetString("From _first subtitle to selection"));
-               fromSelectionToLastSubtitleRadioButton = new RadioButton(allSubtitlesRadioButton, 
Catalog.GetString("From selection to _last subtitle"));
+               allSubtitlesRadioButton = new RadioButton(DialogStrings.ApplyToAllSubtitles);
+               selectedSubtitlesRadioButton = new RadioButton(allSubtitlesRadioButton, 
DialogStrings.ApplyToSelection);
+               fromFirstSubtitleToSelectionRadioButton = new RadioButton(allSubtitlesRadioButton, 
DialogStrings.ApplyToFirstToSelection);
+               fromSelectionToLastSubtitleRadioButton = new RadioButton(allSubtitlesRadioButton, 
DialogStrings.ApplyToSelectionToLast);
 
                Box applyToFrameVBox = new Box(Orientation.Vertical, WidgetStyles.BoxSpacingMedium);
                applyToFrameVBox.BorderWidth = WidgetStyles.BorderWidthMedium;
@@ -137,9 +140,7 @@ public class TimingsShiftDialog : BaseDialog {
                UpdateFromSelection();
                UpdateVideoButtonSensitivity();
                
-               Base.TimingModeChanged += OnBaseTimingModeChanged;
-               Base.VideoLoaded += OnBaseVideoLoaded;
-               Base.VideoUnloaded += OnBaseVideoUnloaded;
+               ConnectEventHandlers();
                
                dialog.ContentArea.ShowAll();
 
@@ -149,7 +150,7 @@ public class TimingsShiftDialog : BaseDialog {
        /* Private methods */
 
        private void UpdateFromTimingMode () {
-               Core.Util.SetSpinButtonTimingMode(spinButton, timingMode);
+               Core.Util.SetSpinButtonTimingMode(spinButton, timingMode, 
Base.Document.Subtitles.Properties.CurrentFrameRate);
                Core.Util.SetSpinButtonMaxAdjustment(spinButton, timingMode, true);
 
                string label = (timingMode == TimingMode.Times ? Catalog.GetString("Time") : 
Catalog.GetString("Frames"));
@@ -163,10 +164,11 @@ public class TimingsShiftDialog : BaseDialog {
 
        private void UpdateFromSelection () {
                int selectionCount = Core.Base.Ui.View.Selection.Count;
-               if (selectionCount > 1)
+               if (selectionCount > 1) {
                        selectedSubtitlesRadioButton.Active = true;
-               else
+               } else {
                        allSubtitlesRadioButton.Active = true;
+               }
        }
 
        private SelectionIntended GetSelectionIntended () {
@@ -215,15 +217,8 @@ public class TimingsShiftDialog : BaseDialog {
                        return;
                }
                
-               int oldValue = (int)spinButton.Value; //contains frames or ms, depending on the old timing 
mode
-               float frameRate = Base.Document.Subtitles.Properties.CurrentFrameRate;
-               double newValue = (newTimingMode == TimingMode.Times ?
-                               TimingUtil.FramesToTime(oldValue, frameRate).TotalMilliseconds :
-                               TimingUtil.TimeMillisecondsToFrames(oldValue, frameRate));
-                               
                timingMode = newTimingMode;
                UpdateFromTimingMode();
-               spinButton.Value = newValue;
     }
     
     private void OnBaseVideoLoaded (Uri videoUri) {
@@ -233,10 +228,22 @@ public class TimingsShiftDialog : BaseDialog {
        private void OnBaseVideoUnloaded () {
                UpdateVideoButtonSensitivity();
        }
+       
+       private void ConnectEventHandlers () {
+               Base.TimingModeChanged += OnBaseTimingModeChanged;
+               Base.VideoLoaded += OnBaseVideoLoaded;
+               Base.VideoUnloaded += OnBaseVideoUnloaded;
+       }
+       
+       private void DisconnectEventHandlers () {
+               Base.TimingModeChanged -= OnBaseTimingModeChanged;
+               Base.VideoLoaded -= OnBaseVideoLoaded;
+               Base.VideoUnloaded -= OnBaseVideoUnloaded;
+       }
 
        protected override bool ProcessResponse (ResponseType response) {
                if (response == ResponseType.Ok) {
-                       if (Math.Abs(spinButton.Value) > float.Epsilon) {
+                       if (spinButton.ValueAsInt > 0) {
                                SelectionIntended selectionIntended = GetSelectionIntended();
        
                                if (timingMode == TimingMode.Times) {
diff --git a/src/GnomeSubtitles/Ui/Menus.cs b/src/GnomeSubtitles/Ui/Menus.cs
index a53d7f5..25c2213 100644
--- a/src/GnomeSubtitles/Ui/Menus.cs
+++ b/src/GnomeSubtitles/Ui/Menus.cs
@@ -145,15 +145,7 @@ public class Menus {
        }
 
        private void SetSubtitleCountDependentSensitivity (int count) {
-               if (count == 0) {
-                       SetSensitivity(WidgetNames.TimingsAdjust, false);
-               }
-               else if (count == 1) {
-                       SetSensitivity(WidgetNames.TimingsAdjust, false);
-               }
-               else {
-                       SetSensitivity(WidgetNames.TimingsAdjust, true);
-               }
+               //Do nothing
        }
 
        private void SetBlankActivity () {
@@ -187,6 +179,7 @@ public class Menus {
                SetSensitivity(WidgetNames.SearchReplace, documentLoaded);
                /* Timings Menu */
                SetSensitivity(WidgetNames.TimingsSynchronize, documentLoaded);
+               SetSensitivity(WidgetNames.TimingsAdjust, documentLoaded);
                SetSensitivity(WidgetNames.TimingsShift, documentLoaded);
                /* Video Menu */
                SetVideoDocumentLoadedSensitivity(documentLoaded);
@@ -212,8 +205,6 @@ public class Menus {
                        /* Search menu */
                        SetSensitivity(WidgetNames.SearchFindNext, false);
                        SetSensitivity(WidgetNames.SearchFindPrevious, false);
-                       /* Timings Menu */
-                       SetSensitivity(WidgetNames.TimingsAdjust, false);
                        /* Toolbar */
                        SetSensitivity(WidgetNames.DeleteSubtitlesButton, false);
                        SetSensitivity(WidgetNames.UndoButton, false);


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