Skip to content

Commit

Permalink
Merge pull request #6270 from yuvipanda/emit-open
Browse files Browse the repository at this point in the history
[WIP] Provide a signal for opening items from a DirListing
  • Loading branch information
blink1073 committed May 23, 2019
2 parents f43c740 + b686f4a commit df62287
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions packages/filebrowser/src/listing.ts
Expand Up @@ -42,6 +42,7 @@ import { Message, MessageLoop } from '@phosphor/messaging';
import { Widget } from '@phosphor/widgets';

import { FileBrowserModel } from './model';
import { ISignal, Signal } from '@phosphor/signaling';

/**
* The class name added to DirListing widget.
Expand Down Expand Up @@ -256,6 +257,13 @@ export class DirListing extends Widget {
return this._sortState;
}

/**
* A signal fired when an item is opened.
*/
get onItemOpened(): ISignal<DirListing, Contents.IModel> {
return this._onItemOpened;
}

/**
* Create an iterator over the listing's selected items.
*
Expand Down Expand Up @@ -897,6 +905,20 @@ export class DirListing extends Widget {
this._startDrag(data.index, event.clientX, event.clientY);
}

/**
* Handle the opening of an item.
*/
private _handleOpen(item: Contents.IModel): void {
this._onItemOpened.emit(item);
if (item.type === 'directory') {
this._model
.cd(item.name)
.catch(error => showErrorMessage('Open directory', error));
} else {
let path = item.path;
this._manager.openOrReveal(path);
}
}
/**
* Handle the `'keydown'` event for the widget.
*/
Expand All @@ -918,17 +940,8 @@ export class DirListing extends Widget {
return;
}

let model = this._model;
let item = this._sortedItems[i];
if (item.type === 'directory') {
model
.cd(item.name)
.catch(error => showErrorMessage('Open directory', error));
} else {
let path = item.path;
this._manager.openOrReveal(path);
}

this._handleOpen(item);
break;
case 38: // Up arrow
this.selectPrevious(event.shiftKey);
Expand Down Expand Up @@ -989,16 +1002,8 @@ export class DirListing extends Widget {
return;
}

let model = this._model;
let item = this._sortedItems[i];
if (item.type === 'directory') {
model
.cd(item.name)
.catch(error => showErrorMessage('Open directory', error));
} else {
let path = item.path;
this._manager.openOrReveal(path);
}
this._handleOpen(item);
}

/**
Expand Down Expand Up @@ -1487,6 +1492,7 @@ export class DirListing extends Widget {
direction: 'ascending',
key: 'name'
};
private _onItemOpened = new Signal<DirListing, Contents.IModel>(this);
private _drag: Drag | null = null;
private _dragData: {
pressX: number;
Expand Down

0 comments on commit df62287

Please sign in to comment.