Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set a property value from the content of a file #130

Closed
end2endzone opened this issue Oct 14, 2023 · 1 comment
Closed

Set a property value from the content of a file #130

end2endzone opened this issue Oct 14, 2023 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@end2endzone
Copy link
Owner

end2endzone commented Oct 14, 2023

Is your feature request related to a problem? Please describe.
It would be useful to be able to set a property from the content of a file.

Describe the solution you'd like

<property name="content" file="C:\foo\bar\baz.txt" />

Describe alternatives you've considered
There is no alternative for this feature.

Additional context
This feature would allow people to do advanced property manipulation such as

<menu name="Copy file content">
  <visibility maxfiles="1" maxfolders="0" />
  <actions>
    <property name="selection.file.content" file="${selection.path}" />
  </actions>
</menu>

or to copy the result of an <exec> element as a property with something such as

<menu name="Capture exec output">
  <actions>
    <exec path="cmd.exe" arguments="/C dir /b &quot;%USERPROFILE%\Documents&quot;> &quot;${temp}\command_output.txt&quot;" />
    <property name="filenames" file="${temp}\command_output.txt" />
  </actions>
</menu>
@end2endzone end2endzone added the enhancement New feature or request label Oct 14, 2023
@end2endzone end2endzone added this to the 0.9.0 milestone Nov 29, 2023
@end2endzone
Copy link
Owner Author

end2endzone commented Nov 30, 2023

The feature does also require an optional filesize attribute. The attribute should be used to define how much of a file (in bytes) can be loaded as a property value. This attribute would prevent loading a huge file in memory by mistake. By default the filesize value should be set to 4096 bytes. If you want to load a file that is bigger than the default, then one has to manually specify a filesize value.

For example, to read the first 10 kb of a file :

<property name="selection.file.content" file="${selection.path}" filesize="10240" />

A special value of 0 would tell the application to load the whole file. For example :

<property name="selection.file.content" file="${selection.path}" filesize="0" />

end2endzone added a commit that referenced this issue Dec 16, 2023
…onfiguration File that matches the current unit test.

Simplified unit test TestActionProperty.testCopyFile() with the QuickLoader.
#130
end2endzone added a commit that referenced this issue Dec 16, 2023
* feature-issue130:
  * Fixed issue #130: Set a property value from the content of a file.
  Created 1 more tests for <property> element with `file` attribute. #130
  - Move code that "execute all actions of a menu" from CContextMenu.cpp to Menu.cpp. - Implemented FindMenuByName() for ConfigManager, Configuration and Menu classes. #111
  - Fixed a major flaw in Configuration::IsValidConfigFile() which could result in unforgettable errors.
  Created class QuickLoader which can be used to automatically load a Configuration File that matches the current unit test. Simplified unit test TestActionProperty.testCopyFile() with the QuickLoader. #130
  Fixed a documentation error about <file> usage.
  Updated documentation of `file` and `filesize` attributes for property element. #130
  Implemented support of `file` and `filesize` attributes for ActionProperty class. #130
  Created new utility functions in SaUtils.h & matching unit tests. #130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant