This pull-request implements saving and loading of the pretty-printer plugin preferences. In the current version pretty-printer simply does not save the preferences to a file so all changes to the preferences get lost after closing geany.
The code for saving and loading the preferences is adopted from the overview plugin. The config file is named ```geany/plugins/pretty-printer/prefs.conf```. You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany-plugins/pull/581
-- Commit Summary --
* pretty-printer: added saving and loading of preferences in/from a file. Fixes #494.
-- File Changes --
M pretty-printer/src/ConfigUI.c (206) M pretty-printer/src/ConfigUI.h (4) M pretty-printer/src/PluginEntry.c (76) M pretty-printer/src/PrettyPrinter.c (2)
-- Patch Links --
https://github.com/geany/geany-plugins/pull/581.patch https://github.com/geany/geany-plugins/pull/581.diff
Thannoy commented on this pull request.
@@ -118,9 +119,204 @@ void saveSettings(void)
ppo->indentChar = gtk_combo_box_get_active(GTK_COMBO_BOX(indentationChar))==0 ? '\t' : ' ';
breakStyle = gtk_combo_box_get_active(GTK_COMBO_BOX(lineBreak)); - if (breakStyle == 0) ppo->newLineChars = "\r"; - else if (breakStyle == 1) ppo->newLineChars = "\n"; - else ppo->newLineChars = "\r\n"; + if (ppo->newLineChars != NULL) + { + g_free ((gpointer)ppo->newLineChars);
(minor) freeing a NULL pointer is perfectly legal. There is no need to test nullity, you can use g_free unconditionally here. (see https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html#g-free)
Thannoy commented on this pull request.
+ kf = g_key_file_new (); + + if (!g_key_file_load_from_data (kf, contents, size, + G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, + error)) + { + g_key_file_free (kf); + return FALSE; + } + + if (g_key_file_has_key (kf, "pretty-printer", "newLineChars", NULL)) + { + if (ppo->newLineChars != NULL ) + { + g_free ((gpointer)ppo->newLineChars);
(minor) same as above, you can use g_free unconditionally here
@LarsGit223 pushed 1 commit.
2149e3f Fixed unnecessary NULL pointer checks on call to 'g_free()'.
@Thannoy: thanks, did not know that. Just fixed it.
Thanks for the PR. I will postpone it for 1.32 as currently there is no active maintainer for the plugin and I will not be able to do proper review until release
:thumbsup: Fine for me. Thanks.
Merged #581.
github-comments@lists.geany.org