Browse Source

Bug fix: update caption after file rename

Oscar Arratia 8 years ago
parent
commit
5e12b644ea
2 changed files with 14 additions and 3 deletions
  1. 9 0
      src/docmanager/widgetmanager.ts
  2. 5 3
      src/docregistry/context.ts

+ 9 - 0
src/docmanager/widgetmanager.ts

@@ -111,6 +111,7 @@ class DocumentWidgetManager implements IDisposable {
 
     this.adoptWidget(context, widget);
     context.fileChanged.connect(this._onFileChanged, this);
+    context.pathChanged.connect(this._onPathChanged, this);
     context.ready.then(() => {
       this.setCaption(widget);
     });
@@ -331,6 +332,14 @@ class DocumentWidgetManager implements IDisposable {
     each(widgets, widget => { this.setCaption(widget); });
   }
 
+  /**
+   * Handle a path changed signal for a context.
+   */
+  private _onPathChanged(context: DocumentRegistry.Context): void {
+    let widgets = Private.widgetsProperty.get(context);
+    each(widgets, widget => { this.setCaption(widget); });
+  }
+
   private _closeGuard = false;
   private _registry: DocumentRegistry = null;
 }

+ 5 - 3
src/docregistry/context.ts

@@ -415,12 +415,14 @@ class Context<T extends DocumentRegistry.IModel> implements DocumentRegistry.ICo
       return;
     }
     if (change.oldValue.path === this._path) {
+      let newPath = change.newValue.path;
       if (this._session) {
-        this._session.rename(change.newValue.path);
+        this._session.rename(newPath);
       } else {
-        this._path = change.newValue.path;
-        this.pathChanged.emit(this._path);
+        this._path = newPath;
       }
+      this._updateContentsModel(change.newValue);
+      this.pathChanged.emit(this._path);
     }
   }