Browse Source

wip updates

Steven Silvester 8 years ago
parent
commit
5eb1e0d4c0
3 changed files with 52 additions and 53 deletions
  1. 39 40
      src/filebrowser/model.ts
  2. 8 8
      src/filebrowser/plugin.ts
  3. 5 5
      src/help/plugin.ts

+ 39 - 40
src/filebrowser/model.ts

@@ -6,23 +6,15 @@ import {
 } from '@jupyterlab/services';
 
 import {
-  IterableOrArrayLike, IIterator, each, toArray
+  ArrayExt, ArrayIterator, IterableOrArrayLike, IIterator, each, toArray
 } from '@phosphor/algorithm';
 
-import {
-  ArrayExt.findFirstIndex
-} from 'phosphor/lib/algorithm/searching';
-
-import {
-  Vector
-} from 'phosphor/lib/collections/vector';
-
 import {
   IDisposable
 } from '@phosphor/disposable';
 
 import {
-  Signal.clearData, defineSignal, ISignal
+  ISignal, Signal
 } from '@phosphor/signaling';
 
 import {
@@ -71,27 +63,37 @@ class FileBrowserModel implements IDisposable, IPathTracker {
   /**
    * A signal emitted when the path changes.
    */
-  pathChanged: ISignal<this, IChangedArgs<string>>;
+  get pathChanged(): ISignal<this, IChangedArgs<string>> {
+    return this._pathChanged;
+  }
 
   /**
    * A signal emitted when the directory listing is refreshed.
    */
-  refreshed: ISignal<this, void>;
+  get refreshed(): ISignal<this, void> {
+    return this._refreshed;
+  }
 
   /**
    * A signal emitted when the running sessions in the directory changes.
    */
-  sessionsChanged: ISignal<this, void>;
+  get sessionsChanged(): ISignal<this, void> {
+    return this._sessionsChanged;
+  }
 
   /**
    * Get the file path changed signal.
    */
-  fileChanged: ISignal<this, Contents.IChangedArgs>;
+  get fileChanged(): ISignal<this, Contents.IChangedArgs> {
+    return this._fileChanged;
+  }
 
   /**
    * A signal emitted when the file browser model loses connection.
    */
-  connectionFailure: ISignal<this, Error>;
+  get connectionFailure(): ISignal<this, Error> {
+    return this._connectionFailure;
+  }
 
   /**
    * Get the current path.
@@ -125,8 +127,8 @@ class FileBrowserModel implements IDisposable, IPathTracker {
     clearTimeout(this._timeoutId);
     clearInterval(this._refreshId);
     clearTimeout(this._blackoutId);
-    this._sessions.clear();
-    this._items.clear();
+    this._sessions.length = 0;
+    this._items.length = 0;
     Signal.clearData(this);
   }
 
@@ -136,7 +138,7 @@ class FileBrowserModel implements IDisposable, IPathTracker {
    * @returns A new iterator over the model's items.
    */
   items(): IIterator<Contents.IModel> {
-    return this._items.iter();
+    return new ArrayIterator(this._items);
   }
 
   /**
@@ -145,7 +147,7 @@ class FileBrowserModel implements IDisposable, IPathTracker {
    * @returns A new iterator over the model's active sessions.
    */
   sessions(): IIterator<Session.IModel> {
-    return this._sessions.iter();
+    return new ArrayIterator(this._sessions);
   }
 
   /**
@@ -176,7 +178,7 @@ class FileBrowserModel implements IDisposable, IPathTracker {
     let options: Contents.IFetchOptions = { content: true };
     this._pendingPath = newValue;
     if (oldValue !== newValue) {
-      this._sessions.clear();
+      this._sessions.length = 0;
     }
     let manager = this._manager;
     this._pending = manager.contents.get(newValue, options).then(contents => {
@@ -186,17 +188,17 @@ class FileBrowserModel implements IDisposable, IPathTracker {
       this._handleContents(contents);
       this._pendingPath = null;
       if (oldValue !== newValue) {
-        this.pathChanged.emit({
+        this._pathChanged.emit({
           name: 'path',
           oldValue,
           newValue
         });
       }
       this._onRunningChanged(manager.sessions, manager.sessions.running());
-      this.refreshed.emit(void 0);
+      this._refreshed.emit(void 0);
     }).catch(error => {
       this._pendingPath = null;
-      this.connectionFailure.emit(error);
+      this._connectionFailure.emit(error);
     });
     return this._pending;
   }
@@ -370,7 +372,7 @@ class FileBrowserModel implements IDisposable, IPathTracker {
     let path = this._model.path;
     path = path ? path + '/' + file.name : file.name;
     let name = file.name;
-    let isNotebook = file.name.ArrayExt.firstIndexOf('.ipynb') !== -1;
+    let isNotebook = file.name.indexOf('.ipynb') !== -1;
     let type: Contents.ContentType = isNotebook ? 'notebook' : 'file';
     let format: Contents.FileFormat = isNotebook ? 'json' : 'base64';
 
@@ -418,25 +420,24 @@ class FileBrowserModel implements IDisposable, IPathTracker {
       mimetype: contents.mimetype,
       format: contents.format
     };
-    this._items.clear();
+    this._items = contents.content;
     this._paths.clear();
     each(contents.content, (model: Contents.IModel) => {
       this._paths.add(model.path);
     });
-    this._items = new Vector<Contents.IModel>(contents.content);
   }
 
   /**
    * Handle a change to the running sessions.
    */
   private _onRunningChanged(sender: Session.IManager, models: IterableOrArrayLike<Session.IModel>): void {
-    this._sessions.clear();
+    this._sessions.length = 0;
     each(models, model => {
       if (this._paths.has(model.notebook.path)) {
-        this._sessions.pushBack(model);
+        this._sessions.push(model);
       }
     });
-    this.refreshed.emit(void 0);
+    this._refreshed.emit(void 0);
   }
 
   /**
@@ -446,13 +447,13 @@ class FileBrowserModel implements IDisposable, IPathTracker {
     let path = this._model.path || '.';
     let value = change.oldValue;
     if (value && value.path && ContentsManager.dirname(value.path) === path) {
-      this.fileChanged.emit(change);
+      this._fileChanged.emit(change);
       this._scheduleUpdate();
       return;
     }
     value = change.newValue;
     if (value && value.path && ContentsManager.dirname(value.path) === path) {
-      this.fileChanged.emit(change);
+      this._fileChanged.emit(change);
       this._scheduleUpdate();
       return;
     }
@@ -489,8 +490,8 @@ class FileBrowserModel implements IDisposable, IPathTracker {
 
   private _maxUploadSizeMb = 15;
   private _manager: ServiceManager.IManager = null;
-  private _sessions = new Vector<Session.IModel>();
-  private _items = new Vector<Contents.IModel>();
+  private _sessions: Session.IModel[] = [];
+  private _items: Contents.IModel[] = [];
   private _paths = new Set<string>();
   private _model: Contents.IModel;
   private _pendingPath: string = null;
@@ -499,16 +500,14 @@ class FileBrowserModel implements IDisposable, IPathTracker {
   private _refreshId = -1;
   private _blackoutId = -1;
   private _requested = false;
+  private _pathChanged = new Signal<this, IChangedArgs<string>>(this);
+  private _refreshed = new Signal<this, void>(this);
+  private _sessionsChanged = new Signal<this, void>(this);
+  private _fileChanged = new Signal<this, Contents.IChangedArgs>(this);
+  private _connectionFailure = new Signal<this, Error>(this);
 }
 
 
-// Define the signals for the `FileBrowserModel` class.
-defineSignal(FileBrowserModel.prototype, 'pathChanged');
-defineSignal(FileBrowserModel.prototype, 'refreshed');
-defineSignal(FileBrowserModel.prototype, 'fileChanged');
-defineSignal(FileBrowserModel.prototype, 'connectionFailure');
-
-
 /**
  * The namespace for the `FileBrowserModel` class statics.
  */

+ 8 - 8
src/filebrowser/plugin.ts

@@ -85,10 +85,10 @@ const NAMESPACE = 'filebrowser';
  * Activate the file browser.
  */
 function activate(app: JupyterLab, manager: IServiceManager, documentManager: IDocumentManager, registry: IDocumentRegistry, mainMenu: IMainMenu, palette: ICommandPalette, restorer: IInstanceRestorer, state: IStateDB): IPathTracker {
-  const { commands, keymap } = app;
+  const { commands } = app;
   let fbModel = new FileBrowserModel({ manager });
   let fbWidget = new FileBrowser({
-    commands, keymap,
+    commands,
     manager: documentManager,
     model: fbModel
   });
@@ -145,7 +145,7 @@ function activate(app: JupyterLab, manager: IServiceManager, documentManager: ID
       let disposables = new DisposableSet();
       let command: string;
 
-      openWith = new Menu({ commands, keymap });
+      openWith = new Menu({ commands });
       openWith.title.label = 'Open With...';
       openWith.disposed.connect(() => { disposables.dispose(); });
 
@@ -306,8 +306,8 @@ function addCommands(app: JupyterLab, fbWidget: FileBrowser, docManager: IDocume
  * Create a top level menu for the file browser.
  */
 function createMenu(app: JupyterLab, creatorCmds: string[]): Menu {
-  let { commands, keymap } = app;
-  let menu = new Menu({ commands, keymap });
+  let { commands } = app;
+  let menu = new Menu({ commands });
   menu.title.label = 'File';
   creatorCmds.forEach(name => {
     menu.addItem({ command: Private.commandForName(name) });
@@ -332,8 +332,8 @@ function createMenu(app: JupyterLab, creatorCmds: string[]): Menu {
  * commands are disposed when the menu itself is disposed.
  */
 function createContextMenu(fbWidget: FileBrowser, openWith: Menu):  Menu {
-  let { commands, keymap } = fbWidget;
-  let menu = new Menu({ commands, keymap });
+  let { commands } = fbWidget;
+  let menu = new Menu({ commands });
   let prefix = `file-browser-${++Private.id}`;
   let disposables = new DisposableSet();
   let command: string;
@@ -351,7 +351,7 @@ function createContextMenu(fbWidget: FileBrowser, openWith: Menu):  Menu {
   menu.addItem({ command });
 
   if (openWith) {
-    menu.addItem({ type: 'submenu', menu: openWith });
+    menu.addItem({ type: 'submenu', submenu: openWith });
   }
 
   command = `${prefix}:rename`;

+ 5 - 5
src/help/plugin.ts

@@ -136,8 +136,8 @@ export default plugin;
 
 /*
   * An IFrame the disposes itself when closed.
-  * 
-  * This is needed to clear the state restoration db when IFrames are closed. 
+  *
+  * This is needed to clear the state restoration db when IFrames are closed.
  */
 class ClosableIFrame extends IFrame {
 
@@ -167,7 +167,7 @@ function activate(app: JupyterLab, mainMenu: IMainMenu, palette: ICommandPalette
 
   // Handle state restoration.
   restorer.restore(tracker, {
-    command, 
+    command,
     args: widget => ({ url: widget.url, text: widget.title.label }),
     name: widget => widget.url
   });
@@ -190,8 +190,8 @@ function activate(app: JupyterLab, mainMenu: IMainMenu, palette: ICommandPalette
    * Create a menu for the help plugin.
    */
   function createMenu(): Menu {
-    let { commands, keymap } = app;
-    let menu = new Menu({ commands, keymap });
+    let { commands } = app;
+    let menu = new Menu({ commands });
     menu.title.label = category;
 
     menu.addItem({ command: AboutCommandIDs.open });