@@ -10,8 +10,8 @@ import {
1010 WidgetTracker
1111} from '@jupyterlab/apputils' ;
1212import { PathExt , URLExt } from '@jupyterlab/coreutils' ;
13- import { FileBrowser , FileBrowserModel } from '@jupyterlab/filebrowser' ;
14- import { Contents } from '@jupyterlab/services' ;
13+ import { FileBrowser } from '@jupyterlab/filebrowser' ;
14+ import { Contents , ContentsManager } from '@jupyterlab/services' ;
1515import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
1616import { ITerminal } from '@jupyterlab/terminal' ;
1717import { TranslationBundle } from '@jupyterlab/translation' ;
@@ -101,7 +101,7 @@ function pluralizedContextLabel(singular: string, plural: string) {
101101export function addCommands (
102102 app : JupyterFrontEnd ,
103103 gitModel : GitExtension ,
104- fileBrowserModel : FileBrowserModel ,
104+ browserTracker : WidgetTracker < FileBrowser > ,
105105 settings : ISettingRegistry . ISettings ,
106106 trans : TranslationBundle
107107) : void {
@@ -178,7 +178,7 @@ export function addCommands(
178178 'Create an empty Git repository or reinitialize an existing one'
179179 ) ,
180180 execute : async ( ) => {
181- const currentPath = fileBrowserModel . path ;
181+ const currentPath = browserTracker . currentWidget . model . path ;
182182 const result = await showDialog ( {
183183 title : trans . __ ( 'Initialize a Repository' ) ,
184184 body : trans . __ ( 'Do you really want to make this directory a Git Repo?' ) ,
@@ -311,14 +311,14 @@ export function addCommands(
311311 gitModel ,
312312 Operation . Clone ,
313313 trans ,
314- { path : fileBrowserModel . path , url : result . value }
314+ { path : browserTracker . currentWidget . model . path , url : result . value }
315315 ) ;
316316 logger . log ( {
317317 message : trans . __ ( 'Successfully cloned' ) ,
318318 level : Level . SUCCESS ,
319319 details
320320 } ) ;
321- await fileBrowserModel . refresh ( ) ;
321+ await browserTracker . currentWidget . model . refresh ( ) ;
322322 } catch ( error ) {
323323 console . error (
324324 'Encountered an error when cloning the repository. Error: ' ,
@@ -483,8 +483,13 @@ export function addCommands(
483483 refreshButton . hide ( ) ;
484484 diffWidget . toolbar . addItem ( 'refresh' , refreshButton ) ;
485485
486- model . changed . connect ( ( ) => {
486+ const refresh = ( ) => {
487487 refreshButton . show ( ) ;
488+ } ;
489+
490+ model . changed . connect ( refresh ) ;
491+ widget . disposed . connect ( ( ) => {
492+ model . changed . disconnect ( refresh ) ;
488493 } ) ;
489494
490495 // Load the diff widget
@@ -629,17 +634,26 @@ export function addCommands(
629634 if ( widget ) {
630635 // Trigger diff model update
631636 if ( diffContext . previousRef === 'HEAD' ) {
632- gitModel . headChanged . connect ( ( ) => {
637+ const updateHead = ( ) => {
633638 model . reference = {
634639 ...model . reference ,
635640 updateAt : Date . now ( )
636641 } ;
642+ } ;
643+
644+ gitModel . headChanged . connect ( updateHead ) ;
645+
646+ widget . disposed . connect ( ( ) => {
647+ gitModel . headChanged . disconnect ( updateHead ) ;
637648 } ) ;
638649 }
650+
639651 // If the diff is on the current file and it is updated => diff model changed
640652 if ( diffContext . currentRef === Git . Diff . SpecialRef . WORKING ) {
641- // More robust than fileBrowser.model.fileChanged
642- app . serviceManager . contents . fileChanged . connect ( ( _ , change ) => {
653+ const updateCurrent = (
654+ m : ContentsManager ,
655+ change : Contents . IChangedArgs
656+ ) => {
643657 const updateAt = new Date (
644658 change . newValue . last_modified
645659 ) . valueOf ( ) ;
@@ -652,6 +666,13 @@ export function addCommands(
652666 updateAt
653667 } ;
654668 }
669+ } ;
670+
671+ // More robust than fileBrowser.model.fileChanged
672+ app . serviceManager . contents . fileChanged . connect ( updateCurrent ) ;
673+
674+ widget . disposed . connect ( ( ) => {
675+ app . serviceManager . contents . fileChanged . disconnect ( updateCurrent ) ;
655676 } ) ;
656677 }
657678 }
0 commit comments