[gnome-subtitles] Allow to handle dialog persistence/scope
- From: Pedro Daniel da Rocha Melo e Castro <pcastro src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-subtitles] Allow to handle dialog persistence/scope
- Date: Sat, 23 May 2009 07:43:34 -0400 (EDT)
commit 2b772036d8a174399ad588687cb1b549610ae6a2
Author: Pedro Castro <mail pedrocastro org>
Date: Sat May 23 12:29:52 2009 +0100
Allow to handle dialog persistence/scope
Dialogs refactored to specify their scope. This is used to decide whether to destroy a dialog on response, when it's closed, or when a document is closed.
---
src/GnomeSubtitles/Dialog/AboutDialog.cs | 23 +----
src/GnomeSubtitles/Dialog/BaseDialog.cs | 93 ++++++++++++++------
src/GnomeSubtitles/Dialog/DialogScope.cs | 40 +++++++++
src/GnomeSubtitles/Dialog/EncodingsDialog.cs | 6 +-
src/GnomeSubtitles/Dialog/FileOpenDialog.cs | 19 +++--
src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs | 9 +--
src/GnomeSubtitles/Dialog/FileSaveAsDialog.cs | 18 +++--
src/GnomeSubtitles/Dialog/GladeDialog.cs | 34 ++-----
src/GnomeSubtitles/Dialog/HeadersDialog.cs | 12 +--
src/GnomeSubtitles/Dialog/MessageDialog.cs | 37 +++-----
src/GnomeSubtitles/Dialog/PreferencesDialog.cs | 12 +--
.../Dialog/SaveConfirmationDialog.cs | 51 ++++-------
src/GnomeSubtitles/Dialog/SearchDialog.cs | 92 ++++++++-----------
src/GnomeSubtitles/Dialog/SetLanguageDialog.cs | 18 ++--
.../Dialog/SubtitleFileChooserDialog.cs | 6 +-
src/GnomeSubtitles/Dialog/TimingsAdjustDialog.cs | 32 ++++---
src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs | 22 ++++--
src/GnomeSubtitles/Dialog/VideoOpenDialog.cs | 20 +++--
src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs | 17 +++--
19 files changed, 293 insertions(+), 268 deletions(-)
diff --git a/src/GnomeSubtitles/Dialog/AboutDialog.cs b/src/GnomeSubtitles/Dialog/AboutDialog.cs
index 139dd6e..0fb2857 100644
--- a/src/GnomeSubtitles/Dialog/AboutDialog.cs
+++ b/src/GnomeSubtitles/Dialog/AboutDialog.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
@@ -24,7 +24,7 @@ using System;
namespace GnomeSubtitles.Dialog {
public class AboutDialog : GladeDialog {
- private new Gtk.AboutDialog dialog = null;
+ private Gtk.AboutDialog dialog = null;
/* Constant strings */
private const string gladeFilename = "AboutDialog.glade";
@@ -33,9 +33,9 @@ public class AboutDialog : GladeDialog {
public AboutDialog () {
SetHooks();
- Init(gladeFilename);
+ Init(gladeFilename, true);
- dialog = base.dialog as Gtk.AboutDialog;
+ dialog = getDialog() as Gtk.AboutDialog;
SetInfo();
}
@@ -62,21 +62,6 @@ public class AboutDialog : GladeDialog {
dialog.Logo = new Gdk.Pixbuf(null, logoFilename);
}
- /* Event members */
-
- #pragma warning disable 169 //Disables warning about handlers not being used
-
- private void OnResponse (object o, ResponseArgs args) {
- switch (args.ResponseId) {
- case ResponseType.Close:
- Close();
- break;
- case ResponseType.Cancel:
- Close();
- break;
- }
- }
-
}
}
diff --git a/src/GnomeSubtitles/Dialog/BaseDialog.cs b/src/GnomeSubtitles/Dialog/BaseDialog.cs
index 4aecfa8..3de1848 100644
--- a/src/GnomeSubtitles/Dialog/BaseDialog.cs
+++ b/src/GnomeSubtitles/Dialog/BaseDialog.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
@@ -23,46 +23,87 @@ namespace GnomeSubtitles.Dialog {
public abstract class BaseDialog {
- #region Protected variables
- protected Gtk.Dialog dialog = null;
- protected bool returnValue = false;
- #endregion
+ private Gtk.Dialog dialog = null;
+ private bool returnValue = false;
public BaseDialog () {
+ }
+
+ /* Properties */
+ public virtual DialogScope Scope {
+ get { return DialogScope.Singleton; }
}
-
-
- #region Public methods
-
+
+ public virtual bool Visible {
+ get { return dialog.Visible; }
+ set {
+ if (value)
+ Show();
+ else
+ Hide();
+ }
+ }
+
+ /* Public Methods */
+
public virtual void Show () {
dialog.Visible = true;
}
-
- public void Close() {
- dialog.Destroy();
- }
-
- public void Hide () {
+
+ public virtual void Hide () {
dialog.Visible = false;
}
+
+ public virtual void Destroy () {
+ dialog.Destroy();
+ }
+
- public bool WaitForResponse () {
+
+ //TODO check if this is needed
+ public virtual bool WaitForResponse () {
dialog.Run();
return returnValue;
}
-
- #endregion
-
-
- #region Events
-
- protected void OnDeleteDoHide (object o, DeleteEventArgs args) {
- Hide();
- args.RetVal = true;
+
+ protected virtual bool ProcessResponse (Gtk.ResponseType response) {
+ return false;
+ }
+
+
+ /* Protected members */
+
+ protected void Init (Gtk.Dialog dialog) {
+ this.dialog = dialog;
+ Util.SetBaseWindowFromUi(dialog);
+ dialog.Response += OnResponse;
}
+
+ protected Gtk.Dialog getDialog () {
+ return dialog;
+ }
+
+ protected void setReturnValue (bool returnValue) {
+ this.returnValue = returnValue;
+ }
+
- #endregion
+ /* Event members */
+
+ protected void OnResponse (object o, ResponseArgs args) {
+ bool keepVisible = ProcessResponse(args.ResponseId);
+ if (keepVisible && (args.ResponseId != ResponseType.DeleteEvent))
+ return;
+
+ if (this.Scope == DialogScope.Singleton)
+ Destroy();
+ else {
+ Hide();
+ args.RetVal = true;
+ }
+ }
+
}
diff --git a/src/GnomeSubtitles/Dialog/DialogScope.cs b/src/GnomeSubtitles/Dialog/DialogScope.cs
new file mode 100644
index 0000000..f663b0d
--- /dev/null
+++ b/src/GnomeSubtitles/Dialog/DialogScope.cs
@@ -0,0 +1,40 @@
+/*
+ * This file is part of Gnome Subtitles.
+ * 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
+ * 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
+ */
+
+namespace GnomeSubtitles.Dialog {
+
+/// <summary>
+/// Represents a dialog scope.
+/// </summary>
+public enum DialogScope {
+
+ /// <summary>The dialog is active until it's closed.</summary>
+ Singleton,
+
+ /// <summary>The dialog is active until the document is closed.</summary>
+ Document,
+
+ /// <summary>The dialog is active until the video is closed.</summary>
+ Video,
+
+ /// <summary>The dialog is active until the application is closed.</summary>
+ Application
+}
+
+}
diff --git a/src/GnomeSubtitles/Dialog/EncodingsDialog.cs b/src/GnomeSubtitles/Dialog/EncodingsDialog.cs
index e607173..ba593e1 100644
--- a/src/GnomeSubtitles/Dialog/EncodingsDialog.cs
+++ b/src/GnomeSubtitles/Dialog/EncodingsDialog.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
@@ -198,10 +198,6 @@ public class EncodingsDialog : GladeDialog {
buttonRemove.Sensitive = sensitive;
}
- private void OnResponse (object o, ResponseArgs args) {
- Close();
- }
-
private void OnAvailableRowActivated (object o, RowActivatedArgs args) {
AddSelectedAvailableEncoding();
}
diff --git a/src/GnomeSubtitles/Dialog/FileOpenDialog.cs b/src/GnomeSubtitles/Dialog/FileOpenDialog.cs
index edbe70d..7adcfca 100644
--- a/src/GnomeSubtitles/Dialog/FileOpenDialog.cs
+++ b/src/GnomeSubtitles/Dialog/FileOpenDialog.cs
@@ -49,7 +49,7 @@ public class FileOpenDialog : SubtitleFileChooserDialog {
public FileOpenDialog () : this(true, Catalog.GetString("Open File")) {
}
- protected FileOpenDialog (bool toEnableVideo, string title) : base(gladeFilename, false) {
+ protected FileOpenDialog (bool toEnableVideo, string title) : base(gladeFilename) {
dialog.Title = title;
if (toEnableVideo)
@@ -73,6 +73,10 @@ public class FileOpenDialog : SubtitleFileChooserDialog {
}
/* Public properties */
+
+ public override DialogScope Scope {
+ get { return DialogScope.Singleton; }
+ }
public bool HasVideoFilename {
get { return chosenVideoUri != null; }
@@ -81,7 +85,8 @@ public class FileOpenDialog : SubtitleFileChooserDialog {
public Uri VideoUri {
get { return chosenVideoUri; }
}
-
+
+
/* Protected members */
protected virtual string GetStartFolder () {
@@ -242,9 +247,9 @@ public class FileOpenDialog : SubtitleFileChooserDialog {
#pragma warning disable 169 //Disables warning about handlers not being used
-
- private void OnResponse (object o, ResponseArgs args) {
- if (args.ResponseId == ResponseType.Ok) {
+
+ protected override bool ProcessResponse (ResponseType response) {
+ if (response == ResponseType.Ok) {
chosenFilename = dialog.Filename;
int activeEncodingComboBoxItem = GetActiveEncodingComboBoxItem();
if (activeEncodingComboBoxItem > 0) {
@@ -256,9 +261,9 @@ public class FileOpenDialog : SubtitleFileChooserDialog {
int videoFileIndex = videoComboBox.Active - 2;
chosenVideoUri = new Uri(videoFiles[videoFileIndex] as string);
}
- returnValue = true;
+ setReturnValue(true);
}
- Close();
+ return false;
}
private void OnCurrentFolderChanged (object o, EventArgs args) {
diff --git a/src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs b/src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs
index 8639f49..d708263 100644
--- a/src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs
+++ b/src/GnomeSubtitles/Dialog/FilePropertiesDialog.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
@@ -98,13 +98,6 @@ public class FilePropertiesDialog : GladeDialog {
private void FillTimingMode (TimingMode mode) {
timingModeValueLabel.Text = mode.ToString();
}
-
-
- #pragma warning disable 169 //Disables warning about handlers not being used
-
- private void OnResponse (object o, ResponseArgs args) {
- Close();
- }
}
diff --git a/src/GnomeSubtitles/Dialog/FileSaveAsDialog.cs b/src/GnomeSubtitles/Dialog/FileSaveAsDialog.cs
index 486484d..195895b 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-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
@@ -43,7 +43,7 @@ public class FileSaveAsDialog : SubtitleFileChooserDialog {
[WidgetAttribute] private ComboBox formatComboBox = null;
[WidgetAttribute] private ComboBox newlineTypeComboBox = null;
- public FileSaveAsDialog (SubtitleTextType textType) : base(gladeFilename, true) {
+ public FileSaveAsDialog (SubtitleTextType textType) : base(gladeFilename) {
this.textType = textType;
SetTitle();
FillFormatComboBox();
@@ -51,6 +51,10 @@ public class FileSaveAsDialog : SubtitleFileChooserDialog {
}
/* Public properties */
+
+ public override DialogScope Scope {
+ get { return DialogScope.Document; }
+ }
public SubtitleType SubtitleType {
get { return chosenSubtitleType; }
@@ -288,20 +292,20 @@ public class FileSaveAsDialog : SubtitleFileChooserDialog {
/* Event members */
#pragma warning disable 169 //Disables warning about handlers not being used
-
- private void OnResponse (object o, ResponseArgs args) {
- if (args.ResponseId == ResponseType.Ok) {
+
+ 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];
- returnValue = true;
+ setReturnValue(true);
chosenNewlineType = GetChosenNewlineType();
}
- Hide();
+ return false;
}
private void OnFormatChanged (object o, EventArgs args) {
diff --git a/src/GnomeSubtitles/Dialog/GladeDialog.cs b/src/GnomeSubtitles/Dialog/GladeDialog.cs
index 56a04b1..63133f4 100644
--- a/src/GnomeSubtitles/Dialog/GladeDialog.cs
+++ b/src/GnomeSubtitles/Dialog/GladeDialog.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;
namespace GnomeSubtitles.Dialog {
-public class GladeDialog : BaseDialog {
+public abstract class GladeDialog : BaseDialog {
private Glade.XML glade = null;
/// <summary>Creates a new instance of the <see cref="GladeDialog" /> class.</summary>
@@ -32,34 +32,23 @@ public class GladeDialog : BaseDialog {
protected GladeDialog () {
}
- /// <summary>Creates a new instance of the <see cref="GladeDialog" /> class, given the filename of the dialog
- /// and persistency possibility.</summary>
+ /// <summary>Creates a new instance of the <see cref="GladeDialog" /> class, given the filename of the dialog.</summary>
/// <param name="filename">The filename of the dialog.</param>
- /// <param name="persistent">Whether the dialog should persist when closed. In that case, it is just hidden.</param>
- protected GladeDialog (string filename) : this(filename, false, true) {
+ protected GladeDialog (string filename) : this(filename, true) {
}
- protected GladeDialog (string filename, bool persistent, bool autoconnect) {
- Init(filename, persistent, autoconnect);
+ protected GladeDialog (string filename, bool autoconnect) {
+ Init(filename, autoconnect);
}
/* Protected members */
- /// <summary>Constructs the dialog in the specified filename.</param>
- /// <param name="filename">The filename of the dialog.</param>
- /// <remarks>Constructing creates the dialog from its filename, autoconnects the handlers,
- /// sets the icon and also sets the dialog as transient for the main window.</summary>
- protected void Init (string filename) {
- Init(filename, false, true);
- }
-
/// <summary>Constructs the dialog with the specified filename, and possibly sets it as persistent.</param>
/// <param name="filename">The filename of the dialog.</param>
- /// <param name="persistent">Whether the dialog should persist when closed. In that case, it is just hidden.</param>
/// <param name="autoconnect">Whether to autoconnect the event handlers.</param>
/// <remarks>Constructing creates the dialog from its filename, autoconnects the handlers,
/// sets the icon and also sets the dialog as transient for the main window.</summary>
- protected void Init (string filename, bool persistent, bool autoconnect) {
+ protected void Init (string filename, bool autoconnect) {
glade = new Glade.XML(null, filename, null, Base.ExecutionContext.TranslationDomain);
if (autoconnect)
@@ -67,14 +56,9 @@ public class GladeDialog : BaseDialog {
else
glade.BindFields(this);
- dialog = glade.GetWidget("dialog") as Gtk.Dialog;
-
- Util.SetBaseWindowToUi(dialog);
-
- if (persistent)
- dialog.DeleteEvent += OnDeleteDoHide;
+ base.Init(glade.GetWidget("dialog") as Gtk.Dialog);
}
-
+
protected void Autoconnect () {
glade.Autoconnect(this);
}
diff --git a/src/GnomeSubtitles/Dialog/HeadersDialog.cs b/src/GnomeSubtitles/Dialog/HeadersDialog.cs
index e3c6c5f..7e5dfa2 100644
--- a/src/GnomeSubtitles/Dialog/HeadersDialog.cs
+++ b/src/GnomeSubtitles/Dialog/HeadersDialog.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
@@ -259,15 +259,13 @@ public class HeadersDialog : GladeDialog {
headers.FontSize = spinButtonSubViewer2FontSize.ValueAsInt;
}
- /* Event handlers */
+ /* Event members */
- #pragma warning disable 169 //Disables warning about handlers not being used
-
- private void OnResponse (object o, ResponseArgs args) {
- if (args.ResponseId == ResponseType.Ok) {
+ protected override bool ProcessResponse (ResponseType response) {
+ if (response == ResponseType.Ok) {
StoreHeaders();
}
- Close();
+ return false;
}
}
diff --git a/src/GnomeSubtitles/Dialog/MessageDialog.cs b/src/GnomeSubtitles/Dialog/MessageDialog.cs
index 493b295..e960204 100644
--- a/src/GnomeSubtitles/Dialog/MessageDialog.cs
+++ b/src/GnomeSubtitles/Dialog/MessageDialog.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
@@ -43,7 +43,7 @@ namespace GnomeSubtitles.Dialog {
}
- #region Protected methods
+ /* Protected methods */
protected void SetText (string primaryText, string secondaryText, params object[] primaryTextArgs) {
SetPrimaryText(primaryText, primaryTextArgs);
@@ -75,49 +75,38 @@ namespace GnomeSubtitles.Dialog {
SetSecondaryText(text, null);
}
- #endregion
- #region Private members
+ /* Private members */
private void Init (MessageType messageType, string primaryText, string secondaryText, params object[]primaryTextArgs) {
string formattedPrimaryText = GetMarkupPrimaryText(primaryText);
-
+
dialog = new Gtk.MessageDialog(Base.Ui.Window, DialogFlags.Modal, messageType, ButtonsType.None, formattedPrimaryText, primaryTextArgs);
- base.dialog = dialog;
-
- dialog.Response += OnResponse;
+ base.Init(dialog);
SetSecondaryText(secondaryText);
-
- Util.SetBaseWindowToUi(dialog);
AddButtons();
}
private string GetMarkupPrimaryText (string primaryText) {
return "<span weight=\"bold\" size=\"larger\">" + primaryText + "</span>";
}
-
- #endregion
-
- #region Abstract methods
+
+
+ /* Abstract methods */
protected abstract void AddButtons ();
-
- #endregion
- #region Event members
-
- protected virtual void OnResponse (object o, ResponseArgs args) {
- ResponseType response = args.ResponseId;
+ /* Event members */
+
+ protected override bool ProcessResponse (ResponseType response) {
if (response == ResponseType.Accept) {
- returnValue = true;
+ setReturnValue(true);
}
- Close();
+ return false;
}
- #endregion
-
}
diff --git a/src/GnomeSubtitles/Dialog/PreferencesDialog.cs b/src/GnomeSubtitles/Dialog/PreferencesDialog.cs
index 90bdf69..8409436 100644
--- a/src/GnomeSubtitles/Dialog/PreferencesDialog.cs
+++ b/src/GnomeSubtitles/Dialog/PreferencesDialog.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
@@ -34,7 +34,7 @@ public class PreferencesDialog : GladeDialog {
[WidgetAttribute] private CheckButton videoAutoChooseFileCheckButton = null;
- public PreferencesDialog () : base(gladeFilename, false, false) {
+ public PreferencesDialog () : base(gladeFilename, false) {
LoadValues();
Autoconnect();
}
@@ -45,14 +45,10 @@ public class PreferencesDialog : GladeDialog {
videoAutoChooseFileCheckButton.Active = Base.Config.PrefsVideoAutoChooseFile;
}
- /* Event handlers */
+ /* Event members */
#pragma warning disable 169 //Disables warning about handlers not being used
-
- private void OnResponse (object o, ResponseArgs args) {
- Close();
- }
-
+
private void OnVideoAutoChooseFileToggled (object o, EventArgs args) {
Base.Config.PrefsVideoAutoChooseFile = videoAutoChooseFileCheckButton.Active;
}
diff --git a/src/GnomeSubtitles/Dialog/SaveConfirmationDialog.cs b/src/GnomeSubtitles/Dialog/SaveConfirmationDialog.cs
index 2f68fe2..5a719aa 100644
--- a/src/GnomeSubtitles/Dialog/SaveConfirmationDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SaveConfirmationDialog.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
@@ -28,10 +28,8 @@ namespace GnomeSubtitles.Dialog {
public abstract class SaveConfirmationDialog : WarningDialog {
private SubtitleTextType textType;
- #region Strings
+ /* Strings */
private string secondaryText = Catalog.GetString("If you don't save, all your changes will be permanently lost.");
- #endregion
-
public SaveConfirmationDialog (string primaryText, SubtitleTextType textType) : base() {
this.textType = textType;
@@ -41,14 +39,12 @@ public abstract class SaveConfirmationDialog : WarningDialog {
}
- #region Abstract methods
+ /* Abstract methods */
protected abstract string GetRejectLabel ();
- #endregion
-
- #region Protected methods
+ /* Protected methods */
protected override void AddButtons () {
string rejectLabel = GetRejectLabel();
@@ -57,26 +53,23 @@ public abstract class SaveConfirmationDialog : WarningDialog {
dialog.AddButton(Stock.Save, ResponseType.Accept);
}
- #endregion
-
-
- #region Events
- protected override void OnResponse (object o, ResponseArgs args) {
- Close();
+ /* Event members */
+
+ protected override bool ProcessResponse (ResponseType response) {
+ Hide();
- ResponseType response = args.ResponseId;
if (response == ResponseType.Reject)
- returnValue = true;
+ setReturnValue(true);
else if (response == ResponseType.Accept) {
if (textType == SubtitleTextType.Text)
- returnValue = Core.Base.Ui.Save();
+ setReturnValue(Core.Base.Ui.Save());
else
- returnValue = Core.Base.Ui.TranslationSave();
+ setReturnValue(Core.Base.Ui.TranslationSave());
}
+
+ return false;
}
-
- #endregion
}
@@ -84,10 +77,9 @@ public abstract class SaveConfirmationDialog : WarningDialog {
public class SaveSubtitlesOnNewFileConfirmationDialog : SaveConfirmationDialog {
- #region Strings
+ /* Strings */
private static string primaryText = Catalog.GetString("Save the changes to subtitles \"{0}\" before creating new subtitles?");
private static string rejectLabel = Catalog.GetString("Create without Saving");
- #endregion
public SaveSubtitlesOnNewFileConfirmationDialog () : base(primaryText, SubtitleTextType.Text) {
}
@@ -96,14 +88,13 @@ public class SaveSubtitlesOnNewFileConfirmationDialog : SaveConfirmationDialog {
}
- #region Protected methods
+ /* Protected methods */
protected override string GetRejectLabel ()
{
return rejectLabel;
}
-
- #endregion
+
}
public class SaveTranslationOnNewFileConfirmationDialog : SaveSubtitlesOnNewFileConfirmationDialog {
@@ -133,14 +124,13 @@ public class SaveSubtitlesOnOpenFileConfirmationDialog : SaveConfirmationDialog
public SaveSubtitlesOnOpenFileConfirmationDialog (string primaryText, SubtitleTextType textType) : base (primaryText, textType) {
}
- #region Protected methods
+ /* Protected methods */
protected override string GetRejectLabel ()
{
return rejectLabel;
}
-
- #endregion
+
}
//This works both for file open and translation open
@@ -163,14 +153,13 @@ public class SaveSubtitlesOnCloseFileConfirmationDialog : SaveConfirmationDialog
public SaveSubtitlesOnCloseFileConfirmationDialog (string primaryText, SubtitleTextType textType) : base(primaryText, textType) {
}
- #region Protected methods
+ /* Protected methods */
protected override string GetRejectLabel ()
{
return rejectLabel;
}
-
- #endregion
+
}
public class SaveTranslationOnCloseConfirmationDialog : SaveSubtitlesOnCloseFileConfirmationDialog {
diff --git a/src/GnomeSubtitles/Dialog/SearchDialog.cs b/src/GnomeSubtitles/Dialog/SearchDialog.cs
index af364d9..b49eac7 100644
--- a/src/GnomeSubtitles/Dialog/SearchDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SearchDialog.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
@@ -57,28 +57,15 @@ public class SearchDialog : GladeDialog {
[WidgetAttribute] private Button buttonReplace = null;
[WidgetAttribute] private Button buttonFind = null;
- public SearchDialog () : base(gladeFilename, true, true) {
+ public SearchDialog () : base(gladeFilename) {
}
-
- public bool ShowReplace2 {
- set {
- if (value == true) {
- dialog.Title = Catalog.GetString("Replace");
- table.RowSpacing = 12;
- }
- else {
- dialog.Title = Catalog.GetString("Find");
- table.RowSpacing = 0;
- }
-
- replaceEntry.Visible = value;
- replaceLabel.Visible = value;
-
- buttonReplaceAll.Visible = value;
- buttonReplace.Visible = value;
- }
+
+ /* Properties */
+
+ public override DialogScope Scope {
+ get { return DialogScope.Document; }
}
-
+
public Regex ForwardRegex {
get { return forwardRegex; }
}
@@ -106,18 +93,20 @@ public class SearchDialog : GladeDialog {
public bool Wrap {
get { return wrapCheckButton.Active; }
}
-
+
+ /* Methods */
+
public override void Show () {
Show(false);
}
public void Show (bool useReplace) {
if (useReplace) {
- dialog.Title = Catalog.GetString("Replace");
+ getDialog().Title = Catalog.GetString("Replace");
table.RowSpacing = 12;
}
else {
- dialog.Title = Catalog.GetString("Find");
+ getDialog().Title = Catalog.GetString("Find");
table.RowSpacing = 0;
}
@@ -131,30 +120,25 @@ public class SearchDialog : GladeDialog {
base.Show();
}
+ /* Private methods */
- /* Private properties */
-
- private bool ValuesHaveChanged {
- get {
- if (!valuesMayHaveChanged)
- return false;
- if (text != findEntry.Text)
- return true;
- if (matchCase != matchCaseCheckButton.Active)
- return true;
- if (backwards != backwardsCheckButton.Active)
- return true;
- if (useRegex != regexCheckButton.Active)
- return true;
- if (wrap != wrapCheckButton.Active)
- return true;
-
+ private bool ValuesHaveChanged () {
+ if (!valuesMayHaveChanged)
return false;
- }
+ if (text != findEntry.Text)
+ return true;
+ if (matchCase != matchCaseCheckButton.Active)
+ return true;
+ if (backwards != backwardsCheckButton.Active)
+ return true;
+ if (useRegex != regexCheckButton.Active)
+ return true;
+ if (wrap != wrapCheckButton.Active)
+ return true;
+
+ return false;
}
-
- /* Private methods */
-
+
private void LoadDialogValues () {
SetFindEntryText();
matchCaseCheckButton.Active = matchCase;
@@ -182,7 +166,7 @@ public class SearchDialog : GladeDialog {
}
private void HandleValuesChange () {
- bool updateRegex = ValuesHaveChanged; //Need to be before SaveDialogValues, as the values will be changed
+ bool updateRegex = ValuesHaveChanged(); //Need to be before SaveDialogValues, as the values will be changed
SaveDialogValues();
if (updateRegex)
UpdateRegex();
@@ -225,21 +209,23 @@ public class SearchDialog : GladeDialog {
#pragma warning disable 169 //Disables warning about handlers not being used
- private void OnResponse (object o, ResponseArgs args) {
- SearchDialogResponse response = (SearchDialogResponse)args.ResponseId;
- switch (response) {
+ protected override bool ProcessResponse (ResponseType response) {
+ SearchDialogResponse searchResponse = (SearchDialogResponse)response;
+ switch (searchResponse) {
case SearchDialogResponse.Find:
Find();
- break;
+ return true;
case SearchDialogResponse.Replace:
Replace();
- break;
+ return true;
case SearchDialogResponse.ReplaceAll:
ReplaceAll();
- break;
+ return true;
case SearchDialogResponse.Close:
Hide();
- break;
+ return false;
+ default:
+ return false;
}
}
diff --git a/src/GnomeSubtitles/Dialog/SetLanguageDialog.cs b/src/GnomeSubtitles/Dialog/SetLanguageDialog.cs
index 3538faa..7c52ecf 100644
--- a/src/GnomeSubtitles/Dialog/SetLanguageDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SetLanguageDialog.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
@@ -117,27 +117,27 @@ public class SetLanguageDialog : GladeDialog {
}
private void SetDialogTitle (SubtitleTextType textType) {
- dialog.Title = (textType == SubtitleTextType.Text ? dialogTitleText : dialogTitleTranslation);
+ getDialog().Title = (textType == SubtitleTextType.Text ? dialogTitleText : dialogTitleTranslation);
}
private void SetIntroLabel (SubtitleTextType textType) {
introLabel.TextWithMnemonic = (textType == SubtitleTextType.Text ? introLabelText : introLabelTranslation);
}
- /* Event handlers */
+ /* Event members */
#pragma warning disable 169 //Disables warning about handlers not being used
-
- private void OnResponse (object o, ResponseArgs args) {
- if (args.ResponseId == ResponseType.Ok)
+
+ protected override bool ProcessResponse (ResponseType response) {
+ if (response == ResponseType.Ok) {
SetSpellLanguage();
-
- Close();
+ }
+ return false;
}
private void OnLanguageRowActivated (object o, RowActivatedArgs args) {
SetSpellLanguage();
- Close();
+ Destroy();
}
diff --git a/src/GnomeSubtitles/Dialog/SubtitleFileChooserDialog.cs b/src/GnomeSubtitles/Dialog/SubtitleFileChooserDialog.cs
index 858dab0..4b38613 100644
--- a/src/GnomeSubtitles/Dialog/SubtitleFileChooserDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SubtitleFileChooserDialog.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
@@ -42,8 +42,8 @@ public abstract class SubtitleFileChooserDialog : GladeDialog {
protected EncodingDescription[] encodings = null;
- protected SubtitleFileChooserDialog (string filename, bool persistent) : base(filename, persistent, true) {
- dialog = base.dialog as FileChooserDialog;
+ protected SubtitleFileChooserDialog (string filename) : base(filename) {
+ dialog = getDialog() as FileChooserDialog;
fixedEncoding = GetFixedEncoding();
SetEncodingComboBox();
diff --git a/src/GnomeSubtitles/Dialog/TimingsAdjustDialog.cs b/src/GnomeSubtitles/Dialog/TimingsAdjustDialog.cs
index ebce48d..b6a97b8 100644
--- a/src/GnomeSubtitles/Dialog/TimingsAdjustDialog.cs
+++ b/src/GnomeSubtitles/Dialog/TimingsAdjustDialog.cs
@@ -1,6 +1,6 @@
/*
* This file is part of Gnome Subtitles.
- * Copyright (C) 2006-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
@@ -121,20 +121,12 @@ public class TimingsAdjustDialog : GladeDialog {
}
}
+ /* Event members */
+
#pragma warning disable 169 //Disables warning about handlers not being used
-
- private void OnToggleAllSubtitles (object o, EventArgs args) {
- if ((o as RadioButton).Active)
- SetApplyToAll();
- }
-
- private void OnToggleSelectedSubtitles (object o, EventArgs args) {
- if ((o as RadioButton).Active)
- SetApplyToSelection();
- }
-
- private void OnResponse (object o, ResponseArgs args) {
- if (args.ResponseId == ResponseType.Ok) {
+
+ protected override bool ProcessResponse (ResponseType response) {
+ if (response == ResponseType.Ok) {
SelectionIntended selectionIntended = (allSubtitlesRadioButton.Active ? SelectionIntended.All : SelectionIntended.Range);
if (timingMode == TimingMode.Times) {
@@ -148,7 +140,17 @@ public class TimingsAdjustDialog : GladeDialog {
Base.CommandManager.Execute(new AdjustTimingsCommand(firstFrame, lastFrame, selectionIntended));
}
}
- Close();
+ return false;
+ }
+
+ private void OnToggleAllSubtitles (object o, EventArgs args) {
+ if ((o as RadioButton).Active)
+ SetApplyToAll();
+ }
+
+ private void OnToggleSelectedSubtitles (object o, EventArgs args) {
+ if ((o as RadioButton).Active)
+ SetApplyToSelection();
}
}
diff --git a/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs b/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs
index ce4a2a4..ce91664 100644
--- a/src/GnomeSubtitles/Dialog/TimingsShiftDialog.cs
+++ b/src/GnomeSubtitles/Dialog/TimingsShiftDialog.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
@@ -43,11 +43,21 @@ public class TimingsShiftDialog : GladeDialog {
[WidgetAttribute] private RadioButton fromFirstSubtitleToSelectionRadioButton = null;
[WidgetAttribute] private RadioButton fromSelectionToLastSubtitleRadioButton = null;
- public TimingsShiftDialog () : base(gladeFilename, true, true){
+ public TimingsShiftDialog () : base(gladeFilename){
InitSpinButton();
UpdateContents(true);
}
+
+ /* Properties */
+
+ public override DialogScope Scope {
+ get { return DialogScope.Document; }
+ }
+
+
+ /* Methods */
+
public override void Show () {
UpdateContents(false);
base.Show();
@@ -132,9 +142,9 @@ public class TimingsShiftDialog : GladeDialog {
private void OnClear (object o, EventArgs args) {
SetSpinButtonValue(0);
}
-
- private void OnResponse (object o, ResponseArgs args) {
- if ((args.ResponseId == ResponseType.Ok) && (spinButton.Value != 0)) {
+
+ protected override bool ProcessResponse (ResponseType response) {
+ if ((response == ResponseType.Ok) && (spinButton.Value != 0)) {
SelectionIntended selectionIntended = GetSelectionIntended();
if (timingMode == TimingMode.Times) {
@@ -146,7 +156,7 @@ public class TimingsShiftDialog : GladeDialog {
Base.CommandManager.Execute(new ShiftTimingsCommand(frames, selectionIntended));
}
}
- Hide();
+ return false;
}
}
diff --git a/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs b/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs
index 43bf798..0ab7410 100644
--- a/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs
+++ b/src/GnomeSubtitles/Dialog/VideoOpenDialog.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
@@ -34,7 +34,7 @@ public class VideoOpenDialog : GladeDialog {
public VideoOpenDialog () : base(gladeFilename) {
- dialog = base.dialog as FileChooserDialog;
+ dialog = getDialog() as FileChooserDialog;
if (Base.IsDocumentLoaded && Base.Document.TextFile.IsPathRooted)
dialog.SetCurrentFolder(Base.Document.TextFile.Directory);
@@ -72,17 +72,19 @@ public class VideoOpenDialog : GladeDialog {
/* Set active filter */
dialog.Filter = videoFilesFilter;
}
+
+ /* Event members */
#pragma warning disable 169 //Disables warning about handlers not being used
-
- private void OnResponse (object o, ResponseArgs args) {
- if (args.ResponseId == ResponseType.Ok) {
- if (dialog.Uri != null)
- chosenUri = new Uri(dialog.Uri);
- returnValue = true;
+ protected override bool ProcessResponse (ResponseType response) {
+ if (response == ResponseType.Ok) {
+ if (dialog.Uri != null) {
+ chosenUri = new Uri(dialog.Uri);
+ }
+ setReturnValue(true);
}
- Close();
+ return false;
}
}
diff --git a/src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs b/src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs
index 75c0d92..ee9c9a8 100644
--- a/src/GnomeSubtitles/Dialog/VideoSeekToDialog.cs
+++ b/src/GnomeSubtitles/Dialog/VideoSeekToDialog.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
@@ -37,12 +37,17 @@ public class VideoSeekToDialog : GladeDialog {
[WidgetAttribute] private SpinButton spinButton = null;
[WidgetAttribute] private Label positionLabel = null;
- public VideoSeekToDialog () : base(gladeFilename, true, true){
+ public VideoSeekToDialog () : base(gladeFilename){
this.timingMode = Base.TimingMode;
InitSpinButton();
}
+ /* Public properties */
+
+ public override DialogScope Scope {
+ get { return DialogScope.Video; }
+ }
/* Private methods */
@@ -75,9 +80,9 @@ public class VideoSeekToDialog : GladeDialog {
private void OnClear (object o, EventArgs args) {
SetSpinButtonValue(0);
}
-
- private void OnResponse (object o, ResponseArgs args) {
- if (args.ResponseId == ResponseType.Ok) {
+
+ protected override bool ProcessResponse (ResponseType response) {
+ if (response == ResponseType.Ok) {
if (timingMode == TimingMode.Times) {
TimeSpan position = TimeSpan.FromMilliseconds(spinButton.Value); //TODO move to Util
Base.Ui.Video.Seek(position);
@@ -86,7 +91,7 @@ public class VideoSeekToDialog : GladeDialog {
Base.Ui.Video.Seek(Convert.ToInt32(spinButton.Value));
}
}
- Close();
+ return false;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]