Don't write scripts to temp file, run in their real location

* This means any changes in the external editor/debugger will be reflected
  properly.
This commit is contained in:
baldurk
2026-08-13 21:05:13 +01:00
parent a113dbbda8
commit bf710530d2
2 changed files with 37 additions and 4 deletions
+35 -4
View File
@@ -347,6 +347,13 @@ PythonShell::PythonShell(ICaptureContext &ctx, QWidget *parent)
updateExtensionProjects();
m_ModifiedExtensions = curModExts;
}
bool hasDebugger = PythonContext::IsDebuggerConnected();
if(m_DebuggerAttached != hasDebugger)
updateNonDebugWarning();
m_DebuggerAttached = hasDebugger;
});
pyStatusTimer->setSingleShot(false);
@@ -555,6 +562,7 @@ void PythonShell::editorTab_Changed(int index)
ui->saveScript->setEnabled(editor && editor->filename() != QString());
enableButtons(ui->newScript->isEnabled());
updateNonDebugWarning();
}
void PythonShell::openFileModified(const QString &path)
@@ -948,6 +956,26 @@ void PythonShell::updateEditorCloseButton()
}
}
void PythonShell::updateNonDebugWarning()
{
m_DebuggerAttached = PythonContext::IsDebuggerConnected();
for(EditorWrapper *edit : m_Editors)
{
if(edit->filename().isEmpty())
{
if(m_DebuggerAttached)
edit->setWarning(
tr("External debugger will not work for unsaved files. "
"Save script to disk to allow debugging."));
}
else
{
edit->setWarning(QString());
}
}
}
void PythonShell::addRecentFile(rdcstr filename)
{
// don't add recent files from UI extensions
@@ -1135,7 +1163,8 @@ void PythonShell::CreateNewScriptEditor(rdcstr name, rdcstr text)
{
makeEditor(name, text);
ui->saveScript->setEnabled(true);
ui->saveScript->setEnabled(false);
updateNonDebugWarning();
}
rdcstr PythonShell::GetScriptText()
@@ -1194,6 +1223,9 @@ void PythonShell::runScript(bool debugging)
if(!editor)
return;
if(editor->isModified() && !editor->filename().isEmpty())
saveEditor(editor, editor->filename());
PythonContext *context = newContext();
ANALYTIC_SET(UIFeatures.PythonInterop, true);
@@ -1304,9 +1336,7 @@ void PythonShell::on_newScript_clicked()
minidocHeader = QFormatStr("# %1\n\n").arg(minidocHeader);
makeEditor("", minidocHeader);
ui->saveScript->setEnabled(false);
CreateNewScriptEditor("", minidocHeader);
}
void PythonShell::on_openScript_clicked()
@@ -1587,6 +1617,7 @@ bool PythonShell::saveEditor(EditorWrapper *editor, QString filename)
QTimer::singleShot(200, [this, filename]() { m_Watcher->addPath(filename); });
editor->setFilename(filename);
updateNonDebugWarning();
return true;
}
else
+2
View File
@@ -182,6 +182,7 @@ private:
QFileSystemWatcher *m_Watcher = NULL;
QList<QString> m_ModifiedExtensions;
bool m_DebuggerAttached = false;
QTimer *m_SyntaxCheckTimer;
@@ -225,6 +226,7 @@ private:
void makeEditor(rdcstr filename, rdcstr text);
void updateEditorCloseButton();
void updateNonDebugWarning();
void addRecentFile(rdcstr filename);
void updateRecentFiles(bool added);