Bläddra i källkod

Expose more of the file browser model at the plugin level

Steven Silvester 8 år sedan
förälder
incheckning
ee7240738f
4 ändrade filer med 46 tillägg och 4 borttagningar
  1. 1 1
      src/filebrowser/buttons.ts
  2. 1 1
      src/filebrowser/listing.ts
  3. 8 1
      src/filebrowser/model.ts
  4. 36 1
      src/filebrowser/tracker.ts

+ 1 - 1
src/filebrowser/buttons.ts

@@ -307,7 +307,7 @@ class FileButtons extends Widget {
       return;
     }
     // Force a refresh of the current directory.
-    this._model.cd('.');
+    this._model.refresh();
   }
 
   /**

+ 1 - 1
src/filebrowser/listing.ts

@@ -1083,7 +1083,7 @@ class DirListing extends Widget {
    */
   private _selectItemByName(name: string): Promise<void> {
     // Make sure the file is available.
-    return this.model.cd('.').then(() => {
+    return this.model.refresh().then(() => {
       if (this.isDisposed) {
         return;
       }

+ 8 - 1
src/filebrowser/model.ts

@@ -148,6 +148,13 @@ class FileBrowserModel implements IDisposable, IPathTracker {
     return this._sessions.iter();
   }
 
+  /**
+   * Force a refresh of the directory contents.
+   */
+  refresh(): Promise<void> {
+    return this.cd('.');
+  }
+
   /**
    * Change directory.
    *
@@ -461,7 +468,7 @@ class FileBrowserModel implements IDisposable, IPathTracker {
       return;
     }
     this._timeoutId = setTimeout(() => {
-      this.cd('.');
+      this.refresh();
       if (this._requested && this._blackoutId !== -1) {
         this._requested = false;
         clearTimeout(this._blackoutId);

+ 36 - 1
src/filebrowser/tracker.ts

@@ -1,6 +1,14 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import {
+  Contents
+} from '@jupyterlab/services';
+
+import {
+  IIterator
+} from 'phosphor/lib/algorithm/iteration';
+
 import {
   ISignal
 } from 'phosphor/lib/core/signaling';
@@ -34,7 +42,34 @@ interface IPathTracker {
   pathChanged: ISignal<IPathTracker, IChangedArgs<string>>;
 
   /**
-   * The current path of the filebrowser.
+   * A signal emitted when the directory listing is refreshed.
+   */
+  refreshed: ISignal<IPathTracker, void>;
+
+  /**
+   * Get the file path changed signal.
+   */
+  fileChanged: ISignal<IPathTracker, Contents.IChangedArgs>;
+
+  /**
+   * A signal emitted when the tracker loses connection.
+   */
+  connectionFailure: ISignal<IPathTracker, Error>;
+
+  /**
+   * The current path of the tracker.
    */
   readonly path: string;
+
+  /**
+   * Create an iterator over the tracker's items.
+   *
+   * @returns A new iterator over the model's items.
+   */
+  items(): IIterator<Contents.IModel>;
+
+  /**
+   * Force a refresh of the directory contents.
+   */
+  refresh(): Promise<void>;
 }