io/fileview: add FileView

This commit is contained in:
outfoxxed 2024-09-09 03:15:16 -07:00
parent 3a1eec0ed5
commit 85be3861ce
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
6 changed files with 635 additions and 1 deletions

48
src/io/FileView.qml Normal file
View file

@ -0,0 +1,48 @@
import Quickshell.Io
FileViewInternal {
property bool preload: this.__preload;
property bool blockLoading: this.__blockLoading;
property bool blockAllReads: this.__blockAllReads;
property string path: this.__path;
onPreloadChanged: this.__preload = preload;
onBlockLoadingChanged: this.__blockLoading = this.blockLoading;
onBlockAllReadsChanged: this.__blockAllReads = this.blockAllReads;
// Unfortunately path can't be kept as an empty string until the file loads
// without using QQmlPropertyValueInterceptor which is private. If we lean fully
// into using private code in the future, there will be no reason not to do it here.
onPathChanged: {
if (!this.preload) this.__preload = false;
this.__path = this.path;
if (this.preload) this.__preload = true;
}
// The C++ side can't force bindings to be resolved in a specific order so
// its done here. Functions are used to avoid the eager loading aspect of properties.
// Preload is set as it is below to avoid starting an async read from a preload
// if the user wants an initial blocking read.
function text(): string {
if (!this.preload) this.__preload = false;
this.__blockLoading = this.blockLoading;
this.__blockAllReads = this.blockAllReads;
this.__path = this.path;
const text = this.__text;
if (this.preload) this.__preload = true;
return text;
}
function data(): string {
if (!this.preload) this.__preload = false;
this.__blockLoading = this.blockLoading;
this.__blockAllReads = this.blockAllReads;
this.__path = this.path;
const data = this.__data;
if (this.preload) this.__preload = true;
return data;
}
}