[gnome-subtitles] Manage dialogs according to their scope.



commit 220672e81afbd2954db2b0a6f2a4b67953142c04
Author: Pedro Castro <mail pedrocastro org>
Date:   Sun May 31 01:30:14 2009 +0100

    Manage dialogs according to their scope.
    
    Refactoring that allows to manage the dialogs' lifetime according to their scope. This allows to destroy them on certain events (document unloaded, video unloaded, etc).
---
 gnome-subtitles.mdp                                |   29 +-
 m4/gnome-doc-utils.m4                              |    3 +-
 m4/intltool.m4                                     |   64 +++--
 src/GnomeSubtitles/Core/EventHandlers.cs           |   21 +-
 src/GnomeSubtitles/Core/Search.cs                  |    2 +-
 src/GnomeSubtitles/Dialog/AboutDialog.cs           |    2 +-
 src/GnomeSubtitles/Dialog/BaseDialog.cs            |    4 +-
 src/GnomeSubtitles/Dialog/Dialogs.cs               |   88 ++++--
 src/GnomeSubtitles/Dialog/FileOpenDialog.cs        |    2 +-
 src/GnomeSubtitles/Dialog/FileSaveAsDialog.cs      |  303 +------------------
 src/GnomeSubtitles/Dialog/MessageDialog.cs         |    2 +-
 src/GnomeSubtitles/Dialog/PreferencesDialog.cs     |    2 +-
 src/GnomeSubtitles/Dialog/SearchDialog.cs          |    8 +-
 src/GnomeSubtitles/Dialog/SetLanguageDialog.cs     |    6 +-
 .../{WarningDialog.cs => SetTextLanguageDialog.cs} |   13 +-
 ...ngDialog.cs => SetTranslationLanguageDialog.cs} |   13 +-
 .../Dialog/SubtitleFileChooserDialog.cs            |    4 +-
 .../Dialog/SubtitleFileSaveAsDialog.cs             |  330 ++++++++++++++++++++
 src/GnomeSubtitles/Dialog/SyncPoints.cs            |  108 -------
 src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs    |    4 +-
 .../Dialog/TimingsSynchronizeDialog.cs             |   10 +-
 ...WarningDialog.cs => TranslationSaveAsDialog.cs} |   13 +-
 .../Dialog/{ => Unmanaged}/BasicErrorDialog.cs     |    4 +-
 .../Dialog/{ => Unmanaged}/ErrorDialog.cs          |    4 +-
 .../Dialog/{ => Unmanaged}/FileOpenErrorDialog.cs  |    4 +-
 .../Dialog/{ => Unmanaged}/FileSaveErrorDialog.cs  |    4 +-
 .../{ => Unmanaged}/SaveConfirmationDialog.cs      |    8 +-
 .../{ => Unmanaged}/SubtitleFileOpenErrorDialog.cs |    4 +-
 .../Dialog/{ => Unmanaged}/VideoErrorDialog.cs     |    4 +-
 .../Dialog/{ => Unmanaged}/WarningDialog.cs        |    4 +-
 src/GnomeSubtitles/Dialog/VideoOpenDialog.cs       |    4 +-
 src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs     |    2 +-
 src/GnomeSubtitles/Execution/BugReporter.cs        |    4 +-
 src/GnomeSubtitles/Ui/MainUi.cs                    |   14 +-
 src/GnomeSubtitles/Ui/VideoPreview/Video.cs        |    2 +-
 src/Makefile.am                                    |    1 +
 36 files changed, 528 insertions(+), 566 deletions(-)

diff --git a/gnome-subtitles.mdp b/gnome-subtitles.mdp
index 9042ace..d7cb739 100644
--- a/gnome-subtitles.mdp
+++ b/gnome-subtitles.mdp
@@ -1,6 +1,6 @@
 <Project name="gnome-subtitles" fileversion="2.0" language="C#" clr-version="Net_2_0" targetFramework="2.0" ctype="DotNetProject">
   <Policies>
-    <TextStylePolicy FileWidth="120" TabWidth="4" TabsToSpaces="False" NoTabsAfterNonTabs="False" RemoveTrailingWhitespace="True" EolMarker="Native" />
+    <TextStylePolicy FileWidth="120" TabWidth="4" TabsToSpaces="False" NoTabsAfterNonTabs="False" RemoveTrailingWhitespace="True" EolMarker="Unix" />
   </Policies>
   <Configurations active="Debug">
     <Configuration name="Debug" ctype="DotNetProjectConfiguration">
@@ -40,21 +40,15 @@
     <File name="data/gnome-subtitles.png" subtype="Code" buildaction="EmbedAsResource" />
     <File name="data/gnome-subtitles-logo.png" subtype="Code" buildaction="EmbedAsResource" />
     <File name="src/GnomeSubtitles/Dialog/TimingsAdjustDialog.cs" subtype="Code" buildaction="Compile" />
-    <File name="src/GnomeSubtitles/Dialog/SaveConfirmationDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Dialog/FileOpenDialog.cs" subtype="Code" buildaction="Compile" />
-    <File name="src/GnomeSubtitles/Dialog/FileOpenErrorDialog.cs" subtype="Code" buildaction="Compile" />
-    <File name="src/GnomeSubtitles/Dialog/FileSaveAsDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Dialog/VideoOpenDialog.cs" subtype="Code" buildaction="Compile" />
-    <File name="src/GnomeSubtitles/Dialog/SubtitleFileOpenErrorDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="data/video-set-subtitle-start-16x.png" subtype="Code" buildaction="EmbedAsResource" />
     <File name="data/video-set-subtitle-end-16x.png" subtype="Code" buildaction="EmbedAsResource" />
     <File name="src/GnomeSubtitles/Dialog/PreferencesDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Dialog/EncodingsDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Execution/BugReporter.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs" subtype="Code" buildaction="Compile" />
-    <File name="src/GnomeSubtitles/Dialog/ErrorDialog.cs" subtype="Code" buildaction="Compile" />
-    <File name="src/GnomeSubtitles/Dialog/FileSaveErrorDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Core/Config.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Core/Base.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Core/Util.cs" subtype="Code" buildaction="Compile" />
@@ -72,7 +66,6 @@
     <File name="src/Glade/TimingsAdjustDialog.glade" subtype="Code" buildaction="EmbedAsResource" />
     <File name="src/Glade/TimingsShiftDialog.glade" subtype="Code" buildaction="EmbedAsResource" />
     <File name="src/Glade/VideoOpenDialog.glade" subtype="Code" buildaction="EmbedAsResource" />
-    <File name="src/GnomeSubtitles/Dialog/VideoErrorDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Dialog/SetLanguageDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="src/Glade/SetLanguageDialog.glade" subtype="Code" buildaction="EmbedAsResource" />
     <File name="src/GnomeSubtitles/Execution/gnome-subtitles.exe.config" subtype="Code" buildaction="EmbedAsResource" />
@@ -130,8 +123,6 @@
     <File name="src/GnomeSubtitles/Dialog/MessageDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Dialog/Util.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Dialog/BaseDialog.cs" subtype="Code" buildaction="Compile" />
-    <File name="src/GnomeSubtitles/Dialog/WarningDialog.cs" subtype="Code" buildaction="Compile" />
-    <File name="src/GnomeSubtitles/Dialog/BasicErrorDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs" subtype="Code" buildaction="Compile" />
     <File name="src/Glade/VideoSeekToDialog.glade" subtype="Code" buildaction="EmbedAsResource" />
     <File name="src/GnomeSubtitles/Dialog/TimingsSynchronizeDialog.cs" subtype="Code" buildaction="Compile" />
@@ -145,16 +136,30 @@
     <File name="src/GnomeSubtitles/Core/SyncPoints.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Core/Command/SynchronizeTimingsCommand.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Dialog/DialogScope.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/Unmanaged" subtype="Directory" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/Unmanaged/BasicErrorDialog.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/Unmanaged/ErrorDialog.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/Unmanaged/FileOpenErrorDialog.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/Unmanaged/FileSaveErrorDialog.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/Unmanaged/SubtitleFileOpenErrorDialog.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/Unmanaged/VideoErrorDialog.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/SubtitleFileSaveAsDialog.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/FileSaveAsDialog.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/TranslationSaveAsDialog.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/Unmanaged/SaveConfirmationDialog.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/Unmanaged/WarningDialog.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/SetTextLanguageDialog.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/SetTranslationLanguageDialog.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
     <ProjectReference type="Gac" localcopy="True" refto="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
     <ProjectReference type="Gac" localcopy="True" refto="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-    <ProjectReference type="Assembly" localcopy="True" refto="../sublib/build/sublib.dll" />
     <ProjectReference type="Gac" localcopy="True" refto="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
-    <ProjectReference type="Gac" localcopy="True" refto="gconf-sharp, Version=2.24.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
     <ProjectReference type="Gac" localcopy="True" refto="glade-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
+    <ProjectReference type="Assembly" localcopy="True" specificVersion="False" refto="../sublib/build/sublib.dll" />
+    <ProjectReference type="Gac" localcopy="True" refto="gconf-sharp, Version=2.24.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
   </References>
   <LanguageParameters StartupObject="GnomeSubtitles.Execution.Executable" ApplicationIcon="." ctype="CSharpProjectParameters" />
   <Deployment.LinuxDeployData generateScript="False" />
diff --git a/m4/gnome-doc-utils.m4 b/m4/gnome-doc-utils.m4
index 04f79bb..4aef712 100644
--- a/m4/gnome-doc-utils.m4
+++ b/m4/gnome-doc-utils.m4
@@ -36,7 +36,8 @@ AM_CONDITIONAL([HAVE_GNOME_DOC_UTILS],[test "$gdu_cv_have_gdu" = "yes"])
 # GNOME_DOC_INIT ([MINIMUM-VERSION],[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
 #
 AC_DEFUN([GNOME_DOC_INIT],
-[
+[AC_REQUIRE([AC_PROG_LN_S])dnl
+
 ifelse([$1],,[gdu_cv_version_required=0.3.2],[gdu_cv_version_required=$1])
 
 PKG_CHECK_EXISTS([gnome-doc-utils >= $gdu_cv_version_required],
diff --git a/m4/intltool.m4 b/m4/intltool.m4
index 563981c..122d773 100644
--- a/m4/intltool.m4
+++ b/m4/intltool.m4
@@ -75,25 +75,25 @@ INTLTOOL_SOUNDLIST_RULE='%.soundlist: %.soundlist.in $(INTLTOOL_MERGE) $(wildcar
     INTLTOOL_SERVICE_RULE='%.service: %.service.in   $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -d -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< [$]@'
    INTLTOOL_POLICY_RULE='%.policy:    %.policy.in    $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*.po) ; LC_ALL=C $(INTLTOOL_MERGE) -x -u -c $(top_builddir)/po/.intltool-merge-cache $(top_srcdir)/po $< [$]@'
 
-AC_SUBST(INTLTOOL_DESKTOP_RULE)
-AC_SUBST(INTLTOOL_DIRECTORY_RULE)
-AC_SUBST(INTLTOOL_KEYS_RULE)
-AC_SUBST(INTLTOOL_PROP_RULE)
-AC_SUBST(INTLTOOL_OAF_RULE)
-AC_SUBST(INTLTOOL_PONG_RULE)
-AC_SUBST(INTLTOOL_SERVER_RULE)
-AC_SUBST(INTLTOOL_SHEET_RULE)
-AC_SUBST(INTLTOOL_SOUNDLIST_RULE)
-AC_SUBST(INTLTOOL_UI_RULE)
-AC_SUBST(INTLTOOL_XAM_RULE)
-AC_SUBST(INTLTOOL_KBD_RULE)
-AC_SUBST(INTLTOOL_XML_RULE)
-AC_SUBST(INTLTOOL_XML_NOMERGE_RULE)
-AC_SUBST(INTLTOOL_CAVES_RULE)
-AC_SUBST(INTLTOOL_SCHEMAS_RULE)
-AC_SUBST(INTLTOOL_THEME_RULE)
-AC_SUBST(INTLTOOL_SERVICE_RULE)
-AC_SUBST(INTLTOOL_POLICY_RULE)
+_IT_SUBST(INTLTOOL_DESKTOP_RULE)
+_IT_SUBST(INTLTOOL_DIRECTORY_RULE)
+_IT_SUBST(INTLTOOL_KEYS_RULE)
+_IT_SUBST(INTLTOOL_PROP_RULE)
+_IT_SUBST(INTLTOOL_OAF_RULE)
+_IT_SUBST(INTLTOOL_PONG_RULE)
+_IT_SUBST(INTLTOOL_SERVER_RULE)
+_IT_SUBST(INTLTOOL_SHEET_RULE)
+_IT_SUBST(INTLTOOL_SOUNDLIST_RULE)
+_IT_SUBST(INTLTOOL_UI_RULE)
+_IT_SUBST(INTLTOOL_XAM_RULE)
+_IT_SUBST(INTLTOOL_KBD_RULE)
+_IT_SUBST(INTLTOOL_XML_RULE)
+_IT_SUBST(INTLTOOL_XML_NOMERGE_RULE)
+_IT_SUBST(INTLTOOL_CAVES_RULE)
+_IT_SUBST(INTLTOOL_SCHEMAS_RULE)
+_IT_SUBST(INTLTOOL_THEME_RULE)
+_IT_SUBST(INTLTOOL_SERVICE_RULE)
+_IT_SUBST(INTLTOOL_POLICY_RULE)
 
 # Check the gettext tools to make sure they are GNU
 AC_PATH_PROG(XGETTEXT, xgettext)
@@ -110,12 +110,17 @@ if test -z "$xgversion" -o -z "$mmversion" -o -z "$mfversion"; then
     AC_MSG_ERROR([GNU gettext tools not found; required for intltool])
 fi
 
-AC_PATH_PROG(INTLTOOL_PERL, [perl])
+AC_PATH_PROG(INTLTOOL_PERL, perl)
 if test -z "$INTLTOOL_PERL"; then
-   AC_MSG_ERROR([perl not found; required for intltool])
+   AC_MSG_ERROR([perl not found])
 fi
-if test -z "`$INTLTOOL_PERL -v | fgrep '5.' 2> /dev/null`"; then
-   AC_MSG_ERROR([perl 5.x required for intltool])
+AC_MSG_CHECKING([for perl >= 5.8.1])
+$INTLTOOL_PERL -e "use 5.8.1;" > /dev/null 2>&1
+if test $? -ne 0; then
+   AC_MSG_ERROR([perl 5.8.1 is required for intltool])
+else
+   IT_PERL_VERSION="`$INTLTOOL_PERL -e \"printf '%vd', $^V\"`"
+   AC_MSG_RESULT([$IT_PERL_VERSION])
 fi
 if test "x$2" != "xno-xml"; then
    AC_MSG_CHECKING([for XML::Parser])
@@ -171,7 +176,7 @@ dnl The following CONFIG_COMMANDS should be exetuted at the very end
 dnl of config.status.
 AC_CONFIG_COMMANDS_PRE([
   AC_CONFIG_COMMANDS([$1/stamp-it], [
-    if [ ! grep "^# INTLTOOL_MAKEFILE$" "$1/Makefile.in" ]; then
+    if [ ! grep "^# INTLTOOL_MAKEFILE$" "$1/Makefile.in" > /dev/null ]; then
        AC_MSG_ERROR([$1/Makefile.in.in was not created by intltoolize.])
     fi
     rm -f "$1/stamp-it" "$1/stamp-it.tmp" "$1/POTFILES" "$1/Makefile.tmp"
@@ -193,6 +198,17 @@ AC_CONFIG_COMMANDS_PRE([
 ])dnl
 ])
 
+# _IT_SUBST(VARIABLE)
+# -------------------
+# Abstract macro to do either _AM_SUBST_NOTMAKE or AC_SUBST
+#
+AC_DEFUN([_IT_SUBST],
+[
+AC_SUBST([$1])
+m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([$1])])
+]
+)
+
 # deprecated macros
 AU_ALIAS([AC_PROG_INTLTOOL], [IT_PROG_INTLTOOL])
 # A hint is needed for aclocal from Automake <= 1.9.4:
diff --git a/src/GnomeSubtitles/Core/EventHandlers.cs b/src/GnomeSubtitles/Core/EventHandlers.cs
index 0f73977..ed00f69 100644
--- a/src/GnomeSubtitles/Core/EventHandlers.cs
+++ b/src/GnomeSubtitles/Core/EventHandlers.cs
@@ -19,6 +19,7 @@
 
 using GnomeSubtitles.Core.Command;
 using GnomeSubtitles.Dialog;
+using GnomeSubtitles.Dialog.Unmanaged;
 using GnomeSubtitles.Ui;
 using Gtk;
 using Mono.Unix;
@@ -68,11 +69,11 @@ public class EventHandlers {
 	}
 	
 	public void OnFileHeaders (object o, EventArgs args) {
-		new HeadersDialog().Show();
+		Base.Dialogs.Get(typeof(HeadersDialog)).Show();
 	}
 	
 	public void OnFileProperties (object o, EventArgs args) {
-		new FilePropertiesDialog().Show();
+		Base.Dialogs.Get(typeof(FilePropertiesDialog)).Show();
 	}
 	
 	public void OnFileClose (object o, EventArgs args) {
@@ -138,7 +139,7 @@ public class EventHandlers {
 	}
 
 	public void OnEditPreferences (object o, EventArgs args) {
-		new PreferencesDialog().Show();
+		Base.Dialogs.Get(typeof(PreferencesDialog)).Show();
 	}
 
 	/* View Menu */
@@ -208,15 +209,15 @@ public class EventHandlers {
 	}
 	
 	public void OnTimingsAdjust (object o, EventArgs args) {
-		new TimingsAdjustDialog().Show();	
+		Base.Dialogs.Get(typeof(TimingsAdjustDialog)).Show();
 	}
 	
 	public void OnTimingsShift (object o, EventArgs args) {
-		Base.Dialogs.TimingsShiftDialog.Show();
+		Base.Dialogs.Get(typeof(TimingsShiftDialog)).Show();
 	}
 	
 	public void OnTimingsSynchronize (object o, EventArgs args) {
-		new TimingsSynchronizeDialog().Show();
+		Base.Dialogs.Get(typeof(TimingsSynchronizeDialog)).Show();
 	}
 	
 	
@@ -244,7 +245,7 @@ public class EventHandlers {
 	}
 	
 	public void OnVideoSeekTo (object o, EventArgs args) {
-		new VideoSeekToDialog().Show();
+		Base.Dialogs.Get(typeof(VideoSeekToDialog)).Show();
 	}
 	
 	public void OnVideoSeekToSelection (object o, EventArgs args) {
@@ -281,11 +282,11 @@ public class EventHandlers {
 	}
 	
 	public void OnToolsSetTextLanguage (object o, EventArgs args) {
-		new SetLanguageDialog(SubtitleTextType.Text).Show();
+		Base.Dialogs.Get(typeof(SetTextLanguageDialog)).Show();
 	}
 	
 	public void OnToolsSetTranslationLanguage (object o, EventArgs args) {
-		new SetLanguageDialog(SubtitleTextType.Translation).Show();
+		Base.Dialogs.Get(typeof(SetTranslationLanguageDialog)).Show();
 	}
 	
 	
@@ -308,7 +309,7 @@ public class EventHandlers {
 	}
 	
 	public void OnHelpAbout (object o, EventArgs args) {
-		new Dialog.AboutDialog().Show();
+		Base.Dialogs.Get(typeof(Dialog.AboutDialog)).Show();
 	}
 	
 	
diff --git a/src/GnomeSubtitles/Core/Search.cs b/src/GnomeSubtitles/Core/Search.cs
index 48923a0..b414173 100644
--- a/src/GnomeSubtitles/Core/Search.cs
+++ b/src/GnomeSubtitles/Core/Search.cs
@@ -92,7 +92,7 @@ public class Search {
 	#region Private methods
 	
 	private void InitDialog (bool showReplace) {
-		dialog = Base.Dialogs.SearchDialog;
+		dialog = Base.Dialogs.Get(typeof(SearchDialog)) as SearchDialog;
 	
 		dialog.Show(showReplace);
 	}
diff --git a/src/GnomeSubtitles/Dialog/AboutDialog.cs b/src/GnomeSubtitles/Dialog/AboutDialog.cs
index 0fb2857..fd594bb 100644
--- a/src/GnomeSubtitles/Dialog/AboutDialog.cs
+++ b/src/GnomeSubtitles/Dialog/AboutDialog.cs
@@ -35,7 +35,7 @@ public class AboutDialog : GladeDialog {
 		SetHooks();
 		Init(gladeFilename, true);
 	
-		dialog = getDialog() as Gtk.AboutDialog;
+		dialog = GetDialog() as Gtk.AboutDialog;
 		SetInfo();
 	}
 	
diff --git a/src/GnomeSubtitles/Dialog/BaseDialog.cs b/src/GnomeSubtitles/Dialog/BaseDialog.cs
index 3de1848..805e853 100644
--- a/src/GnomeSubtitles/Dialog/BaseDialog.cs
+++ b/src/GnomeSubtitles/Dialog/BaseDialog.cs
@@ -80,11 +80,11 @@ public abstract class BaseDialog {
 		dialog.Response += OnResponse;
 	}
 
-	protected Gtk.Dialog getDialog () {
+	protected Gtk.Dialog GetDialog () {
 		return dialog;
 	}
 
-	protected void setReturnValue (bool returnValue) {
+	protected void SetReturnValue (bool returnValue) {
 		this.returnValue = returnValue;
 	}
 
diff --git a/src/GnomeSubtitles/Dialog/Dialogs.cs b/src/GnomeSubtitles/Dialog/Dialogs.cs
index d63c89e..5c3f02d 100644
--- a/src/GnomeSubtitles/Dialog/Dialogs.cs
+++ b/src/GnomeSubtitles/Dialog/Dialogs.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2007-2008 Pedro Castro
+ * Copyright (C) 2007-2009 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
@@ -17,49 +17,67 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-using SubLib.Core.Domain;
+using GnomeSubtitles.Core;
+using System.Collections;
+using System;
 
 namespace GnomeSubtitles.Dialog {
 
 public class Dialogs {
-	private FileSaveAsDialog fileSaveAsDialog = null;
-	private FileSaveAsDialog translationSaveAsDialog = null;
-	private SearchDialog searchDialog = null;
-	private TimingsShiftDialog timingsShiftDialog = null;
-	
-	public FileSaveAsDialog FileSaveAsDialog {
-		get {
-			if (fileSaveAsDialog == null)
-				fileSaveAsDialog = new FileSaveAsDialog(SubtitleTextType.Text);
-			
-			return fileSaveAsDialog;		
-		}
+	private Hashtable dialogs = new Hashtable();
+
+	public Dialogs () {
+		Base.InitFinished += OnBaseInitFinished;
 	}
-	
-	public FileSaveAsDialog TranslationSaveAsDialog {
-		get {
-			if (translationSaveAsDialog == null)
-				translationSaveAsDialog = new FileSaveAsDialog(SubtitleTextType.Translation);
-			
-			return translationSaveAsDialog;		
+
+	/* Public methods */
+
+	public BaseDialog Get (Type dialogType, params object[] args) {
+		BaseDialog dialog = dialogs[dialogType] as BaseDialog;
+		if (dialog == null) {
+			object newDialog = Activator.CreateInstance(dialogType, args);
+			if (!(newDialog is BaseDialog))
+				return null;
+
+			dialog = newDialog as BaseDialog;
+			if (dialog.Scope != DialogScope.Singleton)
+				dialogs[dialogType] = dialog;
 		}
+		return dialog;
 	}
-	
-	public SearchDialog SearchDialog {
-		get {
-			if (searchDialog == null)
-				searchDialog = new SearchDialog();
-			
-			return searchDialog;		
+
+	/* Event members */
+
+	private void OnBaseInitFinished () {
+    	Base.DocumentUnloaded += OnBaseDocumentUnloaded;
+		Base.VideoUnloaded += OnBaseVideoUnloaded;
+    }
+
+	private void OnBaseDocumentUnloaded (Document document) {
+		ICollection keyCollection = dialogs.Keys;
+		Type[] keys = new Type[keyCollection.Count];
+		keyCollection.CopyTo(keys, 0);
+		for (int index = 0 ; index < keys.Length ; index++) {
+			Type type = keys[index];
+			BaseDialog dialog = dialogs[type] as BaseDialog;
+			if ((dialog.Scope == DialogScope.Singleton) || (dialog.Scope == DialogScope.Document)) {
+				dialog.Destroy();
+				dialogs.Remove(type);
+			}
 		}
 	}
-	
-	public TimingsShiftDialog TimingsShiftDialog {
-		get {
-			if (timingsShiftDialog == null)
-				timingsShiftDialog = new TimingsShiftDialog();
-			
-			return timingsShiftDialog;		
+
+	private void OnBaseVideoUnloaded () {
+		ICollection keyCollection = dialogs.Keys;
+		Type[] keys = new Type[keyCollection.Count];
+		keyCollection.CopyTo(keys, 0);
+		for (int index = 0 ; index < keys.Length ; index++) {
+			Type type = keys[index];
+			BaseDialog dialog = dialogs[type] as BaseDialog;
+			if (dialog.Scope == DialogScope.Video) {
+				dialog.Destroy();
+				dialogs.Remove(type);
+			}
 		}
 	}
 
diff --git a/src/GnomeSubtitles/Dialog/FileOpenDialog.cs b/src/GnomeSubtitles/Dialog/FileOpenDialog.cs
index 7adcfca..817c412 100644
--- a/src/GnomeSubtitles/Dialog/FileOpenDialog.cs
+++ b/src/GnomeSubtitles/Dialog/FileOpenDialog.cs
@@ -261,7 +261,7 @@ public class FileOpenDialog : SubtitleFileChooserDialog {
 				int videoFileIndex = videoComboBox.Active - 2;
 				chosenVideoUri = new Uri(videoFiles[videoFileIndex] as string);
 			}			
-			setReturnValue(true);
+			SetReturnValue(true);
 		}
 		return false;
 	}
diff --git a/src/GnomeSubtitles/Dialog/FileSaveAsDialog.cs b/src/GnomeSubtitles/Dialog/FileSaveAsDialog.cs
index 195895b..7f66e2e 100644
--- a/src/GnomeSubtitles/Dialog/FileSaveAsDialog.cs
+++ b/src/GnomeSubtitles/Dialog/FileSaveAsDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2009 Pedro Castro
+ * Copyright (C) 2009 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
@@ -17,310 +17,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-using Glade;
-using GnomeSubtitles.Core;
-using Gtk;
-using Mono.Unix;
 using SubLib.Core.Domain;
-using System;
-using System.IO;
-using System.Text;
 
 namespace GnomeSubtitles.Dialog {
 
-public class FileSaveAsDialog : SubtitleFileChooserDialog {
-	private SubtitleTextType textType;
-	private SubtitleType chosenSubtitleType;
-	private SubtitleTypeInfo[] subtitleTypes = null;
-	private NewlineType chosenNewlineType;
-
-	/* Constant strings */
-	private const string gladeFilename = "FileSaveAsDialog.glade";
-	
-	/* Widgets */
-	
-	[WidgetAttribute] private ComboBox encodingComboBox = null;
-	[WidgetAttribute] private ComboBox formatComboBox = null;
-	[WidgetAttribute] private ComboBox newlineTypeComboBox = null;
-
-	public FileSaveAsDialog (SubtitleTextType textType) : base(gladeFilename) {
-		this.textType = textType;
-		SetTitle();
-		FillFormatComboBox();
-		FillNewlineTypeComboBox();
-	}
-	
-	/* Public properties */
-
-	public override DialogScope Scope {
-		get { return DialogScope.Document; }
-	}
-	
-	public SubtitleType SubtitleType {
-		get { return chosenSubtitleType; }
-	}
-	
-	public NewlineType NewlineType {
-		get { return chosenNewlineType; }
-	}
-	
-	/* Public methods */
-	
-	public override void Show () {
-		UpdateContents();
-		base.Show();		
-	}
-	
-	/* Protected methods */
+public class FileSaveAsDialog : SubtitleFileSaveAsDialog {
 	
-	protected override int GetFixedEncoding () {
-		try {
-			return Base.Document.TextFile.Encoding.CodePage;
-		}
-		catch (NullReferenceException) {
-			return -1;
-		}
-	}
-	
-	protected override ComboBox GetEncodingComboBox () {
-		return encodingComboBox;
-	}
-	
-	/* Private members */
-	
-	private void SetTitle () {
-		if (textType == SubtitleTextType.Text)
-			dialog.Title = Catalog.GetString("Save As");
-		else
-			dialog.Title = Catalog.GetString("Save Translation As");
-	
-	}
-	
-	private void UpdateContents () {
-		FileProperties fileProperties = (textType == SubtitleTextType.Text ? Base.Document.TextFile : Base.Document.TranslationFile);
-	
-		if (fileProperties.IsPathRooted)
-			dialog.SetCurrentFolder(fileProperties.Directory);
-		else
-			dialog.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
-			
-		dialog.CurrentName = fileProperties.Filename;
-
-		/* There seems to be a bug in GTK that makes the dialog return null for currentFolder and currentFilename
-		   while in the constructor. After constructing it works fine. */
-
-		SetActiveFormat();
-		SetActiveNewlineType();
-	}
-
-	private void FillFormatComboBox () {
-		subtitleTypes = Subtitles.AvailableTypesSorted;
-		
-		foreach (SubtitleTypeInfo typeInfo in subtitleTypes) {
-			formatComboBox.AppendText(typeInfo.Name + " (" + typeInfo.ExtensionsAsText + ")");
-		}	
-	}
-
-	private void SetActiveFormat () {
-		SubtitleType subtitleType = Base.Document.TextFile.SubtitleType; //The type of the subtitle file
-		int position = FindSubtitleTypePosition(subtitleType);
-		if (position != -1) {
-			formatComboBox.Active = position;
-			return;
-		}
-		
-		/* The current subtitle type was not found, trying the most common based on the TimingMode */
-		TimingMode timingMode = Base.TimingMode;
-		
-		/* If timing mode is Frames, set to MicroDVD */
-		if (timingMode == TimingMode.Frames) {
-			position = FindSubtitleTypePosition(SubtitleType.MicroDVD);
-			if (position != -1) {
-				formatComboBox.Active = position;
-				return;
-			}
-		}
-		
-		/* If SubRip subtitle type is found, use it */
-		position = FindSubtitleTypePosition(SubtitleType.SubRip);
-		if (position != -1) {
-			formatComboBox.Active = position;
-			return;
-		}
-		
-		/* All options tried to no aval, selecting the first */
-		formatComboBox.Active = 0;
-	}
-	
-	private int FindSubtitleTypePosition (SubtitleType type) {
-		for (int position = 0 ; position < subtitleTypes.Length ; position++) {
-			SubtitleType current = subtitleTypes[position].Type;
-			if (current == type)
-				return position;
-		}
-		return -1;
-	}
-	
-	private string UpdateFilenameExtension (string filename, SubtitleType type) {
-		SubtitleTypeInfo typeInfo = Subtitles.GetAvailableType(type);
-		string newExtensionDotted = "." + typeInfo.PreferredExtension;
-
-		int index = -1;
-		string extensionDotted = "." + GetFilenameExtension(filename, out index);
-		
-		if (extensionDotted == newExtensionDotted) //filename already has the correct extension
-			return filename;
-		else if (index == -1) //filename doesn't have an extension, appending
-			return filename + newExtensionDotted;
-		else if (IsSubtitleExtension(extensionDotted))  { //filename's extension is a subtitle extension
-			int dotIndex = index - 1;
-			return filename.Substring(0, dotIndex) + newExtensionDotted;
-		}
-		else //filename's extension is not a subtitle extension
-			return filename + newExtensionDotted;
-	}
-
-	private string AddExtensionIfNeeded (SubtitleType type) {
-		string filename = dialog.Filename;
-		int index = 0;
-		string extension = GetFilenameExtension(filename, out index);
-
-		SubtitleTypeInfo typeInfo = Subtitles.GetAvailableType(type);
-		if (typeInfo.HasExtension(extension))
-			return filename;
-		else
-			return filename + "." + typeInfo.PreferredExtension;
-	}
-	
-	private bool IsSubtitleExtension (string dottedExtension) {
-		string extension = dottedExtension.Substring(1); //Remove the starting dot
-		foreach (SubtitleTypeInfo type in subtitleTypes) {
-			if (type.HasExtension(extension))
-				return true;
-		}
-		return false;
-	}
-
-	/// <summary>Returns the extension for the specified filename.</summary>
-	private string GetFilenameExtension (string filename, out int index) {
-		int dotIndex = filename.LastIndexOf('.');
-		if ((dotIndex != -1) && (dotIndex != (filename.Length - 1))) {
-			index = dotIndex + 1;
-			return filename.Substring(index);
-		}
-		else {
-			index = -1;
-			return String.Empty;
-		}
-	}
-	
-	private void FillNewlineTypeComboBox () {
-		string mac = "Macintosh";
-		string unix = "Unix";
-		string windows = "Windows";
-		string systemDefault = " (" + Catalog.GetString("System Default") + ")";
-		
-		NewlineType systemNewline = GetSystemNewlineType();
-		SetSystemNewlineSuffix(systemNewline, ref mac, ref unix, ref windows, systemDefault);
-		
-		newlineTypeComboBox.AppendText(mac);
-		newlineTypeComboBox.AppendText(unix);
-		newlineTypeComboBox.AppendText(windows);
-	}
-	
-	private void SetActiveNewlineType () {
-		NewlineType systemNewline = GetSystemNewlineType();
-		NewlineType documentNewline = Base.Document.TextFile.NewlineType;
-		NewlineType newlineToMakeActive = (documentNewline != NewlineType.Unknown ? documentNewline : systemNewline);
-		int item = GetNewlineTypePosition(newlineToMakeActive);
-		newlineTypeComboBox.Active = item;	
-	}
-	
-	private NewlineType GetSystemNewlineType () {
-		switch (Environment.NewLine) {
-			case "\n":
-				return NewlineType.Unix;
-			case "\r":
-				return NewlineType.Macintosh;
-			case "\r\n":
-				return NewlineType.Windows;
-			default:
-				return NewlineType.Unknown;
-		}
-	}
-	
-	private void SetSystemNewlineSuffix (NewlineType newline, ref string mac, ref string unix, ref string windows, string suffix) {
-		switch (newline) {
-			case NewlineType.Macintosh:
-				mac += suffix;
-				break;
-			case NewlineType.Unix:
-				unix += suffix;
-				break;
-			case NewlineType.Windows:
-				windows += suffix;
-				break;
-		}
-	}
-	
-	private int GetNewlineTypePosition (NewlineType newline) {
-		switch (newline) {
-			case NewlineType.Macintosh:
-				return 0;
-			case NewlineType.Unix:
-				return 1;
-			case NewlineType.Windows:
-				return 2;
-			default:
-				return 1;
-		}	
-	}
-	
-	private NewlineType GetChosenNewlineType () {
-		switch (newlineTypeComboBox.Active) {
-			case 0:
-				return NewlineType.Macintosh;
-			case 1:
-				return NewlineType.Unix;
-			case 2:
-				return NewlineType.Windows;
-			default:
-				return NewlineType.Unix;
-		}
-	}
-
-	/* Event members */
-
-	#pragma warning disable 169		//Disables warning about handlers not being used
-
-	protected override bool ProcessResponse (ResponseType response) {
-		if (response == ResponseType.Ok) {
-			int formatIndex = formatComboBox.Active;
-			chosenSubtitleType = subtitleTypes[formatIndex].Type;
-			chosenFilename = AddExtensionIfNeeded(chosenSubtitleType);
-			
-			int encodingIndex = GetActiveEncodingComboBoxItem();
-			chosenEncoding = encodings[encodingIndex];
-			setReturnValue(true);
-			
-			chosenNewlineType = GetChosenNewlineType();
-		}
-		return false;
-	}
-
-	private void OnFormatChanged (object o, EventArgs args) {
-		SubtitleType type = subtitleTypes[formatComboBox.Active].Type;
-		string filename = dialog.Filename;
-		if ((filename == null) || (filename == String.Empty))
-			return;
-
-		string folder = dialog.CurrentFolder;
-		if ((folder != null) && (folder != String.Empty)) {
-			filename = filename.Substring(folder.Length + 1);
-		}
-
-		filename = UpdateFilenameExtension(filename, type);
-		dialog.CurrentName = filename;
+	public FileSaveAsDialog () : base(SubtitleTextType.Text) {
 	}
 
 }
diff --git a/src/GnomeSubtitles/Dialog/MessageDialog.cs b/src/GnomeSubtitles/Dialog/MessageDialog.cs
index e960204..d80e6b7 100644
--- a/src/GnomeSubtitles/Dialog/MessageDialog.cs
+++ b/src/GnomeSubtitles/Dialog/MessageDialog.cs
@@ -102,7 +102,7 @@ namespace GnomeSubtitles.Dialog {
 
 		protected override bool ProcessResponse (ResponseType response) {
 			if (response == ResponseType.Accept) {
-				setReturnValue(true);
+				SetReturnValue(true);
 			}
 			return false;
 		}
diff --git a/src/GnomeSubtitles/Dialog/PreferencesDialog.cs b/src/GnomeSubtitles/Dialog/PreferencesDialog.cs
index 8409436..0188ca3 100644
--- a/src/GnomeSubtitles/Dialog/PreferencesDialog.cs
+++ b/src/GnomeSubtitles/Dialog/PreferencesDialog.cs
@@ -34,7 +34,7 @@ public class PreferencesDialog : GladeDialog {
 	[WidgetAttribute] private CheckButton videoAutoChooseFileCheckButton = null;
 
 
-	public PreferencesDialog () : base(gladeFilename, false) {
+	private PreferencesDialog () : base(gladeFilename, false) {
 		LoadValues();
 		Autoconnect();
 	}
diff --git a/src/GnomeSubtitles/Dialog/SearchDialog.cs b/src/GnomeSubtitles/Dialog/SearchDialog.cs
index b49eac7..a8ac7da 100644
--- a/src/GnomeSubtitles/Dialog/SearchDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SearchDialog.cs
@@ -60,12 +60,14 @@ public class SearchDialog : GladeDialog {
 	public SearchDialog () : base(gladeFilename) {
 	}
 
-	/* Properties */
+	/* Overriden members */
 
 	public override DialogScope Scope {
 		get { return DialogScope.Document; }
 	}
 
+	/* Properties */
+
 	public Regex ForwardRegex {
 		get { return forwardRegex; }
 	}
@@ -102,11 +104,11 @@ public class SearchDialog : GladeDialog {
 	
 	public void Show (bool useReplace) {
 		if (useReplace) {
-			getDialog().Title = Catalog.GetString("Replace");
+			GetDialog().Title = Catalog.GetString("Replace");
 			table.RowSpacing = 12;
 		}
 		else {
-			getDialog().Title = Catalog.GetString("Find");
+			GetDialog().Title = Catalog.GetString("Find");
 			table.RowSpacing = 0;
 		}
 		
diff --git a/src/GnomeSubtitles/Dialog/SetLanguageDialog.cs b/src/GnomeSubtitles/Dialog/SetLanguageDialog.cs
index 7c52ecf..1be2cbb 100644
--- a/src/GnomeSubtitles/Dialog/SetLanguageDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SetLanguageDialog.cs
@@ -26,7 +26,7 @@ using System;
 
 namespace GnomeSubtitles.Dialog {
 
-public class SetLanguageDialog : GladeDialog {
+public abstract class SetLanguageDialog : GladeDialog {
 	private ListStore store = null;
 	private int colNum = 0;
 	private SubtitleTextType textType;
@@ -46,7 +46,7 @@ public class SetLanguageDialog : GladeDialog {
 	[WidgetAttribute] private Label introLabel = null;
 
 
-	public SetLanguageDialog (SubtitleTextType textType) : base(gladeFilename) {
+	protected SetLanguageDialog (SubtitleTextType textType) : base(gladeFilename) {
 		this.textType = textType;
 	
 		SetDialogTitle(textType);
@@ -117,7 +117,7 @@ public class SetLanguageDialog : GladeDialog {
 	}
 	
 	private void SetDialogTitle (SubtitleTextType textType) {
-		getDialog().Title = (textType == SubtitleTextType.Text ? dialogTitleText : dialogTitleTranslation);
+		GetDialog().Title = (textType == SubtitleTextType.Text ? dialogTitleText : dialogTitleTranslation);
 	}
 	
 	private void SetIntroLabel (SubtitleTextType textType) {
diff --git a/src/GnomeSubtitles/Dialog/WarningDialog.cs b/src/GnomeSubtitles/Dialog/SetTextLanguageDialog.cs
similarity index 73%
copy from src/GnomeSubtitles/Dialog/WarningDialog.cs
copy to src/GnomeSubtitles/Dialog/SetTextLanguageDialog.cs
index 38c04a4..754c901 100644
--- a/src/GnomeSubtitles/Dialog/WarningDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SetTextLanguageDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2008 Pedro Castro
+ * Copyright (C) 2009 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
@@ -17,18 +17,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-using Gtk;
-using Mono.Unix;
-using System;
+using SubLib.Core.Domain;
 
 namespace GnomeSubtitles.Dialog {
 
-public abstract class WarningDialog : MessageDialog {
+public class SetTextLanguageDialog : SetLanguageDialog {
 	
-	public WarningDialog () : base(MessageType.Warning) {
-	}
-
-	public WarningDialog (string primary, string secondary) : base(MessageType.Warning, primary, secondary) {
+	public SetTextLanguageDialog () : base(SubtitleTextType.Text) {
 	}
 
 }
diff --git a/src/GnomeSubtitles/Dialog/WarningDialog.cs b/src/GnomeSubtitles/Dialog/SetTranslationLanguageDialog.cs
similarity index 73%
copy from src/GnomeSubtitles/Dialog/WarningDialog.cs
copy to src/GnomeSubtitles/Dialog/SetTranslationLanguageDialog.cs
index 38c04a4..09d8c37 100644
--- a/src/GnomeSubtitles/Dialog/WarningDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SetTranslationLanguageDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2008 Pedro Castro
+ * Copyright (C) 2009 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
@@ -17,18 +17,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-using Gtk;
-using Mono.Unix;
-using System;
+using SubLib.Core.Domain;
 
 namespace GnomeSubtitles.Dialog {
 
-public abstract class WarningDialog : MessageDialog {
+public class SetTranslationLanguageDialog : SetLanguageDialog {
 	
-	public WarningDialog () : base(MessageType.Warning) {
-	}
-
-	public WarningDialog (string primary, string secondary) : base(MessageType.Warning, primary, secondary) {
+	public SetTranslationLanguageDialog () : base(SubtitleTextType.Translation) {
 	}
 
 }
diff --git a/src/GnomeSubtitles/Dialog/SubtitleFileChooserDialog.cs b/src/GnomeSubtitles/Dialog/SubtitleFileChooserDialog.cs
index 4b38613..98fb1bb 100644
--- a/src/GnomeSubtitles/Dialog/SubtitleFileChooserDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SubtitleFileChooserDialog.cs
@@ -43,7 +43,7 @@ public abstract class SubtitleFileChooserDialog : GladeDialog {
 
 
 	protected SubtitleFileChooserDialog (string filename) : base(filename) {
-		dialog = getDialog() as FileChooserDialog;
+		dialog = GetDialog() as FileChooserDialog;
 		
 		fixedEncoding = GetFixedEncoding();
 		SetEncodingComboBox();
@@ -183,7 +183,7 @@ public abstract class SubtitleFileChooserDialog : GladeDialog {
 		ComboBox comboBox = o as ComboBox;
 		int itemCount = comboBox.Model.IterNChildren();
 		if (comboBox.Active == (itemCount - 1)) {
-			EncodingsDialog dialog = new EncodingsDialog();
+			EncodingsDialog dialog = Base.Dialogs.Get(typeof(EncodingsDialog)) as EncodingsDialog;
 			dialog.Show();
 			dialog.WaitForResponse();
 			UpdateEncodingComboBox(comboBox, dialog.ChosenNames);
diff --git a/src/GnomeSubtitles/Dialog/SubtitleFileSaveAsDialog.cs b/src/GnomeSubtitles/Dialog/SubtitleFileSaveAsDialog.cs
new file mode 100644
index 0000000..6b5a14d
--- /dev/null
+++ b/src/GnomeSubtitles/Dialog/SubtitleFileSaveAsDialog.cs
@@ -0,0 +1,330 @@
+/*
+ * This file is part of Gnome Subtitles.
+ * Copyright (C) 2006-2009 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 Glade;
+using GnomeSubtitles.Core;
+using Gtk;
+using Mono.Unix;
+using SubLib.Core.Domain;
+using System;
+using System.IO;
+using System.Text;
+
+namespace GnomeSubtitles.Dialog {
+
+public abstract class SubtitleFileSaveAsDialog : SubtitleFileChooserDialog {
+	private SubtitleTextType textType;
+	private SubtitleType chosenSubtitleType;
+	private SubtitleTypeInfo[] subtitleTypes = null;
+	private NewlineType chosenNewlineType;
+
+	/* Constant strings */
+	private const string gladeFilename = "FileSaveAsDialog.glade";
+	
+	/* Widgets */
+	
+	[WidgetAttribute] private ComboBox encodingComboBox = null;
+	[WidgetAttribute] private ComboBox formatComboBox = null;
+	[WidgetAttribute] private ComboBox newlineTypeComboBox = null;
+
+	protected SubtitleFileSaveAsDialog (SubtitleTextType textType) : base(gladeFilename) {
+		this.textType = textType;
+		SetTitle();
+		FillFormatComboBox();
+		FillNewlineTypeComboBox();
+	}
+
+	/* Overriden members */
+
+	public override DialogScope Scope {
+		get { return DialogScope.Document; }
+	}
+
+	/* Public properties */
+	
+	public SubtitleType SubtitleType {
+		get { return chosenSubtitleType; }
+	}
+	
+	public NewlineType NewlineType {
+		get { return chosenNewlineType; }
+	}
+	
+	/* Public methods */
+	
+	public override void Show () {
+		UpdateContents();
+		base.Show();		
+	}
+	
+	/* Protected methods */
+	
+	protected override int GetFixedEncoding () {
+		try {
+			return Base.Document.TextFile.Encoding.CodePage;
+		}
+		catch (NullReferenceException) {
+			return -1;
+		}
+	}
+	
+	protected override ComboBox GetEncodingComboBox () {
+		return encodingComboBox;
+	}
+	
+	/* Private members */
+	
+	private void SetTitle () {
+		if (textType == SubtitleTextType.Text)
+			dialog.Title = Catalog.GetString("Save As");
+		else
+			dialog.Title = Catalog.GetString("Save Translation As");
+	
+	}
+	
+	private void UpdateContents () {
+		FileProperties fileProperties = (textType == SubtitleTextType.Text ? Base.Document.TextFile : Base.Document.TranslationFile);
+	
+		if (fileProperties.IsPathRooted)
+			dialog.SetCurrentFolder(fileProperties.Directory);
+		else
+			dialog.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
+			
+		dialog.CurrentName = fileProperties.Filename;
+
+		/* There seems to be a bug in GTK that makes the dialog return null for currentFolder and currentFilename
+		   while in the constructor. After constructing it works fine. */
+
+		SetActiveFormat();
+		SetActiveNewlineType();
+	}
+
+	private void FillFormatComboBox () {
+		subtitleTypes = Subtitles.AvailableTypesSorted;
+		
+		foreach (SubtitleTypeInfo typeInfo in subtitleTypes) {
+			formatComboBox.AppendText(typeInfo.Name + " (" + typeInfo.ExtensionsAsText + ")");
+		}	
+	}
+
+	private void SetActiveFormat () {
+		SubtitleType subtitleType = Base.Document.TextFile.SubtitleType; //The type of the subtitle file
+		int position = FindSubtitleTypePosition(subtitleType);
+		if (position != -1) {
+			formatComboBox.Active = position;
+			return;
+		}
+		
+		/* The current subtitle type was not found, trying the most common based on the TimingMode */
+		TimingMode timingMode = Base.TimingMode;
+		
+		/* If timing mode is Frames, set to MicroDVD */
+		if (timingMode == TimingMode.Frames) {
+			position = FindSubtitleTypePosition(SubtitleType.MicroDVD);
+			if (position != -1) {
+				formatComboBox.Active = position;
+				return;
+			}
+		}
+		
+		/* If SubRip subtitle type is found, use it */
+		position = FindSubtitleTypePosition(SubtitleType.SubRip);
+		if (position != -1) {
+			formatComboBox.Active = position;
+			return;
+		}
+		
+		/* All options tried to no aval, selecting the first */
+		formatComboBox.Active = 0;
+	}
+	
+	private int FindSubtitleTypePosition (SubtitleType type) {
+		for (int position = 0 ; position < subtitleTypes.Length ; position++) {
+			SubtitleType current = subtitleTypes[position].Type;
+			if (current == type)
+				return position;
+		}
+		return -1;
+	}
+	
+	private string UpdateFilenameExtension (string filename, SubtitleType type) {
+		SubtitleTypeInfo typeInfo = Subtitles.GetAvailableType(type);
+		string newExtensionDotted = "." + typeInfo.PreferredExtension;
+
+		int index = -1;
+		string extensionDotted = "." + GetFilenameExtension(filename, out index);
+		
+		if (extensionDotted == newExtensionDotted) //filename already has the correct extension
+			return filename;
+		else if (index == -1) //filename doesn't have an extension, appending
+			return filename + newExtensionDotted;
+		else if (IsSubtitleExtension(extensionDotted))  { //filename's extension is a subtitle extension
+			int dotIndex = index - 1;
+			return filename.Substring(0, dotIndex) + newExtensionDotted;
+		}
+		else //filename's extension is not a subtitle extension
+			return filename + newExtensionDotted;
+	}
+
+	private string AddExtensionIfNeeded (SubtitleType type) {
+		string filename = dialog.Filename;
+		int index = 0;
+		string extension = GetFilenameExtension(filename, out index);
+
+		SubtitleTypeInfo typeInfo = Subtitles.GetAvailableType(type);
+		if (typeInfo.HasExtension(extension))
+			return filename;
+		else
+			return filename + "." + typeInfo.PreferredExtension;
+	}
+	
+	private bool IsSubtitleExtension (string dottedExtension) {
+		string extension = dottedExtension.Substring(1); //Remove the starting dot
+		foreach (SubtitleTypeInfo type in subtitleTypes) {
+			if (type.HasExtension(extension))
+				return true;
+		}
+		return false;
+	}
+
+	/// <summary>Returns the extension for the specified filename.</summary>
+	private string GetFilenameExtension (string filename, out int index) {
+		int dotIndex = filename.LastIndexOf('.');
+		if ((dotIndex != -1) && (dotIndex != (filename.Length - 1))) {
+			index = dotIndex + 1;
+			return filename.Substring(index);
+		}
+		else {
+			index = -1;
+			return String.Empty;
+		}
+	}
+	
+	private void FillNewlineTypeComboBox () {
+		string mac = "Macintosh";
+		string unix = "Unix";
+		string windows = "Windows";
+		string systemDefault = " (" + Catalog.GetString("System Default") + ")";
+		
+		NewlineType systemNewline = GetSystemNewlineType();
+		SetSystemNewlineSuffix(systemNewline, ref mac, ref unix, ref windows, systemDefault);
+		
+		newlineTypeComboBox.AppendText(mac);
+		newlineTypeComboBox.AppendText(unix);
+		newlineTypeComboBox.AppendText(windows);
+	}
+	
+	private void SetActiveNewlineType () {
+		NewlineType systemNewline = GetSystemNewlineType();
+		NewlineType documentNewline = Base.Document.TextFile.NewlineType;
+		NewlineType newlineToMakeActive = (documentNewline != NewlineType.Unknown ? documentNewline : systemNewline);
+		int item = GetNewlineTypePosition(newlineToMakeActive);
+		newlineTypeComboBox.Active = item;	
+	}
+	
+	private NewlineType GetSystemNewlineType () {
+		switch (Environment.NewLine) {
+			case "\n":
+				return NewlineType.Unix;
+			case "\r":
+				return NewlineType.Macintosh;
+			case "\r\n":
+				return NewlineType.Windows;
+			default:
+				return NewlineType.Unknown;
+		}
+	}
+	
+	private void SetSystemNewlineSuffix (NewlineType newline, ref string mac, ref string unix, ref string windows, string suffix) {
+		switch (newline) {
+			case NewlineType.Macintosh:
+				mac += suffix;
+				break;
+			case NewlineType.Unix:
+				unix += suffix;
+				break;
+			case NewlineType.Windows:
+				windows += suffix;
+				break;
+		}
+	}
+	
+	private int GetNewlineTypePosition (NewlineType newline) {
+		switch (newline) {
+			case NewlineType.Macintosh:
+				return 0;
+			case NewlineType.Unix:
+				return 1;
+			case NewlineType.Windows:
+				return 2;
+			default:
+				return 1;
+		}	
+	}
+	
+	private NewlineType GetChosenNewlineType () {
+		switch (newlineTypeComboBox.Active) {
+			case 0:
+				return NewlineType.Macintosh;
+			case 1:
+				return NewlineType.Unix;
+			case 2:
+				return NewlineType.Windows;
+			default:
+				return NewlineType.Unix;
+		}
+	}
+
+	/* Event members */
+
+	#pragma warning disable 169		//Disables warning about handlers not being used
+
+	protected override bool ProcessResponse (ResponseType response) {
+		if (response == ResponseType.Ok) {
+			int formatIndex = formatComboBox.Active;
+			chosenSubtitleType = subtitleTypes[formatIndex].Type;
+			chosenFilename = AddExtensionIfNeeded(chosenSubtitleType);
+			
+			int encodingIndex = GetActiveEncodingComboBoxItem();
+			chosenEncoding = encodings[encodingIndex];
+			SetReturnValue(true);
+			
+			chosenNewlineType = GetChosenNewlineType();
+		}
+		return false;
+	}
+
+	private void OnFormatChanged (object o, EventArgs args) {
+		SubtitleType type = subtitleTypes[formatComboBox.Active].Type;
+		string filename = dialog.Filename;
+		if ((filename == null) || (filename == String.Empty))
+			return;
+
+		string folder = dialog.CurrentFolder;
+		if ((folder != null) && (folder != String.Empty)) {
+			filename = filename.Substring(folder.Length + 1);
+		}
+
+		filename = UpdateFilenameExtension(filename, type);
+		dialog.CurrentName = filename;
+	}
+
+}
+
+}
diff --git a/src/GnomeSubtitles/Dialog/SyncPoints.cs b/src/GnomeSubtitles/Dialog/SyncPoints.cs
deleted file mode 100644
index 2c41b01..0000000
--- a/src/GnomeSubtitles/Dialog/SyncPoints.cs
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * This file is part of Gnome Subtitles.
- * Copyright (C) 2008 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 Gtk;
-using SubLib.Core.Domain;
-using System.Collections;
-
-namespace GnomeSubtitles.Dialog {
-
-public class SyncPoints {
-	private ListStore model = new ListStore(typeof(SyncPoint));
-	private SubLib.Core.Domain.SyncPoints collection = new SubLib.Core.Domain.SyncPoints();
-	
-	
-	public SyncPoints () : base() {
-		LoadModelFromCollection();
-	}
-	
-	/* Indexers */
-	
-	public SyncPoint this [TreeIter iter] {
-		get { return model.GetValue(iter, 0) as SyncPoint; }
-	}
-
-	public SyncPoint this [TreePath path] {
-		get { return collection[path.Indices[0]]; }
-	}
-	
-	/* Public properties */
-
-	public ListStore Model {
-		get { return model; }
-	}
-	
-	public SubLib.Core.Domain.SyncPoints Collection {
-		get { return collection; }
-	}
-	
-	/* Public methods */
-	
-	public void InsertSorted (SyncPoint syncPoint) {
-		for (int index = 0 ; index < collection.Count ; index++) {
-			SyncPoint existing = collection[index] as SyncPoint;
-			if (syncPoint.SubtitleNumber == existing.SubtitleNumber) { //Found an existing sync point for this subtitle number
-				Replace(index, syncPoint);
-				return;
-			}
-			else if (syncPoint.SubtitleNumber < existing.SubtitleNumber) { //The new sync point comes before the current
-				Insert(index, syncPoint);
-				return;
-			}
-		}
-		/* Inserting in the end */
-		Add(syncPoint);
-	}
-	
-	public IEnumerator GetEnumerator () {
-		return collection.GetEnumerator();
-	}
-	
-
-	/* Private members */
-
-	private void LoadModelFromCollection () {
-		model.Clear();
-		foreach (SyncPoint syncPoint in collection) {
-			model.AppendValues(syncPoint);
-		}
-	}
-	
-		
-	private void Insert (int index, SyncPoint syncPoint) {
-		collection.Insert(index, syncPoint);
-		model.SetValue(model.Insert(index), 0, syncPoint);
-	}
-	
-	private void Replace (int index, SyncPoint syncPoint) {
-		collection.Replace(index, syncPoint);
-		
-		TreeIter iter;
-		model.GetIterFromString(out iter, index.ToString());
-		model.SetValue(iter, 0, syncPoint);
-	}
-	
-	private void Add (SyncPoint syncPoint) {
-		collection.Add(syncPoint);
-		model.AppendValues(syncPoint);
-	}
-
-}
-
-}
diff --git a/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs b/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs
index ce91664..8201228 100644
--- a/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs
+++ b/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs
@@ -48,14 +48,12 @@ public class TimingsShiftDialog : GladeDialog {
 		UpdateContents(true);
 	}
 
-
-	/* Properties */
+	/* Overriden members */
 
 	public override DialogScope Scope {
 		get { return DialogScope.Document; }
 	}
 
-
 	/* Methods */
 
 	public override void Show () {
diff --git a/src/GnomeSubtitles/Dialog/TimingsSynchronizeDialog.cs b/src/GnomeSubtitles/Dialog/TimingsSynchronizeDialog.cs
index bd632ae..e891f9b 100644
--- a/src/GnomeSubtitles/Dialog/TimingsSynchronizeDialog.cs
+++ b/src/GnomeSubtitles/Dialog/TimingsSynchronizeDialog.cs
@@ -58,11 +58,19 @@ public class TimingsSynchronizeDialog : GladeDialog {
 		
 		UpdateStatusMessage();
 	}
-	
+
+	/* Overriden members */
+
+	public override DialogScope Scope {
+		get { return DialogScope.Document; }
+	}
+
 	public override void Destroy () {
 		Base.Ui.View.Selection.Changed -= OnUiViewSelectionChanged;
 		base.Destroy();
 	}
+
+	
 	
 	/* Private methods */
 	
diff --git a/src/GnomeSubtitles/Dialog/WarningDialog.cs b/src/GnomeSubtitles/Dialog/TranslationSaveAsDialog.cs
similarity index 73%
copy from src/GnomeSubtitles/Dialog/WarningDialog.cs
copy to src/GnomeSubtitles/Dialog/TranslationSaveAsDialog.cs
index 38c04a4..acd603a 100644
--- a/src/GnomeSubtitles/Dialog/WarningDialog.cs
+++ b/src/GnomeSubtitles/Dialog/TranslationSaveAsDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2008 Pedro Castro
+ * Copyright (C) 2009 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
@@ -17,18 +17,13 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-using Gtk;
-using Mono.Unix;
-using System;
+using SubLib.Core.Domain;
 
 namespace GnomeSubtitles.Dialog {
 
-public abstract class WarningDialog : MessageDialog {
+public class TranslationSaveAsDialog : SubtitleFileSaveAsDialog {
 	
-	public WarningDialog () : base(MessageType.Warning) {
-	}
-
-	public WarningDialog (string primary, string secondary) : base(MessageType.Warning, primary, secondary) {
+	public TranslationSaveAsDialog () : base(SubtitleTextType.Translation) {
 	}
 
 }
diff --git a/src/GnomeSubtitles/Dialog/BasicErrorDialog.cs b/src/GnomeSubtitles/Dialog/Unmanaged/BasicErrorDialog.cs
similarity index 92%
rename from src/GnomeSubtitles/Dialog/BasicErrorDialog.cs
rename to src/GnomeSubtitles/Dialog/Unmanaged/BasicErrorDialog.cs
index dd2f676..4ae91be 100644
--- a/src/GnomeSubtitles/Dialog/BasicErrorDialog.cs
+++ b/src/GnomeSubtitles/Dialog/Unmanaged/BasicErrorDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2008 Pedro Castro
+ * Copyright (C) 2008-2009 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
@@ -21,7 +21,7 @@ using Gtk;
 using Mono.Unix;
 using System;
 
-namespace GnomeSubtitles.Dialog {
+namespace GnomeSubtitles.Dialog.Unmanaged {
 
 public class BasicErrorDialog : ErrorDialog {
 
diff --git a/src/GnomeSubtitles/Dialog/ErrorDialog.cs b/src/GnomeSubtitles/Dialog/Unmanaged/ErrorDialog.cs
similarity index 94%
rename from src/GnomeSubtitles/Dialog/ErrorDialog.cs
rename to src/GnomeSubtitles/Dialog/Unmanaged/ErrorDialog.cs
index 0e75441..ea3f500 100644
--- a/src/GnomeSubtitles/Dialog/ErrorDialog.cs
+++ b/src/GnomeSubtitles/Dialog/Unmanaged/ErrorDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2007-2008 Pedro Castro
+ * Copyright (C) 2007-2009 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
@@ -21,7 +21,7 @@ using Gtk;
 using Mono.Unix;
 using System;
 
-namespace GnomeSubtitles.Dialog {
+namespace GnomeSubtitles.Dialog.Unmanaged {
 
 public abstract class ErrorDialog : MessageDialog {
 
diff --git a/src/GnomeSubtitles/Dialog/FileOpenErrorDialog.cs b/src/GnomeSubtitles/Dialog/Unmanaged/FileOpenErrorDialog.cs
similarity index 96%
rename from src/GnomeSubtitles/Dialog/FileOpenErrorDialog.cs
rename to src/GnomeSubtitles/Dialog/Unmanaged/FileOpenErrorDialog.cs
index 5d7ca70..77db280 100644
--- a/src/GnomeSubtitles/Dialog/FileOpenErrorDialog.cs
+++ b/src/GnomeSubtitles/Dialog/Unmanaged/FileOpenErrorDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2008 Pedro Castro
+ * Copyright (C) 2006-2009 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
@@ -21,7 +21,7 @@ using Gtk;
 using Mono.Unix;
 using System;
 
-namespace GnomeSubtitles.Dialog {
+namespace GnomeSubtitles.Dialog.Unmanaged {
 
 public abstract class FileOpenErrorDialog : ErrorDialog {
 	
diff --git a/src/GnomeSubtitles/Dialog/FileSaveErrorDialog.cs b/src/GnomeSubtitles/Dialog/Unmanaged/FileSaveErrorDialog.cs
similarity index 96%
rename from src/GnomeSubtitles/Dialog/FileSaveErrorDialog.cs
rename to src/GnomeSubtitles/Dialog/Unmanaged/FileSaveErrorDialog.cs
index 043754b..4c23b89 100644
--- a/src/GnomeSubtitles/Dialog/FileSaveErrorDialog.cs
+++ b/src/GnomeSubtitles/Dialog/Unmanaged/FileSaveErrorDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2007-2008 Pedro Castro
+ * Copyright (C) 2007-2009 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
@@ -24,7 +24,7 @@ using System;
 using System.IO;
 using System.Security;
 
-namespace GnomeSubtitles.Dialog {
+namespace GnomeSubtitles.Dialog.Unmanaged {
 
 public class FileSaveErrorDialog : ErrorDialog {
 	
diff --git a/src/GnomeSubtitles/Dialog/SaveConfirmationDialog.cs b/src/GnomeSubtitles/Dialog/Unmanaged/SaveConfirmationDialog.cs
similarity index 97%
rename from src/GnomeSubtitles/Dialog/SaveConfirmationDialog.cs
rename to src/GnomeSubtitles/Dialog/Unmanaged/SaveConfirmationDialog.cs
index 5a719aa..49558d9 100644
--- a/src/GnomeSubtitles/Dialog/SaveConfirmationDialog.cs
+++ b/src/GnomeSubtitles/Dialog/Unmanaged/SaveConfirmationDialog.cs
@@ -23,7 +23,7 @@ using Mono.Unix;
 using SubLib.Core.Domain;
 using System;
 
-namespace GnomeSubtitles.Dialog {
+namespace GnomeSubtitles.Dialog.Unmanaged {
 
 public abstract class SaveConfirmationDialog : WarningDialog {
 	private SubtitleTextType textType;
@@ -60,12 +60,12 @@ public abstract class SaveConfirmationDialog : WarningDialog {
 		Hide();
 
 		if (response == ResponseType.Reject)
-			setReturnValue(true);
+			SetReturnValue(true);
 		else if (response == ResponseType.Accept) {
 			if (textType == SubtitleTextType.Text)
-				setReturnValue(Core.Base.Ui.Save());
+				SetReturnValue(Core.Base.Ui.Save());
 			else
-				setReturnValue(Core.Base.Ui.TranslationSave());
+				SetReturnValue(Core.Base.Ui.TranslationSave());
 		}
 
 		return false;
diff --git a/src/GnomeSubtitles/Dialog/SubtitleFileOpenErrorDialog.cs b/src/GnomeSubtitles/Dialog/Unmanaged/SubtitleFileOpenErrorDialog.cs
similarity index 96%
rename from src/GnomeSubtitles/Dialog/SubtitleFileOpenErrorDialog.cs
rename to src/GnomeSubtitles/Dialog/Unmanaged/SubtitleFileOpenErrorDialog.cs
index 143724a..099ce75 100644
--- a/src/GnomeSubtitles/Dialog/SubtitleFileOpenErrorDialog.cs
+++ b/src/GnomeSubtitles/Dialog/Unmanaged/SubtitleFileOpenErrorDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2008 Pedro Castro
+ * Copyright (C) 2006-2009 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
@@ -23,7 +23,7 @@ using System;
 using System.IO;
 using System.Security;
 
-namespace GnomeSubtitles.Dialog {
+namespace GnomeSubtitles.Dialog.Unmanaged {
 
 public class SubtitleFileOpenErrorDialog : FileOpenErrorDialog {
 
diff --git a/src/GnomeSubtitles/Dialog/VideoErrorDialog.cs b/src/GnomeSubtitles/Dialog/Unmanaged/VideoErrorDialog.cs
similarity index 94%
rename from src/GnomeSubtitles/Dialog/VideoErrorDialog.cs
rename to src/GnomeSubtitles/Dialog/Unmanaged/VideoErrorDialog.cs
index 0fc8527..a026381 100644
--- a/src/GnomeSubtitles/Dialog/VideoErrorDialog.cs
+++ b/src/GnomeSubtitles/Dialog/Unmanaged/VideoErrorDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2007-2008 Pedro Castro
+ * Copyright (C) 2007-2009 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
@@ -21,7 +21,7 @@ using GnomeSubtitles.Ui.VideoPreview.Exceptions;
 using Mono.Unix;
 using System;
 
-namespace GnomeSubtitles.Dialog {
+namespace GnomeSubtitles.Dialog.Unmanaged {
 
 public class VideoErrorDialog : FileOpenErrorDialog {
 
diff --git a/src/GnomeSubtitles/Dialog/WarningDialog.cs b/src/GnomeSubtitles/Dialog/Unmanaged/WarningDialog.cs
similarity index 92%
rename from src/GnomeSubtitles/Dialog/WarningDialog.cs
rename to src/GnomeSubtitles/Dialog/Unmanaged/WarningDialog.cs
index 38c04a4..27f77da 100644
--- a/src/GnomeSubtitles/Dialog/WarningDialog.cs
+++ b/src/GnomeSubtitles/Dialog/Unmanaged/WarningDialog.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2008 Pedro Castro
+ * Copyright (C) 2008-2009 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
@@ -21,7 +21,7 @@ using Gtk;
 using Mono.Unix;
 using System;
 
-namespace GnomeSubtitles.Dialog {
+namespace GnomeSubtitles.Dialog.Unmanaged {
 
 public abstract class WarningDialog : MessageDialog {
 	
diff --git a/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs b/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs
index 0ab7410..4083cc7 100644
--- a/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs
+++ b/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs
@@ -34,7 +34,7 @@ public class VideoOpenDialog : GladeDialog {
 	
 	
 	public VideoOpenDialog () : base(gladeFilename) {
-		dialog = getDialog() as FileChooserDialog;
+		dialog = GetDialog() as FileChooserDialog;
 
 		if (Base.IsDocumentLoaded && Base.Document.TextFile.IsPathRooted)
 			dialog.SetCurrentFolder(Base.Document.TextFile.Directory);
@@ -82,7 +82,7 @@ public class VideoOpenDialog : GladeDialog {
 			if (dialog.Uri != null) {
 				chosenUri = new Uri(dialog.Uri);
 			}
-			setReturnValue(true);
+			SetReturnValue(true);
 		}
 		return false;
 	}
diff --git a/src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs b/src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs
index ee9c9a8..795a0db 100644
--- a/src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs
+++ b/src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs
@@ -43,7 +43,7 @@ public class VideoSeekToDialog : GladeDialog {
 		InitSpinButton();
 	}
 
-	/* Public properties */
+	/* Overriden members */
 
 	public override DialogScope Scope {
 		get { return DialogScope.Video; }
diff --git a/src/GnomeSubtitles/Execution/BugReporter.cs b/src/GnomeSubtitles/Execution/BugReporter.cs
index 2f95605..07184c7 100644
--- a/src/GnomeSubtitles/Execution/BugReporter.cs
+++ b/src/GnomeSubtitles/Execution/BugReporter.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2007-2008 Pedro Castro
+ * Copyright (C) 2007-2009 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
@@ -18,7 +18,7 @@
  */
 
 using GnomeSubtitles.Core;
-using GnomeSubtitles.Dialog;
+using GnomeSubtitles.Dialog.Unmanaged;
 using Mono.Unix;
 using System;
 using System.ComponentModel;
diff --git a/src/GnomeSubtitles/Ui/MainUi.cs b/src/GnomeSubtitles/Ui/MainUi.cs
index e295093..615c243 100644
--- a/src/GnomeSubtitles/Ui/MainUi.cs
+++ b/src/GnomeSubtitles/Ui/MainUi.cs
@@ -20,6 +20,7 @@
 using GnomeSubtitles.Core;
 using GnomeSubtitles.Core.Command;
 using GnomeSubtitles.Dialog;
+using GnomeSubtitles.Dialog.Unmanaged;
 using GnomeSubtitles.Ui.Edit;
 using GnomeSubtitles.Ui.VideoPreview;
 using GnomeSubtitles.Ui.View;
@@ -141,7 +142,7 @@ public class MainUi {
     /// <remarks>If there's a document currently open with unsaved changes, a warning dialog
     /// is shown before opening the new file.</remarks>
     public void Open () {
-    	FileOpenDialog dialog = new FileOpenDialog();
+		FileOpenDialog dialog = Base.Dialogs.Get(typeof(FileOpenDialog)) as FileOpenDialog;
     	dialog.Show();
     	bool gotOpenResponse = dialog.WaitForResponse();
     	if (gotOpenResponse && ToOpenAfterWarning()) {
@@ -153,7 +154,8 @@ public class MainUi {
     }
         
     public void OpenVideo () {
-    	VideoOpenDialog dialog = new VideoOpenDialog();
+		
+    	VideoOpenDialog dialog = Base.Dialogs.Get(typeof(VideoOpenDialog)) as VideoOpenDialog;
     	dialog.Show();
 		bool toOpen = dialog.WaitForResponse();
 		if (toOpen) {
@@ -177,7 +179,7 @@ public class MainUi {
     /// <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>
     public bool SaveAs () {
-		FileSaveAsDialog dialog = Base.Dialogs.FileSaveAsDialog;
+		FileSaveAsDialog dialog = Base.Dialogs.Get(typeof(FileSaveAsDialog)) as FileSaveAsDialog;
 		FileProperties properties = ShowSaveAsDialog(dialog);
 		if (properties != null) {
 			Save(properties);
@@ -200,7 +202,7 @@ public class MainUi {
     /// <remarks>If there's a translation currently open with unsaved changes, a warning dialog
     /// is shown before opening the new file.</remarks>
     public void TranslationOpen () {
-    	FileOpenDialog dialog = new FileTranslationOpenDialog();
+    	FileOpenDialog dialog = Base.Dialogs.Get(typeof(FileTranslationOpenDialog)) as FileOpenDialog;
     	dialog.Show();
     	bool toOpen = dialog.WaitForResponse();
     	if (toOpen && ToOpenTranslationAfterWarning()) {
@@ -225,7 +227,7 @@ public class MainUi {
     /// <summary>Executes a translation SaveAs operation.</summary>
     /// <returns>Whether the translation file was saved or not.</returns>
     public bool TranslationSaveAs () {
-		FileSaveAsDialog dialog = Base.Dialogs.TranslationSaveAsDialog;
+		TranslationSaveAsDialog dialog = Base.Dialogs.Get(typeof(TranslationSaveAsDialog)) as TranslationSaveAsDialog;
 		FileProperties properties = ShowSaveAsDialog(dialog);
 		if (properties != null) {
 			SaveTranslation(properties);
@@ -330,7 +332,7 @@ public class MainUi {
 	/// <summary>Displays a SaveAs dialog and gets the chosen options as <cref="FileProperties" />.</summary>
 	/// <param name="dialog">The dialog to display.</param>
 	/// <returns>The chosen file properties, or null in case SaveAs was canceled.</returns>
-	private FileProperties ShowSaveAsDialog (FileSaveAsDialog dialog) {
+	private FileProperties ShowSaveAsDialog (SubtitleFileSaveAsDialog dialog) {
 		dialog.Show();
 		bool toSaveAs = dialog.WaitForResponse();
 		if (!toSaveAs)
diff --git a/src/GnomeSubtitles/Ui/VideoPreview/Video.cs b/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
index f39c4a9..47d8baa 100644
--- a/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
+++ b/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
@@ -18,7 +18,7 @@
  */
 
 using GnomeSubtitles.Core;
-using GnomeSubtitles.Dialog;
+using GnomeSubtitles.Dialog.Unmanaged;
 using Gtk;
 using GStreamer;
 using SubLib.Core;
diff --git a/src/Makefile.am b/src/Makefile.am
index bee2401..7859b2d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,6 +17,7 @@ GS_SOURCES = \
 	$(srcdir)/GnomeSubtitles/Core/*.cs \
 	$(srcdir)/GnomeSubtitles/Core/Command/*.cs \
 	$(srcdir)/GnomeSubtitles/Dialog/*.cs \
+	$(srcdir)/GnomeSubtitles/Dialog/Unmanaged/*.cs \
 	$(srcdir)/GnomeSubtitles/Execution/*.cs \
 	$(srcdir)/GnomeSubtitles/Ui/*.cs \
 	$(srcdir)/GnomeSubtitles/Ui/Edit/*.cs \



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