[gnome-subtitles] Watch subtitle selection change when SubtitleEditText/Translation are visible



commit 33ee73ef875e058a72041f99201aa18a4afe800a
Author: Pedro Castro <pedro gnomesubtitles org>
Date:   Sat Jul 16 20:34:31 2011 +0100

    Watch subtitle selection change when SubtitleEditText/Translation are visible
    
    Events that are dependent on document/translation loaded are now in SubtitleEditText/Translation

 src/GnomeSubtitles/Ui/Edit/SubtitleEditText.cs     |   23 ++++++++--
 src/GnomeSubtitles/Ui/Edit/SubtitleEditTextView.cs |   47 +++++++++-----------
 .../Ui/Edit/SubtitleEditTranslation.cs             |   24 +++++-----
 3 files changed, 52 insertions(+), 42 deletions(-)
---
diff --git a/src/GnomeSubtitles/Ui/Edit/SubtitleEditText.cs b/src/GnomeSubtitles/Ui/Edit/SubtitleEditText.cs
index 8d4b7f9..6c00e51 100644
--- a/src/GnomeSubtitles/Ui/Edit/SubtitleEditText.cs
+++ b/src/GnomeSubtitles/Ui/Edit/SubtitleEditText.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2007-2009 Pedro Castro
+ * Copyright (C) 2007-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
@@ -57,17 +57,30 @@ public class SubtitleEditText : SubtitleEditTextView {
 	
 	/* Event members */
 	
-	protected override void ConnectLanguageChangedSignal () {
-		Base.SpellLanguages.TextLanguageChanged += OnSpellLanguageChanged;
-	}
-	
 	private void OnBaseInitFinished () {
 		Base.Ui.Edit.TranslationEdit.ToggleOverwrite += OnTranslationEditToggleOverwrite;
+
+		Base.DocumentLoaded += OnBaseDocumentLoaded;
+		Base.DocumentUnloaded += OnBaseDocumentUnloaded;
 	}
 	
 	private void OnTranslationEditToggleOverwrite (object o, EventArgs args) {
 		ToggleOverwriteSilent();
 	}
+	
+	private void OnBaseDocumentLoaded (Document document) {
+		Base.Ui.View.Selection.Changed += OnSubtitleSelectionChanged;
+		
+		Base.SpellLanguages.ToggleEnabled += OnSpellToggleEnabled;
+		Base.SpellLanguages.TextLanguageChanged += OnSpellLanguageChanged;
+	}
+	
+	private void OnBaseDocumentUnloaded (Document document) {
+		Base.Ui.View.Selection.Changed -= OnSubtitleSelectionChanged;
+		
+		Base.SpellLanguages.ToggleEnabled += OnSpellToggleEnabled;
+		Base.SpellLanguages.TextLanguageChanged += OnSpellLanguageChanged;
+	}
 }
 
 }
\ No newline at end of file
diff --git a/src/GnomeSubtitles/Ui/Edit/SubtitleEditTextView.cs b/src/GnomeSubtitles/Ui/Edit/SubtitleEditTextView.cs
index 9a74ce9..2c10448 100644
--- a/src/GnomeSubtitles/Ui/Edit/SubtitleEditTextView.cs
+++ b/src/GnomeSubtitles/Ui/Edit/SubtitleEditTextView.cs
@@ -73,7 +73,6 @@ public abstract class SubtitleEditTextView {
 	protected abstract void ExecuteInsertCommand (int index, string insertion);
 	protected abstract void ExecuteDeleteCommand (int index, string deletion, int cursor);
 	protected abstract SpellLanguage GetSpellActiveLanguage ();
-	protected abstract void ConnectLanguageChangedSignal ();
 	
 	/* Events */
 	public event EventHandler ToggleOverwrite = null;
@@ -391,17 +390,6 @@ public abstract class SubtitleEditTextView {
 			EmitToggleOverwrite();
 	}
 	
-	private void OnSpellToggleEnabled () {
-		bool enabled = Base.SpellLanguages.Enabled;
-		if (enabled) {
-			GtkSpellAttach();
-			SpellLanguage language = GetSpellActiveLanguage();
-			GtkSpellSetLanguage(language);
-		}
-		else
-			GtkSpellDetach();
-	}
-	
 	private void OnDestroyed (object o, EventArgs args) {
 		GtkSpellDetach();
 	}
@@ -442,20 +430,6 @@ public abstract class SubtitleEditTextView {
 		textView.KeyPressEvent += OnKeyPressed;
 		textView.ToggleOverwrite += OnToggleOverwrite;
 		textView.Destroyed += OnDestroyed;
-		
-		/* Spell signals */
-		Base.SpellLanguages.ToggleEnabled += OnSpellToggleEnabled;
-		ConnectLanguageChangedSignal();
-		
-		/* Selection signals */
-		Base.Ui.View.Selection.Changed += OnSubtitleSelectionChanged;
-    }
-    
-    private void OnSubtitleSelectionChanged (TreePath[] paths, Subtitle subtitle) {
-    	if (subtitle != null)
-    		LoadSubtitle(subtitle);
-    	else
-    		ClearFields();
     }
     
     private void EmitToggleOverwrite () {
@@ -471,9 +445,30 @@ public abstract class SubtitleEditTextView {
 			GtkSpellSetLanguage(language);
 		}
 	}
+		
+	protected void OnSpellToggleEnabled () {
+		bool enabled = Base.SpellLanguages.Enabled;
+		if (enabled) {
+			GtkSpellAttach();
+			SpellLanguage language = GetSpellActiveLanguage();
+			GtkSpellSetLanguage(language);
+		}
+		else
+			GtkSpellDetach();
+	}
+
+	protected void OnSubtitleSelectionChanged (TreePath[] paths, Subtitle subtitle) {
+		if (subtitle != null)
+    		LoadSubtitle(subtitle);
+    	else
+    		ClearFields();
+    }
 	
 	protected void SetVisibility (bool visible) {
 		GetScrolledWindow().Visible = visible;
+		if (!visible) {
+			ClearFields();
+		}
 	}
 	
 	protected void ClearFields () {
diff --git a/src/GnomeSubtitles/Ui/Edit/SubtitleEditTranslation.cs b/src/GnomeSubtitles/Ui/Edit/SubtitleEditTranslation.cs
index ca1b3e0..aa7c9ec 100644
--- a/src/GnomeSubtitles/Ui/Edit/SubtitleEditTranslation.cs
+++ b/src/GnomeSubtitles/Ui/Edit/SubtitleEditTranslation.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2007-2009 Pedro Castro
+ * Copyright (C) 2007-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
@@ -56,27 +56,29 @@ public class SubtitleEditTranslation : SubtitleEditTextView {
 	}
 	
 	/* Event members */
-	
-	protected override void ConnectLanguageChangedSignal () {
-		Base.SpellLanguages.TranslationLanguageChanged += OnSpellLanguageChanged;
-	}
 
 	private void OnBaseInitFinished () {
 		Base.Ui.Edit.TextEdit.ToggleOverwrite += OnTextEditToggleOverwrite;
+		
 		Base.TranslationLoaded += OnBaseTranslationLoaded;
 		Base.TranslationUnloaded += OnBaseTranslationUnloaded;
 	}
 	
 	private void OnBaseTranslationLoaded () {
-		Subtitle subtitle = Base.Ui.View.Selection.Subtitle;
-		if (subtitle != null)
-			LoadSubtitle(subtitle);
-
-    	SetVisibility(true);
+		Base.Ui.View.Selection.Changed += OnSubtitleSelectionChanged;
+    	    	
+    	Base.SpellLanguages.ToggleEnabled += OnSpellToggleEnabled;
+		Base.SpellLanguages.TranslationLanguageChanged += OnSpellLanguageChanged;
+		
+		SetVisibility(true);
 	}
 	
 	private void OnBaseTranslationUnloaded () {
-		ClearFields();
+		Base.Ui.View.Selection.Changed -= OnSubtitleSelectionChanged;
+		
+		Base.SpellLanguages.ToggleEnabled -= OnSpellToggleEnabled;
+		Base.SpellLanguages.TranslationLanguageChanged -= OnSpellLanguageChanged;
+		
     	SetVisibility(false);
 	}
 	



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