forked from quickshell/quickshell
io/fileview: add adapter support and JsonAdapter
This commit is contained in:
parent
cb69c2d016
commit
fee4942771
6 changed files with 487 additions and 2 deletions
|
@ -289,6 +289,12 @@ void FileViewWriter::write(
|
|||
}
|
||||
}
|
||||
|
||||
FileView::~FileView() {
|
||||
if (this->mAdapter) {
|
||||
this->mAdapter->setFileView(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void FileView::loadAsync(bool doStringConversion) {
|
||||
// Writes update via operationFinished, making a read both invalid and outdated.
|
||||
if (!this->liveOperation || this->pathInFlight != this->targetPath) {
|
||||
|
@ -636,4 +642,55 @@ void FileView::setBlockAllReads(bool blockAllReads) {
|
|||
}
|
||||
}
|
||||
|
||||
FileViewAdapter* FileView::adapter() const { return this->mAdapter; }
|
||||
|
||||
void FileView::setAdapter(FileViewAdapter* adapter) {
|
||||
if (adapter == this->mAdapter) return;
|
||||
|
||||
if (this->mAdapter) {
|
||||
this->mAdapter->setFileView(nullptr);
|
||||
QObject::disconnect(this->mAdapter, nullptr, this, nullptr);
|
||||
}
|
||||
|
||||
this->mAdapter = adapter;
|
||||
|
||||
if (adapter) {
|
||||
this->mAdapter->setFileView(this);
|
||||
QObject::connect(adapter, &FileViewAdapter::adapterUpdated, this, &FileView::adapterUpdated);
|
||||
QObject::connect(adapter, &QObject::destroyed, this, &FileView::onAdapterDestroyed);
|
||||
}
|
||||
|
||||
emit this->adapterChanged();
|
||||
}
|
||||
|
||||
void FileView::writeAdapter() {
|
||||
if (!this->mAdapter) {
|
||||
qmlWarning(this) << "Cannot call writeAdapter without an adapter.";
|
||||
return;
|
||||
}
|
||||
|
||||
this->setData(this->mAdapter->serializeAdapter());
|
||||
}
|
||||
|
||||
void FileView::onAdapterDestroyed() { this->mAdapter = nullptr; }
|
||||
|
||||
void FileViewAdapter::setFileView(FileView* fileView) {
|
||||
if (fileView == this->mFileView) return;
|
||||
|
||||
if (this->mFileView) {
|
||||
QObject::disconnect(this->mFileView, nullptr, this, nullptr);
|
||||
}
|
||||
|
||||
this->mFileView = fileView;
|
||||
|
||||
if (fileView) {
|
||||
QObject::connect(fileView, &FileView::dataChanged, this, &FileViewAdapter::onDataChanged);
|
||||
this->setFileView(fileView);
|
||||
} else {
|
||||
this->setFileView(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void FileViewAdapter::onDataChanged() { this->deserializeAdapter(this->mFileView->data()); }
|
||||
|
||||
} // namespace qs::io
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue