提交 74f0c4b2 编写于 作者: I isidor

FileStat.root

上级 7aeeeecd
......@@ -431,7 +431,7 @@ export class ExplorerView extends CollapsibleView {
// Add the new file to its parent (Model)
parents.forEach(p => {
const childElement = FileStat.create(addedElement);
const childElement = FileStat.create(addedElement, p.root);
p.removeChild(childElement); // make sure to remove any previous version of the file if any
p.addChild(childElement);
// Refresh the Parent (View)
......@@ -719,7 +719,7 @@ export class ExplorerView extends CollapsibleView {
// Load Root Stat with given target path configured
const promise = this.fileService.resolveFiles(targetsToResolve).then(stats => {
// Convert to model
const modelStats = stats.map((stat, index) => FileStat.create(stat, targetsToResolve[index].options.resolveTo));
const modelStats = stats.map((stat, index) => FileStat.create(stat, targetsToResolve[index].root.resource, targetsToResolve[index].options.resolveTo));
// Subsequent refresh: Merge stat into our local model and refresh tree
modelStats.forEach((modelStat, index) => FileStat.mergeLocalWithDisk(modelStat, this.model.roots[index]));
......@@ -806,7 +806,7 @@ export class ExplorerView extends CollapsibleView {
return this.fileService.resolveFile(rootUri, options).then(stat => {
// Convert to model
const modelStat = FileStat.create(stat, options.resolveTo);
const modelStat = FileStat.create(stat, rootUri, options.resolveTo);
const root = this.model.roots.filter(r => r.resource.toString() === rootUri.toString()).pop();
// Update Input with disk Stat
FileStat.mergeLocalWithDisk(modelStat, root);
......
......@@ -71,15 +71,7 @@ export class FileDataSource implements IDataSource {
return 'model';
}
// TODO@Isidor each file stat should have a reference to the root, this way you do not have to walk up the parent chain
let parent = stat.parent;
let depth = 0;
while (parent) {
parent = parent.parent;
depth++;
}
return `${depth}:${stat.getId()}`;
return `${stat.root.toString()}:${stat.getId()}`;
}
public hasChildren(tree: ITree, stat: FileStat | Model): boolean {
......@@ -103,7 +95,7 @@ export class FileDataSource implements IDataSource {
const promise = this.fileService.resolveFile(stat.resource, { resolveSingleChildDescendants: true }).then(dirStat => {
// Convert to view model
const modelDirStat = FileStat.create(dirStat);
const modelDirStat = FileStat.create(dirStat, stat.root);
// Add children to folder
for (let i = 0; i < modelDirStat.children.length; i++) {
......
......@@ -25,7 +25,7 @@ export class Model {
private _roots: FileStat[];
constructor( @IWorkspaceContextService private contextService: IWorkspaceContextService) {
const setRoots = () => this._roots = this.contextService.getWorkspace2().roots.map(uri => new FileStat(uri));
const setRoots = () => this._roots = this.contextService.getWorkspace2().roots.map(uri => new FileStat(uri, uri));
this.contextService.onDidChangeWorkspaceRoots(() => setRoots());
setRoots();
}
......@@ -67,7 +67,7 @@ export class FileStat implements IFileStat {
public isDirectoryResolved: boolean;
constructor(resource: URI, isDirectory?: boolean, hasChildren?: boolean, name: string = paths.basename(resource.fsPath), mtime?: number, etag?: string) {
constructor(resource: URI, public root: URI, isDirectory?: boolean, hasChildren?: boolean, name: string = paths.basename(resource.fsPath), mtime?: number, etag?: string) {
this.resource = resource;
this.name = name;
this.isDirectory = !!isDirectory;
......@@ -87,8 +87,8 @@ export class FileStat implements IFileStat {
return this.resource.toString();
}
public static create(raw: IFileStat, resolveTo?: URI[]): FileStat {
const stat = new FileStat(raw.resource, raw.isDirectory, raw.hasChildren, raw.name, raw.mtime, raw.etag);
public static create(raw: IFileStat, root: URI, resolveTo?: URI[]): FileStat {
const stat = new FileStat(raw.resource, root, raw.isDirectory, raw.hasChildren, raw.name, raw.mtime, raw.etag);
// Recursively add children if present
if (stat.isDirectory) {
......@@ -103,7 +103,7 @@ export class FileStat implements IFileStat {
// Recurse into children
if (raw.children) {
for (let i = 0, len = raw.children.length; i < len; i++) {
const child = FileStat.create(raw.children[i], resolveTo);
const child = FileStat.create(raw.children[i], root, resolveTo);
child.parent = stat;
stat.children.push(child);
stat.hasChildren = stat.children.length > 0;
......@@ -313,7 +313,7 @@ export class NewStatPlaceholder extends FileStat {
private directoryPlaceholder: boolean;
constructor(isDirectory: boolean) {
super(URI.file(''));
super(URI.file(''), URI.file(''));
this.id = NewStatPlaceholder.ID++;
this.isDirectoryResolved = isDirectory;
......
......@@ -14,7 +14,7 @@ import { validateFileName } from 'vs/workbench/parts/files/browser/fileActions';
import { FileStat } from 'vs/workbench/parts/files/common/explorerModel';
function createStat(path, name, isFolder, hasChildren, size, mtime) {
return new FileStat(toResource(path), isFolder, hasChildren, name, mtime);
return new FileStat(toResource(path), toResource(path), isFolder, hasChildren, name, mtime);
}
function toResource(path) {
......@@ -246,20 +246,20 @@ suite('Files - View Model', () => {
test('Merge Local with Disk', function () {
const d = new Date().toUTCString();
const merge1 = new FileStat(URI.file(join('C:\\', '/path/to')), true, false, 'to', Date.now(), d);
const merge2 = new FileStat(URI.file(join('C:\\', '/path/to')), true, false, 'to', Date.now(), new Date(0).toUTCString());
const merge1 = new FileStat(URI.file(join('C:\\', '/path/to')), URI.file(join('C:\\', '/path')), true, false, 'to', Date.now(), d);
const merge2 = new FileStat(URI.file(join('C:\\', '/path/to')), URI.file(join('C:\\', '/path')), true, false, 'to', Date.now(), new Date(0).toUTCString());
// Merge Properties
FileStat.mergeLocalWithDisk(merge2, merge1);
assert.strictEqual(merge1.mtime, merge2.mtime);
// Merge Child when isDirectoryResolved=false is a no-op
merge2.addChild(new FileStat(URI.file(join('C:\\', '/path/to/foo.html')), true, false, 'foo.html', Date.now(), d));
merge2.addChild(new FileStat(URI.file(join('C:\\', '/path/to/foo.html')), URI.file(join('C:\\', '/path')), true, false, 'foo.html', Date.now(), d));
FileStat.mergeLocalWithDisk(merge2, merge1);
assert.strictEqual(merge1.children.length, 0);
// Merge Child with isDirectoryResolved=true
const child = new FileStat(URI.file(join('C:\\', '/path/to/foo.html')), true, false, 'foo.html', Date.now(), d);
const child = new FileStat(URI.file(join('C:\\', '/path/to/foo.html')), URI.file(join('C:\\', '/path')), true, false, 'foo.html', Date.now(), d);
merge2.removeChild(child);
merge2.addChild(child);
merge2.isDirectoryResolved = true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册