Skip to content

Commit

Permalink
Add history context menu button in the file browser (jupyterlab#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
navn-r committed Jul 13, 2021
1 parent a915184 commit 47c27ce
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/commandsAndMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
discardIcon,
gitIcon,
openIcon,
removeIcon
removeIcon,
historyIcon
} from './style/icons';
import {
CommandIDs,
Expand Down Expand Up @@ -893,6 +894,17 @@ export function addCommands(
}
});

commands.addCommand(ContextCommandIDs.gitFileHistory, {
label: trans.__('History'),
caption: trans.__('View the history of this file'),
execute: args => {
// TODO: Implement
const { files } = args as any as CommandArguments.IGitContextAction;
console.log('History Clicked', files.length === 1);
},
icon: historyIcon.bindprops({ stylesheet: 'menuItem' })
});

commands.addCommand(ContextCommandIDs.gitNoAction, {
label: trans.__('No actions available'),
isEnabled: () => false,
Expand Down Expand Up @@ -1071,6 +1083,14 @@ export function addFileBrowserContextMenu(
)
);

// if looking at a single file that is not untracked
if (
items.length === 1 &&
(allCommands.size === 0 || !statuses.has('untracked'))
) {
allCommands.add(ContextCommandIDs.gitFileHistory);
}

// if looking at a tracked file with no changes,
// it has no status, nor any actions available
// (although `git rm` would be a valid action)
Expand Down
5 changes: 5 additions & 0 deletions src/style/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import removeSvg from '../../style/icons/remove.svg';
import rewindSvg from '../../style/icons/rewind.svg';
import tagSvg from '../../style/icons/tag.svg';
import trashSvg from '../../style/icons/trash.svg';
import clockSvg from '../../style/icons/clock.svg';

export const gitIcon = new LabIcon({ name: 'git', svgstr: gitSvg });
export const addIcon = new LabIcon({
Expand Down Expand Up @@ -79,3 +80,7 @@ export const trashIcon = new LabIcon({
name: 'git:trash',
svgstr: trashSvg
});
export const historyIcon = new LabIcon({
name: 'git:history',
svgstr: clockSvg
});
1 change: 1 addition & 0 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ export enum ContextCommandIDs {
gitFileUnstage = 'git:context-unstage',
gitFileStage = 'git:context-stage',
gitFileTrack = 'git:context-track',
gitFileHistory = 'git:context-history',
gitIgnore = 'git:context-ignore',
gitIgnoreExtension = 'git:context-ignoreExtension',
gitNoAction = 'git:no-action'
Expand Down
14 changes: 14 additions & 0 deletions style/icons/clock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 47c27ce

Please sign in to comment.