[latexila/wip/gspell] spell: store document spell settings in file metadata
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila/wip/gspell] spell: store document spell settings in file metadata
- Date: Fri, 25 Sep 2015 15:51:44 +0000 (UTC)
commit 7da9a9ff1ea7ab7d0a990621fe54ff54ce430597
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Sep 25 17:23:48 2015 +0200
spell: store document spell settings in file metadata
src/document.vala | 23 +++++++++++++++++++++++
src/document_view.vala | 14 +++++++++++++-
2 files changed, 36 insertions(+), 1 deletions(-)
---
diff --git a/src/document.vala b/src/document.vala
index 23e8062..4d83039 100644
--- a/src/document.vala
+++ b/src/document.vala
@@ -599,4 +599,27 @@ public class Document : Gtk.SourceBuffer
return true;
}
+
+ public void set_metadata (string key, string? val)
+ {
+ FileInfo info = new FileInfo ();
+
+ if (val != null)
+ info.set_attribute_string (key, val);
+ else
+ // Unset the key
+ info.set_attribute (key, FileAttributeType.INVALID, null);
+
+ if (this.location != null)
+ {
+ try
+ {
+ this.location.set_attributes_from_info (info, FileQueryInfoFlags.NONE);
+ }
+ catch (Error error)
+ {
+ warning ("Set document metadata failed: %s", error.message);
+ }
+ }
+ }
}
diff --git a/src/document_view.vala b/src/document_view.vala
index cb08d3c..786013c 100644
--- a/src/document_view.vala
+++ b/src/document_view.vala
@@ -23,6 +23,11 @@ public class DocumentView : Gtk.SourceView
{
public const double SCROLL_MARGIN = 0.02;
+ private static const string METADATA_ATTRIBUTE_SPELL_LANGUAGE =
+ "metadata::latexila-spell-language";
+ private static const string METADATA_ATTRIBUTE_INLINE_SPELL =
+ "metadata::latexila-inline-spell";
+
private GLib.Settings _editor_settings;
private Pango.FontDescription _font_desc;
private Gspell.Checker? _spell_checker = null;
@@ -219,7 +224,14 @@ public class DocumentView : Gtk.SourceView
dialog.run ();
- _spell_checker.set_language (dialog.get_language ());
+ unowned Gspell.Language? lang = dialog.get_language ();
+ _spell_checker.set_language (lang);
+
+ Document doc = get_buffer () as Document;
+ if (lang != null)
+ doc.set_metadata (METADATA_ATTRIBUTE_SPELL_LANGUAGE, lang.to_key ());
+ else
+ doc.set_metadata (METADATA_ATTRIBUTE_SPELL_LANGUAGE, null);
dialog.destroy ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]