[gnome-subtitles] Option to save Translation when saving Subtitles (fixes #511167)



commit b3b6630214892fc3a83dd270ebc8a8cb310c34c9
Author: Pedro Castro <mail>
Date:   Sun Feb 7 20:35:52 2010 +0000

    Option to save Translation when saving Subtitles (fixes #511167)

 data/gnome-subtitles.schemas                   |   11 +++++++++++
 src/Glade/PreferencesDialog.glade              |    3 ++-
 src/GnomeSubtitles/Core/Config.cs              |    7 +++++++
 src/GnomeSubtitles/Core/EventHandlers.cs       |    8 ++++++++
 src/GnomeSubtitles/Dialog/PreferencesDialog.cs |   11 +++++++++--
 src/GnomeSubtitles/Ui/MainUi.cs                |   10 ++++++----
 6 files changed, 43 insertions(+), 7 deletions(-)
---
diff --git a/data/gnome-subtitles.schemas b/data/gnome-subtitles.schemas
index 2dd49fc..48dbee8 100644
--- a/data/gnome-subtitles.schemas
+++ b/data/gnome-subtitles.schemas
@@ -14,6 +14,17 @@
 			</locale>
 		</schema>
 		<schema>
+			<key>/schemas/apps/gnome-subtitles/preferences/translation/save_all</key>
+			<applyto>/apps/gnome-subtitles/preferences/translation/save_all</applyto>
+			<owner>gnome-subtitles</owner>
+			<type>bool</type>
+			<default>TRUE</default>
+			<locale name="C">
+				<short>Save translation when saving subtitles</short>
+				<long>Whether to save existing translations when saving subtitles.</long>
+			</locale>
+		</schema>
+		<schema>
 			<key>/schemas/apps/gnome-subtitles/preferences/video/auto_choose_file</key>
 			<applyto>/apps/gnome-subtitles/preferences/video/auto_choose_file</applyto>
 			<owner>gnome-subtitles</owner>
diff --git a/src/Glade/PreferencesDialog.glade b/src/Glade/PreferencesDialog.glade
index 9070be2..d908f54 100644
--- a/src/Glade/PreferencesDialog.glade
+++ b/src/Glade/PreferencesDialog.glade
@@ -34,13 +34,14 @@
                         <property name="orientation">vertical</property>
                         <property name="spacing">5</property>
                         <child>
-                          <widget class="GtkCheckButton" id="translationSaveCheckButton">
+                          <widget class="GtkCheckButton" id="translationSaveAllCheckButton">
                             <property name="label" translatable="yes">When saving subtitles, also save their _translation</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>
+                            <signal name="toggled" handler="OnTranslationSaveAllToggled"/>
                           </widget>
                           <packing>
                             <property name="position">0</property>
diff --git a/src/GnomeSubtitles/Core/Config.cs b/src/GnomeSubtitles/Core/Config.cs
index 2460ab1..dba9839 100644
--- a/src/GnomeSubtitles/Core/Config.cs
+++ b/src/GnomeSubtitles/Core/Config.cs
@@ -44,6 +44,7 @@ public class Config {
 	private const string keyPrefsVideo = keyPrefs + "video/";
 	private const string keyPrefsWindow = keyPrefs + "window/";
 	private const string keyPrefsDefaults = keyPrefs + "defaults/";
+	private const string keyPrefsTranslation = keyPrefs + "translation/";
 
 	/* Constant key strings */
 	private const string keyPrefsEncodingsShownInMenu = keyPrefsEncodings + "shown_in_menu";
@@ -62,6 +63,7 @@ public class Config {
 	private const string keyPrefsDefaultsFileSaveFormat = keyPrefsDefaults + "file_save_format";
 	private const string keyPrefsDefaultsFileSaveNewlineOption = keyPrefsDefaults + "file_save_newline_option";
 	private const string keyPrefsDefaultsFileSaveNewline = keyPrefsDefaults + "file_save_newline";
+	private const string keyPrefsTranslationSaveAll = keyPrefsTranslation + "save_all";
 
 	public Config () {
 		client = new Client();
@@ -176,6 +178,11 @@ public class Config {
 		set { Set(keyPrefsDefaultsFileSaveNewline, value.ToString()); }
 	}
 
+	public bool PrefsTranslationSaveAll {
+		get { return GetBool(keyPrefsTranslationSaveAll, true); }
+		set { Set(keyPrefsTranslationSaveAll, value); }
+	}
+
 	
 	/* Private members */
 	
diff --git a/src/GnomeSubtitles/Core/EventHandlers.cs b/src/GnomeSubtitles/Core/EventHandlers.cs
index cf19198..98261ae 100644
--- a/src/GnomeSubtitles/Core/EventHandlers.cs
+++ b/src/GnomeSubtitles/Core/EventHandlers.cs
@@ -44,10 +44,18 @@ public class EventHandlers {
 	
 	public void OnFileSave (object o, EventArgs args) {
 		Base.Ui.Save();
+
+		if (Base.Config.PrefsTranslationSaveAll) {
+			OnFileTranslationSave(o, args);
+		}
 	}
 	
 	public void OnFileSaveAs (object o, EventArgs args) {
 		Base.Ui.SaveAs();
+		
+		if (Base.Config.PrefsTranslationSaveAll) {
+			OnFileTranslationSave(o, args);
+		}
 	}
 	
 	public void OnFileTranslationNew (object o, EventArgs args) {
diff --git a/src/GnomeSubtitles/Dialog/PreferencesDialog.cs b/src/GnomeSubtitles/Dialog/PreferencesDialog.cs
index aefb71e..b586423 100644
--- a/src/GnomeSubtitles/Dialog/PreferencesDialog.cs
+++ b/src/GnomeSubtitles/Dialog/PreferencesDialog.cs
@@ -40,7 +40,7 @@ public class PreferencesDialog : GladeDialog {
 	private NewlineTypeComboBox fileSaveNewline = null;
 
 	/* Widgets */
-	[WidgetAttribute] private CheckButton translationSaveCheckButton = null;
+	[WidgetAttribute] private CheckButton translationSaveAllCheckButton = null;
 	[WidgetAttribute] private CheckButton videoAutoChooseFileCheckButton = null;
 	[WidgetAttribute] private ComboBox fileOpenEncodingComboBox = null;
 	[WidgetAttribute] private ComboBox fileOpenFallbackEncodingComboBox = null;
@@ -57,6 +57,9 @@ public class PreferencesDialog : GladeDialog {
 	/* Private members */
 	
 	private void LoadValues () {
+		/* Translation Save All */
+		translationSaveAllCheckButton.Active = Base.Config.PrefsTranslationSaveAll;
+
 		SetDefaultsFileOpenEncoding();
 		SetDefaultsFileOpenFallbackEncoding();
 		SetDefaultsFileSaveEncoding();
@@ -148,7 +151,7 @@ public class PreferencesDialog : GladeDialog {
 	}
 
 	private void ResetDialogToDefaults () {
-		translationSaveCheckButton.Active = true;
+		translationSaveAllCheckButton.Active = true;
 
 		fileOpenEncoding.ActiveSelection = 0; //Auto detect
 		fileOpenFallbackEncoding.ActiveSelection = 0; //Current Locale
@@ -267,6 +270,10 @@ public class PreferencesDialog : GladeDialog {
 		Base.Config.PrefsVideoAutoChooseFile = videoAutoChooseFileCheckButton.Active;
 	}
 
+	private void OnTranslationSaveAllToggled (object o, EventArgs args) {
+		Base.Config.PrefsTranslationSaveAll = translationSaveAllCheckButton.Active;
+	}
+
 	protected override bool ProcessResponse (ResponseType response) {
 		if (response == ResponseType.Cancel) {
 			ResetDialogToDefaults();
diff --git a/src/GnomeSubtitles/Ui/MainUi.cs b/src/GnomeSubtitles/Ui/MainUi.cs
index c2487ba..576541c 100644
--- a/src/GnomeSubtitles/Ui/MainUi.cs
+++ b/src/GnomeSubtitles/Ui/MainUi.cs
@@ -176,7 +176,7 @@ public class MainUi {
     
     /// <summary>Executes a Save operation.</summary>
     /// <remarks>If the document hasn't been saved before, a SaveAs is executed.</remarks>
-    /// <returns>Whether the file was saved or not.</returns>
+    /// <returns>Whether the file was saved.</returns>
     public bool Save () {
     	if (Base.Document.CanTextBeSaved) { //Check if document can be saved or needs a SaveAs
 			Save(Base.Document.TextFile);
@@ -188,7 +188,7 @@ public class MainUi {
 
     /// <summary>Executes a SaveAs operation.</summary>
     /// <remarks>After saving, the timing mode is set to the timing mode of the subtitle format using when saving.</remarks>
-    /// <returns>Whether the file was saved or not.</returns>
+    /// <returns>Whether the file was saved.</returns>
     public bool SaveAs () {
 		FileSaveAsDialog dialog = Base.Dialogs.Get(typeof(FileSaveAsDialog)) as FileSaveAsDialog;
 		FileProperties properties = ShowSaveAsDialog(dialog);
@@ -322,8 +322,10 @@ public class MainUi {
 			FileSaveErrorDialog errorDialog = new FileSaveErrorDialog(fileProperties.Path, exception);
 			errorDialog.Show();
 			bool toSaveAgain = errorDialog.WaitForResponse();
-	    	if (toSaveAgain)
-	    		SaveAs();	
+	    	if (toSaveAgain) {
+	    		SaveAs();
+				return;
+			}
 		}
 	}
 	



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