[gnome-subtitles] Allow to set default newline type, for saving files, in the preferences
- From: Pedro Daniel da Rocha Melo e Castro <pcastro src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-subtitles] Allow to set default newline type, for saving files, in the preferences
- Date: Sun, 31 Jan 2010 17:56:06 +0000 (UTC)
commit e00715f0148668b34d358f6b7d3f99a7a516ffa6
Author: Pedro Castro <mail>
Date: Sun Jan 31 17:55:54 2010 +0000
Allow to set default newline type, for saving files, in the preferences
gnome-subtitles.mdp | 1 +
src/Glade/FileSaveAsDialog.glade | 5 +-
src/Glade/PreferencesDialog.glade | 2 +-
src/GnomeSubtitles/Core/Config.cs | 13 ++
src/GnomeSubtitles/Core/Util.cs | 15 ++-
src/GnomeSubtitles/Dialog/PreferencesDialog.cs | 40 +++++-
.../Dialog/SubtitleFileSaveAsDialog.cs | 123 ++++----------
.../Ui/Component/NewlineTypeComboBox.cs | 175 ++++++++++++++++++++
.../Ui/Component/SubtitleFormatComboBox.cs | 10 +-
src/SubLib/Core/Domain/Enumerations.cs | 11 +-
10 files changed, 288 insertions(+), 107 deletions(-)
---
diff --git a/gnome-subtitles.mdp b/gnome-subtitles.mdp
index b88f9b2..97465c2 100644
--- a/gnome-subtitles.mdp
+++ b/gnome-subtitles.mdp
@@ -247,6 +247,7 @@
<File name="src/GnomeSubtitles/Ui/Component/EncodingComboBox.cs" subtype="Code" buildaction="Compile" />
<File name="src/GnomeSubtitles/Ui/Component/ComboBoxUtil.cs" subtype="Code" buildaction="Compile" />
<File name="src/GnomeSubtitles/Ui/Component/SubtitleFormatComboBox.cs" subtype="Code" buildaction="Compile" />
+ <File name="src/GnomeSubtitles/Ui/Component/NewlineTypeComboBox.cs" subtype="Code" buildaction="Compile" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
diff --git a/src/Glade/FileSaveAsDialog.glade b/src/Glade/FileSaveAsDialog.glade
index f390848..b4d751f 100644
--- a/src/Glade/FileSaveAsDialog.glade
+++ b/src/Glade/FileSaveAsDialog.glade
@@ -9,10 +9,10 @@
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<property name="has_separator">False</property>
+ <property name="use_preview_label">False</property>
<property name="preview_widget_active">False</property>
- <property name="do_overwrite_confirmation">True</property>
<property name="action">save</property>
- <property name="use_preview_label">False</property>
+ <property name="do_overwrite_confirmation">True</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialogVBox">
<property name="visible">True</property>
@@ -58,7 +58,6 @@
<widget class="GtkComboBox" id="subtitleFormatComboBox">
<property name="visible">True</property>
<property name="items" translatable="yes"></property>
- <signal name="changed" handler="OnFormatChanged"/>
</widget>
<packing>
<property name="left_attach">1</property>
diff --git a/src/Glade/PreferencesDialog.glade b/src/Glade/PreferencesDialog.glade
index 2cfb778..c8b18a7 100644
--- a/src/Glade/PreferencesDialog.glade
+++ b/src/Glade/PreferencesDialog.glade
@@ -244,7 +244,7 @@
</packing>
</child>
<child>
- <widget class="GtkComboBox" id="combobox3">
+ <widget class="GtkComboBox" id="fileSaveNewlineComboBox">
<property name="visible">True</property>
</widget>
<packing>
diff --git a/src/GnomeSubtitles/Core/Config.cs b/src/GnomeSubtitles/Core/Config.cs
index 6112503..4b0a6fd 100644
--- a/src/GnomeSubtitles/Core/Config.cs
+++ b/src/GnomeSubtitles/Core/Config.cs
@@ -31,6 +31,7 @@ public enum ConfigFileSaveEncodingOption { KeepExisting = 0, RememberLastUsed =
public enum ConfigFileSaveEncoding { KeepExisting = -1, CurrentLocale = 0, Fixed = 1 }; //KeepExisting=-1 because it doesn't appear
public enum ConfigFileSaveFormatOption { KeepExisting = 0, RememberLastUsed = 1, Specific = 3 }; //Values match ordering where the options are used
public enum ConfigFileSaveFormat { KeepExisting = -1, Fixed = 0 }; //KeepExisting=-1 because it doesn't appear
+public enum ConfigFileSaveNewlineOption { RememberLastUsed = 0, Specific = 2 }; //Values match ordering where the options are used
public class Config {
private Client client = null;
@@ -59,6 +60,8 @@ public class Config {
private const string keyPrefsDefaultsFileSaveEncoding = keyPrefsDefaults + "file_save_encoding";
private const string keyPrefsDefaultsFileSaveFormatOption = keyPrefsDefaults + "file_save_format_option";
private const string keyPrefsDefaultsFileSaveFormat = keyPrefsDefaults + "file_save_format";
+ private const string keyPrefsDefaultsFileSaveNewlineOption = keyPrefsDefaults + "file_save_newline_option";
+ private const string keyPrefsDefaultsFileSaveNewline = keyPrefsDefaults + "file_save_newline";
public Config () {
client = new Client();
@@ -163,6 +166,16 @@ public class Config {
set { Set(keyPrefsDefaultsFileSaveFormat, value.ToString()); }
}
+ public ConfigFileSaveNewlineOption PrefsDefaultsFileSaveNewlineOption {
+ get { return (ConfigFileSaveNewlineOption)GetEnumValue(keyPrefsDefaultsFileSaveNewlineOption, ConfigFileSaveNewlineOption.Specific); }
+ set { Set(keyPrefsDefaultsFileSaveNewlineOption, value.ToString()); }
+ }
+
+ public NewlineType PrefsDefaultsFileSaveNewline {
+ get { return (NewlineType)GetEnumValue(keyPrefsDefaultsFileSaveNewline, Core.Util.GetSystemNewlineType()); }
+ set { Set(keyPrefsDefaultsFileSaveNewline, value.ToString()); }
+ }
+
/* Private members */
diff --git a/src/GnomeSubtitles/Core/Util.cs b/src/GnomeSubtitles/Core/Util.cs
index 07c8439..4aa5e95 100644
--- a/src/GnomeSubtitles/Core/Util.cs
+++ b/src/GnomeSubtitles/Core/Util.cs
@@ -1,6 +1,6 @@
/*
* This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2009 Pedro Castro
+ * Copyright (C) 2006-2010 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
@@ -236,6 +236,19 @@ public class Util {
return String.Format(text, args);
}
+ public static 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;
+ }
+ }
+
}
}
diff --git a/src/GnomeSubtitles/Dialog/PreferencesDialog.cs b/src/GnomeSubtitles/Dialog/PreferencesDialog.cs
index 1bbc213..3bb93ae 100644
--- a/src/GnomeSubtitles/Dialog/PreferencesDialog.cs
+++ b/src/GnomeSubtitles/Dialog/PreferencesDialog.cs
@@ -37,6 +37,7 @@ public class PreferencesDialog : GladeDialog {
private EncodingComboBox fileOpenFallbackEncoding = null;
private EncodingComboBox fileSaveEncoding = null;
private SubtitleFormatComboBox fileSaveFormat = null;
+ private NewlineTypeComboBox fileSaveNewline = null;
/* Widgets */
[WidgetAttribute] private CheckButton videoAutoChooseFileCheckButton = null;
@@ -44,6 +45,7 @@ public class PreferencesDialog : GladeDialog {
[WidgetAttribute] private ComboBox fileOpenFallbackEncodingComboBox = null;
[WidgetAttribute] private ComboBox fileSaveEncodingComboBox = null;
[WidgetAttribute] private ComboBox fileSaveFormatComboBox = null;
+ [WidgetAttribute] private ComboBox fileSaveNewlineComboBox = null;
public PreferencesDialog () : base(gladeFilename, false) {
@@ -58,6 +60,7 @@ public class PreferencesDialog : GladeDialog {
SetDefaultsFileOpenFallbackEncoding();
SetDefaultsFileSaveEncoding();
SetDefaultsFileSaveFormat();
+ SetDefaultsFileSaveNewline();
/* Video Auto choose file */
videoAutoChooseFileCheckButton.Active = Base.Config.PrefsVideoAutoChooseFile;
@@ -128,6 +131,21 @@ public class PreferencesDialog : GladeDialog {
fileSaveFormat.SelectionChanged += OnDefaultsFileSaveFormatChanged;
}
+ private void SetDefaultsFileSaveNewline () {
+ string[] additionalActions = { Catalog.GetString("Remember Last Used") }; //TODO change label
+ NewlineType newlineTypeToSelect = NewlineType.Unknown;
+ ConfigFileSaveNewlineOption fileSaveNewlineOption = Base.Config.PrefsDefaultsFileSaveNewlineOption;
+ if (fileSaveNewlineOption == ConfigFileSaveNewlineOption.Specific) {
+ newlineTypeToSelect = Base.Config.PrefsDefaultsFileSaveNewline;
+ }
+
+ fileSaveNewline = new NewlineTypeComboBox(fileSaveNewlineComboBox, newlineTypeToSelect, additionalActions);
+ if (fileSaveNewlineOption != ConfigFileSaveNewlineOption.Specific) {
+ fileSaveNewline.ActiveSelection = (int)fileSaveNewlineOption;
+ }
+ fileSaveNewline.SelectionChanged += OnDefaultsFileSaveNewlineChanged;
+ }
+
/* Event members */
@@ -207,11 +225,31 @@ public class PreferencesDialog : GladeDialog {
}
}
else {
- /* If encoding option is keep existing or remember last, use keep existing */
+ /* If format option is keep existing or remember last, use keep existing */
Base.Config.PrefsDefaultsFileSaveFormat = ConfigFileSaveFormat.KeepExisting;
}
}
+ private void OnDefaultsFileSaveNewlineChanged (object o, EventArgs args) {
+ int active = fileSaveNewline.ActiveSelection;
+ ConfigFileSaveNewlineOption activeOption = (ConfigFileSaveNewlineOption)Enum.ToObject(typeof(ConfigFileSaveNewlineOption), active);
+ if (((int)activeOption) > ((int)ConfigFileSaveNewlineOption.Specific)) //Positions higher than specific are always specific too
+ activeOption = ConfigFileSaveNewlineOption.Specific;
+
+ Base.Config.PrefsDefaultsFileSaveNewlineOption = activeOption;
+ /* If newline is specific, newlineOption=Specific and newline holds the newline type name */
+ if (activeOption == ConfigFileSaveNewlineOption.Specific) {
+ NewlineType chosenNewlineType = fileSaveNewline.ChosenNewlineType;
+ if (!chosenNewlineType.Equals(NewlineType.Unknown)) {
+ Base.Config.PrefsDefaultsFileSaveNewline = chosenNewlineType;
+ }
+ }
+ else {
+ /* If newline option is remember last, use the system default */
+ Base.Config.PrefsDefaultsFileSaveNewline = Core.Util.GetSystemNewlineType();
+ }
+ }
+
private void OnVideoAutoChooseFileToggled (object o, EventArgs args) {
Base.Config.PrefsVideoAutoChooseFile = videoAutoChooseFileCheckButton.Active;
}
diff --git a/src/GnomeSubtitles/Dialog/SubtitleFileSaveAsDialog.cs b/src/GnomeSubtitles/Dialog/SubtitleFileSaveAsDialog.cs
index a795c02..3547e9b 100644
--- a/src/GnomeSubtitles/Dialog/SubtitleFileSaveAsDialog.cs
+++ b/src/GnomeSubtitles/Dialog/SubtitleFileSaveAsDialog.cs
@@ -42,8 +42,9 @@ public abstract class SubtitleFileSaveAsDialog : GladeDialog {
private const string gladeFilename = "FileSaveAsDialog.glade";
/* Components */
- private EncodingComboBox encodingComboBox = null;
- private SubtitleFormatComboBox formatComboBox = null;
+ private EncodingComboBox encodingComboBoxComponent = null;
+ private SubtitleFormatComboBox formatComboBoxComponent = null;
+ private NewlineTypeComboBox newlineComboBoxComponent = null;
/* Widgets */
[WidgetAttribute] private ComboBox fileEncodingComboBox = null;
@@ -59,9 +60,10 @@ public abstract class SubtitleFileSaveAsDialog : GladeDialog {
InitEncodingComboBox();
InitFormatComboBox();
+ InitNewlineComboBox();
- FillNewlineTypeComboBox();
- UpdateContents(); //TODO check
+ SetDialogFromFileProperties();
+ ConnectHandlers();
}
@@ -96,11 +98,11 @@ public abstract class SubtitleFileSaveAsDialog : GladeDialog {
fixedEncoding = encodingDescription.CodePage;
}
- this.encodingComboBox = new EncodingComboBox(fileEncodingComboBox, false, null, fixedEncoding);
+ this.encodingComboBoxComponent = new EncodingComboBox(fileEncodingComboBox, false, null, fixedEncoding);
/* Only need to handle the case of currentLocale, as Fixed and Keep Existent is handled before */
if (encodingConfig == ConfigFileSaveEncoding.CurrentLocale)
- encodingComboBox.ActiveSelection = (int)encodingConfig;
+ encodingComboBoxComponent.ActiveSelection = (int)encodingConfig;
}
private void InitFormatComboBox () {
@@ -114,7 +116,16 @@ public abstract class SubtitleFileSaveAsDialog : GladeDialog {
fixedSubtitleType = SubtitleType.SubRip;
}
- this.formatComboBox = new SubtitleFormatComboBox(subtitleFormatComboBox, fixedSubtitleType, null);
+ this.formatComboBoxComponent = new SubtitleFormatComboBox(subtitleFormatComboBox, fixedSubtitleType, null);
+ }
+
+ private void InitNewlineComboBox () {
+ NewlineType newlineTypeToSelect = Base.Config.PrefsDefaultsFileSaveNewline;
+ /* If no newline type set, or system default unknown, use Unix */
+ if (newlineTypeToSelect == NewlineType.Unknown)
+ newlineTypeToSelect = NewlineType.Unix;
+
+ this.newlineComboBoxComponent = new NewlineTypeComboBox(newlineTypeComboBox, newlineTypeToSelect, null);
}
private void SetTitle () {
@@ -142,7 +153,7 @@ public abstract class SubtitleFileSaveAsDialog : GladeDialog {
}
}
- private void UpdateContents () {
+ private void SetDialogFromFileProperties () {
FileProperties fileProperties = (textType == SubtitleTextType.Text ? Base.Document.TextFile : Base.Document.TranslationFile);
if (fileProperties.IsPathRooted)
@@ -152,10 +163,9 @@ public abstract class SubtitleFileSaveAsDialog : GladeDialog {
dialog.CurrentName = fileProperties.Filename;
+ //TODO
/* 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. */
-
- SetActiveNewlineType();
}
@@ -202,93 +212,23 @@ public abstract class SubtitleFileSaveAsDialog : GladeDialog {
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
+ private void ConnectHandlers () {
+ this.formatComboBoxComponent.SelectionChanged += OnFormatChanged;
+ }
+
protected override bool ProcessResponse (ResponseType response) {
if (response == ResponseType.Ok) {
/* Check chosen encoding */
- chosenEncoding = encodingComboBox.ChosenEncoding;
+ chosenEncoding = encodingComboBoxComponent.ChosenEncoding;
if (Base.Config.PrefsDefaultsFileSaveEncodingOption == ConfigFileSaveEncodingOption.RememberLastUsed) {
- int activeAction = encodingComboBox.ActiveSelection;
+ int activeAction = encodingComboBoxComponent.ActiveSelection;
ConfigFileSaveEncoding activeOption = (ConfigFileSaveEncoding)Enum.ToObject(typeof(ConfigFileSaveEncoding), activeAction);
if (((int)activeOption) >= ((int)ConfigFileSaveEncoding.Fixed)) {
Base.Config.PrefsDefaultsFileSaveEncodingFixed = chosenEncoding.Name;
@@ -299,13 +239,16 @@ public abstract class SubtitleFileSaveAsDialog : GladeDialog {
}
/* Check chosen subtitle format */
- chosenSubtitleType = formatComboBox.ChosenSubtitleType;
+ chosenSubtitleType = formatComboBoxComponent.ChosenSubtitleType;
if (Base.Config.PrefsDefaultsFileSaveFormatOption == ConfigFileSaveFormatOption.RememberLastUsed) {
Base.Config.PrefsDefaultsFileSaveFormatFixed = chosenSubtitleType;
}
/* Check chosen newline type */
- chosenNewlineType = GetChosenNewlineType();
+ chosenNewlineType = newlineComboBoxComponent.ChosenNewlineType;
+ if (Base.Config.PrefsDefaultsFileSaveNewlineOption == ConfigFileSaveNewlineOption.RememberLastUsed) {
+ Base.Config.PrefsDefaultsFileSaveNewline = chosenNewlineType;
+ }
/* Check chosen filename */
chosenFilename = AddExtensionIfNeeded(chosenSubtitleType);
@@ -325,7 +268,7 @@ public abstract class SubtitleFileSaveAsDialog : GladeDialog {
filename = filename.Substring(folder.Length + 1);
}
- SubtitleType subtitleType = formatComboBox.ChosenSubtitleType;
+ SubtitleType subtitleType = formatComboBoxComponent.ChosenSubtitleType;
filename = UpdateFilenameExtension(filename, subtitleType);
dialog.CurrentName = filename;
}
diff --git a/src/GnomeSubtitles/Ui/Component/NewlineTypeComboBox.cs b/src/GnomeSubtitles/Ui/Component/NewlineTypeComboBox.cs
new file mode 100644
index 0000000..0242a81
--- /dev/null
+++ b/src/GnomeSubtitles/Ui/Component/NewlineTypeComboBox.cs
@@ -0,0 +1,175 @@
+/*
+ * This file is part of Gnome Subtitles.
+ * Copyright (C) 2006-2010 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 Mono.Unix;
+using SubLib.Core.Domain;
+using System;
+
+namespace GnomeSubtitles.Ui.Component {
+
+public class NewlineTypeComboBox {
+
+ private ComboBox comboBox = null;
+ private NewlineType newlineTypeToSelect = NewlineType.Unknown;
+ private string[] additionalActions = null;
+
+ public NewlineTypeComboBox (ComboBox comboBox, NewlineType newlineTypeToSelect, string[] additionalActions) {
+ this.comboBox = comboBox;
+ this.newlineTypeToSelect = newlineTypeToSelect;
+ this.additionalActions = additionalActions;
+
+ InitComboBoxModel();
+ FillComboBox();
+ ConnectHandlers();
+ }
+
+ /* Events */
+
+ public event EventHandler SelectionChanged;
+
+
+ /* Public properties */
+
+ public bool HasChosenAction {
+ get { return comboBox.Active < GetActionCount(); }
+ }
+
+ public int ChosenAction {
+ get { return (HasChosenAction ? comboBox.Active : -1); }
+ }
+
+ public NewlineType ChosenNewlineType {
+ get {
+ int active = comboBox.Active;
+ int actionCount = GetActionCount();
+ if (active < actionCount) //An action is active
+ return NewlineType.Unknown;
+ else {
+ int newlineTypePosition = active - (actionCount > 0 ? actionCount + 1 : 0) + 1; //plus 1 because NewlineType 0 is unknown
+ return (NewlineType)Enum.ToObject(typeof(NewlineType), newlineTypePosition);
+ }
+ }
+ }
+
+ public int ActiveSelection {
+ get { return comboBox.Active; }
+ set { SetActiveItem(value, false); }
+ }
+
+
+ /* Private members */
+
+ private void InitComboBoxModel () {
+ ComboBoxUtil.InitComboBox(comboBox);
+ }
+
+ private void FillComboBox () {
+ DisconnectComboBoxChangedSignal();
+
+ (comboBox.Model as ListStore).Clear();
+
+ bool hasAdditionalActions = (additionalActions != null) && (additionalActions.Length > 0);
+
+ /* Add additional actions */
+ if (hasAdditionalActions) {
+ foreach (string additionalAction in additionalActions) {
+ comboBox.AppendText(additionalAction);
+ }
+ comboBox.AppendText("-");
+ }
+
+ /* Prepare newline types to add */
+ string mac = "Macintosh";
+ string unix = "Unix";
+ string windows = "Windows";
+ string systemDefault = " (" + Catalog.GetString("System Default") + ")";
+ NewlineType systemNewline = Core.Util.GetSystemNewlineType();
+ SetSystemNewlineSuffix(systemNewline, ref mac, ref unix, ref windows, systemDefault);
+
+ /* Add newline types */
+ comboBox.AppendText(mac);
+ comboBox.AppendText(unix);
+ comboBox.AppendText(windows);
+
+ if (newlineTypeToSelect != NewlineType.Unknown) {
+ int activeItem = (int)newlineTypeToSelect - 1 + (hasAdditionalActions ? additionalActions.Length + 1 : 0);
+ SetActiveItem(activeItem, false); //Don't use silent change because the signal is already disabled
+ }
+
+ ConnectComboBoxChangedSignal();
+ }
+
+ private void SetActiveItem (int item, bool silent) {
+ int itemCount = comboBox.Model.IterNChildren();
+ if (itemCount == 0)
+ return;
+
+ if (silent)
+ DisconnectComboBoxChangedSignal();
+
+ comboBox.Active = item;
+
+ if (silent)
+ ConnectComboBoxChangedSignal();
+ }
+
+ private int GetActionCount () {
+ return (additionalActions != null ? additionalActions.Length : 0);
+ }
+
+ 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;
+ }
+ }
+
+ /* Event members */
+
+ #pragma warning disable 169 //Disables warning about handlers not being used
+
+ private void ConnectHandlers () {
+ comboBox.RowSeparatorFunc = ComboBoxUtil.SeparatorFunc;
+ }
+
+ private void ConnectComboBoxChangedSignal () {
+ comboBox.Changed += OnComboBoxChanged;
+ }
+
+ private void DisconnectComboBoxChangedSignal () {
+ comboBox.Changed -= OnComboBoxChanged;
+ }
+
+ private void OnComboBoxChanged (object o, EventArgs args) {
+ if (SelectionChanged != null) {
+ SelectionChanged(o, args);
+ }
+ }
+
+}
+
+}
diff --git a/src/GnomeSubtitles/Ui/Component/SubtitleFormatComboBox.cs b/src/GnomeSubtitles/Ui/Component/SubtitleFormatComboBox.cs
index c4672f7..5f71c79 100644
--- a/src/GnomeSubtitles/Ui/Component/SubtitleFormatComboBox.cs
+++ b/src/GnomeSubtitles/Ui/Component/SubtitleFormatComboBox.cs
@@ -91,17 +91,15 @@ public class SubtitleFormatComboBox {
int currentItem = 0;
int activeItem = 0;
+ bool hasAdditionalActions = (additionalActions != null) && (additionalActions.Length > 0);
+
/* Add additional actions */
- if (additionalActions != null) {
+ if (hasAdditionalActions) {
foreach (string additionalAction in additionalActions) {
comboBox.AppendText(additionalAction);
- currentItem++;
}
- }
-
- if (currentItem != 0) {
comboBox.AppendText("-");
- currentItem++;
+ currentItem += additionalActions.Length + 1;
}
/* Add subtitle formats */
diff --git a/src/SubLib/Core/Domain/Enumerations.cs b/src/SubLib/Core/Domain/Enumerations.cs
index c04f68c..751c158 100644
--- a/src/SubLib/Core/Domain/Enumerations.cs
+++ b/src/SubLib/Core/Domain/Enumerations.cs
@@ -1,6 +1,6 @@
/*
* This file is part of SubLib.
- * Copyright (C) 2005-2008 Pedro Castro
+ * Copyright (C) 2005-2010 Pedro Castro
*
* SubLib is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -107,15 +107,16 @@ public enum SubtitleType {
public enum NewlineType {
/// <summary>Unknown newline type.</summary>
Unknown ,
+
+ /// <summary>Macintosh newline type.</summary>
+ Macintosh,
/// <summary>Unix newline type.</summary>
Unix,
/// <summary>Windows newline type.</summary>
- Windows,
-
- /// <summary>Macintosh newline type.</summary>
- Macintosh,
+ Windows
+
};
/// <summary>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]