diff options
| author | Matthias Melcher <github@matthiasm.com> | 2023-10-21 18:41:51 +0200 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2023-10-21 18:41:57 +0200 |
| commit | bbf0ea664dbc9d0b6faa29e3b9752fec6a094bba (patch) | |
| tree | 4f7fa2f2f80ac75416e920420b313dbdc9e6841c /fluid | |
| parent | 0c35212467f3b0d1aa632a1febb06c09f4b170f1 (diff) | |
Removes dependency on Fl_Preferences::get/set(.., Fl_String, ...)
Diffstat (limited to 'fluid')
| -rw-r--r-- | fluid/Fd_Snap_Action.cxx | 3 | ||||
| -rw-r--r-- | fluid/shell_command.cxx | 53 | ||||
| -rw-r--r-- | fluid/shell_command.h | 4 |
3 files changed, 50 insertions, 10 deletions
diff --git a/fluid/Fd_Snap_Action.cxx b/fluid/Fd_Snap_Action.cxx index 7c5b81e4d..56d1486e2 100644 --- a/fluid/Fd_Snap_Action.cxx +++ b/fluid/Fd_Snap_Action.cxx @@ -18,6 +18,7 @@ #include "Fl_Group_Type.h" #include "alignment_panel.h" +#include "shell_command.h" // get and set Fl_String preferences #include "file.h" #include <FL/fl_draw.H> @@ -692,7 +693,7 @@ void Fd_Layout_List::read(Fl_Preferences &prefs, Fd_Tool_Store storage) { Fl_Preferences prefs_list(prefs, "Layouts"); Fl_String cs; int cp = 0; - prefs_list.get("current_suite", cs, ""); + preferences_get(prefs_list, "current_suite", cs, ""); prefs_list.get("current_preset", cp, 0); for (int i = 0; i < prefs_list.groups(); ++i) { Fl_Preferences prefs_suite(prefs_list, Fl_Preferences::Name(i)); diff --git a/fluid/shell_command.cxx b/fluid/shell_command.cxx index 4eb32bcc1..118cf00d3 100644 --- a/fluid/shell_command.cxx +++ b/fluid/shell_command.cxx @@ -104,6 +104,41 @@ static Fl_String fltk_config_cmd; static Fl_Process s_proc; + +/** + Reads an entry from the group. A default value must be + supplied. The return value indicates if the value was available + (non-zero) or the default was used (0). + + \param[in] prefs preference group + \param[in] key name of entry + \param[out] value returned from preferences or default value if none was set + \param[in] defaultValue default value to be used if no preference was set + \return 0 if the default value was used + */ +char preferences_get(Fl_Preferences &prefs, const char *key, Fl_String &value, const Fl_String &defaultValue) { + char *v = NULL; + char ret = prefs.get(key, v, defaultValue.c_str()); + value = v; + ::free(v); + return ret; +} + +/** + Sets an entry (name/value pair). The return value indicates if there + was a problem storing the data in memory. However it does not + reflect if the value was actually stored in the preference file. + + \param[in] prefs preference group + \param[in] entry name of entry + \param[in] value set this entry to value (stops at the first nul character). + \return 0 if setting the value failed + */ +char preferences_set(Fl_Preferences &prefs, const char *key, const Fl_String &value) { + return prefs.set(key, value.c_str()); +} + + /** \class Fl_Process Launch an external shell command. */ @@ -532,26 +567,26 @@ bool Fd_Shell_Command::is_active() { void Fd_Shell_Command::read(Fl_Preferences &prefs) { int tmp; - prefs.get("name", name, "<unnamed>"); - prefs.get("label", label, "<no label>"); + preferences_get(prefs, "name", name, "<unnamed>"); + preferences_get(prefs, "label", label, "<no label>"); prefs.get("shortcut", tmp, 0); shortcut = (Fl_Shortcut)tmp; prefs.get("storage", tmp, -1); if (tmp != -1) storage = (Fd_Tool_Store)tmp; prefs.get("condition", condition, ALWAYS); - prefs.get("condition_data", condition_data, ""); - prefs.get("command", command, ""); + preferences_get(prefs, "condition_data", condition_data, ""); + preferences_get(prefs, "command", command, ""); prefs.get("flags", flags, 0); } void Fd_Shell_Command::write(Fl_Preferences &prefs, bool save_location) { - prefs.set("name", name); - prefs.set("label", label); + preferences_set(prefs, "name", name); + preferences_set(prefs, "label", label); if (shortcut != 0) prefs.set("shortcut", (int)shortcut); if (save_location) prefs.set("storage", (int)storage); if (condition != ALWAYS) prefs.set("condition", condition); - if (!condition_data.empty()) prefs.set("condition_data", condition_data); - if (!command.empty()) prefs.set("command", command); + if (!condition_data.empty()) preferences_set(prefs, "condition_data", condition_data); + if (!command.empty()) preferences_set(prefs, "command", command); if (flags != 0) prefs.set("flags", flags); } @@ -667,7 +702,7 @@ void Fd_Shell_Command_List::read(Fl_Preferences &prefs, Fd_Tool_Store storage) { cmd->name = "Sample Shell Command"; cmd->label = "Sample Shell Command"; cmd->shortcut = FL_ALT+'g'; - fluid_prefs.get("shell_command", cmd->command, "echo \"Sample Shell Command\""); + preferences_get(fluid_prefs, "shell_command", cmd->command, "echo \"Sample Shell Command\""); fluid_prefs.get("shell_savefl", save_fl, 1); fluid_prefs.get("shell_writecode", save_code, 1); fluid_prefs.get("shell_writemsgs", save_strings, 0); diff --git a/fluid/shell_command.h b/fluid/shell_command.h index ea39375f2..e2e553d7b 100644 --- a/fluid/shell_command.h +++ b/fluid/shell_command.h @@ -37,6 +37,10 @@ struct Fl_Menu_Item; class Fl_Widget; +class Fl_Preferences; + +char preferences_get(Fl_Preferences &prefs, const char *key, Fl_String &value, const Fl_String &defaultValue); +char preferences_set(Fl_Preferences &prefs, const char *key, const Fl_String &value); void run_shell_command(const Fl_String &cmd, int flags); |
