Skip to content

Commit

Permalink
Scripting: Made TextFile.commit and BinaryFile.commit close as well
Browse files Browse the repository at this point in the history
Usually commit() would also close the device, except when save writing
of files is disabled. Make sure the device is always closed.
  • Loading branch information
bjorn committed Mar 2, 2020
1 parent 2883ae3 commit 0f1e566
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions docs/reference/scripting.rst
Expand Up @@ -1542,9 +1542,9 @@ TextFile.writeLine(text : string) : void
Writes a string to the file and appends a newline character.

TextFile.commit() : void
Commits all written text to disk. Should be called when writing to files in
WriteOnly mode. Failing to call this function will result in cancelling the
operation, unless safe writing to files is disabled.
Commits all written text to disk and closes the file. Should be called when
writing to files in WriteOnly mode. Failing to call this function will
result in cancelling the operation, unless safe writing to files is disabled.

TextFile.close() : void
Closes the file. It is recommended to always call this function as soon as
Expand Down Expand Up @@ -1598,9 +1598,10 @@ BinaryFile.write(data : ArrayBuffer) : void
Writes *data* into the file at the current position.

BinaryFile.commit() : void
Commits all written data to disk. Should be called when writing to files in
WriteOnly mode. Failing to call this function will result in cancelling the
operation, unless safe writing to files is disabled.
Commits all written data to disk and closes the file. Should be called when
writing to files in WriteOnly mode. Failing to call this function will
result in cancelling the operation, unless safe writing to files is
disabled.

BinaryFile.close() : void
Closes the file. It is recommended to always call this function as soon as
Expand Down
4 changes: 4 additions & 0 deletions src/tiled/scriptfile.cpp
Expand Up @@ -178,6 +178,8 @@ void ScriptBinaryFile::commit()
"Could not write to '%1': %2").arg(m_file->fileName(),
m_file->errorString()));
}

close();
}

void ScriptBinaryFile::close()
Expand Down Expand Up @@ -317,6 +319,8 @@ void ScriptTextFile::commit()
"Could not write to '%1': %2").arg(m_file->fileName(),
m_file->errorString()));
}

close();
}

void ScriptTextFile::close()
Expand Down

0 comments on commit 0f1e566

Please sign in to comment.