From a165aa203a8982f7d9f5e67073408141b70178d8 Mon Sep 17 00:00:00 2001 From: ianhi Date: Mon, 31 Aug 2020 13:21:20 -0400 Subject: [PATCH 1/5] don't use docmanager reload when opening gitignore this would affect all open widgets, not just the gitignore editor and could result in unsaved changes being lost --- src/commandsAndMenu.ts | 5 +---- src/components/FileList.tsx | 10 ++-------- src/model.ts | 14 ++++++++++++++ src/tokens.ts | 7 +++++++ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/commandsAndMenu.ts b/src/commandsAndMenu.ts index 88fac284d..f6db10b32 100644 --- a/src/commandsAndMenu.ts +++ b/src/commandsAndMenu.ts @@ -200,10 +200,7 @@ export function addCommands( execute: async () => { await model.ensureGitignore(); const gitModel = model as GitExtension; - await gitModel.commands.execute('docmanager:reload'); - await gitModel.commands.execute('docmanager:open', { - path: model.getRelativeFilePath('.gitignore') - }); + gitModel.openGitignore(); } }); diff --git a/src/components/FileList.tsx b/src/components/FileList.tsx index c97c1b154..39d78c9ad 100644 --- a/src/components/FileList.tsx +++ b/src/components/FileList.tsx @@ -160,10 +160,7 @@ export class FileList extends React.Component { execute: async () => { if (this.state.selectedFile) { await this.props.model.ignore(this.state.selectedFile.to, false); - await this.props.model.commands.execute('docmanager:reload'); - await this.props.model.commands.execute('docmanager:open', { - path: this.props.model.getRelativeFilePath('.gitignore') - }); + this.props.model.openGitignore(); } } }); @@ -187,10 +184,7 @@ export class FileList extends React.Component { }); if (result.button.label === 'Ignore') { await this.props.model.ignore(this.state.selectedFile.to, true); - await this.props.model.commands.execute('docmanager:reload'); - await this.props.model.commands.execute('docmanager:open', { - path: this.props.model.getRelativeFilePath('.gitignore') - }); + this.props.model.openGitignore(); } } } diff --git a/src/model.ts b/src/model.ts index c09e0223f..43c630f0f 100644 --- a/src/model.ts +++ b/src/model.ts @@ -1274,6 +1274,20 @@ export class GitExtension implements IGitExtension { return Promise.resolve(response); } + /** + * open new editor or show an existing editor of the + * .gitignore file. If the editor does not have unsaved changes + * then ensure the editor's content matches the file on disk + */ + openGitignore() { + const widget = this._docmanager.openOrReveal( + this.getRelativeFilePath('.gitignore') + ); + if (widget && !widget.context.model.dirty) { + widget.context.revert(); + } + } + /** * Get list of files changed between two commits or two branches * @param base id of base commit or base branch for comparison diff --git a/src/tokens.ts b/src/tokens.ts index 88f76deb9..cbf6a479d 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -284,6 +284,13 @@ export interface IGitExtension extends IDisposable { */ ensureGitignore(): Promise; + /** + * open new editor or show an existing editor of the + * .gitignore file. If the editor does not have unsaved changes + * then ensure the editor's content matches the file on disk + */ + openGitignore(): void; + /** * Add an entry in .gitignore file * From b188d7e977b1cfd977cf41f0b4e2990c9a9edfe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Tue, 1 Sep 2020 08:59:40 +0200 Subject: [PATCH 2/5] Debug binder --- binder/postBuild | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binder/postBuild b/binder/postBuild index 233572629..a5acb0b41 100644 --- a/binder/postBuild +++ b/binder/postBuild @@ -1,4 +1,4 @@ #!/usr/bin/env bash pip install . jupyter serverextension enable --sys-prefix --py nbgitpuller -jupyter lab build +jupyter lab build --dev-build=False --debug From 2b7199294c4140a820cb26788de4af55c7169157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Collonval?= Date: Tue, 1 Sep 2020 09:25:27 +0200 Subject: [PATCH 3/5] Turn off minimization --- binder/postBuild | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binder/postBuild b/binder/postBuild index a5acb0b41..c59547846 100644 --- a/binder/postBuild +++ b/binder/postBuild @@ -1,4 +1,4 @@ #!/usr/bin/env bash pip install . jupyter serverextension enable --sys-prefix --py nbgitpuller -jupyter lab build --dev-build=False --debug +jupyter lab build --dev-build=False --minimize=False --debug From 9f1998f55eede8258323748fffb563081d8b0cc8 Mon Sep 17 00:00:00 2001 From: Frederic Collonval Date: Thu, 3 Sep 2020 19:58:43 +0200 Subject: [PATCH 4/5] All actions handle by the model --- src/commandsAndMenu.ts | 2 -- src/components/FileList.tsx | 2 -- src/model.ts | 32 ++++++++++++++++++-------------- src/tokens.ts | 7 ------- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/src/commandsAndMenu.ts b/src/commandsAndMenu.ts index f6db10b32..ca1105d6d 100644 --- a/src/commandsAndMenu.ts +++ b/src/commandsAndMenu.ts @@ -199,8 +199,6 @@ export function addCommands( isEnabled: () => model.pathRepository !== null, execute: async () => { await model.ensureGitignore(); - const gitModel = model as GitExtension; - gitModel.openGitignore(); } }); diff --git a/src/components/FileList.tsx b/src/components/FileList.tsx index 39d78c9ad..c65d7313a 100644 --- a/src/components/FileList.tsx +++ b/src/components/FileList.tsx @@ -160,7 +160,6 @@ export class FileList extends React.Component { execute: async () => { if (this.state.selectedFile) { await this.props.model.ignore(this.state.selectedFile.to, false); - this.props.model.openGitignore(); } } }); @@ -184,7 +183,6 @@ export class FileList extends React.Component { }); if (result.button.label === 'Ignore') { await this.props.model.ignore(this.state.selectedFile.to, true); - this.props.model.openGitignore(); } } } diff --git a/src/model.ts b/src/model.ts index 43c630f0f..b9944a5a0 100644 --- a/src/model.ts +++ b/src/model.ts @@ -1240,6 +1240,7 @@ export class GitExtension implements IGitExtension { }); this.refreshStatus(); + this._openGitignore(); return Promise.resolve(response); } @@ -1271,23 +1272,10 @@ export class GitExtension implements IGitExtension { }); this.refreshStatus(); + this._openGitignore(); return Promise.resolve(response); } - /** - * open new editor or show an existing editor of the - * .gitignore file. If the editor does not have unsaved changes - * then ensure the editor's content matches the file on disk - */ - openGitignore() { - const widget = this._docmanager.openOrReveal( - this.getRelativeFilePath('.gitignore') - ); - if (widget && !widget.context.model.dirty) { - widget.context.revert(); - } - } - /** * Get list of files changed between two commits or two branches * @param base id of base commit or base branch for comparison @@ -1437,6 +1425,22 @@ export class GitExtension implements IGitExtension { return this._taskID; } + /** + * open new editor or show an existing editor of the + * .gitignore file. If the editor does not have unsaved changes + * then ensure the editor's content matches the file on disk + */ + private _openGitignore() { + if (this._docmanager) { + const widget = this._docmanager.openOrReveal( + this.getRelativeFilePath('.gitignore') + ); + if (widget && !widget.context.model.dirty) { + widget.context.revert(); + } + } + } + /** * if file is open in JupyterLab find the widget and ensure the JupyterLab * version matches the version on disk. Do nothing if the file has unsaved changes diff --git a/src/tokens.ts b/src/tokens.ts index cbf6a479d..88f76deb9 100644 --- a/src/tokens.ts +++ b/src/tokens.ts @@ -284,13 +284,6 @@ export interface IGitExtension extends IDisposable { */ ensureGitignore(): Promise; - /** - * open new editor or show an existing editor of the - * .gitignore file. If the editor does not have unsaved changes - * then ensure the editor's content matches the file on disk - */ - openGitignore(): void; - /** * Add an entry in .gitignore file * From 0cfd13b78ab5797bf2d8d2c914fb995c6c3cfaaa Mon Sep 17 00:00:00 2001 From: ianhi Date: Thu, 3 Sep 2020 14:07:01 -0400 Subject: [PATCH 5/5] remove unused import --- src/commandsAndMenu.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/commandsAndMenu.ts b/src/commandsAndMenu.ts index ca1105d6d..685f2de66 100644 --- a/src/commandsAndMenu.ts +++ b/src/commandsAndMenu.ts @@ -12,7 +12,6 @@ import { ITerminal } from '@jupyterlab/terminal'; import { CommandRegistry } from '@lumino/commands'; import { Menu } from '@lumino/widgets'; import { IGitExtension } from './tokens'; -import { GitExtension } from './model'; import { GitCredentialsForm } from './widgets/CredentialsBox'; import { doGitClone } from './widgets/gitClone'; import { GitPullPushDialog, Operation } from './widgets/gitPushPull';