[gnome-text-editor] languagedialog: save language to extended attribute
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] languagedialog: save language to extended attribute
- Date: Tue, 18 Jan 2022 21:46:48 +0000 (UTC)
commit e81931f24d5adbf1af78495a5d649d88b1b275b3
Author: Christian Hergert <chergert redhat com>
Date: Tue Jan 18 13:46:40 2022 -0800
languagedialog: save language to extended attribute
When the user manually changes the document syntax language, we can
persist an extended attribute which is used the next time the file is
loaded from storage.
We only do this on manual changes to avoid setting extended attributes
for every file we simply open.
Fixes #292
src/editor-window-actions.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
---
diff --git a/src/editor-window-actions.c b/src/editor-window-actions.c
index ed1e639..afa34b1 100644
--- a/src/editor-window-actions.c
+++ b/src/editor-window-actions.c
@@ -158,6 +158,23 @@ editor_window_actions_save_as_cb (GtkWidget *widget,
_editor_page_save_as (page, NULL);
}
+static void
+editor_window_actions_notify_language_cb (EditorDocument *document,
+ GParamSpec *pspec,
+ EditorLanguageDialog *dialog)
+{
+ GtkSourceLanguage *language;
+ const char *language_id = NULL;
+
+ g_assert (EDITOR_IS_DOCUMENT (document));
+ g_assert (EDITOR_IS_LANGUAGE_DIALOG (dialog));
+
+ if ((language = editor_language_dialog_get_language (dialog)))
+ language_id = gtk_source_language_get_id (language);
+
+ _editor_document_persist_syntax_language (document, language_id);
+}
+
static void
editor_window_actions_change_language_cb (GtkWidget *widget,
const char *action_name,
@@ -183,6 +200,17 @@ editor_window_actions_change_language_cb (GtkWidget *widget,
g_object_bind_property (document, "language", dialog, "language",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+ /* We only want to persist the language to underlying storage if the
+ * user changes the value using the language dialog. Otherwise, we can't
+ * update to better content-type discovery in updates of shared-mime-info
+ * or GtkSourceView as they'd be pinned to the first result we ever get.
+ */
+ g_signal_connect_object (dialog,
+ "notify::language",
+ G_CALLBACK (editor_window_actions_notify_language_cb),
+ document,
+ G_CONNECT_SWAPPED);
+
gtk_window_present (GTK_WINDOW (dialog));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]