These changes do not affect current usage.
* Make StashPref and StashGroup publicly accessible so lookup functions to make Geany preferences available to plugins can be added later. * Add comment field to StashPref. - stash_group_add_comment() * Add double key type: - utils_get_setting_double() in utils.c - stash_group_add_double() in stash.c
You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany/pull/3000
-- Commit Summary --
* Modify/Extend Stash Settings API
-- File Changes --
M doc/stash-example.c (19) M src/plugindata.h (2) M src/stash.c (125) M src/stash.h (47) M src/utils.c (55) M src/utils.h (2)
-- Patch Links --
https://github.com/geany/geany/pull/3000.patch https://github.com/geany/geany/pull/3000.diff
`stash-example.c` using `stash_group_add_comment()` and `stash_group_add_double()`. ```C StashGroup *group; gboolean porcelain_enabled; gchar *potter_name; gint stock; gdouble price; const gchar filename[] = "/path/data.conf";
/* setup the group */ group = stash_group_new("cup"); stash_group_add_boolean(group, &porcelain_enabled, "porcelain", TRUE); stash_group_add_comment(group, "porcelain", "Is the cup made of porcelain?");
stash_group_add_string(group, &potter_name, "potter_name", "Miss Clay"); stash_group_add_comment(group, "potter_name", "Who made the cup?");
stash_group_add_integer(group, &stock, "stock", 5); stash_group_add_comment(group, "stock", "How many do we have?");
stash_group_add_double(group, &price, "price", 1.50); stash_group_add_comment(group, "price", "How much does the cup cost?");
/* load the settings from a file */ if (!stash_group_load_from_file(group, filename)) g_warning(_("Could not load keyfile %s!"), filename);
/* now use settings porcelain_enabled, potter_name, stock, and price */ /* ... */
/* save settings to file */ if (stash_group_save_to_file(group, filename, G_KEY_FILE_NONE) != 0) g_error(_("Could not save keyfile %s!"), filename);
/* free memory */ stash_group_free(group); ```
@xiota pushed 1 commit.
199f118ff0bb2c42b00738364707d538523e3fee Mark comments as translatable in stash-example.c
@xiota pushed 1 commit.
01bb1e86fb28cefce57eebc565633724fdea57ed Add StashGroup lookup by name
@xiota pushed 1 commit.
95de5b559f25c6b43073a73661951c396976f4a4 Add runtime override of StashPref settings
@xiota pushed 1 commit.
46feb82ac40712dd65f3a89326be14822cef0f52 Fix memory usage/segfault
Example of finding group and pref by name: ```C StashGroup *group = stash_group_get_group_by_name("cup"); if (group) { StashPref *pref = stash_group_get_pref_by_name(group, "price"); if (pref) { msgwin_status_add("%s.%s = %f", group->name, pref->key_name, *(gdouble *)pref->setting); } else { msgwin_status_add("pref not found"); } } else { msgwin_status_add("group not found"); } ```
Problem: Doesn't work if used after `stash_group_free()`.
In addition to reviewing memory management... Some potential solutions: * Rewrite "free" to defer actual deallocation until Geany is being shutdown. Pro: Minimize changes to existing code, maybe. Con: "free" doesn't do what it says it will. * Rewrite code to defer deallocation until Geany is being shutdown. Pro: "free" does what it says it will. Con: Probably will require extensive changes to existing code. * Replace "free" with "free_later" (or some such). Pro: "free" and "free_later" do what they say they will. Just need to replace "free" with "free_later" in existing code. Con: Use of "free" can still prevent the lookup from working.
@xiota pushed 1 commit.
2ffea94e89a065651e21cce7b40524d70a1dfd13 Change StashGroup lookup methods
@xiota pushed 10 commits.
30f346927c2d93f0a11ef8d6f1ba05629ff0422f Move "Send Selection to" from Edit/Format to Edit b7b2331788e533aa9e01f8eb49195c00b21d3d0c Add keybindings to toggle focus between: bb37dbedbbbb50ef9e4b12f81631c93f650b187c Add Fountain screenplay parser 151362b82e78b8594d72cb92d5c2a464b58281ff Add option to hide warning for unwritable project files 1d7a2524b2b9bcc6891b5c5f3d89b8f02a7d1a34 Add option use status window for warnings about unwritable project files bcc212b3c55a6e5ab532ec28e506f94d6cc06a2a Fix markdown crash f055bb62b14badb8abaa46da962e2875525f6fe0 Add option to disable editor zooming via scrollwheel d2d19796ca9a186b718a6082ac7fd6b921e54a5c Add option to use status window to warn about unwritable project files a0e50f2eee74b331b9d1f2facc16ac7ce66e9333 Fix buggy save/restore position and geometry e1b0391d73c2507ba0893f99a6566dc084b2d35a Yet another API change
@xiota pushed 1 commit.
09fc51bce3b921dd454ab89818848c1bb4c4493d Yet another API change
Force push because got git branches mixed up. `get_stash_groups()` is to make testing easier without recompiling Geany. Probaby won't be in the final PR. Functions to access ```C GPtrArray *get_stash_groups(); // To make testing easier. Will probably be removed in final PR.
StashGroup *stash_group_get_group(const gchar *group_name, const gchar *key_name);
StashPref *stash_group_get_pref_by_name(StashGroup *group, const gchar *key_name); ``` Example - list all groups and names: ```C++ GPtrArray *test = get_stash_groups();
gpointer item; guint i; foreach_ptr_array(item, i, test) { if (item) { StashGroup *group = (StashGroup *)item; msgwin_status_add("group = %s", group->name); } } ``` Output: ``` group = geany group = geany group = geany group = geany group = geany group = build-menu group = geany group = search group = search group = search group = search group = plugins group = geany group = VTE ``` Notably, in `keyfile.c`, groups with the same name (geany and search) are created multiple times. Why? Is it necessary? Would it work if the old group with the same name is returned instead of a brand new group?
Example, looking up a Geany group and pref: ```C++ StashGroup *group = stash_group_get_group("VTE", nullptr); StashPref *pref = stash_group_get_pref_by_name(group, "send_selection_unsafe");
if (group && pref) { msgwin_status_add("%s.%s = %d", group->name, pref->key_name, *(gboolean *)pref->setting); } ``` Output: ``` VTE.send_selection_unsafe = 0 ```
@xiota pushed 1 commit.
91272adddea127258baeab49caea62b07df460fb Tweak overrides and API
Over-ride example: ```C++ StashGroup *group = stash_group_get_group("geany", "interface"); StashPref *pref = stash_group_get_pref_by_name(group, "warn_on_project_close"); if (group && pref) { stash_group_pref_set_override(pref, (gpointer) true); }
stash_group_pref_unset_override(pref); ```
Can you please break this into multiple PRs? I'm not sure if all changes are truly useful. I would start by exposing what's currently implemented and then add functionality on-top in separate PRs.
@kugel- What changes are you not sure will be useful?
@xiota pushed 1 commit.
c50bc4e2d17a2332b10ddc841686280ae948f76c Extend Stash Settings System
Force push because it's easier to work with a single commit when figuring out how to separate into separate PRs.
@kugel- first PR split from this one #3004. Will split others as they're accepted/merged.
@xiota pushed 6 commits.
f811c590b11f2d3b85368f3a58ac52cd176a289b Stash Settings: Expose StashPref to plugins, look up by name eda045625ea4d1a6059d8d301970cd9ed879a595 fix comment typo b14430c0bd5936d80089271fe3e2d146b830cac5 Stash Settings: Add key comments 5af5612c2cb59d90d913a7e8774dc177fd6fcbc0 Stash Settings: Expose StashGroup to plugins, look up by name+prefix 5b9912d490c3456e1888bce40ffb1f7e3f6a8249 Stash Settings: Add runtime override a1f43d1ac03e107bcdd97e93ced9f415a03f4c22 Stash Settings: Add session support
Closed #3000.
github-comments@lists.geany.org