gnome-subtitles r977 - in trunk/src/GnomeSubtitles: Core Dialogs SubtitleEdit
- From: pcastro svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-subtitles r977 - in trunk/src/GnomeSubtitles: Core Dialogs SubtitleEdit
- Date: Sun, 16 Mar 2008 17:53:42 +0000 (GMT)
Author: pcastro
Date: Sun Mar 16 17:53:41 2008
New Revision: 977
URL: http://svn.gnome.org/viewvc/gnome-subtitles?rev=977&view=rev
Log:
Finalized support for Spellcheck.
Included console prints for debugging.
Modified:
trunk/src/GnomeSubtitles/Core/SpellLanguage.cs
trunk/src/GnomeSubtitles/Core/SpellLanguages.cs
trunk/src/GnomeSubtitles/Dialogs/SetLanguageDialog.cs
trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditText.cs
trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditTextView.cs
trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditTranslation.cs
Modified: trunk/src/GnomeSubtitles/Core/SpellLanguage.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Core/SpellLanguage.cs (original)
+++ trunk/src/GnomeSubtitles/Core/SpellLanguage.cs Sun Mar 16 17:53:41 2008
@@ -32,13 +32,13 @@
/* Static variables */
private static string langGroupName = "lang";
private static string countryGroupName = "country";
- private static Regex regex = new Regex(@"(?<" + langGroupName + @">[a-zA-Z0-9]+)([^a-zA-Z0-9]+(?<" + countryGroupName + @">[a-zA-Z0-9]+))?$", RegexOptions.IgnoreCase);
+ private static Regex regex = new Regex(@"^(?<" + langGroupName + @">[a-zA-Z]+)(_(?<" + countryGroupName + @">[a-zA-Z]+))?$", RegexOptions.IgnoreCase);
public SpellLanguage (String id) {
this.id = id;
this.name = GetNameFromID(id);
}
-
+
/* Properties */
public string ID {
@@ -69,47 +69,44 @@
/* Private members */
private string GetNameFromID (string id) {
- System.Console.WriteLine("ID: " + id);
string lang = null;
string country = null;
bool parsed = ParseID(id, ref lang, ref country);
- System.Console.WriteLine("Parsed? " + parsed);
- string builtID = null;
- if (parsed) {
- builtID = lang;
- if ((country != null) && (country != String.Empty))
- builtID += "-" + country;
- }
- else
- builtID = id;
+
+ if (!parsed)
+ return GetUnknownNameFromID(id);
+
+ string builtID = lang;
+ if ((country != null) && (country != String.Empty))
+ builtID += "-" + country;
CultureInfo info = null;
try {
info = new CultureInfo(builtID);
}
- catch (Exception e) {
- System.Console.WriteLine(e);
- return prefixUnknown + " (" + id + ")";
+ catch (Exception) {
+ return GetUnknownNameFromID(id);
}
return info.EnglishName;
}
+ private string GetUnknownNameFromID (String id) {
+ return prefixUnknown + " (" + id + ")";
+ }
+
private bool ParseID (string id, ref string lang, ref string country) {
Match match = regex.Match(id);
if (!match.Success)
return false;
- System.Console.WriteLine("Match was successful");
Group langGroup = match.Groups[langGroupName];
if (!langGroup.Success)
return false;
lang = langGroup.Value;
- System.Console.WriteLine("Lang group was successful: " + lang);
Group countryGroup = match.Groups[countryGroupName];
country = (countryGroup.Success ? countryGroup.Value : null);
- System.Console.WriteLine("Country group was successful: " + country);
return true;
}
Modified: trunk/src/GnomeSubtitles/Core/SpellLanguages.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Core/SpellLanguages.cs (original)
+++ trunk/src/GnomeSubtitles/Core/SpellLanguages.cs Sun Mar 16 17:53:41 2008
@@ -67,14 +67,12 @@
get { return GetActiveLanguageIndex(SubtitleTextType.Translation); }
}
- public string ActiveTextLanguage {
+ public SpellLanguage ActiveTextLanguage {
get { return GetActiveLanguage(SubtitleTextType.Text); }
- set { SetActiveLanguage(SubtitleTextType.Text, value); }
}
- public string ActiveTranslationLanguage {
+ public SpellLanguage ActiveTranslationLanguage {
get { return GetActiveLanguage(SubtitleTextType.Translation); }
- set { SetActiveLanguage(SubtitleTextType.Translation, value); }
}
public bool HasActiveTextLanguage {
@@ -103,28 +101,48 @@
return activeTranslationLanguageIndex;
}
- public string GetActiveLanguage (SubtitleTextType textType) {
+ public SpellLanguage GetActiveLanguage (SubtitleTextType textType) {
int index = GetActiveLanguageIndex(textType);
- if (index == -1)
- return String.Empty;
+ return GetLanguage(index);
+ }
+
+ public SpellLanguage GetLanguage (int index) {
+ if ((index < 0) || (index >= languages.Count))
+ return null;
else
- return languages[index] as string;
+ return languages[index] as SpellLanguage;
}
- public void SetActiveLanguage (SubtitleTextType textType, string language) {
- int index = GetLanguageIndex(language);
+ public void SetActiveLanguage (SubtitleTextType textType, string languageID) {
+ int index = GetLanguageIndex(languageID);
SetActiveLanguageIndex(textType, index);
-
- bool isEmpty = ((index == -1) || (language == null) || (language == String.Empty));
- string activeLanguage = (isEmpty ? String.Empty : language);
- SetActiveLanguageInConfig(textType, activeLanguage);
+ }
+
+ public void SetActiveLanguageIndex (SubtitleTextType textType, int index) {
+ bool isEmpty = ((index < 0) || (index >= languages.Count));
+
+ SpellLanguage activeLanguage = null;
+ if (isEmpty)
+ index = -1;
+ else
+ activeLanguage = languages[index] as SpellLanguage;
+
+ System.Console.Error.WriteLine("Setting active language: " + (activeLanguage == null ? "none." : activeLanguage.ID));
+
+ /* Set index variable */
+ if (textType == SubtitleTextType.Text)
+ activeTextLanguageIndex = index;
+ else
+ activeTranslationLanguageIndex = index;
+
+ String activeLanguageID = (isEmpty ? String.Empty : activeLanguage.ID);
+ SetActiveLanguageInConfig(textType, activeLanguageID);
EmitLanguageChanged(textType);
if (!isEmpty)
Global.GUI.Menus.SetToolsAutocheckSpellingSensitivity(true);
}
-
/* LibEnchant imports */
[DllImport ("libenchant")]
@@ -157,13 +175,7 @@
enchant_broker_free(broker);
languages.Sort();
- }
-
- private void SetActiveLanguageIndex (SubtitleTextType textType, int index) {
- if (textType == SubtitleTextType.Text)
- activeTextLanguageIndex = index;
- else
- activeTranslationLanguageIndex = index;
+ System.Console.Error.WriteLine("Got " + languages.Count + " languages.");
}
private void GetActiveLanguagesFromConfig () {
@@ -185,8 +197,13 @@
Global.Config.PrefsSpellCheckActiveTranslationLanguage = activeLanguage;
}
- private int GetLanguageIndex (String language) {
- return languages.IndexOf(language);
+ private int GetLanguageIndex (string languageID) {
+ for (int index = 0 ; index < languages.Count ; index++) {
+ SpellLanguage language = languages[index] as SpellLanguage;
+ if (language.ID == languageID)
+ return index;
+ }
+ return -1;
}
private void Init () {
Modified: trunk/src/GnomeSubtitles/Dialogs/SetLanguageDialog.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Dialogs/SetLanguageDialog.cs (original)
+++ trunk/src/GnomeSubtitles/Dialogs/SetLanguageDialog.cs Sun Mar 16 17:53:41 2008
@@ -88,24 +88,22 @@
return activeLanguageIndex;
}
-
+
private void SetSpellLanguage () {
- string activeLanguage = GetSelectedLanguage();
- Global.SpellLanguages.SetActiveLanguage(textType, activeLanguage);
+ int selectedLanguageIndex = GetSelectedLanguageIndex();
+ Global.SpellLanguages.SetActiveLanguageIndex(textType, selectedLanguageIndex);
}
- private string GetSelectedLanguage () {
+ private int GetSelectedLanguageIndex () {
int count = languagesTreeView.Selection.CountSelectedRows();
if (count != 1)
- return String.Empty;
+ return -1;
TreePath path = GetSelectedPath(languagesTreeView);
if (path == null)
- return String.Empty;
-
- TreeIter iter;
- languagesTreeView.Model.GetIter(out iter, path);
- return languagesTreeView.Model.GetValue(iter, colNum) as string;
+ return -1;
+
+ return Util.PathToInt(path);
}
private TreePath GetSelectedPath (TreeView tree) {
Modified: trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditText.cs
==============================================================================
--- trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditText.cs (original)
+++ trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditText.cs Sun Mar 16 17:53:41 2008
@@ -47,7 +47,7 @@
Global.CommandManager.Execute(new DeleteTextCommand(index, text, cursor));
}
- protected override string GetSpellActiveLanguage () {
+ protected override SpellLanguage GetSpellActiveLanguage () {
return Global.SpellLanguages.ActiveTextLanguage;
}
Modified: trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditTextView.cs
==============================================================================
--- trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditTextView.cs (original)
+++ trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditTextView.cs Sun Mar 16 17:53:41 2008
@@ -69,7 +69,7 @@
protected abstract string GetSubtitleTextContent (Subtitle subtitle);
protected abstract void ExecuteInsertCommand (int index, string insertion);
protected abstract void ExecuteDeleteCommand (int index, string deletion, int cursor);
- protected abstract string GetSpellActiveLanguage ();
+ protected abstract SpellLanguage GetSpellActiveLanguage ();
protected abstract void ConnectLanguageChangedSignal ();
/* Events */
@@ -221,9 +221,8 @@
return (spellTextView != IntPtr.Zero);
}
- private bool GtkSpellSetLanguage (string language) {
- bool isEmpty = ((language == null) || (language == String.Empty));
- if (isEmpty) {
+ private bool GtkSpellSetLanguage (SpellLanguage language) {
+ if (language == null) {
if (IsGtkSpellAttached()) {
GtkSpellDetach();
}
@@ -233,7 +232,11 @@
if (!IsGtkSpellAttached()) {
GtkSpellAttach();
}
- return gtkspell_set_language(spellTextView, language, IntPtr.Zero);
+ bool result = gtkspell_set_language(spellTextView, language.ID, IntPtr.Zero);
+ if (!result)
+ GtkSpellDetach();
+
+ return result;
}
}
@@ -385,7 +388,7 @@
bool enabled = Global.SpellLanguages.Enabled;
if (enabled) {
GtkSpellAttach();
- string language = GetSpellActiveLanguage();
+ SpellLanguage language = GetSpellActiveLanguage();
GtkSpellSetLanguage(language);
}
else
@@ -446,7 +449,7 @@
protected void OnSpellLanguageChanged (object o, EventArgs args) {
if (Global.SpellLanguages.Enabled) {
- string language = GetSpellActiveLanguage();
+ SpellLanguage language = GetSpellActiveLanguage();
GtkSpellSetLanguage(language);
}
}
Modified: trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditTranslation.cs
==============================================================================
--- trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditTranslation.cs (original)
+++ trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditTranslation.cs Sun Mar 16 17:53:41 2008
@@ -47,7 +47,7 @@
Global.CommandManager.Execute(new DeleteTranslationCommand(index, text, cursor));
}
- protected override string GetSpellActiveLanguage () {
+ protected override SpellLanguage GetSpellActiveLanguage () {
return Global.SpellLanguages.ActiveTranslationLanguage;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]