gnome-subtitles r961 - in trunk: . data src src/Glade src/GnomeSubtitles/Core src/GnomeSubtitles/Dialogs src/GnomeSubtitles/SubtitleEdit
- From: pcastro svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-subtitles r961 - in trunk: . data src src/Glade src/GnomeSubtitles/Core src/GnomeSubtitles/Dialogs src/GnomeSubtitles/SubtitleEdit
- Date: Sun, 2 Mar 2008 01:34:10 +0000 (GMT)
Author: pcastro
Date: Sun Mar 2 01:34:10 2008
New Revision: 961
URL: http://svn.gnome.org/viewvc/gnome-subtitles?rev=961&view=rev
Log:
Initial support for spell checking, based on a patch from SchAmane (Bug #462317 â Spellchecker support).
Added:
trunk/src/Glade/SetLanguageDialog.glade
trunk/src/GnomeSubtitles/Core/SpellLanguages.cs
trunk/src/GnomeSubtitles/Dialogs/SetLanguageDialog.cs
Modified:
trunk/configure.ac
trunk/data/gnome-subtitles.schemas
trunk/gnome-subtitles.mdp
trunk/src/Glade/MainWindow.glade
trunk/src/GnomeSubtitles/Core/Config.cs
trunk/src/GnomeSubtitles/Core/EventHandlers.cs
trunk/src/GnomeSubtitles/Core/Global.cs
trunk/src/GnomeSubtitles/Core/Menus.cs
trunk/src/GnomeSubtitles/Core/WidgetNames.cs
trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditTextView.cs
trunk/src/Makefile.am
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Sun Mar 2 01:34:10 2008
@@ -125,6 +125,8 @@
PKG_CHECK_MODULES(MONO, mono >= $MONO_REQUIRED_VERSION)
PKG_CHECK_MODULES(GTKSHARP, gtk-sharp-2.0 glade-sharp-2.0 gnome-sharp-2.0 gconf-sharp-2.0 >= $GTKSHARP_REQUIRED_VERSION)
PKG_CHECK_MODULES(GTK, gtk+-2.0 >= $GTK_REQUIRED_VERSION)
+PKG_CHECK_MODULES(GTKSPELL, gtkspell-2.0)
+PKG_CHECK_MODULES(LIBENCHANT, enchant)
AC_SUBST(MCS)
Modified: trunk/data/gnome-subtitles.schemas
==============================================================================
--- trunk/data/gnome-subtitles.schemas (original)
+++ trunk/data/gnome-subtitles.schemas Sun Mar 2 01:34:10 2008
@@ -25,6 +25,28 @@
</locale>
</schema>
<schema>
+ <key>/schemas/apps/gnome-subtitles/preferences/spellcheck/active_language</key>
+ <applyto>/apps/gnome-subtitles/preferences/spellcheck/active_language</applyto>
+ <owner>gnome-subtitles</owner>
+ <type>string</type>
+ <default></default>
+ <locale name="C">
+ <short>Active spellcheck language</short>
+ <long>The language used to check the spelling of subtitle text.</long>
+ </locale>
+ </schema>
+ <schema>
+ <key>/schemas/apps/gnome-subtitles/preferences/spellcheck/autocheck</key>
+ <applyto>/apps/gnome-subtitles/preferences/spellcheck/autocheck</applyto>
+ <owner>gnome-subtitles</owner>
+ <type>bool</type>
+ <default>FALSE</default>
+ <locale name="C">
+ <short>Autocheck spelling</short>
+ <long>Whether to automatically check the spelling of subtitle text.</long>
+ </locale>
+ </schema>
+ <schema>
<key>/schemas/apps/gnome-subtitles/preferences/window/width</key>
<applyto>/apps/gnome-subtitles/preferences/window/width</applyto>
<owner>gnome-subtitles</owner>
Modified: trunk/gnome-subtitles.mdp
==============================================================================
--- trunk/gnome-subtitles.mdp (original)
+++ trunk/gnome-subtitles.mdp Sun Mar 2 01:34:10 2008
@@ -118,6 +118,9 @@
<File name="./src/Glade/VideoOpenDialog.glade" subtype="Code" buildaction="EmbedAsResource" />
<File name="./src/GnomeSubtitles/Video/PlayerPositionWatcher.cs" subtype="Code" buildaction="Compile" />
<File name="./src/GnomeSubtitles/Dialogs/VideoErrorDialog.cs" subtype="Code" buildaction="Compile" />
+ <File name="./src/GnomeSubtitles/Dialogs/SetLanguageDialog.cs" subtype="Code" buildaction="Compile" />
+ <File name="./src/GnomeSubtitles/Core/SpellLanguages.cs" subtype="Code" buildaction="Compile" />
+ <File name="./src/Glade/SetLanguageDialog.glade" subtype="Code" buildaction="EmbedAsResource" />
</Contents>
<References>
<ProjectReference type="Gac" localcopy="True" refto="gtk-sharp, Version=2.8.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
Modified: trunk/src/Glade/MainWindow.glade
==============================================================================
--- trunk/src/Glade/MainWindow.glade (original)
+++ trunk/src/Glade/MainWindow.glade Sun Mar 2 01:34:10 2008
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.0 on Sun Jan 20 23:49:07 2008
+<!--Generated with glade3 3.4.0 on Sat Mar 1 22:54:48 2008
Version: 3.0.1
Date: Thu Dec 7 16:42:10 2006
User: noup
@@ -557,7 +557,7 @@
<child>
<widget class="GtkMenuItem" id="timings">
<property name="visible">True</property>
- <property name="label" translatable="yes">_Timings</property>
+ <property name="label" translatable="yes">T_imings</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="timingsMenu">
@@ -848,6 +848,40 @@
</widget>
</child>
<child>
+ <widget class="GtkMenuItem" id="tools">
+ <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</property>
+ <property name="label" translatable="yes">_Tools</property>
+ <property name="use_underline">True</property>
+ <child>
+ <widget class="GtkMenu" id="menu2">
+ <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</property>
+ <child>
+ <widget class="GtkCheckMenuItem" id="toolsAutocheckSpelling">
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="label" translatable="yes">_Autocheck Spelling</property>
+ <property name="use_underline">True</property>
+ <signal name="toggled" handler="OnToolsAutocheckSpelling"/>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkMenuItem" id="toolsSetLanguage">
+ <property name="visible">True</property>
+ <property name="sensitive">False</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="label" translatable="yes">_Set Language</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="OnToolsSetLanguage"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ <child>
<widget class="GtkMenuItem" id="help">
<property name="visible">True</property>
<property name="label" translatable="yes">_Help</property>
Added: trunk/src/Glade/SetLanguageDialog.glade
==============================================================================
--- (empty file)
+++ trunk/src/Glade/SetLanguageDialog.glade Sun Mar 2 01:34:10 2008
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
+<!--*- mode: xml -*-->
+<glade-interface>
+ <widget class="GtkDialog" id="dialog">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Set language</property>
+ <property name="modal">True</property>
+ <property name="destroy_with_parent">True</property>
+ <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+ <property name="has_separator">False</property>
+ <signal name="response" handler="OnResponse"/>
+ <child internal-child="vbox">
+ <widget class="GtkVBox" id="dialogVBox">
+ <property name="visible">True</property>
+ <property name="spacing">2</property>
+ <child>
+ <widget class="GtkVBox" id="vBox">
+ <property name="visible">True</property>
+ <property name="border_width">5</property>
+ <property name="spacing">11</property>
+ <child>
+ <widget class="GtkLabel" id="introLabel">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Select the _language of the current subtitles.</property>
+ <property name="use_underline">True</property>
+ <property name="wrap">True</property>
+ <property name="mnemonic_widget">languagesTreeView</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkScrolledWindow" id="scrolledWindow">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+ <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property>
+ <child>
+ <widget class="GtkTreeView" id="languagesTreeView">
+ <property name="height_request">180</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="headers_visible">False</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child internal-child="action_area">
+ <widget class="GtkHButtonBox" id="dialogActionArea">
+ <property name="visible">True</property>
+ <property name="layout_style">GTK_BUTTONBOX_END</property>
+ <child>
+ <widget class="GtkButton" id="buttonCancel">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="label">gtk-cancel</property>
+ <property name="use_stock">True</property>
+ <property name="response_id">-6</property>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkButton" id="buttonOK">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="label">gtk-ok</property>
+ <property name="use_stock">True</property>
+ <property name="response_id">-5</property>
+ </widget>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="pack_type">GTK_PACK_END</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+</glade-interface>
Modified: trunk/src/GnomeSubtitles/Core/Config.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Core/Config.cs (original)
+++ trunk/src/GnomeSubtitles/Core/Config.cs Sun Mar 2 01:34:10 2008
@@ -1,6 +1,6 @@
/*
* This file is part of Gnome Subtitles.
- * Copyright (C) 2007 Pedro Castro
+ * Copyright (C) 2007-2008 Pedro Castro
*
* Gnome Subtitles is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,11 +29,14 @@
private const string keyPrefix = "/apps/gnome-subtitles/";
private const string keyPrefs = keyPrefix + "preferences/";
private const string keyPrefsEncodings = keyPrefs + "encodings/";
+ private const string keyPrefsSpellCheck = keyPrefs + "spellcheck/";
private const string keyPrefsVideo = keyPrefs + "video/";
private const string keyPrefsWindow = keyPrefs + "window/";
/* Constant key strings */
private const string keyPrefsEncodingsShownInMenu = keyPrefsEncodings + "shown_in_menu";
+ private const string keyPrefsSpellCheckActiveLanguage = keyPrefsSpellCheck + "active_language";
+ private const string keyPrefsSpellCheckAutocheck = keyPrefsSpellCheck + "autocheck";
private const string keyPrefsVideoAutoChooseFile = keyPrefsVideo + "auto_choose_file";
private const string keyPrefsWindowHeight = keyPrefsWindow + "height";
private const string keyPrefsWindowWidth = keyPrefsWindow + "width";
@@ -52,6 +55,16 @@
set { SetStrings(keyPrefsEncodingsShownInMenu, value); }
}
+ public string PrefsSpellCheckActiveLanguage {
+ get { return GetString(keyPrefsSpellCheckActiveLanguage, String.Empty); }
+ set { Set(keyPrefsSpellCheckActiveLanguage, value); }
+ }
+
+ public bool PrefsSpellCheckAutocheck {
+ get { return GetBool(keyPrefsSpellCheckAutocheck, false); }
+ set { Set(keyPrefsSpellCheckAutocheck, value); }
+ }
+
public bool PrefsVideoAutoChooseFile {
get { return GetBool(keyPrefsVideoAutoChooseFile, true); }
set { Set(keyPrefsVideoAutoChooseFile, value); }
@@ -69,6 +82,15 @@
/* Private members */
+ private string GetString (string key, string defaultValue) {
+ try {
+ return (string)client.Get(key);
+ }
+ catch (Exception) {
+ return defaultValue;
+ }
+ }
+
private bool GetBool (string key, bool defaultValue) {
try {
return (bool)client.Get(key);
Modified: trunk/src/GnomeSubtitles/Core/EventHandlers.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Core/EventHandlers.cs (original)
+++ trunk/src/GnomeSubtitles/Core/EventHandlers.cs Sun Mar 2 01:34:10 2008
@@ -266,6 +266,17 @@
}
}
+ /* Tools Menu */
+
+ public void OnToolsAutocheckSpelling (object o, EventArgs args) {
+ bool enabled = (o as CheckMenuItem).Active;
+ Global.SpellLanguages.Enabled = enabled;
+ }
+
+ public void OnToolsSetLanguage (object o, EventArgs args) {
+ new SetLanguageDialog().Show();
+ }
+
/* Help Menu */
Modified: trunk/src/GnomeSubtitles/Core/Global.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Core/Global.cs (original)
+++ trunk/src/GnomeSubtitles/Core/Global.cs Sun Mar 2 01:34:10 2008
@@ -1,6 +1,6 @@
/*
* This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2007 Pedro Castro
+ * Copyright (C) 2006-2008 Pedro Castro
*
* Gnome Subtitles is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -36,6 +36,7 @@
private static Clipboards clipboards = null;
private static Config config = null;
private static Dialogs dialogs = null;
+ private static SpellLanguages spellLanguages = null;
private static Document document = null;
private static TimingMode timingMode = TimingMode.Times;
@@ -71,6 +72,10 @@
get { return dialogs; }
}
+ public static SpellLanguages SpellLanguages {
+ get { return spellLanguages; }
+ }
+
public static Document Document {
get { return document; }
}
@@ -169,6 +174,7 @@
clipboards = new Clipboards();
config = new Config();
dialogs = new Dialogs();
+ spellLanguages = new SpellLanguages();
/* Initialize the GUI */
gui = new GUI(handlers, out glade);
Modified: trunk/src/GnomeSubtitles/Core/Menus.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Core/Menus.cs (original)
+++ trunk/src/GnomeSubtitles/Core/Menus.cs Sun Mar 2 01:34:10 2008
@@ -41,6 +41,7 @@
public void BlankStartUp () {
SetBlankSensitivity();
+ SetBlankActivity();
}
public void UpdateFromNewDocument (bool wasLoaded) {
@@ -48,6 +49,10 @@
SetSubtitleCountDependentSensitivity(Global.Document.Subtitles.Collection.Count);
SetFrameRateMenus();
SetActiveTimingMode(Global.TimingMode);
+
+ SetToolsSetLanguageSensitivity(true);
+ SetToolsAutocheckSpellingSensitivity(Global.SpellLanguages.HasActiveLanguage);
+ SetCheckMenuItemActivity(WidgetNames.ToolsAutocheckSpelling, Global.SpellLanguages.Enabled);
}
public void UpdateFromNewTranslationDocument () {
@@ -148,6 +153,14 @@
SetSensitivity(WidgetNames.SearchFindPrevious, true);
}
+ public void SetToolsSetLanguageSensitivity (bool sensitivity) {
+ SetSensitivity(WidgetNames.ToolsSetLanguage, sensitivity);
+ }
+
+ public void SetToolsAutocheckSpellingSensitivity (bool sensitivity) {
+ SetSensitivity(WidgetNames.ToolsAutocheckSpelling, sensitivity);
+ }
+
public void SetViewVideoActivity (bool activity) {
SetCheckMenuItemActivity(WidgetNames.ViewVideo, activity);
}
@@ -245,6 +258,8 @@
SetSensitivity(WidgetNames.SearchFindNext, false);
SetSensitivity(WidgetNames.SearchFindPrevious, false);
SetSensitivity(WidgetNames.SearchReplace, false);
+ /* Tools Menu */
+ SetToolsAutocheckSpellingSensitivity(false);
/* Toolbar */
SetSensitivity(WidgetNames.SaveButton, false);
SetSensitivity(WidgetNames.UndoButton, false);
@@ -259,6 +274,10 @@
SetSensitivity(WidgetNames.UnderlineButton, false);
}
+ private void SetBlankActivity () {
+ SetCheckMenuItemActivity(WidgetNames.ToolsAutocheckSpelling, Global.SpellLanguages.Enabled);
+ }
+
private void SetNewDocumentSensitivity (bool wasLoaded) {
if (!wasLoaded) {
/* File Menu */
@@ -278,6 +297,9 @@
/* Search Menu */
SetSensitivity(WidgetNames.SearchFind, true);
SetSensitivity(WidgetNames.SearchReplace, true);
+ /* Tools Menu */
+ SetToolsSetLanguageSensitivity(true);
+
/* Toolbar */
SetSensitivity(WidgetNames.SaveButton, true);
SetSensitivity(WidgetNames.FindButton, true);
Added: trunk/src/GnomeSubtitles/Core/SpellLanguages.cs
==============================================================================
--- (empty file)
+++ trunk/src/GnomeSubtitles/Core/SpellLanguages.cs Sun Mar 2 01:34:10 2008
@@ -0,0 +1,180 @@
+/*
+ * This file is part of Gnome Subtitles.
+ * Copyright (C) 2008 Pedro Castro
+ *
+ * Gnome Subtitles is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Gnome Subtitles is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+using Gtk;
+using System;
+using System.Collections;
+using System.Runtime.InteropServices;
+using SubLib;
+
+namespace GnomeSubtitles {
+
+/* Delegates */
+public delegate void LanguageListHandler (string langTag, string providerName, string providerDesc, string providerFile, IntPtr userdata);
+
+public class SpellLanguages {
+ private ArrayList languages = null;
+ private int activeLanguageIndex = -1;
+ private bool enabled = false;
+
+ private LanguageListHandler languageListHandler = null;
+
+
+ public SpellLanguages () {
+ languageListHandler = OnLanguageList;
+ GetAvailableLanguages();
+ GetEnabledFromConfig();
+ }
+
+ /* Events */
+ public event EventHandler LanguageChanged = null;
+ public event EventHandler ToggleEnabled = null;
+
+
+ /* Public members */
+
+ public ArrayList Languages {
+ get {
+ if (languages == null)
+ GetAvailableLanguages();
+
+ return languages;
+ }
+ }
+
+ public int ActiveLanguageIndex {
+ get { return activeLanguageIndex; }
+ }
+
+ public string ActiveLanguage {
+ get {
+ if (activeLanguageIndex == -1)
+ return String.Empty;
+ else
+ return languages[activeLanguageIndex] as string;
+ }
+ set {
+ int index = GetActiveLanguageIndex(value);
+ activeLanguageIndex = index;
+
+ bool isEmpty = ((index == -1) || (value == null) || (value == String.Empty));
+ string activeLanguage = (isEmpty ? String.Empty : value);
+ SetActiveLanguageInConfig(activeLanguage);
+
+ EmitLanguageChanged();
+ if (!isEmpty)
+ Global.GUI.Menus.SetToolsAutocheckSpellingSensitivity(true);
+ }
+ }
+
+ public bool HasActiveLanguage {
+ get { return activeLanguageIndex != -1; }
+ }
+
+ public bool Enabled {
+ set {
+ if (value != enabled) {
+ enabled = value;
+ Global.Config.PrefsSpellCheckAutocheck = value;
+ EmitToggleEnabled();
+ }
+ }
+ get { return enabled; }
+ }
+
+
+ /* LibEnchant imports */
+
+ [DllImport ("libenchant.so.1")]
+ static extern IntPtr enchant_broker_init ();
+
+ [DllImport ("libenchant.so.1")]
+ static extern void enchant_broker_free (IntPtr broker);
+
+ [DllImport ("libenchant.so.1")]
+ static extern void enchant_broker_list_dicts (IntPtr broker, LanguageListHandler cb, IntPtr userdata);
+
+
+ /* Private members */
+
+ private void GetAvailableLanguages () {
+ if (languages == null)
+ Init();
+
+ FillLanguages();
+ GetActiveLanguageFromConfig();
+ }
+
+ private void FillLanguages () {
+ IntPtr broker = enchant_broker_init ();
+ if (broker == IntPtr.Zero)
+ return;
+
+ enchant_broker_list_dicts (broker, languageListHandler, IntPtr.Zero);
+
+ enchant_broker_free(broker);
+
+ languages.Sort();
+ }
+
+ private void GetActiveLanguageFromConfig () {
+ string activeLanguage = Global.Config.PrefsSpellCheckActiveLanguage;
+ this.activeLanguageIndex = GetActiveLanguageIndex(activeLanguage);
+ }
+
+ private void GetEnabledFromConfig () {
+ this.enabled = Global.Config.PrefsSpellCheckAutocheck && this.HasActiveLanguage;
+
+ /* Check for inconsistency */
+ if (Global.Config.PrefsSpellCheckAutocheck && (!this.HasActiveLanguage))
+ Global.Config.PrefsSpellCheckAutocheck = false;
+ }
+
+ private void SetActiveLanguageInConfig (string activeLanguage) {
+ Global.Config.PrefsSpellCheckActiveLanguage = activeLanguage;
+ }
+
+ private int GetActiveLanguageIndex (String activeLanguage) {
+ return languages.IndexOf(activeLanguage);
+ }
+
+ private void Init () {
+ languages = new ArrayList();
+ activeLanguageIndex = -1;
+ }
+
+ /* Event members */
+
+ private void OnLanguageList (string langTag, string providerName, string providerDesc, string providerFile, IntPtr userdata) {
+ languages.Add(langTag);
+ }
+
+ private void EmitToggleEnabled () {
+ if (this.ToggleEnabled != null)
+ this.ToggleEnabled(this, EventArgs.Empty);
+ }
+
+ private void EmitLanguageChanged () {
+ if (this.LanguageChanged != null)
+ this.LanguageChanged(this, EventArgs.Empty);
+ }
+
+}
+
+}
Modified: trunk/src/GnomeSubtitles/Core/WidgetNames.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Core/WidgetNames.cs (original)
+++ trunk/src/GnomeSubtitles/Core/WidgetNames.cs Sun Mar 2 01:34:10 2008
@@ -78,6 +78,10 @@
public const string VideoSeekToSelection = "videoSeekToSelection";
public const string VideoSetSubtitleStart = "videoSetSubtitleStart";
public const string VideoSetSubtitleEnd = "videoSetSubtitleEnd";
+
+ /* Tools Menu */
+ public const string ToolsAutocheckSpelling = "toolsAutocheckSpelling";
+ public const string ToolsSetLanguage = "toolsSetLanguage";
/* Toolbar */
Added: trunk/src/GnomeSubtitles/Dialogs/SetLanguageDialog.cs
==============================================================================
--- (empty file)
+++ trunk/src/GnomeSubtitles/Dialogs/SetLanguageDialog.cs Sun Mar 2 01:34:10 2008
@@ -0,0 +1,121 @@
+/*
+ * This file is part of Gnome Subtitles.
+ * Copyright (C) 2008 Pedro Castro
+ *
+ * Gnome Subtitles is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Gnome Subtitles is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+using Glade;
+using Gtk;
+using System;
+
+namespace GnomeSubtitles {
+
+public class SetLanguageDialog : GladeDialog {
+ private ListStore store = null;
+ private int colNum = 0;
+
+ /* Constant strings */
+ private const string gladeFilename = "SetLanguageDialog.glade";
+
+ /* Widgets */
+
+ [WidgetAttribute] private TreeView languagesTreeView;
+
+
+ public SetLanguageDialog () : base(gladeFilename) {
+ FillAvailableLanguages();
+ SelectActiveLanguage();
+ }
+
+ /* Private members */
+
+ private void FillAvailableLanguages () {
+ TreeViewColumn col = new TreeViewColumn("col", new CellRendererText(), "text", colNum);
+ languagesTreeView.AppendColumn(col);
+
+ store = new ListStore(typeof(string));
+ foreach (string language in Global.SpellLanguages.Languages) {
+ store.AppendValues(language);
+ }
+
+ languagesTreeView.Model = store;
+ }
+
+ private void SelectActiveLanguage () {
+ int count = store.IterNChildren();
+ if (count == 0)
+ return;
+
+ int activeLanguageIndex = GetActiveLanguageIndex(count);
+
+
+ TreePath path = Util.IntToPath(activeLanguageIndex);
+ languagesTreeView.ScrollToCell(path, null, true, 0.5f, 0.5f);
+ languagesTreeView.SetCursor(path, null, false);
+ }
+
+ private int GetActiveLanguageIndex (int count) {
+ int activeLanguageIndex = Global.SpellLanguages.ActiveLanguageIndex;
+ /* Set active language to the first if invalid */
+ if ((activeLanguageIndex == -1) || (activeLanguageIndex >= count))
+ activeLanguageIndex = 0;
+
+ return activeLanguageIndex;
+ }
+
+ private void SetSpellLanguage () {
+ string activeLanguage = GetSelectedLanguage();
+ Global.SpellLanguages.ActiveLanguage = activeLanguage;
+ }
+
+ private string GetSelectedLanguage () {
+ int count = languagesTreeView.Selection.CountSelectedRows();
+ if (count != 1)
+ return String.Empty;
+
+ 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;
+ }
+
+ private TreePath GetSelectedPath (TreeView tree) {
+ TreePath[] paths = tree.Selection.GetSelectedRows();
+ if ((paths == null) || (paths.Length != 1))
+ return null;
+
+ TreePath selected = paths[0];
+ return selected;
+ }
+
+ /* Event handlers */
+
+ #pragma warning disable 169 //Disables warning about handlers not being used
+
+ private void OnResponse (object o, ResponseArgs args) {
+ if (args.ResponseId == ResponseType.Ok)
+ SetSpellLanguage();
+
+ Close();
+ }
+
+
+}
+
+}
Modified: trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditTextView.cs
==============================================================================
--- trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditTextView.cs (original)
+++ trunk/src/GnomeSubtitles/SubtitleEdit/SubtitleEditTextView.cs Sun Mar 2 01:34:10 2008
@@ -1,6 +1,6 @@
/*
* This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2007 Pedro Castro
+ * Copyright (C) 2006-2008 Pedro Castro
*
* Gnome Subtitles is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
using SubLib;
using System;
using System.Collections;
+using System.Runtime.InteropServices;
namespace GnomeSubtitles {
@@ -40,7 +41,9 @@
/* Other */
private Subtitle subtitle = null;
-
+ private IntPtr spellTextView = IntPtr.Zero;
+
+
public SubtitleEditTextView (TextView textView) {
this.textView = textView;
@@ -189,7 +192,29 @@
isToggleOverwriteSilent = false;
}
-
+ /* GtkSpell */
+ [DllImport ("libgtkspell.so.0")]
+ static extern IntPtr gtkspell_new_attach (IntPtr textView, string locale, IntPtr error);
+
+ [DllImport ("libgtkspell.so.0")]
+ static extern void gtkspell_detach (IntPtr obj);
+
+ [DllImport ("libgtkspell.so.0")]
+ static extern bool gtkspell_set_language (IntPtr textView, string lang, IntPtr error);
+
+ private void GtkSpellDetach () {
+ if (spellTextView != IntPtr.Zero)
+ gtkspell_detach(spellTextView);
+ }
+
+ private void GtkSpellAttach () {
+ spellTextView = gtkspell_new_attach(textView.Handle, null, IntPtr.Zero);
+ }
+
+ private bool GtkSpellSetLanguage (string language) {
+ return gtkspell_set_language(spellTextView, "asdasd", IntPtr.Zero);
+ }
+
/* Private methods */
@@ -275,7 +300,8 @@
private void GrabFocus () {
textView.GrabFocus();
}
-
+
+
/* Event methods */
private void OnBufferChanged (object o, EventArgs args) {
@@ -333,6 +359,28 @@
EmitToggleOverwrite();
}
+ private void OnSpellToggleEnabled (object o, EventArgs args) {
+ bool enabled = Global.SpellLanguages.Enabled;
+ if (enabled) {
+ GtkSpellAttach();
+ string language = Global.SpellLanguages.ActiveLanguage;
+ GtkSpellSetLanguage(language);
+ }
+ else
+ GtkSpellDetach();
+ }
+
+ private void OnSpellLanguageChanged (object o, EventArgs args) {
+ if (Global.SpellLanguages.Enabled) {
+ string language = Global.SpellLanguages.ActiveLanguage;
+ GtkSpellSetLanguage(language);
+ }
+ }
+
+ private void OnDestroyed (object o, EventArgs args) {
+ GtkSpellDetach();
+ }
+
[GLib.ConnectBefore]
private void OnKeyPressed (object o, KeyPressEventArgs args) {
Gdk.Key key = args.Event.Key;
@@ -367,6 +415,11 @@
textView.FocusOutEvent += OnFocusOut;
textView.KeyPressEvent += OnKeyPressed;
textView.ToggleOverwrite += OnToggleOverwrite;
+ TextView.Destroyed += OnDestroyed;
+
+ /* Spell signals */
+ Global.SpellLanguages.ToggleEnabled += OnSpellToggleEnabled;
+ Global.SpellLanguages.LanguageChanged += OnSpellLanguageChanged;
}
private void EmitToggleOverwrite () {
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Sun Mar 2 01:34:10 2008
@@ -29,6 +29,7 @@
$(srcdir)/Glade/PreferencesDialog.glade \
$(srcdir)/Glade/ReportBugWindow.glade \
$(srcdir)/Glade/SearchDialog.glade \
+ $(srcdir)/Glade/SetLanguageDialog.glade \
$(srcdir)/Glade/TimingsAdjustDialog.glade \
$(srcdir)/Glade/TimingsShiftDialog.glade \
$(srcdir)/Glade/VideoOpenDialog.glade \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]