static void gedit_document_dispose (GObject *object) { GeditDocumentPrivate *priv; gedit_debug (DEBUG_DOCUMENT); priv = gedit_document_get_instance_private (GEDIT_DOCUMENT (object)); /* Metadata must be saved here and not in finalize because the language * is gone by the time finalize runs. */ if (priv->file != NULL) { save_metadata (GEDIT_DOCUMENT (object)); g_object_unref (priv->file); priv->file = NULL; } g_clear_object (&priv->editor_settings); g_clear_object (&priv->metadata_info); g_clear_object (&priv->search_context); G_OBJECT_CLASS (gedit_document_parent_class)->dispose (object); }
static void update_empty_search (GeditDocument *doc) { GeditDocumentPrivate *priv; gboolean new_value; priv = gedit_document_get_instance_private (doc); if (priv->search_context == NULL) { new_value = TRUE; } else { GtkSourceSearchSettings *search_settings; search_settings = gtk_source_search_context_get_settings (priv->search_context); new_value = gtk_source_search_settings_get_search_text (search_settings) == NULL; } if (priv->empty_search != new_value) { priv->empty_search = new_value; g_object_notify (G_OBJECT (doc), "empty-search"); } }
/** * gedit_document_get_short_name_for_display: * @doc: a #GeditDocument. * * Note: this never returns %NULL. **/ gchar * gedit_document_get_short_name_for_display (GeditDocument *doc) { GeditDocumentPrivate *priv; GFile *location; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), g_strdup ("")); priv = gedit_document_get_instance_private (doc); location = gtk_source_file_get_location (priv->file); if (priv->short_name != NULL) { return g_strdup (priv->short_name); } else if (location == NULL) { return g_strdup_printf (_("Unsaved Document %d"), priv->untitled_number); } else { return gedit_utils_basename_for_display (location); } }
static void gedit_document_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GeditDocument *doc = GEDIT_DOCUMENT (object); GeditDocumentPrivate *priv = gedit_document_get_instance_private (doc); switch (prop_id) { case PROP_SHORTNAME: G_GNUC_BEGIN_IGNORE_DEPRECATIONS; gedit_document_set_short_name_for_display (doc, g_value_get_string (value)); G_GNUC_END_IGNORE_DEPRECATIONS; break; case PROP_CONTENT_TYPE: set_content_type (doc, g_value_get_string (value)); break; case PROP_USE_GVFS_METADATA: priv->use_gvfs_metadata = g_value_get_boolean (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void set_language (GeditDocument *doc, GtkSourceLanguage *lang, gboolean set_by_user) { GeditDocumentPrivate *priv; GtkSourceLanguage *old_lang; gedit_debug (DEBUG_DOCUMENT); priv = gedit_document_get_instance_private (doc); old_lang = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (doc)); if (old_lang == lang) { return; } gtk_source_buffer_set_language (GTK_SOURCE_BUFFER (doc), lang); if (set_by_user) { const gchar *language = get_language_string (doc); gedit_document_set_metadata (doc, GEDIT_METADATA_ATTRIBUTE_LANGUAGE, language, NULL); } priv->language_set_by_user = set_by_user; }
/* * Deletion and external modification is only checked for local files. */ gboolean _gedit_document_needs_saving (GeditDocument *doc) { GeditDocumentPrivate *priv; gboolean externally_modified = FALSE; gboolean deleted = FALSE; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE); priv = gedit_document_get_instance_private (doc); if (gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc))) { return TRUE; } if (gtk_source_file_is_local (priv->file)) { gtk_source_file_check_file_on_disk (priv->file); externally_modified = gtk_source_file_is_externally_modified (priv->file); deleted = gtk_source_file_is_deleted (priv->file); } return (externally_modified || deleted) && !priv->create; }
static void set_content_type (GeditDocument *doc, const gchar *content_type) { GeditDocumentPrivate *priv; gedit_debug (DEBUG_DOCUMENT); priv = gedit_document_get_instance_private (doc); if (content_type == NULL) { GFile *location; gchar *guessed_type = NULL; /* If content type is null, we guess from the filename */ location = gtk_source_file_get_location (priv->file); if (location != NULL) { gchar *basename; basename = g_file_get_basename (location); guessed_type = g_content_type_guess (basename, NULL, 0, NULL); g_free (basename); } set_content_type_no_guess (doc, guessed_type); g_free (guessed_type); } else { set_content_type_no_guess (doc, content_type); } }
static void gedit_document_init (GeditDocument *doc) { GeditDocumentPrivate *priv; GtkSourceStyleScheme *style_scheme; gedit_debug (DEBUG_DOCUMENT); doc->priv = gedit_document_get_instance_private (doc); priv = doc->priv; priv->editor_settings = g_settings_new ("org.gnome.gedit.preferences.editor"); priv->untitled_number = get_untitled_number (); priv->content_type = get_default_content_type (); priv->readonly = FALSE; priv->language_set_by_user = FALSE; priv->empty_search = TRUE; g_get_current_time (&doc->priv->time_of_last_save_or_load); priv->file = gtk_source_file_new (); g_signal_connect_object (priv->file, "notify::location", G_CALLBACK (on_location_changed), doc, 0); g_settings_bind (priv->editor_settings, GEDIT_SETTINGS_MAX_UNDO_ACTIONS, doc, "max-undo-levels", G_SETTINGS_BIND_GET); g_settings_bind (priv->editor_settings, GEDIT_SETTINGS_BRACKET_MATCHING, doc, "highlight-matching-brackets", G_SETTINGS_BIND_GET); style_scheme = get_default_style_scheme (priv->editor_settings); if (style_scheme != NULL) { gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (doc), style_scheme); } g_signal_connect (doc, "notify::content-type", G_CALLBACK (on_content_type_changed), NULL); }
/** * gedit_document_get_deleted: * @doc: a #GeditDocument. * * Returns: whether the file has been deleted. * * Deprecated: 3.18: Unused function. */ gboolean gedit_document_get_deleted (GeditDocument *doc) { GeditDocumentPrivate *priv; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE); priv = gedit_document_get_instance_private (doc); return gtk_source_file_is_deleted (priv->file); }
gboolean gedit_document_is_untitled (GeditDocument *doc) { GeditDocumentPrivate *priv; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), TRUE); priv = gedit_document_get_instance_private (doc); return gtk_source_file_get_location (priv->file) == NULL; }
/** * gedit_document_get_search_context: * @doc: a #GeditDocument * * Gets the search context. Use this function only if you have used * gedit_document_set_search_context() before. You should not alter other search * contexts, so you have to verify that the returned search context is yours. * One way to verify that is to compare the search settings object, or to mark * the search context with g_object_set_data(). * * Returns: (transfer none): the current search context of the document, or NULL * if there is no current search context. */ GtkSourceSearchContext * gedit_document_get_search_context (GeditDocument *doc) { GeditDocumentPrivate *priv; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL); priv = gedit_document_get_instance_private (doc); return priv->search_context; }
/** * gedit_document_get_compression_type: * @doc: a #GeditDocument. * * Returns: the compression type. * Deprecated: 3.14: use gtk_source_file_get_compression_type() instead. */ GtkSourceCompressionType gedit_document_get_compression_type (GeditDocument *doc) { GeditDocumentPrivate *priv; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), 0); priv = gedit_document_get_instance_private (doc); return gtk_source_file_get_compression_type (priv->file); }
gboolean _gedit_document_get_create (GeditDocument *doc) { GeditDocumentPrivate *priv; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE); priv = gedit_document_get_instance_private (doc); return priv->create; }
/** * gedit_document_get_encoding: * @doc: a #GeditDocument. * * Returns: the encoding. * Deprecated: 3.14: use gtk_source_file_get_encoding() instead. */ const GtkSourceEncoding * gedit_document_get_encoding (GeditDocument *doc) { GeditDocumentPrivate *priv; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL); priv = gedit_document_get_instance_private (doc); return gtk_source_file_get_encoding (priv->file); }
gchar * gedit_document_get_content_type (GeditDocument *doc) { GeditDocumentPrivate *priv; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL); priv = gedit_document_get_instance_private (doc); return g_strdup (priv->content_type); }
gboolean _gedit_document_get_empty_search (GeditDocument *doc) { GeditDocumentPrivate *priv; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), TRUE); priv = gedit_document_get_instance_private (doc); return priv->empty_search; }
/** * gedit_document_get_file: * @doc: a #GeditDocument. * * Gets the associated #GtkSourceFile. You should use it only for reading * purposes, not for creating a #GtkSourceFileLoader or #GtkSourceFileSaver, * because gedit does some extra work when loading or saving a file and * maintains an internal state. If you use in a plugin a file loader or saver on * the returned #GtkSourceFile, the internal state of gedit won't be updated. * * If you want to save the #GeditDocument to a secondary file, you can create a * new #GtkSourceFile and use a #GtkSourceFileSaver. * * Returns: (transfer none): the associated #GtkSourceFile. * Since: 3.14 */ GtkSourceFile * gedit_document_get_file (GeditDocument *doc) { GeditDocumentPrivate *priv; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL); priv = gedit_document_get_instance_private (doc); return priv->file; }
void _gedit_document_set_create (GeditDocument *doc, gboolean create) { GeditDocumentPrivate *priv; g_return_if_fail (GEDIT_IS_DOCUMENT (doc)); priv = gedit_document_get_instance_private (doc); priv->create = create != FALSE; }
/** * gedit_document_get_location: * @doc: a #GeditDocument * * Returns: (allow-none) (transfer full): a copy of the internal #GFile * * Deprecated: 3.14: use gtk_source_file_get_location() instead. Attention, * gedit_document_get_location() has a transfer full for the return value, while * gtk_source_file_get_location() has a transfer none. */ GFile * gedit_document_get_location (GeditDocument *doc) { GeditDocumentPrivate *priv; GFile *location; priv = gedit_document_get_instance_private (doc); g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL); location = gtk_source_file_get_location (priv->file); return location != NULL ? g_object_ref (location) : NULL; }
static void gedit_document_end_user_action (GtkTextBuffer *buffer) { GeditDocumentPrivate *priv; priv = gedit_document_get_instance_private (GEDIT_DOCUMENT (buffer)); --priv->user_action; if (GTK_TEXT_BUFFER_CLASS (gedit_document_parent_class)->end_user_action != NULL) { GTK_TEXT_BUFFER_CLASS (gedit_document_parent_class)->end_user_action (buffer); } }
/** * gedit_document_set_location: * @doc: a #GeditDocument. * @location: the new location. * * Deprecated: 3.14: use gtk_source_file_set_location() instead. */ void gedit_document_set_location (GeditDocument *doc, GFile *location) { GeditDocumentPrivate *priv; g_return_if_fail (GEDIT_IS_DOCUMENT (doc)); g_return_if_fail (G_IS_FILE (location)); priv = gedit_document_get_instance_private (doc); gtk_source_file_set_location (priv->file, location); set_content_type (doc, NULL); }
gboolean gedit_document_is_untouched (GeditDocument *doc) { GeditDocumentPrivate *priv; GFile *location; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), TRUE); priv = gedit_document_get_instance_private (doc); location = gtk_source_file_get_location (priv->file); return location == NULL && !gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)); }
static GtkSourceLanguage * guess_language (GeditDocument *doc) { GeditDocumentPrivate *priv; gchar *data; GtkSourceLanguageManager *manager = gtk_source_language_manager_get_default (); GtkSourceLanguage *language = NULL; priv = gedit_document_get_instance_private (doc); data = gedit_document_get_metadata (doc, GEDIT_METADATA_ATTRIBUTE_LANGUAGE); if (data != NULL) { gedit_debug_message (DEBUG_DOCUMENT, "Language from metadata: %s", data); if (!g_str_equal (data, NO_LANGUAGE_NAME)) { language = gtk_source_language_manager_get_language (manager, data); } g_free (data); } else { GFile *location; gchar *basename = NULL; location = gtk_source_file_get_location (priv->file); gedit_debug_message (DEBUG_DOCUMENT, "Sniffing Language"); if (location != NULL) { basename = g_file_get_basename (location); } else if (priv->short_name != NULL) { basename = g_strdup (priv->short_name); } language = gtk_source_language_manager_guess_language (manager, basename, priv->content_type); g_free (basename); } return language; }
/** * gedit_document_set_short_name_for_display: * @doc: * @short_name: (allow-none): * * Deprecated: 3.18: Unused function. The intent is to change the * #GeditDocument:shortname property to be read-only. */ void gedit_document_set_short_name_for_display (GeditDocument *doc, const gchar *short_name) { GeditDocumentPrivate *priv; g_return_if_fail (GEDIT_IS_DOCUMENT (doc)); priv = gedit_document_get_instance_private (doc); g_free (priv->short_name); priv->short_name = g_strdup (short_name); g_object_notify (G_OBJECT (doc), "shortname"); }
/** * gedit_document_set_short_name_for_display: * @doc: * @short_name: (allow-none): * * Deprecated: 3.18: Unused function. The intent is to change the * #GeditDocument:shortname property to be read-only. */ void gedit_document_set_short_name_for_display (GeditDocument *doc, const gchar *short_name) { GeditDocumentPrivate *priv; g_return_if_fail (GEDIT_IS_DOCUMENT (doc)); priv = gedit_document_get_instance_private (doc); g_free (priv->short_name); priv->short_name = g_strdup (short_name); g_object_notify_by_pspec (G_OBJECT (doc), properties[PROP_SHORTNAME]); }
glong _gedit_document_get_seconds_since_last_save_or_load (GeditDocument *doc) { GeditDocumentPrivate *priv; GTimeVal current_time; gedit_debug (DEBUG_DOCUMENT); g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), -1); priv = gedit_document_get_instance_private (doc); g_get_current_time (¤t_time); return (current_time.tv_sec - priv->time_of_last_save_or_load.tv_sec); }
static gchar * get_metadata_from_gvfs (GeditDocument *doc, const gchar *key) { GeditDocumentPrivate *priv; priv = gedit_document_get_instance_private (doc); if (priv->metadata_info != NULL && g_file_info_has_attribute (priv->metadata_info, key)) { return g_strdup (g_file_info_get_attribute_string (priv->metadata_info, key)); } return NULL; }
static void gedit_document_constructed (GObject *object) { GeditDocument *doc = GEDIT_DOCUMENT (object); GeditDocumentPrivate *priv; priv = gedit_document_get_instance_private (doc); /* Bind construct properties. */ g_settings_bind (priv->editor_settings, GEDIT_SETTINGS_ENSURE_TRAILING_NEWLINE, doc, "implicit-trailing-newline", G_SETTINGS_BIND_GET | G_SETTINGS_BIND_NO_SENSITIVITY); G_OBJECT_CLASS (gedit_document_parent_class)->constructed (object); }
static void saved_query_info_cb (GFile *location, GAsyncResult *result, GeditDocument *doc) { GeditDocumentPrivate *priv; GFileInfo *info; const gchar *content_type = NULL; GError *error = NULL; priv = gedit_document_get_instance_private (doc); info = g_file_query_info_finish (location, result, &error); if (error != NULL) { g_warning ("Document saving: query info error: %s", error->message); g_error_free (error); error = NULL; } if (info != NULL && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE)) { content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); } set_content_type (doc, content_type); if (info != NULL) { /* content_type (owned by info) is no longer needed. */ g_object_unref (info); } g_get_current_time (&priv->time_of_last_save_or_load); priv->create = FALSE; gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), FALSE); save_encoding_metadata (doc); /* Async operation finished. */ g_object_unref (doc); }
/** * gedit_document_get_mime_type: * @doc: a #GeditDocument. * * Note: this never returns %NULL. **/ gchar * gedit_document_get_mime_type (GeditDocument *doc) { GeditDocumentPrivate *priv; g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), g_strdup ("text/plain")); priv = gedit_document_get_instance_private (doc); if (priv->content_type != NULL && !g_content_type_is_unknown (priv->content_type)) { return g_content_type_get_mime_type (priv->content_type); } return g_strdup ("text/plain"); }