[gnome-subtitles/gtk3] FileProperties and BaseDialog refactor
- From: Pedro Daniel da Rocha Melo e Castro <pcastro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-subtitles/gtk3] FileProperties and BaseDialog refactor
- Date: Sun, 14 Jan 2018 15:49:04 +0000 (UTC)
commit 397986c470b0574a24cd791c3629e08edc292394
Author: Pedro Castro <pedro gnomesubtitles org>
Date: Sun Jan 14 15:47:13 2018 +0000
FileProperties and BaseDialog refactor
src/Glade/MainWindow.ui | 20 +++--
.../{ => old.glade}/FilePropertiesDialog.glade | 0
.../FilePropertiesDialog.ui} | 66 +++++++-------
src/GnomeSubtitles/Dialog/AboutDialog.cs | 4 +-
src/GnomeSubtitles/Dialog/BaseDialog.cs | 25 +++---
src/GnomeSubtitles/Dialog/EncodingsDialog.cs | 22 ++--
src/GnomeSubtitles/Dialog/FileOpenDialog.cs | 33 +++----
src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs | 102 ++++++++++----------
src/GnomeSubtitles/Dialog/FileSaveDialog.cs | 16 ++--
src/GnomeSubtitles/Dialog/HeadersDialog.cs | 11 +-
src/GnomeSubtitles/Dialog/MessageDialog.cs | 2 +-
src/GnomeSubtitles/Dialog/SearchDialog.cs | 4 +-
src/GnomeSubtitles/Dialog/SetLanguageDialog.cs | 2 +-
src/GnomeSubtitles/Dialog/VideoOpenDialog.cs | 19 ++--
14 files changed, 165 insertions(+), 161 deletions(-)
---
diff --git a/src/Glade/MainWindow.ui b/src/Glade/MainWindow.ui
index b1e2085..6122edb 100644
--- a/src/Glade/MainWindow.ui
+++ b/src/Glade/MainWindow.ui
@@ -125,6 +125,7 @@
<child>
<object class="GtkMenuItem" id="fileTranslationReload">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Reload</property>
<property name="use_underline">True</property>
@@ -135,6 +136,7 @@
<child>
<object class="GtkMenuItem" id="fileTranslationSave">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Save</property>
<property name="use_underline">True</property>
@@ -144,6 +146,7 @@
<child>
<object class="GtkMenuItem" id="fileTranslationSaveAs">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Save _As</property>
<property name="use_underline">True</property>
@@ -153,6 +156,7 @@
<child>
<object class="GtkMenuItem" id="fileTranslationClose">
<property name="visible">True</property>
+ <property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Close</property>
<property name="use_underline">True</property>
@@ -244,8 +248,8 @@
<property name="label" translatable="yes">_Redo</property>
<property name="use_underline">True</property>
<signal name="activate" handler="OnEditRedo" swapped="no"/>
- <accelerator key="z" signal="activate" modifiers="GDK_SHIFT_MASK |
GDK_CONTROL_MASK"/>
<accelerator key="y" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+ <accelerator key="z" signal="activate" modifiers="GDK_SHIFT_MASK |
GDK_CONTROL_MASK"/>
</object>
</child>
<child>
@@ -567,8 +571,8 @@
<property name="label" translatable="yes">Find Ne_xt</property>
<property name="use_underline">True</property>
<signal name="activate" handler="OnSearchFindNext" swapped="no"/>
- <accelerator key="g" signal="activate" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="F3" signal="activate"/>
+ <accelerator key="g" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</object>
</child>
<child>
@@ -578,8 +582,8 @@
<property name="label" translatable="yes">Find Pre_vious</property>
<property name="use_underline">True</property>
<signal name="activate" handler="OnSearchFindPrevious" swapped="no"/>
- <accelerator key="g" signal="activate" modifiers="GDK_SHIFT_MASK |
GDK_CONTROL_MASK"/>
<accelerator key="F3" signal="activate" modifiers="GDK_SHIFT_MASK"/>
+ <accelerator key="g" signal="activate" modifiers="GDK_SHIFT_MASK |
GDK_CONTROL_MASK"/>
</object>
</child>
<child>
@@ -820,8 +824,8 @@
<property name="label" translatable="yes">_Play / Pause</property>
<property name="use_underline">True</property>
<signal name="activate" handler="OnVideoPlayPause" swapped="no"/>
- <accelerator key="p" signal="activate" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="F5" signal="activate"/>
+ <accelerator key="p" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</object>
</child>
<child>
@@ -843,8 +847,8 @@
<property name="label" translatable="yes">R_ewind</property>
<property name="use_underline">True</property>
<signal name="activate" handler="OnVideoRewind" swapped="no"/>
- <accelerator key="k" signal="activate" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="F6" signal="activate"/>
+ <accelerator key="k" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</object>
</child>
<child>
@@ -855,8 +859,8 @@
<property name="label" translatable="yes">_Forward</property>
<property name="use_underline">True</property>
<signal name="activate" handler="OnVideoForward" swapped="no"/>
- <accelerator key="l" signal="activate" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="F7" signal="activate"/>
+ <accelerator key="l" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</object>
</child>
<child>
@@ -884,8 +888,8 @@
<property name="label" translatable="yes">Seek _to Selection</property>
<property name="use_underline">True</property>
<signal name="activate" handler="OnVideoSeekToSelection" swapped="no"/>
- <accelerator key="r" signal="activate" modifiers="GDK_SHIFT_MASK |
GDK_CONTROL_MASK"/>
<accelerator key="F4" signal="activate" modifiers="GDK_SHIFT_MASK |
GDK_CONTROL_MASK"/>
+ <accelerator key="r" signal="activate" modifiers="GDK_SHIFT_MASK |
GDK_CONTROL_MASK"/>
</object>
</child>
<child>
@@ -896,8 +900,8 @@
<property name="label" translatable="yes">Select _Nearest Subtitle</property>
<property name="use_underline">True</property>
<signal name="activate" handler="OnVideoSelectNearestSubtitle" swapped="no"/>
- <accelerator key="r" signal="activate" modifiers="GDK_CONTROL_MASK"/>
<accelerator key="F4" signal="activate" modifiers="GDK_CONTROL_MASK"/>
+ <accelerator key="r" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</object>
</child>
<child>
diff --git a/src/Glade/FilePropertiesDialog.glade b/src/Glade/old.glade/FilePropertiesDialog.glade
similarity index 100%
copy from src/Glade/FilePropertiesDialog.glade
copy to src/Glade/old.glade/FilePropertiesDialog.glade
diff --git a/src/Glade/FilePropertiesDialog.glade b/src/Glade/old.glade/FilePropertiesDialog.ui
similarity index 84%
rename from src/Glade/FilePropertiesDialog.glade
rename to src/Glade/old.glade/FilePropertiesDialog.ui
index dbf401e..92ce8bb 100644
--- a/src/Glade/FilePropertiesDialog.glade
+++ b/src/Glade/old.glade/FilePropertiesDialog.ui
@@ -1,19 +1,19 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<glade-interface>
+<?xml version="1.0"?>
+<interface>
<!-- interface-requires gtk+ 2.16 -->
<!-- interface-naming-policy toplevel-contextual -->
- <widget class="GtkDialog" id="dialog">
+ <object class="GtkDialog" id="dialog">
<property name="title" translatable="yes">File Properties</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
- <widget class="GtkVBox" id="dialogVBox">
+ <object class="GtkVBox" id="dialogVBox">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property>
<property name="spacing">2</property>
<child>
- <widget class="GtkTable" id="table">
+ <object class="GtkTable" id="table">
<property name="visible">True</property>
<property name="border_width">15</property>
<property name="n_rows">5</property>
@@ -21,23 +21,23 @@
<property name="column_spacing">15</property>
<property name="row_spacing">15</property>
<child>
- <widget class="GtkLabel" id="nameLabel">
+ <object class="GtkLabel" id="nameLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes"><b>Name:</b></property>
<property name="use_markup">True</property>
- </widget>
+ </object>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="pathLabel">
+ <object class="GtkLabel" id="pathLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes"><b>Path:</b></property>
<property name="use_markup">True</property>
- </widget>
+ </object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
@@ -45,12 +45,12 @@
</packing>
</child>
<child>
- <widget class="GtkLabel" id="encodingLabel">
+ <object class="GtkLabel" id="encodingLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes"><b>Character Coding:</b></property>
<property name="use_markup">True</property>
- </widget>
+ </object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
@@ -58,12 +58,12 @@
</packing>
</child>
<child>
- <widget class="GtkLabel" id="subtitleFormatLabel">
+ <object class="GtkLabel" id="subtitleFormatLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes"><b>Subtitle Format:</b></property>
<property name="use_markup">True</property>
- </widget>
+ </object>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
@@ -71,12 +71,12 @@
</packing>
</child>
<child>
- <widget class="GtkLabel" id="timingModeLabel">
+ <object class="GtkLabel" id="timingModeLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes"><b>Timing Mode:</b></property>
<property name="use_markup">True</property>
- </widget>
+ </object>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
@@ -84,21 +84,21 @@
</packing>
</child>
<child>
- <widget class="GtkLabel" id="nameValueLabel">
+ <object class="GtkLabel" id="nameValueLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
- </widget>
+ </object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
- <widget class="GtkLabel" id="pathValueLabel">
+ <object class="GtkLabel" id="pathValueLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="ellipsize">end</property>
- </widget>
+ </object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
@@ -107,10 +107,10 @@
</packing>
</child>
<child>
- <widget class="GtkLabel" id="encodingValueLabel">
+ <object class="GtkLabel" id="encodingValueLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
- </widget>
+ </object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
@@ -119,10 +119,10 @@
</packing>
</child>
<child>
- <widget class="GtkLabel" id="subtitleFormatValueLabel">
+ <object class="GtkLabel" id="subtitleFormatValueLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
- </widget>
+ </object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
@@ -131,10 +131,10 @@
</packing>
</child>
<child>
- <widget class="GtkLabel" id="timingModeValueLabel">
+ <object class="GtkLabel" id="timingModeValueLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
- </widget>
+ </object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
@@ -142,38 +142,38 @@
<property name="bottom_attach">5</property>
</packing>
</child>
- </widget>
+ </object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
- <widget class="GtkHButtonBox" id="actionArea">
+ <object class="GtkHButtonBox" id="actionArea">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property>
<property name="layout_style">end</property>
<child>
- <widget class="GtkButton" id="closeButton">
+ <object class="GtkButton" id="closeButton">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="use_stock">True</property>
- </widget>
+ </object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
- </widget>
+ </object>
<packing>
<property name="expand">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
- </widget>
+ </object>
</child>
- </widget>
-</glade-interface>
+ </object>
+</interface>
diff --git a/src/GnomeSubtitles/Dialog/AboutDialog.cs b/src/GnomeSubtitles/Dialog/AboutDialog.cs
index 2bd4574..79b5598 100644
--- a/src/GnomeSubtitles/Dialog/AboutDialog.cs
+++ b/src/GnomeSubtitles/Dialog/AboutDialog.cs
@@ -24,7 +24,6 @@ using System;
namespace GnomeSubtitles.Dialog {
public class AboutDialog : BuilderDialog {
- private Gtk.AboutDialog dialog = null;
/* Constant strings */
private const string gladeFilename = "AboutDialog.glade";
@@ -35,7 +34,6 @@ public class AboutDialog : BuilderDialog {
SetHooks();
Init(gladeFilename, true);
- dialog = GetDialog() as Gtk.AboutDialog;
SetInfo();
}
@@ -56,6 +54,8 @@ public class AboutDialog : BuilderDialog {
}
private void SetInfo () {
+ Gtk.AboutDialog dialog = Dialog as Gtk.AboutDialog;
+
dialog.Version = Base.ExecutionContext.Version;
dialog.Logo = new Gdk.Pixbuf(null, logoFilename);
}
diff --git a/src/GnomeSubtitles/Dialog/BaseDialog.cs b/src/GnomeSubtitles/Dialog/BaseDialog.cs
index b7d0748..a8f6d9f 100644
--- a/src/GnomeSubtitles/Dialog/BaseDialog.cs
+++ b/src/GnomeSubtitles/Dialog/BaseDialog.cs
@@ -25,7 +25,6 @@ namespace GnomeSubtitles.Dialog {
public abstract class BaseDialog {
- private Gtk.Dialog dialog = null;
private bool returnValue = false;
//Hack because gtk# doesn't support this flag yet (as of 2017). Ref:
https://git.gnome.org/browse/gtk+/tree/gtk/gtkdialog.h (GTK_DIALOG_USE_HEADER_BAR)
@@ -46,7 +45,7 @@ public abstract class BaseDialog {
}
public virtual bool Visible {
- get { return dialog.Visible; }
+ get { return Dialog.Visible; }
set {
if (value)
Show();
@@ -55,18 +54,22 @@ public abstract class BaseDialog {
}
}
+ protected Gtk.Dialog Dialog {
+ get; private set;
+ }
+
/* Public Methods */
public virtual void Show () {
- dialog.Visible = true;
+ Dialog.Visible = true;
}
public virtual void Hide () {
- dialog.Visible = false;
+ Dialog.Visible = false;
}
public virtual void Destroy () {
- dialog.Destroy();
+ Dialog.Destroy();
EmitDestroyedEvent();
}
@@ -74,7 +77,7 @@ public abstract class BaseDialog {
//TODO check if this is needed
public virtual bool WaitForResponse () {
- dialog.Run();
+ Dialog.Run();
return returnValue;
}
@@ -86,15 +89,11 @@ public abstract class BaseDialog {
/* Protected members */
protected void Init (Gtk.Dialog dialog) {
- this.dialog = dialog;
+ Dialog = dialog;
//SetBaseWindow(dialog, Base.Ui.Window);
- dialog.Response += OnResponse;
- dialog.DeleteEvent += OnDeleteEvent;
- }
-
- protected Gtk.Dialog GetDialog () {
- return dialog;
+ Dialog.Response += OnResponse;
+ Dialog.DeleteEvent += OnDeleteEvent;
}
protected void SetReturnValue (bool returnValue) {
diff --git a/src/GnomeSubtitles/Dialog/EncodingsDialog.cs b/src/GnomeSubtitles/Dialog/EncodingsDialog.cs
index d86463b..5396e3d 100644
--- a/src/GnomeSubtitles/Dialog/EncodingsDialog.cs
+++ b/src/GnomeSubtitles/Dialog/EncodingsDialog.cs
@@ -35,17 +35,13 @@ public class EncodingsDialog : BaseDialog {
/* Widgets */
- private Gtk.Dialog dialog = null;
- private TreeView availableTreeView = null;
- private TreeView shownTreeView = null;
- private Button buttonAdd = null;
- private Button buttonRemove = null;
+ private TreeView availableTreeView;
+ private TreeView shownTreeView;
+ private Button buttonAdd;
+ private Button buttonRemove;
public EncodingsDialog (Window parent) : base() {
- BuildDialog(parent);
-
- ConnectSignals();
- base.Init(dialog);
+ base.Init(BuildDialog(parent));
}
/* Public properties */
@@ -56,8 +52,8 @@ public class EncodingsDialog : BaseDialog {
/* Private members */
- private void BuildDialog (Window parent) {
- dialog = new Gtk.Dialog(Catalog.GetString("Character Encodings"), parent, DialogFlags.Modal |
DialogFlagsUseHeaderBar);
+ private Gtk.Dialog BuildDialog (Window parent) {
+ Gtk.Dialog dialog = new Gtk.Dialog(Catalog.GetString("Character Encodings"), parent,
DialogFlags.Modal | DialogFlagsUseHeaderBar);
dialog.DefaultWidth = 600;
dialog.DefaultHeight = 400;
@@ -107,6 +103,10 @@ public class EncodingsDialog : BaseDialog {
dialog.ContentArea.Add(grid);
dialog.ContentArea.ShowAll();
+
+ ConnectSignals();
+
+ return dialog;
}
private void FillAvailableEncodings () {
diff --git a/src/GnomeSubtitles/Dialog/FileOpenDialog.cs b/src/GnomeSubtitles/Dialog/FileOpenDialog.cs
index 6a1525a..0e3e568 100644
--- a/src/GnomeSubtitles/Dialog/FileOpenDialog.cs
+++ b/src/GnomeSubtitles/Dialog/FileOpenDialog.cs
@@ -33,8 +33,7 @@ using SubLib.Util;
namespace GnomeSubtitles.Dialog {
public class FileOpenDialog : BaseDialog {
- protected FileChooserDialog dialog;
-
+
private string chosenFilename = String.Empty;
private EncodingDescription chosenEncoding = EncodingDescription.Empty;
private ArrayList videoFiles = null; //The full paths of the video files in the current dir
@@ -54,13 +53,7 @@ public class FileOpenDialog : BaseDialog {
}
protected FileOpenDialog (bool toEnableVideo, string title) : base() {
- BuildDialog(title);
-
- if (toEnableVideo) {
- EnableVideo();
- }
-
- base.Init(dialog);
+ base.Init(BuildDialog(toEnableVideo, title));
}
@@ -103,8 +96,8 @@ public class FileOpenDialog : BaseDialog {
/* Private members */
- private void BuildDialog(string title) {
- dialog = new FileChooserDialog(title, Base.Ui.Window, FileChooserAction.Open,
+ private FileChooserDialog BuildDialog(bool toEnableVideo, string title) {
+ FileChooserDialog dialog = new FileChooserDialog(title, Base.Ui.Window,
FileChooserAction.Open,
Util.GetStockLabel("gtk-cancel"), ResponseType.Cancel,
Util.GetStockLabel("gtk-open"), ResponseType.Ok);
dialog.DefaultResponse = ResponseType.Ok;
@@ -133,8 +126,14 @@ public class FileOpenDialog : BaseDialog {
//Other stuff
- SetFilters();
+ SetFilters(dialog);
dialog.SetCurrentFolder(GetStartFolder());
+
+ if (toEnableVideo) {
+ EnableVideo(dialog);
+ }
+
+ return dialog;
}
private EncodingComboBox BuildEncodingComboBox () {
@@ -164,7 +163,7 @@ public class FileOpenDialog : BaseDialog {
string folder = String.Empty;
try {
- folder = dialog.CurrentFolder;
+ folder = (Dialog as FileChooserDialog).CurrentFolder;
}
catch (Exception e) {
Logger.Error(e, "Caught exception when trying to get the current folder");
@@ -207,7 +206,7 @@ public class FileOpenDialog : BaseDialog {
string filePath = String.Empty;
try {
- filePath = dialog.Filename;
+ filePath = (Dialog as FileChooserDialog).Filename;
}
catch (Exception e) {
Logger.Error(e, "Caught exception when trying to get the current filename");
@@ -255,7 +254,7 @@ public class FileOpenDialog : BaseDialog {
return filename;
}
- private void EnableVideo () {
+ private void EnableVideo (FileChooserDialog dialog) {
videoLabel.Visible = true;
videoComboBox.Visible = true;
@@ -269,7 +268,7 @@ public class FileOpenDialog : BaseDialog {
/* Note: It would be nice show a separator after "All Subtitle Files" but filters
* don't allow to set a separator function like we do in a normal combo box.
*/
- private void SetFilters () {
+ private void SetFilters (FileChooserDialog dialog) {
SubtitleTypeInfo[] types = Subtitles.AvailableTypesSorted;
FileFilter[] filters = new FileFilter[types.Length + 2];
int filterPosition = 0;
@@ -311,7 +310,7 @@ public class FileOpenDialog : BaseDialog {
protected override bool ProcessResponse (ResponseType response) {
if (response == ResponseType.Ok) {
- chosenFilename = dialog.Filename;
+ chosenFilename = (Dialog as FileChooserDialog).Filename;
chosenEncoding = encodingComboBox.ChosenEncoding;
if (Base.Config.FileOpenEncodingOption ==
ConfigFileOpenEncodingOption.RememberLastUsed) {
diff --git a/src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs
b/src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs
index 9b8d635..9590dd5 100644
--- a/src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs
+++ b/src/GnomeSubtitles/Dialog/FilePropertiesDialog.cs
@@ -27,76 +27,78 @@ using System.Text;
namespace GnomeSubtitles.Dialog {
-public class FilePropertiesDialog : BuilderDialog {
+//TODO check if we still need all these properties, and whether others should be added (e.g.,
video/translation file)
+public class FilePropertiesDialog : BaseDialog {
- /* Constant strings */
- private const string gladeFilename = "FilePropertiesDialog.glade";
-
- /* Widgets */
-
- [Builder.Object] private Label nameValueLabel = null;
- [Builder.Object] private Label pathValueLabel = null;
- [Builder.Object] private Label encodingValueLabel = null;
- [Builder.Object] private Label subtitleFormatValueLabel = null;
- [Builder.Object] private Label timingModeValueLabel = null;
-
- public FilePropertiesDialog () : base(gladeFilename) {
- FillLabelValues();
+ public FilePropertiesDialog () : base() {
+ Init(BuildDialog());
}
/* Private methods */
- private void FillLabelValues () {
+ private Gtk.Dialog BuildDialog() {
FileProperties properties = Base.Document.TextFile;
- FillName(properties.Filename);
- FillPath(properties.Directory);
- FillEncoding(properties.Encoding);
- FillSubtitleFormat(properties.SubtitleType);
- FillTimingMode(properties.TimingMode);
- }
+ Gtk.Dialog dialog = new Gtk.Dialog(Catalog.GetString("File Properties"), Base.Ui.Window,
DialogFlags.Modal | DialogFlagsUseHeaderBar);
- private void FillName (string name) {
- if (name == String.Empty)
- name = Catalog.GetString("Unknown");
+// dialog.DefaultResponse = ResponseType.Ok;
+// dialog.DefaultWidth = 600;
+// dialog.DefaultHeight = 550;
- nameValueLabel.Text = name;
- }
+ Grid grid = new Grid();
+ grid.BorderWidth = 15;
+ grid.ColumnSpacing = 15;
+ grid.RowSpacing = 15;
+
+ grid.Attach(CreateFieldLabel(Catalog.GetString("File Name")), 0, 0, 1, 1);
+ grid.Attach(CreateValueLabel(properties.Filename), 1, 0, 1, 1);
+
+ grid.Attach(CreateFieldLabel(Catalog.GetString("Path")), 0, 1, 1, 1);
+ grid.Attach(CreateValueLabel(properties.Directory), 1, 1, 1, 1);
- private void FillPath (string path) {
- if (path == String.Empty)
- path = Catalog.GetString("Unknown");
+ grid.Attach(CreateFieldLabel(Catalog.GetString("Character Encoding")), 0, 2, 1, 1);
+ grid.Attach(CreateValueLabel(GetEncoding(properties.Encoding)), 1, 2, 1, 1);
- pathValueLabel.Text = path;
+ grid.Attach(CreateFieldLabel(Catalog.GetString("Subtitle Format")), 0, 3, 1, 1);
+ grid.Attach(CreateValueLabel(GetSubtitleFormat(properties.SubtitleType)), 1, 3, 1, 1);
+
+ grid.Attach(CreateFieldLabel(Catalog.GetString("Timing Mode")), 0, 4, 1, 1);
+ grid.Attach(CreateValueLabel(properties.TimingMode.ToString()), 1, 4, 1, 1);
+
+ dialog.ContentArea.Add(grid);
+ dialog.ContentArea.ShowAll();
+ return dialog;
}
- private void FillEncoding (Encoding encoding) {
- string encodingName = String.Empty;
- if (encoding == null)
- encodingName = Catalog.GetString("Unknown");
- else {
- encodingName = Encodings.GetEncodingName(encoding.CodePage);
- if ((encodingName == null) || (encodingName == String.Empty))
- encodingName = Catalog.GetString("Unknown");
- }
+ private Label CreateFieldLabel (string text) {
+ Label label = new Label();
+ label.Markup = "<b>" + text + "</b>";
+ label.SetAlignment(0f, 0.5f);
+ return label;
+ }
- encodingValueLabel.Text = encodingName;
+ private Label CreateValueLabel (string text) {
+ Label label = new Label();
+ label.Text = (String.IsNullOrEmpty(text) ? "-" : text);
+ label.SetAlignment(0f, 0.5f);
+ return label;
}
- private void FillSubtitleFormat (SubtitleType type) {
- string format = String.Empty;
- if (type == SubtitleType.Unknown)
- format = Catalog.GetString("Unknown");
- else {
- SubtitleTypeInfo typeInfo = Subtitles.GetAvailableType(type);
- format = typeInfo.Name;
+ private string GetEncoding (Encoding encoding) {
+ if (encoding == null) {
+ return null;
}
- subtitleFormatValueLabel.Text = format;
+ return Encodings.GetEncodingName(encoding.CodePage);
}
- private void FillTimingMode (TimingMode mode) {
- timingModeValueLabel.Text = mode.ToString();
+ private string GetSubtitleFormat (SubtitleType type) {
+ if (type == SubtitleType.Unknown) {
+ return null;
+ }
+
+ SubtitleTypeInfo typeInfo = Subtitles.GetAvailableType(type);
+ return typeInfo.Name;
}
}
diff --git a/src/GnomeSubtitles/Dialog/FileSaveDialog.cs b/src/GnomeSubtitles/Dialog/FileSaveDialog.cs
index 941e1d8..acc4ce5 100644
--- a/src/GnomeSubtitles/Dialog/FileSaveDialog.cs
+++ b/src/GnomeSubtitles/Dialog/FileSaveDialog.cs
@@ -29,8 +29,6 @@ using System.Text;
namespace GnomeSubtitles.Dialog {
public class FileSaveDialog : BaseDialog {
- protected FileChooserDialog dialog;
-
private string chosenFilename = String.Empty;
private EncodingDescription chosenEncoding = EncodingDescription.Empty;
private SubtitleType chosenSubtitleType;
@@ -45,9 +43,7 @@ public class FileSaveDialog : BaseDialog {
}
protected FileSaveDialog (string title) : base() {
- BuildDialog(title);
-
- base.Init(dialog);
+ base.Init(BuildDialog(title));
}
@@ -88,8 +84,8 @@ public class FileSaveDialog : BaseDialog {
/* Private members */
- private void BuildDialog (string title) {
- dialog = new FileChooserDialog(title, Base.Ui.Window, FileChooserAction.Save,
+ private FileChooserDialog BuildDialog (string title) {
+ FileChooserDialog dialog = new FileChooserDialog(title, Base.Ui.Window,
FileChooserAction.Save,
Util.GetStockLabel("gtk-cancel"), ResponseType.Cancel,
Util.GetStockLabel("gtk-save"), ResponseType.Ok);
dialog.DefaultResponse = ResponseType.Ok;
@@ -129,6 +125,8 @@ public class FileSaveDialog : BaseDialog {
dialog.SetCurrentFolder(GetStartFolder());
dialog.CurrentName = GetStartFilename();
+
+ return dialog;
}
private void BuildFormatComboBox () {
@@ -211,7 +209,7 @@ public class FileSaveDialog : BaseDialog {
}
private string AddExtensionIfNeeded (SubtitleType type) {
- string filename = dialog.Filename;
+ string filename = (Dialog as FileChooserDialog).Filename;
int index = 0;
string extension = GetFilenameExtension(filename, out index);
@@ -275,6 +273,8 @@ public class FileSaveDialog : BaseDialog {
}
private void OnFormatChanged (object o, EventArgs args) {
+ FileChooserDialog dialog = Dialog as FileChooserDialog;
+
string filename = dialog.Filename;
if ((filename == null) || (filename == String.Empty))
return;
diff --git a/src/GnomeSubtitles/Dialog/HeadersDialog.cs b/src/GnomeSubtitles/Dialog/HeadersDialog.cs
index 6bfe47f..8a2c270 100644
--- a/src/GnomeSubtitles/Dialog/HeadersDialog.cs
+++ b/src/GnomeSubtitles/Dialog/HeadersDialog.cs
@@ -29,7 +29,6 @@ namespace GnomeSubtitles.Dialog {
public class HeadersDialog : BaseDialog {
- private Gtk.Dialog dialog;
private Headers headers;
//Property Changed event
@@ -39,16 +38,14 @@ public class HeadersDialog : BaseDialog {
public HeadersDialog () : base() {
headers = (Headers)Base.Document.Subtitles.Properties.Headers.Clone();
- BuildDialog();
-
- base.Init(dialog);
+ base.Init(BuildDialog());
}
/* Private members */
- private void BuildDialog() {
- dialog = new Gtk.Dialog(Catalog.GetString("Headers"), Base.Ui.Window, DialogFlags.Modal |
DialogFlagsUseHeaderBar,
+ private Gtk.Dialog BuildDialog() {
+ Gtk.Dialog dialog = new Gtk.Dialog(Catalog.GetString("Headers"), Base.Ui.Window,
DialogFlags.Modal | DialogFlagsUseHeaderBar,
Util.GetStockLabel("gtk-cancel"), ResponseType.Cancel,
Util.GetStockLabel("gtk-apply"), ResponseType.Ok);
dialog.DefaultResponse = ResponseType.Ok;
@@ -178,6 +175,8 @@ public class HeadersDialog : BaseDialog {
//Finalize
dialog.ContentArea.Add(notebook);
dialog.ContentArea.ShowAll();
+
+ return dialog;
}
private Grid CreatePageWithGrid(Notebook notebook, string tabLabel) {
diff --git a/src/GnomeSubtitles/Dialog/MessageDialog.cs b/src/GnomeSubtitles/Dialog/MessageDialog.cs
index 2f73ee6..3c09234 100644
--- a/src/GnomeSubtitles/Dialog/MessageDialog.cs
+++ b/src/GnomeSubtitles/Dialog/MessageDialog.cs
@@ -23,7 +23,7 @@ using System;
namespace GnomeSubtitles.Dialog {
- public abstract class MessageDialog : BaseDialog {
+public abstract class MessageDialog : BaseDialog {
protected Gtk.MessageDialog dialog = null;
public MessageDialog (MessageType messageType) : base() {
diff --git a/src/GnomeSubtitles/Dialog/SearchDialog.cs b/src/GnomeSubtitles/Dialog/SearchDialog.cs
index 8b5f3a8..ca82f74 100644
--- a/src/GnomeSubtitles/Dialog/SearchDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SearchDialog.cs
@@ -104,11 +104,11 @@ public class SearchDialog : BuilderDialog {
public void Show (bool useReplace) {
if (useReplace) {
- GetDialog().Title = Catalog.GetString("Replace");
+ Dialog.Title = Catalog.GetString("Replace");
table.RowSpacing = 12;
}
else {
- GetDialog().Title = Catalog.GetString("Find");
+ Dialog.Title = Catalog.GetString("Find");
table.RowSpacing = 0;
}
diff --git a/src/GnomeSubtitles/Dialog/SetLanguageDialog.cs b/src/GnomeSubtitles/Dialog/SetLanguageDialog.cs
index dbfab73..0534e5f 100644
--- a/src/GnomeSubtitles/Dialog/SetLanguageDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SetLanguageDialog.cs
@@ -117,7 +117,7 @@ public abstract class SetLanguageDialog : BuilderDialog {
}
private void SetDialogTitle (SubtitleTextType textType) {
- GetDialog().Title = (textType == SubtitleTextType.Text ? dialogTitleText :
dialogTitleTranslation);
+ Dialog.Title = (textType == SubtitleTextType.Text ? dialogTitleText : dialogTitleTranslation);
}
private void SetIntroLabel (SubtitleTextType textType) {
diff --git a/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs b/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs
index c23bb49..5169e77 100644
--- a/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs
+++ b/src/GnomeSubtitles/Dialog/VideoOpenDialog.cs
@@ -25,13 +25,10 @@ using System;
namespace GnomeSubtitles.Dialog {
public class VideoOpenDialog : BaseDialog {
- protected FileChooserDialog dialog = null;
- private Uri chosenUri = null;
+ private Uri chosenUri;
public VideoOpenDialog () : base() {
- BuildDialog();
-
- base.Init(dialog);
+ base.Init(BuildDialog());
}
/* Public properties */
@@ -42,8 +39,8 @@ public class VideoOpenDialog : BaseDialog {
/* Private methods */
- private void BuildDialog() {
- dialog = new FileChooserDialog(Catalog.GetString("Open Video"), Base.Ui.Window,
FileChooserAction.Open,
+ private FileChooserDialog BuildDialog() {
+ FileChooserDialog dialog = new FileChooserDialog(Catalog.GetString("Open Video"),
Base.Ui.Window, FileChooserAction.Open,
Util.GetStockLabel("gtk-cancel"), ResponseType.Cancel,
Util.GetStockLabel("gtk-open"), ResponseType.Ok);
dialog.DefaultResponse = ResponseType.Ok;
@@ -55,9 +52,12 @@ public class VideoOpenDialog : BaseDialog {
}
SetFilters();
+
+ return dialog;
}
private void SetFilters () {
+ FileChooserDialog dialog = Dialog as FileChooserDialog;
/* Video files */
FileFilter videoFilesFilter = new FileFilter();
@@ -89,8 +89,9 @@ public class VideoOpenDialog : BaseDialog {
protected override bool ProcessResponse (ResponseType response) {
if (response == ResponseType.Ok) {
- if (dialog.Uri != null) {
- chosenUri = new Uri(dialog.Uri);
+ string uri = (Dialog as FileChooserDialog).Uri;
+ if (uri != null) {
+ chosenUri = new Uri(uri);
}
SetReturnValue(true);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]