[gnome-subtitles] Fixed bug #621145 - Shift selected lines with Keyboard shortcuts, with support from Zsolt Kozak Adde



commit fae0ebf46f43244ae3a0532897544d23321d8264
Author: Pedro Castro <mail pedrocastro org>
Date:   Sun Jun 5 19:13:42 2011 +0100

    Fixed bug #621145 - Shift selected lines with Keyboard shortcuts, with support from Zsolt Kozak
    Added shortcuts for changing subtitle start (Ctrl++,Ctrl+-), end (Ctrl+Alt++,Ctrl+Alt+-) and shifting a subtitle selection (Ctrl+Shift++,Ctrl+Shift+-)

 gnome-subtitles.mdp                                |    1 +
 m4/intltool.m4                                     |    2 +-
 src/Glade/MainWindow.glade                         |   18 +++---
 src/GnomeSubtitles/Core/Base.cs                    |    8 ++-
 src/GnomeSubtitles/Core/EventHandlers.cs           |   77 ++++++++++++++++++++
 src/GnomeSubtitles/Core/GlobalAccelerators.cs      |   69 ++++++++++++++++++
 src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs    |    1 +
 src/GnomeSubtitles/Ui/Edit/SubtitleEdit.cs         |    6 ++-
 .../Ui/Edit/SubtitleEditSpinButtons.cs             |   16 ++++
 9 files changed, 186 insertions(+), 12 deletions(-)
---
diff --git a/gnome-subtitles.mdp b/gnome-subtitles.mdp
index e22ffb8..0ad0b60 100644
--- a/gnome-subtitles.mdp
+++ b/gnome-subtitles.mdp
@@ -254,6 +254,7 @@
     <File subtype="Code" buildaction="Compile" name="src/GnomeSubtitles/Core/Command/TranslatorCommand.cs" />
     <File subtype="Code" buildaction="Compile" name="src/SubLib/Exceptions/TranslatorException.cs" />
     <File subtype="Code" buildaction="Compile" name="src/SubLib/Core/Translator.cs" />
+    <File subtype="Code" buildaction="Compile" name="src/GnomeSubtitles/Core/GlobalAccelerators.cs" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
diff --git a/m4/intltool.m4 b/m4/intltool.m4
index 122d773..839e855 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 exetuted at the very end
+dnl The following CONFIG_COMMANDS should be executed 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 154cc68..ec82787 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="Y" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="Z" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
+                        <accelerator key="Y" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -562,8 +562,8 @@
                         <property name="label" translatable="yes">Find Ne_xt</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnSearchFindNext"/>
-                        <accelerator key="F3" signal="activate"/>
                         <accelerator key="g" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F3" signal="activate"/>
                       </widget>
                     </child>
                     <child>
@@ -573,8 +573,8 @@
                         <property name="label" translatable="yes">Find Pre_vious</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnSearchFindPrevious"/>
-                        <accelerator key="F3" signal="activate" modifiers="GDK_SHIFT_MASK"/>
                         <accelerator key="g" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
+                        <accelerator key="F3" signal="activate" modifiers="GDK_SHIFT_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -818,8 +818,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">False</property>
                         <signal name="activate" handler="OnVideoPlayPause"/>
-                        <accelerator key="F5" signal="activate"/>
                         <accelerator key="p" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F5" signal="activate"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoPlayPauseImage">
                             <property name="visible">True</property>
@@ -846,8 +846,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">False</property>
                         <signal name="activate" handler="OnVideoRewind"/>
-                        <accelerator key="F6" signal="activate"/>
                         <accelerator key="k" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F6" signal="activate"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoRewindImage">
                             <property name="visible">True</property>
@@ -865,8 +865,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">False</property>
                         <signal name="activate" handler="OnVideoForward"/>
-                        <accelerator key="F7" signal="activate"/>
                         <accelerator key="l" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="F7" signal="activate"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoForwardImage">
                             <property name="visible">True</property>
@@ -906,8 +906,8 @@
                         <property name="label" translatable="yes">Seek _to Selection</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoSeekToSelection"/>
-                        <accelerator key="F4" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                         <accelerator key="r" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
+                        <accelerator key="F4" signal="activate" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -917,8 +917,8 @@
                         <property name="label" translatable="yes">Select Nearest Subtitle</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoSelectNearestSubtitle"/>
-                        <accelerator key="r" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                         <accelerator key="F4" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="r" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
@@ -927,8 +927,8 @@
                         <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"/>
                         <accelerator key="F3" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+                        <accelerator key="j" signal="activate" modifiers="GDK_CONTROL_MASK"/>
                       </widget>
                     </child>
                     <child>
diff --git a/src/GnomeSubtitles/Core/Base.cs b/src/GnomeSubtitles/Core/Base.cs
index 5ec258e..0719dfe 100644
--- a/src/GnomeSubtitles/Core/Base.cs
+++ b/src/GnomeSubtitles/Core/Base.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2010 Pedro Castro
+ * Copyright (C) 2006-2011 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
@@ -44,6 +44,7 @@ public class Base {
 	private static EventHandlers handlers = null;
 	private static CommandManager commandManager = null;
 	private static Clipboards clipboards = null;
+	private static GlobalAccelerators globalAccelerators = null;
 	private static DragDrop dragDrop = null;
 	private static Config config = null;
 	private static Dialogs dialogs = null;
@@ -86,6 +87,10 @@ public class Base {
 	public static Clipboards Clipboards {
 		get { return clipboards; }
 	}
+	
+	public static GlobalAccelerators GlobalAccelerators {
+		get { return globalAccelerators; }
+	}
 
 	public static DragDrop DragDrop {
 		get { return dragDrop; }
@@ -271,6 +276,7 @@ public class Base {
 		
 		/* Initialize misc */
 		clipboards = new Clipboards();
+		globalAccelerators = new GlobalAccelerators();
 		dragDrop = new DragDrop();
 		config = new Config();
 		dialogs = new Dialogs();
diff --git a/src/GnomeSubtitles/Core/EventHandlers.cs b/src/GnomeSubtitles/Core/EventHandlers.cs
index 0697bd8..2a50226 100644
--- a/src/GnomeSubtitles/Core/EventHandlers.cs
+++ b/src/GnomeSubtitles/Core/EventHandlers.cs
@@ -21,6 +21,7 @@ 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;
@@ -33,6 +34,7 @@ namespace GnomeSubtitles.Core {
 public class EventHandlers {
 	private bool buttonStartEndKeyPressed = false; //Used to match grab focus and key release events
 	
+
 	/* File Menu */
 	
 	public void OnFileNew (object o, EventArgs args) {
@@ -459,6 +461,81 @@ public class EventHandlers {
 
 		Gtk.Drag.Finish(args.Context, success, false, args.Time);
 	}
+	
+	
+	/* Global Accelerators */
+
+	public void OnGlobalSubtitleStartIncrease (object o, EventArgs args) {
+		if (Base.Ui.View.Selection.Count == 1) {
+			Base.Ui.Edit.SpinButtons.StartSpinButtonIncreaseStep();
+		}
+	}
+	
+	public void OnGlobalSubtitleStartDecrease (object o, EventArgs args) {
+		/* Do nothing if there isn't only 1 subtitle selected */
+		if (Base.Ui.View.Selection.Count != 1)
+			return;
+		
+		Subtitle subtitle = Base.Ui.View.Selection.Subtitle;
+		if ((Base.TimingModeIsTimes && (subtitle.Times.Start >= TimeSpan.FromMilliseconds(Base.Config.PrefsTimingsTimeStep)))
+				|| (!Base.TimingModeIsTimes) && (subtitle.Frames.Start >= Base.Config.PrefsTimingsFramesStep)){
+
+			Base.Ui.Edit.SpinButtons.StartSpinButtonDecreaseStep();
+		}
+	}
+	
+	public void OnGlobalSubtitleEndIncrease (object o, EventArgs args) {
+		if (Base.Ui.View.Selection.Count == 1) {
+			Base.Ui.Edit.SpinButtons.EndSpinButtonIncreaseStep();
+		}
+	}
+	
+	public void OnGlobalSubtitleEndDecrease (object o, EventArgs args) {
+		/* Do nothing if there isn't only 1 subtitle selected */
+		if (Base.Ui.View.Selection.Count != 1)
+			return;
+		
+		Subtitle subtitle = Base.Ui.View.Selection.Subtitle;
+		if ((Base.TimingModeIsTimes && (subtitle.Times.End >= TimeSpan.FromMilliseconds(Base.Config.PrefsTimingsTimeStep)))
+				|| (!Base.TimingModeIsTimes) && (subtitle.Frames.End >= Base.Config.PrefsTimingsFramesStep)){
+
+			Base.Ui.Edit.SpinButtons.EndSpinButtonDecreaseStep();
+		}
+	}
+	
+	public void OnGlobalSelectionShiftIncrease (object o, EventArgs args) {
+		/* Do nothing if no subtitles are selected */
+		if (Base.Ui.View.Selection.Count == 0)
+			return;
+		
+		if (Base.TimingModeIsTimes) {
+			Base.CommandManager.Execute(new ShiftTimingsCommand(TimeSpan.FromMilliseconds(Base.Config.PrefsTimingsTimeStep), SelectionIntended.Simple));
+		}
+		else {
+			Base.CommandManager.Execute(new ShiftTimingsCommand(Base.Config.PrefsTimingsFramesStep, SelectionIntended.Simple));
+		}
+	}
+	
+	public void OnGlobalSelectionShiftDecrease (object o, EventArgs args) {
+		Subtitle firstSelectedSubtitle = Base.Ui.View.Selection.FirstSubtitle;
+		
+		/* Do nothing if no subtitles are selected */
+		if (firstSelectedSubtitle == null)
+			return;
+		
+		if (Base.TimingModeIsTimes) {
+			TimeSpan timeStep = TimeSpan.FromMilliseconds(Base.Config.PrefsTimingsTimeStep);
+			if (firstSelectedSubtitle.Times.Start >= timeStep) {
+				Base.CommandManager.Execute(new ShiftTimingsCommand(timeStep.Negate(), SelectionIntended.Simple));
+			}
+		}
+		else {
+			int framesStep = Base.Config.PrefsTimingsFramesStep;
+			if (firstSelectedSubtitle.Frames.Start >= framesStep) {
+				Base.CommandManager.Execute(new ShiftTimingsCommand(-framesStep, SelectionIntended.Simple));
+			}
+		}
+	}
 
 }
 
diff --git a/src/GnomeSubtitles/Core/GlobalAccelerators.cs b/src/GnomeSubtitles/Core/GlobalAccelerators.cs
new file mode 100644
index 0000000..21a0b5a
--- /dev/null
+++ b/src/GnomeSubtitles/Core/GlobalAccelerators.cs
@@ -0,0 +1,69 @@
+/*
+ * This file is part of Gnome Subtitles.
+ * Copyright (C) 2011 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 Gdk;
+using Gtk;
+using System;
+
+namespace GnomeSubtitles.Core {
+
+public class GlobalAccelerators {
+	private AccelGroup accelGroup = null;
+	private Menu hiddenMenu = null; //Needed to assign actions, not visible
+	
+	public GlobalAccelerators () {
+		Base.InitFinished += OnBaseInitFinished;
+	}
+	
+	/* Private members */
+	
+	private void Init () {
+		this.accelGroup = new AccelGroup();
+		this.hiddenMenu = new Menu();
+		
+		Base.Ui.Window.AddAccelGroup(this.accelGroup);
+
+		AddAccelerator((uint)Gdk.Key.plus, Gdk.ModifierType.ControlMask, AccelFlags.Visible, Base.Handlers.OnGlobalSubtitleStartIncrease);
+		AddAccelerator((uint)Gdk.Key.minus, Gdk.ModifierType.ControlMask, AccelFlags.Visible, Base.Handlers.OnGlobalSubtitleStartDecrease);
+		
+		AddAccelerator((uint)Gdk.Key.plus, Gdk.ModifierType.ControlMask | Gdk.ModifierType.Mod1Mask, AccelFlags.Visible, Base.Handlers.OnGlobalSubtitleEndIncrease);
+		AddAccelerator((uint)Gdk.Key.minus, Gdk.ModifierType.ControlMask | Gdk.ModifierType.Mod1Mask, AccelFlags.Visible, Base.Handlers.OnGlobalSubtitleEndDecrease);
+		
+		AddAccelerator((uint)Gdk.Key.asterisk, Gdk.ModifierType.ControlMask, AccelFlags.Visible, Base.Handlers.OnGlobalSelectionShiftIncrease); //Ctrl Shift + is actually Ctrl *
+		AddAccelerator((uint)Gdk.Key.underscore, Gdk.ModifierType.ControlMask, AccelFlags.Visible, Base.Handlers.OnGlobalSelectionShiftDecrease); //Ctrl Shift - is actually Ctrl _
+	}
+	
+	private void AddAccelerator (uint key, ModifierType modifiers, AccelFlags accelFlags, EventHandler handler) {
+		MenuItem menuItem = new MenuItem();
+		menuItem.AddAccelerator("activate", this.accelGroup, key, modifiers, accelFlags);
+		menuItem.Activated += handler;
+		menuItem.Show();
+		
+		this.hiddenMenu.Append(menuItem);
+	}
+	
+	/* Event members */
+	
+	private void OnBaseInitFinished () {
+		Init();
+    }
+
+}
+
+}
\ No newline at end of file
diff --git a/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs b/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs
index 2531575..9dee714 100644
--- a/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs
+++ b/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs
@@ -29,6 +29,7 @@ using System;
 namespace GnomeSubtitles.Dialog {
 
 //TODO set spinButton limits according to selection type
+//FIXME show informative message about the Ctrl+Shift++ shortcuts
 public class TimingsShiftDialog : GladeDialog {
 	private TimingMode timingMode = TimingMode.Frames;
 
diff --git a/src/GnomeSubtitles/Ui/Edit/SubtitleEdit.cs b/src/GnomeSubtitles/Ui/Edit/SubtitleEdit.cs
index 41c244a..dc8093a 100644
--- a/src/GnomeSubtitles/Ui/Edit/SubtitleEdit.cs
+++ b/src/GnomeSubtitles/Ui/Edit/SubtitleEdit.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2009 Pedro Castro
+ * Copyright (C) 2006-2009,2011 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
@@ -62,6 +62,10 @@ public class SubtitleEdit {
     	get { return translationEdit; }
     }
     
+    public SubtitleEditSpinButtons SpinButtons {
+    	get { return spinButtons; }
+    }
+    
     /// <summary>The current text selection, either text or translation. An empty string if no text is selected.</summary>
     public string SelectedTextContent {
 		get {
diff --git a/src/GnomeSubtitles/Ui/Edit/SubtitleEditSpinButtons.cs b/src/GnomeSubtitles/Ui/Edit/SubtitleEditSpinButtons.cs
index 604a27e..61dfae3 100644
--- a/src/GnomeSubtitles/Ui/Edit/SubtitleEditSpinButtons.cs
+++ b/src/GnomeSubtitles/Ui/Edit/SubtitleEditSpinButtons.cs
@@ -70,6 +70,22 @@ public class SubtitleEditSpinButtons {
     	endSpinButton = this.endSpinButton;
     	durationSpinButton = this.durationSpinButton;
     }
+    
+    public void StartSpinButtonIncreaseStep () {
+    	startSpinButton.Spin(SpinType.StepForward, 0); //0 uses the defined stepIncrement
+    }
+
+    public void StartSpinButtonDecreaseStep () {
+    	startSpinButton.Spin(SpinType.StepBackward, 0); //0 uses the defined stepIncrement
+    }
+    
+    public void EndSpinButtonIncreaseStep () {
+    	endSpinButton.Spin(SpinType.StepForward, 0); //0 uses the defined stepIncrement
+    }
+
+    public void EndSpinButtonDecreaseStep () {
+    	endSpinButton.Spin(SpinType.StepBackward, 0); //0 uses the defined stepIncrement
+    }
 
 
 	/* Private methods */



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