3131
3232#include " PythonModule.h"
3333#include " SceneNodeBuffer.h"
34+ #include " ui/ieventmanager.h"
3435
3536#include " os/path.h"
3637#include < functional>
3738#include " string/case_conv.h"
39+ #include " settings/SettingsManager.h"
3840
3941namespace script
4042{
@@ -95,6 +97,8 @@ void ScriptingSystem::initialise()
9597
9698 // Search script folder for commands
9799 reloadScripts ();
100+
101+ GlobalEventManager ().connectDeferredAccelerators ();
98102}
99103
100104void ScriptingSystem::runScriptFile (const cmd::ArgumentList& args)
@@ -138,12 +142,12 @@ void ScriptingSystem::executeCommand(const std::string& name)
138142 UndoableCommand cmd (" runScriptCommand " + name);
139143
140144 // Execute the script file behind this command
141- executeScriptFile (found->second ->getFilename (), true );
145+ _pythonModule-> executeScriptFile (found-> second -> getBasePath (), found->second ->getFilename (), true );
142146}
143147
144- void ScriptingSystem::loadCommandScript (const std::string& scriptFilename)
148+ void ScriptingSystem::loadCommandScript (const std::string& basePath, const std::string& scriptFilename)
145149{
146- auto command = _pythonModule->createScriptCommand (_scriptPath , scriptFilename);
150+ auto command = _pythonModule->createScriptCommand (basePath , scriptFilename);
147151
148152 if (!command)
149153 {
@@ -173,29 +177,37 @@ void ScriptingSystem::reloadScripts()
173177 _commands.clear ();
174178
175179 // Initialise the search's starting point
176- fs::path start = fs::path (_scriptPath) / COMMAND_PATH;
177-
178- if (!fs::exists (start))
180+ auto scanDirectory = [&](const std::string& basePath)
179181 {
180- rWarning () << " Couldn't find scripts folder: " << start.string () << std::endl;
181- return ;
182- }
182+ fs::path start = fs::path (basePath) / COMMAND_PATH;
183183
184- for (fs::recursive_directory_iterator it (start);
185- it != fs::recursive_directory_iterator (); ++it)
186- {
187- // Get the candidate
188- const fs::path& candidate = *it;
184+ if (!fs::exists (start))
185+ {
186+ return ;
187+ }
189188
190- if (fs::is_directory (candidate)) continue ;
189+ for (fs::recursive_directory_iterator it (start);
190+ it != fs::recursive_directory_iterator (); ++it)
191+ {
192+ const fs::path& candidate = *it;
191193
192- std::string extension = os::getExtension (candidate.string ());
193- string::to_lower (extension);
194+ if (fs::is_directory (candidate)) continue ;
194195
195- if (extension != PYTHON_FILE_EXTENSION) continue ;
196+ std::string extension = os::getExtension (candidate.string ());
197+ string::to_lower (extension);
196198
197- // Script file found, construct a new command
198- loadCommandScript (os::getRelativePath (candidate.generic_string (), _scriptPath));
199+ if (extension != PYTHON_FILE_EXTENSION) continue ;
200+
201+ // Script file found, construct a new command
202+ loadCommandScript (basePath, os::getRelativePath (candidate.generic_string (), basePath));
203+ }
204+ };
205+
206+ scanDirectory (_scriptPath);
207+
208+ if (!_userScriptPath.empty ())
209+ {
210+ scanDirectory (_userScriptPath);
199211 }
200212
201213 rMessage () << " ScriptModule: Found " << _commands.size () << " commands." << std::endl;
@@ -208,6 +220,9 @@ void ScriptingSystem::initialiseModule(const IApplicationContext& ctx)
208220 // Construct the script path
209221 _scriptPath = ctx.getRuntimeDataPath () + SCRIPT_PATH;
210222
223+ settings::SettingsManager manager (ctx);
224+ _userScriptPath = manager.getCurrentVersionSettingsFolder () + SCRIPT_PATH;
225+
211226 // Set up the python interpreter
212227 _pythonModule.reset (new PythonModule);
213228
@@ -274,6 +289,7 @@ void ScriptingSystem::shutdownModule()
274289
275290 _commands.clear ();
276291 _scriptPath.clear ();
292+ _userScriptPath.clear ();
277293 _pythonModule.reset ();
278294}
279295
0 commit comments