Revision: 1789 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1789&view=re... Author: colombanw Date: 2010-12-29 14:33:39 +0000 (Wed, 29 Dec 2010)
Log Message: ----------- GeanyGenDoc: Don't copy system file to when opening filetype configuration
Don't unconditionally copy the system configuration file to the user configuration directory when user calls "Edit Current Language Configuration". Now we rather open the current file (as usually chosen) without copying it, so it gets written to the user configuration directory upon save but not before.
This avoids copying useless configuration files to the user directory that may hide new versions of the system configuration.
Modified Paths: -------------- trunk/geany-plugins/geanygendoc/TODO trunk/geany-plugins/geanygendoc/src/ggd-plugin.c trunk/geany-plugins/geanygendoc/src/ggd-utils.c trunk/geany-plugins/geanygendoc/src/ggd-utils.h
Modified: trunk/geany-plugins/geanygendoc/TODO =================================================================== --- trunk/geany-plugins/geanygendoc/TODO 2010-12-27 21:07:26 UTC (rev 1788) +++ trunk/geany-plugins/geanygendoc/TODO 2010-12-29 14:33:39 UTC (rev 1789) @@ -17,12 +17,3 @@
* Add a pop-up menu to the document type selector for common actions (edit, clear, etc.). - -* When user choose "edit current language configuration", don't copy the system - configuration if the user don't have one, but simply open the system one with - the correct path for it to be saved on the user's configurations directory - when actually saved. - This would implement "copy on write" style copying, which would avoid landing - user configuration files just because they opened it once (e.g. by mistake). - This is a real problem since we use user's config first, so they won't get - the possible updates of the default distribution in such cases.
Modified: trunk/geany-plugins/geanygendoc/src/ggd-plugin.c =================================================================== --- trunk/geany-plugins/geanygendoc/src/ggd-plugin.c 2010-12-27 21:07:26 UTC (rev 1788) +++ trunk/geany-plugins/geanygendoc/src/ggd-plugin.c 2010-12-29 14:33:39 UTC (rev 1789) @@ -304,19 +304,50 @@
doc = document_get_current (); if (DOC_VALID (doc)) { - gchar *path; + gchar *path_read; + gchar *path_write; GError *err = NULL;
- path = ggd_file_type_manager_get_conf_path (doc->file_type->id, - GGD_PERM_R | GGD_PERM_W, &err); - if (! path) { + path_write = ggd_file_type_manager_get_conf_path (doc->file_type->id, + GGD_PERM_W | GGD_PERM_NOCREAT, + &err); + if (! path_write) { msgwin_status_add (_("Failed to find configuration file " "for file type "%s": %s"), doc->file_type->name, err->message); g_error_free (err); } else { - document_open_file (path, FALSE, NULL, NULL); - g_free (path); + gchar *text = NULL; + + path_read = ggd_file_type_manager_get_conf_path (doc->file_type->id, + GGD_PERM_R, &err); + if (! path_read) { + text = g_strdup (_( + "# Configuration for this file type doesn't exist yet.\n" + "# To create it, just write it in this file and save it. For the description\n" + "# of the syntax of this file, please refer to the manual.\n" + )); + } else { + gchar *content = NULL; + gsize length; + + if (! g_file_get_contents (path_read, &content, &length, &err)) { + g_warning (_("Failed to load file "%s": %s"), + path_read, err->message); + g_error_free (err); + } else { + text = encodings_convert_to_utf8 (content, length, NULL); + g_free (content); + } + g_free (path_read); + } + /* It's no Ruby, but it is the closest one I've found. It has: + * - # comments + * - multi-line double-quoted strings + */ + document_new_file (path_write, filetypes[GEANY_FILETYPES_RUBY], text); + g_free (text); + g_free (path_write); } } }
Modified: trunk/geany-plugins/geanygendoc/src/ggd-utils.c =================================================================== --- trunk/geany-plugins/geanygendoc/src/ggd-utils.c 2010-12-27 21:07:26 UTC (rev 1788) +++ trunk/geany-plugins/geanygendoc/src/ggd-utils.c 2010-12-29 14:33:39 UTC (rev 1789) @@ -134,6 +134,10 @@ * Configuration files may be either the system-wide or the user-specific ones, * depending on their existence and on the requested permissions. * + * If @GGD_PERM_NOCREAT is not given in @perms_req and @GGD_PERM_W is, the file + * at the returned path will be copied from the system configuration directory, + * or created empty if the system file doesn't exist. + * * Returns: The path for the requested configuration file or %NULL if not found. */ gchar * @@ -193,6 +197,9 @@
g_clear_error (error); set_file_error_from_errno (error, errnum, user_dir); + } else if (perms_req & GGD_PERM_NOCREAT) { + /* just give the user path if user don't want the copy to be done */ + path = user_path; } else { GError *gerr = NULL;
Modified: trunk/geany-plugins/geanygendoc/src/ggd-utils.h =================================================================== --- trunk/geany-plugins/geanygendoc/src/ggd-utils.h 2010-12-27 21:07:26 UTC (rev 1788) +++ trunk/geany-plugins/geanygendoc/src/ggd-utils.h 2010-12-29 14:33:39 UTC (rev 1789) @@ -35,13 +35,16 @@ * @GGD_PERM_R: Read permission * @GGD_PERM_W: Write permission * @GGD_PERM_RW: Both read and write permissions + * @GGD_PERM_NOCREAT: Don't create new files * * Flags representing permissions. */ enum _GgdPerms { - GGD_PERM_R = 1 << 0, - GGD_PERM_W = 1 << 1, - GGD_PERM_RW = GGD_PERM_R | GGD_PERM_W + GGD_PERM_R = 1 << 0, + GGD_PERM_W = 1 << 1, + GGD_PERM_RW = GGD_PERM_R | GGD_PERM_W, + /* a bit ugly, it isn't a permission */ + GGD_PERM_NOCREAT = 1 << 2 };
typedef enum _GgdPerms GgdPerms;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.