From f5d46ef3cce4ee9e73802815e7ec8eecbaa057ad Mon Sep 17 00:00:00 2001 From: Paolo Borelli Date: Thu, 2 Feb 2012 23:25:28 +0100 Subject: [PATCH] Remove the gedit style scheme manager instance Instead of reimplementing our singleton for the style scheme manager, leverage the gtksourceview one, so that plugins can simply obtain it with get_default(). We just need to make sure the search path is set at startup before any document is opened. The utility functions to install/uninstall a style scheme are now in the pref dialog file since in five years we never needed to export them or use them in another context. --- gedit/Makefile.am | 2 - gedit/dialogs/gedit-preferences-dialog.c | 267 ++++++++++++++++-- gedit/gedit-app.c | 12 + gedit/gedit-dirs.c | 11 + gedit/gedit-dirs.h | 2 + gedit/gedit-document.c | 10 +- gedit/gedit-settings.c | 15 +- gedit/gedit-style-scheme-manager.c | 335 ----------------------- gedit/gedit-style-scheme-manager.h | 54 ---- 9 files changed, 283 insertions(+), 425 deletions(-) delete mode 100644 gedit/gedit-style-scheme-manager.c delete mode 100644 gedit/gedit-style-scheme-manager.h diff --git a/gedit/Makefile.am b/gedit/Makefile.am index 2c41ed3935..aac53fa491 100644 --- a/gedit/Makefile.am +++ b/gedit/Makefile.am @@ -123,7 +123,6 @@ NOINST_H_FILES = \ gedit-session.h \ gedit-settings.h \ gedit-status-combo-box.h \ - gedit-style-scheme-manager.h \ gedit-tab-label.h \ gedittextregion.h \ gedit-ui.h \ @@ -208,7 +207,6 @@ libgedit_c_files = \ gedit-settings.c \ gedit-statusbar.c \ gedit-status-combo-box.c \ - gedit-style-scheme-manager.c \ gedit-tab.c \ gedit-tab-label.c \ gedit-utils.c \ diff --git a/gedit/dialogs/gedit-preferences-dialog.c b/gedit/dialogs/gedit-preferences-dialog.c index d58b41a575..74cb254c23 100644 --- a/gedit/dialogs/gedit-preferences-dialog.c +++ b/gedit/dialogs/gedit-preferences-dialog.c @@ -35,15 +35,17 @@ #include #include +#include #include +#include #include +#include #include "gedit-preferences-dialog.h" #include "gedit-utils.h" #include "gedit-debug.h" #include "gedit-document.h" -#include "gedit-style-scheme-manager.h" #include "gedit-dirs.h" #include "gedit-settings.h" #include "gedit-utils.h" @@ -464,16 +466,36 @@ setup_font_colors_page_font_section (GeditPreferencesDialog *dlg) G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET); } +static gboolean +is_gedit_user_style_scheme (const gchar *scheme_id) +{ + GtkSourceStyleSchemeManager *manager; + GtkSourceStyleScheme *scheme; + gboolean res = FALSE; + + manager = gtk_source_style_scheme_manager_get_default (); + scheme = gtk_source_style_scheme_manager_get_scheme (manager, scheme_id); + if (scheme != NULL) + { + const gchar *filename; + + filename = gtk_source_style_scheme_get_filename (scheme); + if (filename != NULL) + { + res = g_str_has_prefix (filename, gedit_dirs_get_user_styles_dir ()); + } + } + + return res; +} + static void set_buttons_sensisitivity_according_to_scheme (GeditPreferencesDialog *dlg, const gchar *scheme_id) { gboolean editable; - - editable = (scheme_id != NULL) && - _gedit_style_scheme_manager_scheme_is_gedit_user_scheme ( - gedit_get_style_scheme_manager (), - scheme_id); + + editable = ((scheme_id != NULL) && is_gedit_user_style_scheme (scheme_id)); gtk_widget_set_sensitive (dlg->priv->uninstall_scheme_button, editable); @@ -509,9 +531,10 @@ static const gchar * ensure_color_scheme_id (GeditPreferencesDialog *dlg, const gchar *id) { + GtkSourceStyleSchemeManager *manager; GtkSourceStyleScheme *scheme = NULL; - GtkSourceStyleSchemeManager *manager = gedit_get_style_scheme_manager (); + manager = gtk_source_style_scheme_manager_get_default (); if (id == NULL) { gchar *pref_id; @@ -545,13 +568,10 @@ ensure_color_scheme_id (GeditPreferencesDialog *dlg, return gtk_source_style_scheme_get_id (scheme); } -/* If def_id is NULL, use the default scheme as returned by - * gedit_style_scheme_manager_get_default_scheme. If this one returns NULL - * use the first available scheme as default */ static const gchar * populate_color_scheme_list (GeditPreferencesDialog *dlg, const gchar *def_id) { - GtkSourceStyleSchemeManager *sm; + GtkSourceStyleSchemeManager *manager; const gchar * const *ids; gint i; @@ -565,8 +585,8 @@ populate_color_scheme_list (GeditPreferencesDialog *dlg, const gchar *def_id) return NULL; } - sm = gedit_get_style_scheme_manager (); - ids = gtk_source_style_scheme_manager_get_scheme_ids (sm); + manager = gtk_source_style_scheme_manager_get_default (); + ids = gtk_source_style_scheme_manager_get_scheme_ids (manager); for (i = 0; ids[i] != NULL; i++) { GtkSourceStyleScheme *scheme; @@ -574,7 +594,7 @@ populate_color_scheme_list (GeditPreferencesDialog *dlg, const gchar *def_id) const gchar *description; GtkTreeIter iter; - scheme = gtk_source_style_scheme_manager_get_scheme (sm, ids[i]); + scheme = gtk_source_style_scheme_manager_get_scheme (manager, ids[i]); name = gtk_source_style_scheme_get_name (scheme); description = gtk_source_style_scheme_get_description (scheme); @@ -600,6 +620,217 @@ populate_color_scheme_list (GeditPreferencesDialog *dlg, const gchar *def_id) return def_id; } +/* + * file_copy: + * @name: a pointer to a %NULL-terminated string, that names + * the file to be copied, in the GLib file name encoding + * @dest_name: a pointer to a %NULL-terminated string, that is the + * name for the destination file, in the GLib file name encoding + * @error: return location for a #GError, or %NULL + * + * Copies file @name to @dest_name. + * + * If the call was successful, it returns %TRUE. If the call was not + * successful, it returns %FALSE and sets @error. The error domain + * is #G_FILE_ERROR. Possible error + * codes are those in the #GFileError enumeration. + * + * Return value: %TRUE on success, %FALSE otherwise. + */ +static gboolean +file_copy (const gchar *name, + const gchar *dest_name, + GError **error) +{ + gchar *contents; + gsize length; + gchar *dest_dir; + + /* FIXME - Paolo (Aug. 13, 2007): + * Since the style scheme files are relatively small, we can implement + * file copy getting all the content of the source file in a buffer and + * then write the content to the destination file. In this way we + * can use the g_file_get_contents and g_file_set_contents and avoid to + * write custom code to copy the file (with sane error management). + * If needed we can improve this code later. */ + + g_return_val_if_fail (name != NULL, FALSE); + g_return_val_if_fail (dest_name != NULL, FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + /* Note: we allow to copy a file to itself since this is not a problem + * in our use case */ + + /* Ensure the destination directory exists */ + dest_dir = g_path_get_dirname (dest_name); + + errno = 0; + if (g_mkdir_with_parents (dest_dir, 0755) != 0) + { + gint save_errno = errno; + gchar *display_filename = g_filename_display_name (dest_dir); + + g_set_error (error, + G_FILE_ERROR, + g_file_error_from_errno (save_errno), + _("Directory '%s' could not be created: g_mkdir_with_parents() failed: %s"), + display_filename, + g_strerror (save_errno)); + + g_free (dest_dir); + g_free (display_filename); + + return FALSE; + } + + g_free (dest_dir); + + if (!g_file_get_contents (name, &contents, &length, error)) + return FALSE; + + if (!g_file_set_contents (dest_name, contents, length, error)) + return FALSE; + + g_free (contents); + + return TRUE; +} + +/* + * install_style_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 #GEDIT_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. + */ +static const gchar * +install_style_scheme (const gchar *fname) +{ + GtkSourceStyleSchemeManager *manager; + gchar *new_file_name = NULL; + gchar *dirname; + const gchar *styles_dir; + GError *error = NULL; + gboolean copied = FALSE; + const gchar* const *ids; + + g_return_val_if_fail (fname != NULL, NULL); + + manager = gtk_source_style_scheme_manager_get_default (); + + dirname = g_path_get_dirname (fname); + styles_dir = gedit_dirs_get_user_styles_dir (); + + 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 GEDIT_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); + + /* 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 (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; +} + +/** + * uninstall_style_scheme: + * @manager: a #GtkSourceStyleSchemeManager + * @id: the id of the style scheme to be uninstalled + * + * Uninstall a user scheme. + * + * If the call was succesful, it returns %TRUE + * otherwise %FALSE. + * + * Return value: %TRUE on success, %FALSE otherwise. + */ +static gboolean +uninstall_style_scheme (const gchar *id) +{ + GtkSourceStyleSchemeManager *manager; + GtkSourceStyleScheme *scheme; + const gchar *filename; + + g_return_val_if_fail (id != NULL, FALSE); + + manager = gtk_source_style_scheme_manager_get_default (); + + scheme = gtk_source_style_scheme_manager_get_scheme (manager, id); + if (scheme == NULL) + return FALSE; + + filename = gtk_source_style_scheme_get_filename (scheme); + if (filename == NULL) + return FALSE; + + if (g_unlink (filename) == -1) + return FALSE; + + /* Reload the available style schemes */ + gtk_source_style_scheme_manager_force_rescan (manager); + + return TRUE; +} + static void add_scheme_chooser_response_cb (GtkDialog *chooser, gint res_id, @@ -619,10 +850,8 @@ add_scheme_chooser_response_cb (GtkDialog *chooser, return; gtk_widget_hide (GTK_WIDGET (chooser)); - - scheme_id = _gedit_style_scheme_manager_install_scheme ( - gedit_get_style_scheme_manager (), - filename); + + scheme_id = install_style_scheme (filename); g_free (filename); if (scheme_id == NULL) @@ -719,7 +948,7 @@ uninstall_scheme_clicked (GtkButton *button, NAME_COLUMN, &name, -1); - if (!_gedit_style_scheme_manager_uninstall_scheme (gedit_get_style_scheme_manager (), id)) + if (!uninstall_style_scheme (id)) { gedit_warning (GTK_WINDOW (dlg), _("Could not remove color scheme \"%s\"."), diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c index 0629268534..49a496c71d 100644 --- a/gedit/gedit-app.c +++ b/gedit/gedit-app.c @@ -37,6 +37,7 @@ #include #include +#include #include "gedit-app.h" #include "gedit-commands.h" @@ -652,6 +653,8 @@ extension_removed (PeasExtensionSet *extensions, static void gedit_app_init (GeditApp *app) { + GtkSourceStyleSchemeManager *manager; + app->priv = GEDIT_APP_GET_PRIVATE (app); /* Load settings */ @@ -661,6 +664,15 @@ gedit_app_init (GeditApp *app) /* initial lockdown state */ app->priv->lockdown = gedit_settings_get_lockdown (GEDIT_SETTINGS (app->priv->settings)); + /* + * We use the default gtksourceview style scheme manager so that plugins + * can obtain it easily without a gedit specific api, but we need to + * add our search path at startup before the manager is actually used. + */ + manager = gtk_source_style_scheme_manager_get_default (); + gtk_source_style_scheme_manager_append_search_path (manager, + gedit_dirs_get_user_styles_dir ()); + app->priv->extensions = peas_extension_set_new (PEAS_ENGINE (gedit_plugins_engine_get_default ()), GEDIT_TYPE_APP_ACTIVATABLE, "app", app, diff --git a/gedit/gedit-dirs.c b/gedit/gedit-dirs.c index 87eb5dff7e..79057e36d3 100644 --- a/gedit/gedit-dirs.c +++ b/gedit/gedit-dirs.c @@ -32,6 +32,7 @@ static gchar *user_config_dir = NULL; static gchar *user_cache_dir = NULL; +static gchar *user_styles_dir = NULL; static gchar *user_plugins_dir = NULL; static gchar *gedit_data_dir = NULL; static gchar *gedit_locale_dir = NULL; @@ -101,6 +102,10 @@ gedit_dirs_init () user_config_dir = g_build_filename (g_get_user_config_dir (), "gedit", NULL); + user_styles_dir = g_build_filename (g_get_user_data_dir (), + "gedit", + "styles", + NULL); user_plugins_dir = g_build_filename (g_get_user_data_dir (), "gedit", "plugins", @@ -138,6 +143,12 @@ gedit_dirs_get_user_cache_dir (void) return user_cache_dir; } +const gchar * +gedit_dirs_get_user_styles_dir (void) +{ + return user_styles_dir; +} + const gchar * gedit_dirs_get_user_plugins_dir (void) { diff --git a/gedit/gedit-dirs.h b/gedit/gedit-dirs.h index 95af4e5c49..eae4f09d0d 100644 --- a/gedit/gedit-dirs.h +++ b/gedit/gedit-dirs.h @@ -38,6 +38,8 @@ const gchar *gedit_dirs_get_user_config_dir (void); const gchar *gedit_dirs_get_user_cache_dir (void); +const gchar *gedit_dirs_get_user_styles_dir (void); + const gchar *gedit_dirs_get_user_plugins_dir (void); const gchar *gedit_dirs_get_gedit_data_dir (void); diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c index 61bf520add..c60b9cc0f0 100644 --- a/gedit/gedit-document.c +++ b/gedit/gedit-document.c @@ -38,13 +38,13 @@ #include #include +#include #include "gedit-settings.h" #include "gedit-document.h" #include "gedit-debug.h" #include "gedit-utils.h" #include "gedit-language-manager.h" -#include "gedit-style-scheme-manager.h" #include "gedit-document-loader.h" #include "gedit-document-saver.h" #include "gedit-marshal.h" @@ -795,15 +795,13 @@ set_encoding (GeditDocument *doc, static GtkSourceStyleScheme * get_default_style_scheme (GSettings *editor_settings) { + GtkSourceStyleSchemeManager *manager; gchar *scheme_id; GtkSourceStyleScheme *def_style; - GtkSourceStyleSchemeManager *manager; - manager = gedit_get_style_scheme_manager (); + manager = gtk_source_style_scheme_manager_get_default (); scheme_id = g_settings_get_string (editor_settings, GEDIT_SETTINGS_SCHEME); - def_style = gtk_source_style_scheme_manager_get_scheme (manager, - scheme_id); - + def_style = gtk_source_style_scheme_manager_get_scheme (manager, scheme_id); if (def_style == NULL) { g_warning ("Default style scheme '%s' cannot be found, falling back to 'classic' style scheme ", scheme_id); diff --git a/gedit/gedit-settings.c b/gedit/gedit-settings.c index cbc24c25e2..a6bb6035c1 100644 --- a/gedit/gedit-settings.c +++ b/gedit/gedit-settings.c @@ -23,13 +23,14 @@ #include +#include + #include "gedit-settings.h" #include "gedit-app.h" #include "gedit-debug.h" #include "gedit-view.h" #include "gedit-window.h" #include "gedit-plugins-engine.h" -#include "gedit-style-scheme-manager.h" #include "gedit-dirs.h" #include "gedit-utils.h" #include "gedit-window-private.h" @@ -209,6 +210,7 @@ on_scheme_changed (GSettings *settings, const gchar *key, GeditSettings *gs) { + GtkSourceStyleSchemeManager *manager; GtkSourceStyleScheme *style; gchar *scheme; GList *docs; @@ -226,18 +228,13 @@ on_scheme_changed (GSettings *settings, g_free (gs->priv->old_scheme); gs->priv->old_scheme = scheme; - style = gtk_source_style_scheme_manager_get_scheme ( - gedit_get_style_scheme_manager (), - scheme); - + manager = gtk_source_style_scheme_manager_get_default (); + style = gtk_source_style_scheme_manager_get_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 ( - gedit_get_style_scheme_manager (), - "classic"); + style = gtk_source_style_scheme_manager_get_scheme (manager, "classic"); if (style == NULL) { g_warning ("Style scheme 'classic' cannot be found, check your GtkSourceView installation."); diff --git a/gedit/gedit-style-scheme-manager.c b/gedit/gedit-style-scheme-manager.c deleted file mode 100644 index f4038946c6..0000000000 --- a/gedit/gedit-style-scheme-manager.c +++ /dev/null @@ -1,335 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * gedit-source-style-manager.c - * - * Copyright (C) 2007 - Paolo Borelli and Paolo Maggi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the gedit Team, 2007. See the AUTHORS file for a - * list of people on the gedit Team. - * See the ChangeLog files for a list of changes. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include -#include - -#include "gedit-style-scheme-manager.h" -#include "gedit-dirs.h" - -static GtkSourceStyleSchemeManager *style_scheme_manager = NULL; - -static gchar * -get_gedit_styles_path (void) -{ - const gchar *config_dir; - gchar *dir = NULL; - - config_dir = gedit_dirs_get_user_config_dir (); - - if (config_dir != NULL) - { - dir = g_build_filename (config_dir, - "styles", - NULL); - } - - return dir; -} - -static void -add_gedit_styles_path (GtkSourceStyleSchemeManager *mgr) -{ - gchar *dir; - - dir = get_gedit_styles_path (); - - if (dir != NULL) - { - gtk_source_style_scheme_manager_append_search_path (mgr, dir); - g_free (dir); - } -} - -/** - * gedit_get_style_scheme_manager: - * - * Returns the unique #GtkSourceStyleSchemeManager instance used by gedit. - * - * Return value: (transfer none): the unique #GtkSourceStyleSchemeManager instance. - */ -GtkSourceStyleSchemeManager * -gedit_get_style_scheme_manager (void) -{ - if (style_scheme_manager == NULL) - { - style_scheme_manager = gtk_source_style_scheme_manager_new (); - add_gedit_styles_path (style_scheme_manager); - } - - return style_scheme_manager; -} - -gboolean -_gedit_style_scheme_manager_scheme_is_gedit_user_scheme (GtkSourceStyleSchemeManager *manager, - const gchar *scheme_id) -{ - GtkSourceStyleScheme *scheme; - gboolean res = FALSE; - - scheme = gtk_source_style_scheme_manager_get_scheme (manager, scheme_id); - if (scheme != NULL) - { - const gchar *filename; - - filename = gtk_source_style_scheme_get_filename (scheme); - if (filename != NULL) - { - gchar *dir; - - dir = get_gedit_styles_path (); - res = g_str_has_prefix (filename, dir); - g_free (dir); - } - } - - return res; -} - -/** - * file_copy: - * @name: a pointer to a %NULL-terminated string, that names - * the file to be copied, in the GLib file name encoding - * @dest_name: a pointer to a %NULL-terminated string, that is the - * name for the destination file, in the GLib file name encoding - * @error: return location for a #GError, or %NULL - * - * Copies file @name to @dest_name. - * - * If the call was successful, it returns %TRUE. If the call was not - * successful, it returns %FALSE and sets @error. The error domain - * is #G_FILE_ERROR. Possible error - * codes are those in the #GFileError enumeration. - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -static gboolean -file_copy (const gchar *name, - const gchar *dest_name, - GError **error) -{ - gchar *contents; - gsize length; - gchar *dest_dir; - - /* FIXME - Paolo (Aug. 13, 2007): - * Since the style scheme files are relatively small, we can implement - * file copy getting all the content of the source file in a buffer and - * then write the content to the destination file. In this way we - * can use the g_file_get_contents and g_file_set_contents and avoid to - * write custom code to copy the file (with sane error management). - * If needed we can improve this code later. */ - - g_return_val_if_fail (name != NULL, FALSE); - g_return_val_if_fail (dest_name != NULL, FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - /* Note: we allow to copy a file to itself since this is not a problem - * in our use case */ - - /* Ensure the destination directory exists */ - dest_dir = g_path_get_dirname (dest_name); - - errno = 0; - if (g_mkdir_with_parents (dest_dir, 0755) != 0) - { - gint save_errno = errno; - gchar *display_filename = g_filename_display_name (dest_dir); - - g_set_error (error, - G_FILE_ERROR, - g_file_error_from_errno (save_errno), - _("Directory '%s' could not be created: g_mkdir_with_parents() failed: %s"), - display_filename, - g_strerror (save_errno)); - - g_free (dest_dir); - g_free (display_filename); - - return FALSE; - } - - g_free (dest_dir); - - if (!g_file_get_contents (name, &contents, &length, error)) - return FALSE; - - if (!g_file_set_contents (dest_name, contents, length, error)) - return FALSE; - - g_free (contents); - - return TRUE; -} - -/** - * _gedit_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 #GEDIT_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 * -_gedit_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_SOURCE_IS_STYLE_SCHEME_MANAGER (manager), NULL); - g_return_val_if_fail (fname != NULL, NULL); - - dirname = g_path_get_dirname (fname); - styles_dir = get_gedit_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 GEDIT_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 ( - gedit_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; -} - -/** - * _gedit_style_scheme_manager_uninstall_scheme: - * @manager: a #GtkSourceStyleSchemeManager - * @id: the id of the style scheme to be uninstalled - * - * Uninstall a user scheme. - * - * If the call was succesful, it returns %TRUE - * otherwise %FALSE. - * - * Return value: %TRUE on success, %FALSE otherwise. - */ -gboolean -_gedit_style_scheme_manager_uninstall_scheme (GtkSourceStyleSchemeManager *manager, - const gchar *id) -{ - GtkSourceStyleScheme *scheme; - const gchar *filename; - - g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager), FALSE); - g_return_val_if_fail (id != NULL, FALSE); - - scheme = gtk_source_style_scheme_manager_get_scheme (manager, id); - if (scheme == NULL) - return FALSE; - - filename = gtk_source_style_scheme_get_filename (scheme); - if (filename == NULL) - return FALSE; - - if (g_unlink (filename) == -1) - return FALSE; - - /* Reload the available style schemes */ - gtk_source_style_scheme_manager_force_rescan (manager); - - return TRUE; -} - -/* ex:set ts=8 noet: */ diff --git a/gedit/gedit-style-scheme-manager.h b/gedit/gedit-style-scheme-manager.h deleted file mode 100644 index 3be1b2fb06..0000000000 --- a/gedit/gedit-style-scheme-manager.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * gedit-style-scheme-manager.h - * - * Copyright (C) 2007 - Paolo Borelli - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307, USA. - * - * $Id: gedit-source-style-manager.h 5598 2007-04-15 13:16:24Z pborelli $ - */ - -#ifndef __GEDIT_STYLE_SCHEME_MANAGER_H__ -#define __GEDIT_STYLE_SCHEME_MANAGER_H__ - -#include - -G_BEGIN_DECLS - -GtkSourceStyleSchemeManager * - gedit_get_style_scheme_manager (void); - -/* - * Non exported functions - */ -gboolean _gedit_style_scheme_manager_scheme_is_gedit_user_scheme - (GtkSourceStyleSchemeManager *manager, - const gchar *scheme_id); - -const gchar *_gedit_style_scheme_manager_install_scheme - (GtkSourceStyleSchemeManager *manager, - const gchar *fname); - -gboolean _gedit_style_scheme_manager_uninstall_scheme - (GtkSourceStyleSchemeManager *manager, - const gchar *id); - -G_END_DECLS - -#endif /* __GEDIT_STYLE_SCHEME_MANAGER_H__ */ - -/* ex:set ts=8 noet: */