remember which speller language was use for each contact. Fixes #8326
This commit is contained in:
parent
4ccfaa1a97
commit
02a0f25781
|
@ -441,11 +441,22 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
lang = gajim.LANG
|
lang = gajim.LANG
|
||||||
if lang:
|
if lang:
|
||||||
try:
|
try:
|
||||||
gtkspell.Spell(self.msg_textview, lang)
|
self.spell = gtkspell.Spell(self.msg_textview, lang)
|
||||||
self.msg_textview.lang = lang
|
self.msg_textview.lang = lang
|
||||||
|
self.spell.connect('language_changed', self.on_language_changed)
|
||||||
except (GObject.GError, RuntimeError, TypeError, OSError):
|
except (GObject.GError, RuntimeError, TypeError, OSError):
|
||||||
dialogs.AspellDictError(lang)
|
dialogs.AspellDictError(lang)
|
||||||
|
|
||||||
|
def on_language_changed(self, spell, lang):
|
||||||
|
per_type = 'contacts'
|
||||||
|
if self.type_id == message_control.TYPE_GC:
|
||||||
|
per_type = 'rooms'
|
||||||
|
if not gajim.config.get_per(per_type, self.contact.jid):
|
||||||
|
gajim.config.add_per(per_type, self.contact.jid)
|
||||||
|
gajim.config.set_per(per_type, self.contact.jid, 'speller_language',
|
||||||
|
lang)
|
||||||
|
self.msg_textview.lang = lang
|
||||||
|
|
||||||
def on_banner_label_populate_popup(self, label, menu):
|
def on_banner_label_populate_popup(self, label, menu):
|
||||||
"""
|
"""
|
||||||
Override the default context menu and add our own menutiems
|
Override the default context menu and add our own menutiems
|
||||||
|
@ -480,19 +491,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
Override the default context menu and we prepend an option to switch
|
Override the default context menu and we prepend an option to switch
|
||||||
languages
|
languages
|
||||||
"""
|
"""
|
||||||
def _on_select_dictionary(widget, lang):
|
|
||||||
per_type = 'contacts'
|
|
||||||
if self.type_id == message_control.TYPE_GC:
|
|
||||||
per_type = 'rooms'
|
|
||||||
if not gajim.config.get_per(per_type, self.contact.jid):
|
|
||||||
gajim.config.add_per(per_type, self.contact.jid)
|
|
||||||
gajim.config.set_per(per_type, self.contact.jid, 'speller_language',
|
|
||||||
lang)
|
|
||||||
spell = gtkspell.get_from_text_view(self.msg_textview)
|
|
||||||
self.msg_textview.lang = lang
|
|
||||||
spell.set_language(lang)
|
|
||||||
widget.set_active(True)
|
|
||||||
|
|
||||||
item = Gtk.MenuItem.new_with_mnemonic(_('_Undo'))
|
item = Gtk.MenuItem.new_with_mnemonic(_('_Undo'))
|
||||||
menu.prepend(item)
|
menu.prepend(item)
|
||||||
id_ = item.connect('activate', self.msg_textview.undo)
|
id_ = item.connect('activate', self.msg_textview.undo)
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
## You should have received a copy of the GNU General Public License
|
## You should have received a copy of the GNU General Public License
|
||||||
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from gi.repository import GObject
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
import gi
|
import gi
|
||||||
gi.require_version('GtkSpell', '3.0')
|
gi.require_version('GtkSpell', '3.0')
|
||||||
|
@ -31,9 +32,14 @@ def ensure_attached(func):
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
class Spell(object):
|
class Spell(GObject.GObject):
|
||||||
|
__gsignals__ = {
|
||||||
|
'language_changed': (GObject.SignalFlags.RUN_FIRST, None, (str,))
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, textview, language=None, create=True):
|
def __init__(self, textview, language=None, create=True, jid=None,
|
||||||
|
per_type=None):
|
||||||
|
GObject.GObject.__init__(self)
|
||||||
if not isinstance(textview, Gtk.TextView):
|
if not isinstance(textview, Gtk.TextView):
|
||||||
raise TypeError("Textview must be derived from Gtk.TextView")
|
raise TypeError("Textview must be derived from Gtk.TextView")
|
||||||
spell = GtkSpell.Checker.get_from_text_view(textview)
|
spell = GtkSpell.Checker.get_from_text_view(textview)
|
||||||
|
@ -47,6 +53,7 @@ class Spell(object):
|
||||||
raise OSError("Unable to attach spell object.")
|
raise OSError("Unable to attach spell object.")
|
||||||
if not self.spell.set_language(language):
|
if not self.spell.set_language(language):
|
||||||
raise OSError("Unable to set language: '%s'" % language)
|
raise OSError("Unable to set language: '%s'" % language)
|
||||||
|
self.spell.connect('language-changed', self.on_language_changed)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if spell:
|
if spell:
|
||||||
|
@ -54,6 +61,9 @@ class Spell(object):
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Textview has no Spell object attached")
|
raise RuntimeError("Textview has no Spell object attached")
|
||||||
|
|
||||||
|
def on_language_changed(self, spell, lang):
|
||||||
|
self.emit('language_changed', lang)
|
||||||
|
|
||||||
@ensure_attached
|
@ensure_attached
|
||||||
def set_language(self, language):
|
def set_language(self, language):
|
||||||
if not self.spell.set_language(language):
|
if not self.spell.set_language(language):
|
||||||
|
@ -68,6 +78,7 @@ class Spell(object):
|
||||||
self.spell.detach()
|
self.spell.detach()
|
||||||
self.spell = None
|
self.spell = None
|
||||||
|
|
||||||
|
GObject.type_register(Spell)
|
||||||
|
|
||||||
def get_from_text_view(textview):
|
def get_from_text_view(textview):
|
||||||
return Spell(textview, create=False)
|
return Spell(textview, create=False)
|
||||||
|
|
Loading…
Reference in New Issue