mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-08-24 23:46:41 +00:00
Run scripts in their place when they are on disk
* We only write the pytmp/script.py for unsaved scripts, so they can be recovered.
This commit is contained in:
@@ -2381,19 +2381,7 @@ void PythonContext::LaunchDebugger(QWidget *window, PersistentConfig &config, QS
|
||||
return;
|
||||
|
||||
if(context_location.isEmpty())
|
||||
{
|
||||
for(QString path : QStandardPaths::standardLocations(QStandardPaths::AppDataLocation))
|
||||
{
|
||||
QDir tmpDir(path);
|
||||
tmpDir.mkpath(lit("pytmp"));
|
||||
tmpDir.cd(lit("pytmp"));
|
||||
if(tmpDir.exists())
|
||||
{
|
||||
context_location = tmpDir.absolutePath();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
// don't overwrite an existing file, to allow user customisation
|
||||
QDir context_dir(context_location);
|
||||
|
||||
@@ -1247,6 +1247,22 @@ void PythonShell::runScript(bool debugging)
|
||||
if(debugging)
|
||||
PythonContext::PrepareDebuggerWait();
|
||||
|
||||
// save any changes
|
||||
if(editor->isModified() && !editor->filename().isEmpty())
|
||||
{
|
||||
saveEditor(editor, editor->filename());
|
||||
}
|
||||
else if(editor->filename().isEmpty())
|
||||
{
|
||||
// write the script as a temporary file, so if we crash it will be recoverable.
|
||||
// this only applies if editor is an unsaved file
|
||||
QString unsavedFile = context->GetTempFilename(lit("script.py"));
|
||||
QFile f(unsavedFile);
|
||||
f.open(QFile::Truncate | QFile::WriteOnly);
|
||||
f.write(script.toUtf8().data());
|
||||
f.close();
|
||||
}
|
||||
|
||||
m_CurLineTimer->start();
|
||||
|
||||
LambdaThread *thread = new LambdaThread([this, debugging, script, context, editor]() {
|
||||
@@ -1254,7 +1270,7 @@ void PythonShell::runScript(bool debugging)
|
||||
|
||||
scriptContext = context;
|
||||
runningScriptEditor = editor->scintilla();
|
||||
context->executeString(lit("script.py"), script, debugging);
|
||||
context->executeString(editor->filename(), script, debugging);
|
||||
scriptContext = NULL;
|
||||
|
||||
GUIInvoke::call(this, [this, context]() {
|
||||
@@ -1263,6 +1279,9 @@ void PythonShell::runScript(bool debugging)
|
||||
context->Finish();
|
||||
runningScriptEditor = NULL;
|
||||
enableButtons(true);
|
||||
|
||||
QString unsavedFile = context->GetTempFilename(lit("script.py"));
|
||||
QFile::remove(unsavedFile);
|
||||
});
|
||||
|
||||
PythonContext::RemoveDebuggableThread();
|
||||
|
||||
Reference in New Issue
Block a user