Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
- fix file explorer not updating correctly
- fix error upon renaming files
  • Loading branch information
solvedDev committed Jan 7, 2020
1 parent 62f4a69 commit a1f97b8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<details
v-else-if="file.is_folder"
:open="file.is_open && !file.absolute_path.includes('cache')"
:key="file.absolute_path + file.is_open"
:key="file.uuid"
>
<summary
@click="file.is_open ? file.close() : file.open()"
Expand Down
26 changes: 20 additions & 6 deletions src/renderer/scripts/Sidebar/FileExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { JSONFileMasks } from "../editor/JSONFileMasks";
import TabSystem from "../TabSystem";
import { BridgeCore } from "../bridgeCore/main";
import InformationWindow from "../commonWindows/Information";
import uuid from "uuid/v4";
declare function requestIdleCallback(cb: () => void): number;

export class FileExplorerStorage {
Expand Down Expand Up @@ -37,6 +38,7 @@ export class FileExplorer {
children: FileExplorer[];
is_loading = true;
loaded_children = false;
uuid = uuid();

loading_promise: Promise<void>;

Expand Down Expand Up @@ -95,6 +97,7 @@ export class FileExplorer {
);
this.sort();
this.loaded_children = true;
this.updateUUID();
}
async refresh() {
this.children = (await fs.readdir(this.absolute_path, { withFileTypes: true }))
Expand All @@ -108,8 +111,18 @@ export class FileExplorer {
)
);
this.sort();
this.updateUUID();
}
loadPrevData(absolute_path: string): [boolean, FileExplorer[]] {
for(let { absolute_path: c_path, is_open, children } of this.children) {
if(absolute_path === c_path) return [ is_open, children ];
}
return [ false, [] ];
}

updateUUID() {
this.uuid = uuid();
}
sort() {
this.children = this.children.sort((a, b) => {
if(a.is_folder && !b.is_folder) return -1;
Expand All @@ -118,17 +131,12 @@ export class FileExplorer {
if(a.name < b.name) return -1;
return 0;
});
this.updateUUID();
}
find(name: string) {
for(let c of this.children)
if(c.name === name) return c;
}
loadPrevData(absolute_path: string): [boolean, FileExplorer[]] {
for(let { absolute_path: c_path, is_open, children } of this.children) {
if(absolute_path === c_path) return [ is_open, children ];
}
return [ false, [] ];
}

async update(absolute_path: string, f_path: string) {
if(this.is_loading) await this.loading_promise;
Expand All @@ -145,6 +153,7 @@ export class FileExplorer {

if(!this.loaded_children && this.is_folder) await this.load();
await Promise.all(this.children.map(c => c.update(this.absolute_path, this.path)));
this.updateUUID();
}
getAllFiles(): string[] {
if(this.name === "cache") return [];
Expand All @@ -167,6 +176,7 @@ export class FileExplorer {
JSONFileMasks.delete(this.absolute_path)
]);
}
this.parent.updateUUID();
}
async duplicate(new_name: string) {
if(this.parent.find(new_name) !== undefined)
Expand All @@ -181,20 +191,24 @@ export class FileExplorer {
]);

this.parent.children.push(new FileExplorer(this.parent, path.join(this.parent.path, new_name), new_path, false));
this.parent.updateUUID();
}
rename(val: string) {
this.name = val;
this.absolute_path = path.join(this.parent.absolute_path, val);
this.path = path.join(this.parent.path, val);
this.updateUUID();
}

open() {
this.is_open = true;
this.updateUUID();
if(!this.loaded_children) this.load();
return this;
}
close() {
this.is_open = false;
this.updateUUID();
return this;
}
}
10 changes: 7 additions & 3 deletions src/renderer/scripts/contextMenus/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ export const FILE_CONTEXT_MENU = async (file_path: string, file: FileExplorer) =
let closed = TabSystem.closeByPath(file_path);

let new_path = path.join(path.dirname(file_path), new_name);
OmegaCache.rename(file_path, new_path);
LightningCache.rename(file_path, new_path);
JSONFileMasks.rename(file_path, new_path);

try {
await OmegaCache.rename(file_path, new_path);
await LightningCache.rename(file_path, new_path);
await JSONFileMasks.rename(file_path, new_path);
} catch {}


await fs.rename(file_path, new_path);
file.rename(new_name);
Expand Down

0 comments on commit a1f97b8

Please sign in to comment.