static void pluma_prefs_manager_source_style_scheme_changed (GSettings *settings, gchar *key, gpointer user_data) { pluma_debug (DEBUG_PREFS); if (strcmp (key, GPM_SOURCE_STYLE_SCHEME) == 0) { static gchar *old_scheme = NULL; gchar *scheme; GtkSourceStyleScheme *style; GList *docs; GList *l; scheme = g_settings_get_string (settings, key); if (old_scheme != NULL && (strcmp (scheme, old_scheme) == 0)) return; g_free (old_scheme); old_scheme = scheme; style = gtk_source_style_scheme_manager_get_scheme ( pluma_get_style_scheme_manager (), scheme); if (style == NULL) { g_warning ("Default style scheme '%s' not found, falling back to 'classic'", scheme); style = gtk_source_style_scheme_manager_get_scheme ( pluma_get_style_scheme_manager (), "classic"); if (style == NULL) { g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); return; } } docs = pluma_app_get_documents (pluma_app_get_default ()); for (l = docs; l != NULL; l = l->next) { g_return_if_fail (GTK_SOURCE_IS_BUFFER (l->data)); gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (l->data), style); } g_list_free (docs); } }
/** * _pluma_style_scheme_manager_install_scheme: * @manager: a #GtkSourceStyleSchemeManager * @fname: the file name of the style scheme to be installed * * Install a new user scheme. * This function copies @fname in #PLUMA_STYLES_DIR and ask the style manager to * recompute the list of available style schemes. It then checks if a style * scheme with the right file name exists. * * If the call was succesful, it returns the id of the installed scheme * otherwise %NULL. * * Return value: the id of the installed scheme, %NULL otherwise. */ const gchar * _pluma_style_scheme_manager_install_scheme (GtkSourceStyleSchemeManager *manager, const gchar *fname) { gchar *new_file_name = NULL; gchar *dirname; gchar *styles_dir; GError *error = NULL; gboolean copied = FALSE; const gchar* const *ids; g_return_val_if_fail (GTK_IS_SOURCE_STYLE_SCHEME_MANAGER (manager), NULL); g_return_val_if_fail (fname != NULL, NULL); dirname = g_path_get_dirname (fname); styles_dir = get_pluma_styles_path(); if (strcmp (dirname, styles_dir) != 0) { gchar *basename; basename = g_path_get_basename (fname); new_file_name = g_build_filename (styles_dir, basename, NULL); g_free (basename); /* Copy the style scheme file into PLUMA_STYLES_DIR */ if (!file_copy (fname, new_file_name, &error)) { g_free (new_file_name); g_message ("Cannot install style scheme:\n%s", error->message); return NULL; } copied = TRUE; } else { new_file_name = g_strdup (fname); } g_free (dirname); g_free (styles_dir); /* Reload the available style schemes */ gtk_source_style_scheme_manager_force_rescan (manager); /* Check the new style scheme has been actually installed */ ids = gtk_source_style_scheme_manager_get_scheme_ids (manager); while (*ids != NULL) { GtkSourceStyleScheme *scheme; const gchar *filename; scheme = gtk_source_style_scheme_manager_get_scheme ( pluma_get_style_scheme_manager (), *ids); filename = gtk_source_style_scheme_get_filename (scheme); if (filename && (strcmp (filename, new_file_name) == 0)) { /* The style scheme has been correctly installed */ g_free (new_file_name); return gtk_source_style_scheme_get_id (scheme); } ++ids; } /* The style scheme has not been correctly installed */ if (copied) g_unlink (new_file_name); g_free (new_file_name); return NULL; }