[gnome-latex/wip/misc] Port to TeplMetadata
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex/wip/misc] Port to TeplMetadata
- Date: Sun, 19 Apr 2020 14:43:02 +0000 (UTC)
commit e627f0f08f6454ed11d98e4bc0fcc630ebb1fcc2
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun Apr 19 16:23:50 2020 +0200
Port to TeplMetadata
src/document.vala | 62 ++++++++------------------------------------------
src/document_view.vala | 4 ++--
src/factory.vala | 6 +++++
src/glatex_app.vala | 1 +
4 files changed, 18 insertions(+), 55 deletions(-)
---
diff --git a/src/document.vala b/src/document.vala
index 1795178..4067f7c 100644
--- a/src/document.vala
+++ b/src/document.vala
@@ -1,7 +1,7 @@
/*
* This file is part of GNOME LaTeX.
*
- * Copyright © 2010-2011 Sébastien Wilmet
+ * Copyright © 2010-2020 Sébastien Wilmet
*
* GNOME LaTeX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -30,7 +30,6 @@ public class Document : Tepl.Buffer
private string? encoding = null;
private bool new_file = true;
private DocumentStructure _structure = null;
- private FileInfo _metadata_info = new FileInfo ();
public Document ()
{
@@ -58,6 +57,11 @@ public class Document : Tepl.Buffer
// Document:location property.
this.bind_property ("location", get_file (), "location",
BindingFlags.DEFAULT | BindingFlags.SYNC_CREATE);
+
+ get_file ().notify["location"].connect (() =>
+ {
+ load_metadata_from_metadata_manager ();
+ });
}
public new void insert (ref TextIter iter, string text, int len)
@@ -85,18 +89,6 @@ public class Document : Tepl.Buffer
public void load (File location)
{
- // First load metadata so when the notify::location signal is emitted,
- // get_metadata() works.
- try
- {
- _metadata_info = location.query_info ("metadata::*", FileQueryInfoFlags.NONE);
- }
- catch (Error e)
- {
- warning ("Get document metadata failed: %s", e.message);
- _metadata_info = new FileInfo ();
- }
-
this.location = location;
try
@@ -201,7 +193,7 @@ public class Document : Tepl.Buffer
RecentManager.get_default ().add_item (location.get_uri ());
backup_made = true;
- save_metadata ();
+ save_metadata_into_metadata_manager ();
}
catch (Error e)
{
@@ -513,45 +505,9 @@ public class Document : Tepl.Buffer
return true;
}
- private void save_metadata ()
- {
- return_if_fail (_metadata_info != null);
-
- if (this.location == null)
- return;
-
- try
- {
- this.location.set_attributes_from_info (_metadata_info,
- FileQueryInfoFlags.NONE);
- }
- catch (Error error)
- {
- warning ("Set document metadata failed: %s", error.message);
- }
- }
-
public void set_metadata (string key, string? val)
{
- return_if_fail (_metadata_info != null);
-
- if (val != null)
- _metadata_info.set_attribute_string (key, val);
- else
- // Unset the key
- _metadata_info.set_attribute (key, FileAttributeType.INVALID, null);
-
- save_metadata ();
- }
-
- public new string? get_metadata (string key)
- {
- return_val_if_fail (_metadata_info != null, null);
-
- if (_metadata_info.has_attribute (key) &&
- _metadata_info.get_attribute_type (key) == FileAttributeType.STRING)
- return _metadata_info.get_attribute_string (key);
-
- return null;
+ get_metadata ().set (key, val);
+ save_metadata_into_metadata_manager ();
}
}
diff --git a/src/document_view.vala b/src/document_view.vala
index 5750252..87e665a 100644
--- a/src/document_view.vala
+++ b/src/document_view.vala
@@ -187,7 +187,7 @@ public class DocumentView : Tepl.View
{
Document doc = get_buffer () as Document;
- string? lang_code = doc.get_metadata (METADATA_ATTRIBUTE_SPELL_LANGUAGE);
+ string? lang_code = doc.get_metadata ().get (METADATA_ATTRIBUTE_SPELL_LANGUAGE);
if (lang_code == null)
lang_code = _editor_settings.get_string ("spell-checking-language");
@@ -211,7 +211,7 @@ public class DocumentView : Tepl.View
bool enabled;
- string? metadata = doc.get_metadata (METADATA_ATTRIBUTE_INLINE_SPELL);
+ string? metadata = doc.get_metadata ().get (METADATA_ATTRIBUTE_INLINE_SPELL);
if (metadata != null)
enabled = metadata == INLINE_SPELL_ENABLED_STR;
else
diff --git a/src/factory.vala b/src/factory.vala
index bdc860c..c38bffd 100644
--- a/src/factory.vala
+++ b/src/factory.vala
@@ -62,4 +62,10 @@ public class Factory : Tepl.AbstractFactory
app.open_documents (files);
}
}
+
+ public override File? create_metadata_manager_file ()
+ {
+ return File.new_build_filename (Environment.get_user_data_dir (), "gnome-latex",
+ "gnome-latex-metadata.xml", null);
+ }
}
diff --git a/src/glatex_app.vala b/src/glatex_app.vala
index 20d55f7..d843d2f 100644
--- a/src/glatex_app.vala
+++ b/src/glatex_app.vala
@@ -48,6 +48,7 @@ public class GlatexApp : Gtk.Application
Tepl.Application tepl_app = Tepl.Application.get_from_gtk_application (this);
tepl_app.handle_activate ();
+ tepl_app.handle_metadata ();
}
public static GlatexApp get_instance ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]