提交 8a401644 编写于 作者: I isidor

explorerView: reduce use of root more

上级 c3e8d3a3
...@@ -301,7 +301,7 @@ export class ExplorerView extends CollapsibleView { ...@@ -301,7 +301,7 @@ export class ExplorerView extends CollapsibleView {
lastActiveFileResource = URI.parse(this.settings[ExplorerView.MEMENTO_LAST_ACTIVE_FILE_RESOURCE]); lastActiveFileResource = URI.parse(this.settings[ExplorerView.MEMENTO_LAST_ACTIVE_FILE_RESOURCE]);
} }
if (lastActiveFileResource && this.isCreated && this.root.find(lastActiveFileResource)) { if (lastActiveFileResource && this.isCreated && this.model.findFirst(lastActiveFileResource)) {
this.editorService.openEditor({ resource: lastActiveFileResource, options: { revealIfVisible: true } }).done(null, errors.onUnexpectedError); this.editorService.openEditor({ resource: lastActiveFileResource, options: { revealIfVisible: true } }).done(null, errors.onUnexpectedError);
return refreshPromise; return refreshPromise;
...@@ -420,25 +420,24 @@ export class ExplorerView extends CollapsibleView { ...@@ -420,25 +420,24 @@ export class ExplorerView extends CollapsibleView {
} }
let modelElement: FileStat; let modelElement: FileStat;
let parent: FileStat; let parents: FileStat[];
let parentResource: URI; let parentResource: URI;
let parentElement: FileStat;
// Add // Add
if (e.operation === FileOperation.CREATE || e.operation === FileOperation.IMPORT || e.operation === FileOperation.COPY) { if (e.operation === FileOperation.CREATE || e.operation === FileOperation.IMPORT || e.operation === FileOperation.COPY) {
const addedElement = e.target; const addedElement = e.target;
parentResource = URI.file(paths.dirname(addedElement.resource.fsPath)); parentResource = URI.file(paths.dirname(addedElement.resource.fsPath));
parentElement = this.root.find(parentResource); parents = this.model.findAll(parentResource);
if (parentElement) { if (parents.length) {
// Add the new file to its parent (Model) // Add the new file to its parent (Model)
const childElement = FileStat.create(addedElement); const childElement = FileStat.create(addedElement);
parentElement.removeChild(childElement); // make sure to remove any previous version of the file if any parents[0].removeChild(childElement); // make sure to remove any previous version of the file if any
parentElement.addChild(childElement); parents[0].addChild(childElement);
// Refresh the Parent (View) // Refresh the Parent (View)
this.explorerViewer.refresh(parentElement).then(() => { this.explorerViewer.refresh(parents).then(() => {
return this.reveal(childElement, 0.5).then(() => { return this.reveal(childElement, 0.5).then(() => {
// Focus new element // Focus new element
...@@ -465,16 +464,16 @@ export class ExplorerView extends CollapsibleView { ...@@ -465,16 +464,16 @@ export class ExplorerView extends CollapsibleView {
// Handle Rename // Handle Rename
if (oldParentResource && newParentResource && oldParentResource.toString() === newParentResource.toString()) { if (oldParentResource && newParentResource && oldParentResource.toString() === newParentResource.toString()) {
modelElement = this.root.find(oldResource); modelElement = this.model.findFirst(oldResource);
if (modelElement) { if (modelElement) {
// Rename File (Model) // Rename File (Model)
modelElement.rename(newElement); modelElement.rename(newElement);
// Update Parent (View) // Update Parent (View)
parent = modelElement.parent; parents = this.model.findAll(modelElement.parent.resource);
if (parent) { if (parents.length) {
this.explorerViewer.refresh(parent).done(() => { this.explorerViewer.refresh(parents).done(() => {
// Select in Viewer if set // Select in Viewer if set
if (restoreFocus) { if (restoreFocus) {
...@@ -487,21 +486,21 @@ export class ExplorerView extends CollapsibleView { ...@@ -487,21 +486,21 @@ export class ExplorerView extends CollapsibleView {
// Handle Move // Handle Move
else if (oldParentResource && newParentResource) { else if (oldParentResource && newParentResource) {
const oldParent = this.root.find(oldParentResource); const oldParents = this.model.findAll(oldParentResource);
const newParent = this.root.find(newParentResource); const newParents = this.model.findAll(newParentResource);
modelElement = this.root.find(oldResource); modelElement = this.model.findFirst(oldResource);
if (oldParent && newParent && modelElement) { if (oldParents.length && newParents.length && modelElement) {
// Move in Model // Move in Model
modelElement.move(newParent, (callback: () => void) => { modelElement.move(newParents[0], (callback: () => void) => {
// Update old parent // Update old parent
this.explorerViewer.refresh(oldParent, true).done(callback, errors.onUnexpectedError); this.explorerViewer.refresh(oldParents, true).done(callback, errors.onUnexpectedError);
}, () => { }, () => {
// Update new parent // Update new parent
this.explorerViewer.refresh(newParent, true).done(() => this.explorerViewer.expand(newParent), errors.onUnexpectedError); this.explorerViewer.refresh(newParents, true).done(() => this.explorerViewer.expand(newParents[0]), errors.onUnexpectedError);
}); });
} }
} }
...@@ -509,16 +508,16 @@ export class ExplorerView extends CollapsibleView { ...@@ -509,16 +508,16 @@ export class ExplorerView extends CollapsibleView {
// Delete // Delete
else if (e.operation === FileOperation.DELETE) { else if (e.operation === FileOperation.DELETE) {
modelElement = this.root.find(e.resource); modelElement = this.model.findFirst(e.resource);
if (modelElement && modelElement.parent) { if (modelElement && modelElement.parent) {
parent = modelElement.parent; parents = this.model.findAll(modelElement.parent.resource);
// Remove Element from Parent (Model) // Remove Element from Parent (Model)
parent.removeChild(modelElement); parents[0].removeChild(modelElement);
// Refresh Parent (View) // Refresh Parent (View)
const restoreFocus = this.explorerViewer.isDOMFocused(); const restoreFocus = this.explorerViewer.isDOMFocused();
this.explorerViewer.refresh(parent).done(() => { this.explorerViewer.refresh(parents).done(() => {
// Ensure viewer has keyboard focus if event originates from viewer // Ensure viewer has keyboard focus if event originates from viewer
if (restoreFocus) { if (restoreFocus) {
...@@ -592,8 +591,8 @@ export class ExplorerView extends CollapsibleView { ...@@ -592,8 +591,8 @@ export class ExplorerView extends CollapsibleView {
} }
// Compute if parent is visible and added file not yet part of it // Compute if parent is visible and added file not yet part of it
const parentStat = this.root.find(URI.file(parent)); const parentStat = this.model.findFirst(URI.file(parent));
if (parentStat && parentStat.isDirectoryResolved && !this.root.find(change.resource)) { if (parentStat && parentStat.isDirectoryResolved && !this.model.findFirst(change.resource)) {
return true; return true;
} }
...@@ -610,7 +609,7 @@ export class ExplorerView extends CollapsibleView { ...@@ -610,7 +609,7 @@ export class ExplorerView extends CollapsibleView {
continue; // out of workspace file continue; // out of workspace file
} }
if (this.root.find(del.resource)) { if (this.model.findFirst(del.resource)) {
return true; return true;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册