Fix custom shader edits to write the exact editor contents to disk

This commit is contained in:
baldurk
2021-05-17 11:55:14 +01:00
parent 4a9d32db3f
commit 331db5b4ba
4 changed files with 36 additions and 2 deletions
+8
View File
@@ -963,6 +963,14 @@ QWidget.
)");
virtual void AddWatch(const rdcstr &expression) = 0;
DOCUMENT(R"(Return the current text of source files within the viewer. Primarily useful for
returning any edits applied when editing a shader.
:return: The current file contents as a list of (filename, contents) pairs.
:rtype: List[Tuple[str,str]]
)");
virtual rdcstrpairs GetCurrentFileContents() = 0;
protected:
IShaderViewer() = default;
~IShaderViewer() = default;
+16
View File
@@ -4086,6 +4086,22 @@ void ShaderViewer::AddWatch(const rdcstr &variable)
ui->watch->QWidget::setFocus();
}
rdcstrpairs ShaderViewer::GetCurrentFileContents()
{
rdcstrpairs files;
for(ScintillaEdit *s : m_Scintillas)
{
// don't include the disassembly view
if(m_DisassemblyView == s)
continue;
QWidget *w = (QWidget *)s;
files.push_back(
{w->property("filename").toString(), QString::fromUtf8(s->getText(s->textLength() + 1))});
}
return files;
}
int ShaderViewer::snippetPos()
{
ShaderEncoding encoding = currentEncoding();
+2
View File
@@ -128,6 +128,8 @@ public:
virtual void AddWatch(const rdcstr &variable) override;
virtual rdcstrpairs GetCurrentFileContents() override;
// ICaptureViewer
void OnCaptureLoaded() override;
void OnCaptureClosed() override;
+10 -2
View File
@@ -4528,16 +4528,24 @@ void TextureViewer::on_customEdit_clicked()
// Save Callback
[thisPointer, key, filename, path](ICaptureContext *ctx, IShaderViewer *viewer, ResourceId,
ShaderStage, ShaderEncoding, ShaderCompileFlags, rdcstr,
bytebuf bytes) {
bytebuf) {
{
// don't trigger a full refresh
if(thisPointer)
thisPointer->m_CustomShaderWriteTime = thisPointer->m_CustomShaderTimer.elapsed();
rdcstrpairs files = viewer->GetCurrentFileContents();
if(files.size() != 1)
qCritical() << "Unexpected number of files in custom shader viewer" << files.count();
if(files.empty())
return;
QFile fileHandle(path);
if(fileHandle.open(QFile::WriteOnly | QIODevice::Truncate | QIODevice::Text))
{
fileHandle.write(QByteArray(bytes));
fileHandle.write(files[0].second.c_str(), files[0].second.size());
fileHandle.close();
// watcher doesn't trigger on internal modifications