Skip to content

Commit

Permalink
Updated documentation for #135. Modified code to fail if a `searchpat…
Browse files Browse the repository at this point in the history
…h` attribute is specified and the search does not find a match.
  • Loading branch information
end2endzone committed Jan 14, 2024
1 parent cf81a53 commit 1dc7d14
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
39 changes: 39 additions & 0 deletions UserManual.md
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,45 @@ For example :



#### searchpath attribute: ####

The `searchpath` attribute allows searching for a file name using the `PATH` environment variable. The attribute defines a file name (including the file extension) to search in the list of directories identified in the `PATH` environment variable. If the given file name cannot be found in a PATH directory, the action execution stop and reports an error.

For example, the following sets the property `python.exe.path` to the location of the python interpreter :
```xml
<property name="python.exe.path" registrykey="python.exe" />
```

This method allows to create generic configuration file that can be used by everyone.

For example :

***Run python script*** :
```xml
<?xml version="1.0" encoding="utf-8"?>
<root>
<shell>
<default>
<!-- Detect PYTHON executable from PATH environment variable. -->
<!-- The property `python.exe.path` is set only if `python.exe` can be found
in the directories listed in PATH environment variable. -->
<property name="python.exe.path" searchpath="python.exe" />
</default>

<menu name="Run with python">
<icon path="${python.exe.path}" index="0" />
<!-- Show the menu only if PYTHON is found in PATH environment variable -->
<visibility properties="python.exe.path" maxfiles="1" maxfolders="0" fileextensions="py" />
<actions>
<exec path="${python.exe.path}" arguments="${selection.path}" />
</actions>
</menu>
</shell>
</root>
```



### &lt;file&gt; action ###

The &lt;file&gt; element is used to create a text file on disk. The content of the file is specified between the opening and closing tags of the &lt;file&gt; element. The &lt;file&gt; element supports dynamic properties and can be used to create default configuration files or create support files for the menu.
Expand Down
10 changes: 6 additions & 4 deletions src/core/ActionProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ namespace shellanything
// Search for a file in PATH environment variable.
std::string abs_path = ra::filesystem::FindFileFromPathsUtf8(searchpath);

// If found
if (!abs_path.empty())
if (abs_path.empty())
{
// Store the result in 'value' as if user set this specific value (to use the same process as a property that sets a value).
value = abs_path;
SA_LOG(WARNING) << "File not found in PATH environment variable: '" << searchpath << "'.";
return false;
}

// Store the result in 'value' as if user set this specific value (to use the same process as a property that sets a value).
value = abs_path;
}

// If exprtk is specified, it has priority over value. This is required to allow setting a property to an empty value (a.k.a. value="").
Expand Down
7 changes: 7 additions & 0 deletions src/tests/test_files/TestActionProperty.testSearchPath.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,12 @@
</actions>
</menu>

<menu name="menu5">
<actions>
<!-- Find `powershell.exe` command -->
<property name="test5" searchpath="powershell.exe" />
</actions>
</menu>

</shell>
</root>

0 comments on commit 1dc7d14

Please sign in to comment.