Skip to content

Commit 6d1d70a

Browse files
committed
added item to "Git" menu to toggle simple staging
1 parent 6c36dcc commit 6d1d70a

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

src/gitMenuCommands.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Dialog, MainAreaWidget, showDialog } from '@jupyterlab/apputils';
33
import { FileBrowser } from '@jupyterlab/filebrowser';
44
import { ITerminal } from '@jupyterlab/terminal';
55
import { IGitExtension } from './tokens';
6+
import { ISettingRegistry } from '@jupyterlab/coreutils';
67

78
/**
89
* The command IDs used by the git plugin.
@@ -12,6 +13,7 @@ export namespace CommandIDs {
1213
export const gitTerminalCommand = 'git:terminal-command';
1314
export const gitInit = 'git:init';
1415
export const gitOpenUrl = 'git:open-url';
16+
export const gitToggleSimpleStaging = 'git:toggle-simple-staging';
1517
}
1618

1719
/**
@@ -20,7 +22,8 @@ export namespace CommandIDs {
2022
export function addCommands(
2123
app: JupyterFrontEnd,
2224
model: IGitExtension,
23-
fileBrowser: FileBrowser
25+
fileBrowser: FileBrowser,
26+
settings: ISettingRegistry.ISettings
2427
) {
2528
const { commands, shell } = app;
2629

@@ -99,4 +102,13 @@ export function addCommands(
99102
window.open(url);
100103
}
101104
});
105+
106+
/** add toggle for simple staging */
107+
commands.addCommand(CommandIDs.gitToggleSimpleStaging, {
108+
label: 'Simple staging',
109+
isToggled: () => !!settings.composite['simpleStaging'],
110+
execute: args => {
111+
settings.set('simpleStaging', !settings.composite['simpleStaging']);
112+
}
113+
});
102114
}

src/index.ts

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import {
44
JupyterFrontEndPlugin
55
} from '@jupyterlab/application';
66
import { IChangedArgs, ISettingRegistry } from '@jupyterlab/coreutils';
7-
import { FileBrowserModel, IFileBrowserFactory } from '@jupyterlab/filebrowser';
7+
import {
8+
FileBrowser,
9+
FileBrowserModel,
10+
IFileBrowserFactory
11+
} from '@jupyterlab/filebrowser';
812
import { IMainMenu } from '@jupyterlab/mainmenu';
913
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
1014
import { defaultIconRegistry } from '@jupyterlab/ui-components';
@@ -60,9 +64,8 @@ function activate(
6064
restorer: ILayoutRestorer,
6165
factory: IFileBrowserFactory,
6266
renderMime: IRenderMimeRegistry,
63-
settings: ISettingRegistry
67+
settingRegistry: ISettingRegistry
6468
): IGitExtension {
65-
const { commands } = app;
6669
const key = plugin.id;
6770

6871
registerGitIcons(defaultIconRegistry);
@@ -81,7 +84,7 @@ function activate(
8184
});
8285

8386
/* Create the widgets */
84-
settings
87+
settingRegistry
8588
.load(key)
8689
.then(settings => {
8790
// Create the Git widget sidebar
@@ -97,6 +100,12 @@ function activate(
97100
// Rank has been chosen somewhat arbitrarily to give priority to the running
98101
// sessions widget in the sidebar.
99102
app.shell.add(gitPlugin, 'left', { rank: 200 });
103+
104+
// add a menu for the plugin
105+
mainMenu.addMenu(
106+
createGitMenu(app, gitExtension, factory.defaultBrowser, settings),
107+
{ rank: 60 }
108+
);
100109
})
101110
.catch(reason => {
102111
console.error(
@@ -105,29 +114,42 @@ function activate(
105114
});
106115

107116
addCloneButton(gitExtension, factory.defaultBrowser);
117+
return gitExtension;
118+
}
119+
120+
/**
121+
* Add commands and menu items
122+
*/
123+
function createGitMenu(
124+
app: JupyterFrontEnd,
125+
gitExtension: IGitExtension,
126+
fileBrowser: FileBrowser,
127+
settings: ISettingRegistry.ISettings
128+
): Menu {
129+
const { commands } = app;
130+
addCommands(app, gitExtension, fileBrowser, settings);
108131

109-
/* Add commands and menu items */
110-
const category = 'Git';
111-
addCommands(app, gitExtension, factory.defaultBrowser);
112132
let menu = new Menu({ commands });
113-
let tutorial = new Menu({ commands });
114-
tutorial.title.label = ' Tutorial ';
115-
menu.title.label = category;
133+
menu.title.label = 'Git';
116134
[CommandIDs.gitUI, CommandIDs.gitTerminalCommand, CommandIDs.gitInit].forEach(
117135
command => {
118136
menu.addItem({ command });
119137
}
120138
);
121139

140+
let tutorial = new Menu({ commands });
141+
tutorial.title.label = ' Tutorial ';
122142
RESOURCES.map(args => {
123143
tutorial.addItem({
124144
args,
125145
command: CommandIDs.gitOpenUrl
126146
});
127147
});
128-
129148
menu.addItem({ type: 'submenu', submenu: tutorial });
130-
mainMenu.addMenu(menu, { rank: 60 });
131149

132-
return gitExtension;
150+
menu.addItem({ type: 'separator' });
151+
152+
menu.addItem({ command: CommandIDs.gitToggleSimpleStaging });
153+
154+
return menu;
133155
}

0 commit comments

Comments
 (0)