Update: 优化Python Online板卡下「本地文件系统」

This commit is contained in:
王立帮
2024-11-27 03:08:43 +08:00
parent b984af1998
commit e0534d607d
9 changed files with 205 additions and 31 deletions

View File

@@ -57,6 +57,7 @@ class FileTree extends Component {
#rootFolderOpened_ = false;
#rootPath_ = '';
#rootName_ = '';
#rootTitle_ = '';
#fs_ = null;
#contextMenu_ = null;
#selected_ = null;
@@ -474,7 +475,7 @@ class FileTree extends Component {
this.nodeAliveRegistry.reset();
this.#jstree_.refresh();
this.watchFolder(this.#rootPath_);
this.#$rootFolder_.attr('title', this.#rootPath_);
this.setRootFolderTitle(this.#rootPath_);
const rootNodeName = path.basename(folderPath).toUpperCase();
this.setRootFolderName(rootNodeName);
}
@@ -492,6 +493,15 @@ class FileTree extends Component {
return this.#rootName_;
}
setRootFolderTitle(name) {
this.#rootTitle_ = name;
this.#$rootFolder_.attr('title', name);
}
getRootFolderTitle() {
return this.#rootTitle_;
}
refreshFolder(folderPath) {
// 延迟刷新节点防止过于频繁的IO操作
let eventId = this.delayRefreshRegistry.getItem(folderPath);
@@ -507,10 +517,9 @@ class FileTree extends Component {
const node = this.#jstree_.get_node(folderPath);
const nodeIsOpened = node && !this.isClosed(folderPath);
if (nodeIsOpened) {
if (this.isWatched(folderPath)) {
this.clearFolderTemp(folderPath);
this.#jstree_.refresh_node(folderPath);
}
this.watchFolder(folderPath);
this.clearFolderTemp(folderPath);
this.#jstree_.refresh_node(folderPath);
} else {
this.unwatchFolder(folderPath);
}
@@ -620,7 +629,7 @@ class FileTree extends Component {
let output = [];
const content = await this.readFolder(inPath);
for (let item of content) {
const { type, id, children } = item;
const { type, id, title, children } = item;
const text = path.basename(id);
let icon = 'icon-doc';
if (type === 'folder') {
@@ -635,7 +644,7 @@ class FileTree extends Component {
li_attr: {
type,
name: text,
title: id
title: title ?? id
},
icon
});

View File

@@ -35,7 +35,7 @@ class Menu {
}
const { id, weight } = item;
if (this.#ids_[id]) {
this.unregister(id);
delete this.#ids_[id];
}
let i = 0;
for (; i < this.#menuItems_.length; i++) {

View File

@@ -71,12 +71,12 @@ const readFile = function(fname, encoding, flag) {
return createPromise(fs.readFile, fname, encoding);
}
const writeFile = function(fname, data, encoding, flag, mode) {
return createPromise(fs.writeFile, fname, data, encoding, flag, mode);
const writeFile = function(fname, data, encoding) {
return createPromise(fs.writeFile, fname, data, encoding);
}
const appendFile = function(fname, data, encoding, flag, mode) {
return createPromise(fs.appendFile, fname, data, encoding, flag, mode);
const appendFile = function(fname, data, encoding) {
return createPromise(fs.appendFile, fname, data, encoding);
}
const chmod = function(p, mode) {