Преглед на файлове

Add and expose `getWidgetById` in instance tracker.

Afshin Darian преди 8 години
родител
ревизия
9127c7ec03
променени са 1 файла, в които са добавени 26 реда и са изтрити 0 реда
  1. 26 0
      src/common/instancetracker.ts

+ 26 - 0
src/common/instancetracker.ts

@@ -70,6 +70,13 @@ interface IInstanceTracker<T extends Widget> extends IDisposable {
    */
   readonly widgetAdded: ISignal<this, T>;
 
+  /**
+   * Get a widget with a specified ID that is held by the tracker.
+   *
+   * @param - id The ID string of the widget.
+   */
+  getWidgetById(id: string): T | null;
+
   /**
    * Iterate through each widget in the tracker.
    *
@@ -223,6 +230,25 @@ class InstanceTracker<T extends Widget> implements IInstanceTracker<T>, IDisposa
     tracker.dispose();
   }
 
+  /**
+   * Get a widget with a specified ID that is held by the tracker.
+   *
+   * @param - id The ID string of the widget.
+   */
+  getWidgetById(id: string): T | null {
+    let result: T = null;
+    each(this._tracker.widgets, widget => {
+      // If a result has already been found, short circuit.
+      if (result) {
+        return;
+      }
+      if (widget.id === id) {
+        result = widget;
+      }
+    });
+    return result;
+  }
+
   /**
    * Find the first widget in the tracker that satisfies a filter function.
    *