Skip to content

Commit

Permalink
Finish up the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Aug 3, 2023
1 parent 0fd46f7 commit bb406b7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 39 deletions.
18 changes: 13 additions & 5 deletions src/cloneCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
import { CommandIDs, IGitExtension, Level } from './tokens';
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
import { Dialog, showDialog } from '@jupyterlab/apputils';
import { Dialog, ICommandPalette, showDialog } from '@jupyterlab/apputils';
import { GitCloneForm } from './widgets/GitCloneForm';
import { logger } from './logger';
import {
Expand All @@ -19,14 +19,16 @@ import { addCloneButton } from './widgets/gitClone';

export const gitCloneCommandPlugin: JupyterFrontEndPlugin<void> = {
id: '@jupyterlab/git:clone',
requires: [ITranslator, IGitExtension, IFileBrowserFactory],
requires: [IGitExtension, IFileBrowserFactory],
optional: [ICommandPalette, ITranslator],
activate: (
app: JupyterFrontEnd,
translator: ITranslator,
gitModel: IGitExtension,
fileBrowserFactory: IFileBrowserFactory
fileBrowserFactory: IFileBrowserFactory,
palette: ICommandPalette | null,
translator: ITranslator | null
) => {
translator = translator || nullTranslator;
translator = translator ?? nullTranslator;
const trans = translator.load('jupyterlab_git');
const fileBrowser = fileBrowserFactory.defaultBrowser;
const fileBrowserModel = fileBrowser.model;
Expand Down Expand Up @@ -89,6 +91,12 @@ export const gitCloneCommandPlugin: JupyterFrontEndPlugin<void> = {

// Add the context menu items for the default file browser
addFileBrowserContextMenu(gitModel, fileBrowser, app.contextMenu, trans);

if (palette) {
// Add the commands to the command palette
const category = 'Git Operations';
palette.addItem({ command: CommandIDs.gitClone, category });
}
},
autoStart: true
};
67 changes: 33 additions & 34 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
} from '@jupyterlab/application';
import {
Dialog,
ICommandPalette,
showErrorMessage,
Toolbar,
ICommandPalette
Toolbar
} from '@jupyterlab/apputils';
import { IChangedArgs } from '@jupyterlab/coreutils';
import { IDocumentManager } from '@jupyterlab/docmanager';
Expand All @@ -17,11 +17,13 @@ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { IStatusBar } from '@jupyterlab/statusbar';
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
import { gitCloneCommandPlugin } from './cloneCommand';
import {
addCommands,
addFileBrowserContextMenu,
createGitMenu
} from './commandsAndMenu';
import { createImageDiff } from './components/diff/ImageDiff';
import { createNotebookDiff } from './components/diff/NotebookDiff';
import { addStatusBarWidget } from './components/StatusWidget';
import { GitExtension } from './model';
Expand All @@ -30,31 +32,26 @@ import { gitIcon } from './style/icons';
import { CommandIDs, Git, IGitExtension } from './tokens';
import { addCloneButton } from './widgets/gitClone';
import { GitWidget } from './widgets/GitWidget';
import { gitCloneCommandPlugin } from './cloneCommand';
import { createImageDiff } from './components/diff/ImageDiff';

export { DiffModel } from './components/diff/model';
export { NotebookDiff } from './components/diff/NotebookDiff';
export { PlainTextDiff } from './components/diff/PlainTextDiff';
export { Git, IGitExtension } from './tokens';
export { logger, LoggerContext } from './logger';
export { Git, IGitExtension } from './tokens';

/**
* The default running sessions extension.
*/
const plugin: JupyterFrontEndPlugin<IGitExtension> = {
id: '@jupyterlab/git:plugin',
requires: [
IMainMenu,
ILayoutRestorer,
IFileBrowserFactory,
IRenderMimeRegistry,
ISettingRegistry,
IDocumentManager,
IStatusBar,
ICommandPalette,
ITranslator
IDocumentManager
],
optional: [IMainMenu, IStatusBar, ICommandPalette, ITranslator],
provides: IGitExtension,
activate,
autoStart: true
Expand All @@ -70,15 +67,15 @@ export default [plugin, gitCloneCommandPlugin];
*/
async function activate(
app: JupyterFrontEnd,
mainMenu: IMainMenu,
restorer: ILayoutRestorer,
factory: IFileBrowserFactory,
renderMime: IRenderMimeRegistry,
settingRegistry: ISettingRegistry,
docmanager: IDocumentManager,
statusBar: IStatusBar,
palette: ICommandPalette,
translator?: ITranslator
mainMenu: IMainMenu | null,
statusBar: IStatusBar | null,
palette: ICommandPalette | null,
translator: ITranslator | null
): Promise<IGitExtension> {
let gitExtension: GitExtension | null = null;
let settings: ISettingRegistry.ISettings;
Expand All @@ -89,7 +86,7 @@ async function activate(
// And it is unlikely that another browser than the default will be used.
// Ref: https://github.com/jupyterlab/jupyterlab-git/issues/1014
const fileBrowser = factory.defaultBrowser;
translator = translator || nullTranslator;
translator = translator ?? nullTranslator;
const trans = translator.load('jupyterlab_git');

// Attempt to load application settings
Expand Down Expand Up @@ -145,7 +142,6 @@ async function activate(
);
return null;
}

// Create the Git model
gitExtension = new GitExtension(docmanager, app.docRegistry, settings);

Expand Down Expand Up @@ -194,22 +190,23 @@ async function activate(
gitPlugin.title.icon = gitIcon;
gitPlugin.title.caption = 'Git';

// Add the commands to the command palette
const category = 'Git Operations';
[
CommandIDs.gitToggleSimpleStaging,
CommandIDs.gitToggleDoubleClickDiff,
CommandIDs.gitOpenGitignore,
CommandIDs.gitShowDiff,
CommandIDs.gitInit,
CommandIDs.gitClone,
CommandIDs.gitMerge,
CommandIDs.gitPush,
CommandIDs.gitPull,
CommandIDs.gitResetToRemote,
CommandIDs.gitManageRemote,
CommandIDs.gitTerminalCommand
].forEach(command => palette.addItem({ command, category }));
if (palette) {
// Add the commands to the command palette
const category = 'Git Operations';
[
CommandIDs.gitToggleSimpleStaging,
CommandIDs.gitToggleDoubleClickDiff,
CommandIDs.gitOpenGitignore,
CommandIDs.gitShowDiff,
CommandIDs.gitInit,
CommandIDs.gitMerge,
CommandIDs.gitPush,
CommandIDs.gitPull,
CommandIDs.gitResetToRemote,
CommandIDs.gitManageRemote,
CommandIDs.gitTerminalCommand
].forEach(command => palette.addItem({ command, category }));
}

// Let the application restorer track the running panel for restoration of
// application state (e.g. setting the running panel as the current side bar
Expand All @@ -221,7 +218,7 @@ async function activate(
app.shell.add(gitPlugin, 'left', { rank: 200 });

// Add a menu for the plugin
if (app.version.split('.').slice(0, 2).join('.') < '3.1') {
if (mainMenu && app.version.split('.').slice(0, 2).join('.') < '3.1') {
// Support JLab 3.0
mainMenu.addMenu(createGitMenu(app.commands, trans), { rank: 60 });
}
Expand All @@ -230,7 +227,9 @@ async function activate(
addCloneButton(gitExtension, fileBrowser, app.commands, trans);

// Add the status bar widget
addStatusBarWidget(statusBar, gitExtension, settings, trans);
if (statusBar) {
addStatusBarWidget(statusBar, gitExtension, settings, trans);
}

// Add the context menu items for the default file browser
addFileBrowserContextMenu(
Expand Down

0 comments on commit bb406b7

Please sign in to comment.