end2endzone / ShellAnything

ShellAnything is a C++ open-source software which allow one to easily customize and add new options to *Windows Explorer* context menu. Define specific actions when a user right-click on a file or a directory.
MIT License
180 stars 27 forks source link

Simplify plugin's validation function #107

Closed end2endzone closed 2 years ago

end2endzone commented 2 years ago

Is your feature request related to a problem? Please describe. The plugin interface function is currently defined as the following:

/// <summary>
/// Function pointer definition for validating a custom attributes.
/// </summary>
/// <param name="names">The names of the attributes as an array of strings.</param>
/// <param name="values">The values of the attributes as an array of strings.</param>
/// <param name="flags">The flags of the attributes. See macros that starts with SA_ATTRIBUTE_FLAG_.</param>
/// <param name="count">Defines how many elements are in the names, values and flags arrays.</param>
/// <returns>Returns 1 on validation success. Returns NULL on error.</returns>
typedef int (*sa_plugin_attribute_validate_func)(sa_context_immutable_t* ctx, const char** /*names*/, const char** /*values*/, const int* /*flags*/, size_t /*count*/);

This function definition is prone to a signature change as new features are added.

It might be interesting to allow the function to have a PropertyStore pointer as an argument. The API should provide getter/setter for a property store object such as the following:

int sa_property_store_has_property(sa_icon_immutable_t* property_store, const char * name);
sa_error_t sa_property_store_get_value_buffer(sa_icon_immutable_t* property_store, int* length, char* buffer, size_t size);

The inversed flags should also be retreived with a function such as

int sa_property_store_is_attribute_inversed(sa_icon_immutable_t* property_store, const char * name);

Describe the solution you'd like The Validator class should use a PropertyStore to store all the attributes. This includes native and plugin based attributes. This would greatly simply the interface for plugins that implement menu validation. The need for a "flag" array which currently contains the "inversed" state of all attributes could also be removed for simplicity.

Describe alternatives you've considered N/A

Additional context N/A

end2endzone commented 2 years ago

Related to #50

end2endzone commented 2 years ago

This proposition also allow to separate the code that implements the attribute's validation from the <visibility> and <validity> xml elements and their attributes.

end2endzone commented 2 years ago

Also define a sa_boolean type to clarify the expected values in api functions that are expecting a boolean value.

end2endzone commented 2 years ago

Migrate to functions with no arguments validation scheme. This is better for an api since it each function is independent from each other. It we need to add/remove arguments, then we only need to create another function. This will offer the longest lifetime to plugins in case the api needs to change.

This implies: