@@ -3,7 +3,12 @@ import {
33 JupyterFrontEnd ,
44 JupyterFrontEndPlugin
55} from '@jupyterlab/application' ;
6- import { Dialog , showErrorMessage , Toolbar } from '@jupyterlab/apputils' ;
6+ import {
7+ Dialog ,
8+ ICommandPalette ,
9+ showErrorMessage ,
10+ Toolbar
11+ } from '@jupyterlab/apputils' ;
712import { IChangedArgs } from '@jupyterlab/coreutils' ;
813import { IDocumentManager } from '@jupyterlab/docmanager' ;
914import { FileBrowserModel , IFileBrowserFactory } from '@jupyterlab/filebrowser' ;
@@ -12,43 +17,41 @@ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
1217import { ISettingRegistry } from '@jupyterlab/settingregistry' ;
1318import { IStatusBar } from '@jupyterlab/statusbar' ;
1419import { ITranslator , nullTranslator } from '@jupyterlab/translation' ;
20+ import { gitCloneCommandPlugin } from './cloneCommand' ;
1521import {
1622 addCommands ,
1723 addFileBrowserContextMenu ,
1824 createGitMenu
1925} from './commandsAndMenu' ;
26+ import { createImageDiff } from './components/diff/ImageDiff' ;
2027import { createNotebookDiff } from './components/diff/NotebookDiff' ;
2128import { addStatusBarWidget } from './components/StatusWidget' ;
2229import { GitExtension } from './model' ;
2330import { getServerSettings } from './server' ;
2431import { gitIcon } from './style/icons' ;
25- import { Git , IGitExtension } from './tokens' ;
32+ import { CommandIDs , Git , IGitExtension } from './tokens' ;
2633import { addCloneButton } from './widgets/gitClone' ;
2734import { GitWidget } from './widgets/GitWidget' ;
28- import { gitCloneCommandPlugin } from './cloneCommand' ;
29- import { createImageDiff } from './components/diff/ImageDiff' ;
3035
3136export { DiffModel } from './components/diff/model' ;
3237export { NotebookDiff } from './components/diff/NotebookDiff' ;
3338export { PlainTextDiff } from './components/diff/PlainTextDiff' ;
34- export { Git , IGitExtension } from './tokens' ;
3539export { logger , LoggerContext } from './logger' ;
40+ export { Git , IGitExtension } from './tokens' ;
3641
3742/**
3843 * The default running sessions extension.
3944 */
4045const plugin : JupyterFrontEndPlugin < IGitExtension > = {
4146 id : '@jupyterlab/git:plugin' ,
4247 requires : [
43- IMainMenu ,
4448 ILayoutRestorer ,
4549 IFileBrowserFactory ,
4650 IRenderMimeRegistry ,
4751 ISettingRegistry ,
48- IDocumentManager ,
49- IStatusBar ,
50- ITranslator
52+ IDocumentManager
5153 ] ,
54+ optional : [ IMainMenu , IStatusBar , ICommandPalette , ITranslator ] ,
5255 provides : IGitExtension ,
5356 activate,
5457 autoStart : true
@@ -64,14 +67,15 @@ export default [plugin, gitCloneCommandPlugin];
6467 */
6568async function activate (
6669 app : JupyterFrontEnd ,
67- mainMenu : IMainMenu ,
6870 restorer : ILayoutRestorer ,
6971 factory : IFileBrowserFactory ,
7072 renderMime : IRenderMimeRegistry ,
7173 settingRegistry : ISettingRegistry ,
7274 docmanager : IDocumentManager ,
73- statusBar : IStatusBar ,
74- translator ?: ITranslator
75+ mainMenu : IMainMenu | null ,
76+ statusBar : IStatusBar | null ,
77+ palette : ICommandPalette | null ,
78+ translator : ITranslator | null
7579) : Promise < IGitExtension > {
7680 let gitExtension : GitExtension | null = null ;
7781 let settings : ISettingRegistry . ISettings ;
@@ -82,7 +86,7 @@ async function activate(
8286 // And it is unlikely that another browser than the default will be used.
8387 // Ref: https://github.com/jupyterlab/jupyterlab-git/issues/1014
8488 const fileBrowser = factory . defaultBrowser ;
85- translator = translator || nullTranslator ;
89+ translator = translator ?? nullTranslator ;
8690 const trans = translator . load ( 'jupyterlab_git' ) ;
8791
8892 // Attempt to load application settings
@@ -186,6 +190,24 @@ async function activate(
186190 gitPlugin . title . icon = gitIcon ;
187191 gitPlugin . title . caption = 'Git' ;
188192
193+ if ( palette ) {
194+ // Add the commands to the command palette
195+ const category = 'Git Operations' ;
196+ [
197+ CommandIDs . gitToggleSimpleStaging ,
198+ CommandIDs . gitToggleDoubleClickDiff ,
199+ CommandIDs . gitOpenGitignore ,
200+ CommandIDs . gitShowDiff ,
201+ CommandIDs . gitInit ,
202+ CommandIDs . gitMerge ,
203+ CommandIDs . gitPush ,
204+ CommandIDs . gitPull ,
205+ CommandIDs . gitResetToRemote ,
206+ CommandIDs . gitManageRemote ,
207+ CommandIDs . gitTerminalCommand
208+ ] . forEach ( command => palette . addItem ( { command, category } ) ) ;
209+ }
210+
189211 // Let the application restorer track the running panel for restoration of
190212 // application state (e.g. setting the running panel as the current side bar
191213 // widget).
@@ -196,7 +218,7 @@ async function activate(
196218 app . shell . add ( gitPlugin , 'left' , { rank : 200 } ) ;
197219
198220 // Add a menu for the plugin
199- if ( app . version . split ( '.' ) . slice ( 0 , 2 ) . join ( '.' ) < '3.1' ) {
221+ if ( mainMenu && app . version . split ( '.' ) . slice ( 0 , 2 ) . join ( '.' ) < '3.1' ) {
200222 // Support JLab 3.0
201223 mainMenu . addMenu ( createGitMenu ( app . commands , trans ) , { rank : 60 } ) ;
202224 }
@@ -205,7 +227,9 @@ async function activate(
205227 addCloneButton ( gitExtension , fileBrowser , app . commands , trans ) ;
206228
207229 // Add the status bar widget
208- addStatusBarWidget ( statusBar , gitExtension , settings , trans ) ;
230+ if ( statusBar ) {
231+ addStatusBarWidget ( statusBar , gitExtension , settings , trans ) ;
232+ }
209233
210234 // Add the context menu items for the default file browser
211235 addFileBrowserContextMenu (
0 commit comments