Skip to content

Commit

Permalink
Add missing Git History command to the command palette
Browse files Browse the repository at this point in the history
Fixes #3256

Signed-off-by: Vincent Fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Oct 26, 2018
1 parent 233802d commit 1d0d011
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
46 changes: 27 additions & 19 deletions packages/git/src/browser/history/git-history-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import { MenuModelRegistry, CommandRegistry, Command, SelectionService } from '@theia/core';
import { AbstractViewContribution } from '@theia/core/lib/browser';
import { AbstractViewContribution, OpenViewArguments } from '@theia/core/lib/browser';
import { injectable, inject, postConstruct } from 'inversify';
import { NAVIGATOR_CONTEXT_MENU } from '@theia/navigator/lib/browser/navigator-contribution';
import { UriCommandHandler, UriAwareCommandHandler } from '@theia/core/lib/common/uri-command-handler';
Expand All @@ -26,18 +26,25 @@ import { GitRepositoryTracker } from '../git-repository-tracker';
import { GitRepositoryProvider } from '../git-repository-provider';
import { EDITOR_CONTEXT_MENU_GIT } from '../git-view-contribution';

export const GIT_HISTORY_ID = 'git-history';
export const GIT_HISTORY_LABEL = 'Git History';
export const GIT_HISTORY_TOGGLE_KEYBINDING = 'alt+h';
export const GIT_HISTORY_MAX_COUNT = 100;

export namespace GitHistoryCommands {
export const OPEN_FILE_HISTORY: Command = {
id: 'git-history:open-file-history',
label: 'Git History'
};
export const OPEN_BRANCH_HISTORY: Command = {
id: 'git-history:open-branch-history'
id: 'git-history:open-branch-history',
label: GIT_HISTORY_LABEL
};
}

export const GIT_HISTORY = 'git-history';
export const GIT_HISTORY_MAX_COUNT = 100;
export interface GitHistoryOpenViewArguments extends OpenViewArguments {
uri: string | undefined;
}

@injectable()
export class GitHistoryContribution extends AbstractViewContribution<GitHistoryWidget> {

Expand All @@ -50,14 +57,14 @@ export class GitHistoryContribution extends AbstractViewContribution<GitHistoryW

constructor() {
super({
widgetId: GIT_HISTORY,
widgetName: 'Git History',
widgetId: GIT_HISTORY_ID,
widgetName: GIT_HISTORY_LABEL,
defaultWidgetOptions: {
area: 'left',
rank: 400
},
toggleCommandId: GitHistoryCommands.OPEN_BRANCH_HISTORY.id,
toggleKeybinding: 'alt+h'
toggleKeybinding: GIT_HISTORY_TOGGLE_KEYBINDING
});
}

Expand All @@ -81,31 +88,32 @@ export class GitHistoryContribution extends AbstractViewContribution<GitHistoryW
});
}

async openView(args?: Partial<GitHistoryOpenViewArguments>): Promise<GitHistoryWidget> {
const widget = await super.openView(args);
this.refreshWidget(args!.uri);
return widget;
}

registerMenus(menus: MenuModelRegistry): void {
menus.registerMenuAction([...NAVIGATOR_CONTEXT_MENU, '5_history'], {
commandId: GitHistoryCommands.OPEN_FILE_HISTORY.id
commandId: GitHistoryCommands.OPEN_FILE_HISTORY.id,
label: GIT_HISTORY_LABEL
});
menus.registerMenuAction(EDITOR_CONTEXT_MENU_GIT, {
commandId: GitHistoryCommands.OPEN_FILE_HISTORY.id
commandId: GitHistoryCommands.OPEN_FILE_HISTORY.id,
label: GIT_HISTORY_LABEL
});
super.registerMenus(menus);
}

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(GitHistoryCommands.OPEN_FILE_HISTORY, this.newUriAwareCommandHandler({
execute: async uri => this.showWidget(uri.toString()),
execute: async uri => this.openView({ activate: true, uri: uri.toString() }),
isEnabled: (uri: URI) => !!this.repositoryProvider.findRepository(uri)
}));
commands.registerCommand(GitHistoryCommands.OPEN_BRANCH_HISTORY, {
execute: () => this.showWidget(undefined)
});
}

async showWidget(uri: string | undefined) {
await this.openView({
activate: true
execute: () => this.openView({ activate: true, uri: undefined })
});
this.refreshWidget(uri);
}

protected async refreshWidget(uri: string | undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { GitHistoryContribution, GIT_HISTORY } from './git-history-contribution';
import { GitHistoryContribution, GIT_HISTORY_ID } from './git-history-contribution';
import { interfaces, Container } from 'inversify';
import { WidgetFactory, OpenHandler, bindViewContribution } from '@theia/core/lib/browser';
import { GitHistoryWidget } from './git-history-widget';
Expand All @@ -30,7 +30,7 @@ export function bindGitHistoryModule(bind: interfaces.Bind) {
bind(GitAvatarService).toSelf().inSingletonScope();
bind(GitHistoryWidget).toSelf();
bind(WidgetFactory).toDynamicValue(ctx => ({
id: GIT_HISTORY,
id: GIT_HISTORY_ID,
createWidget: () => ctx.container.get<GitHistoryWidget>(GitHistoryWidget)
}));

Expand Down
8 changes: 4 additions & 4 deletions packages/git/src/browser/history/git-history-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Message } from '@phosphor/messaging';
import { AutoSizer, List, ListRowRenderer, ListRowProps, InfiniteLoader, IndexRange, ScrollParams } from 'react-virtualized';
import { GIT_RESOURCE_SCHEME } from '../git-resource';
import URI from '@theia/core/lib/common/uri';
import { GIT_HISTORY, GIT_HISTORY_MAX_COUNT } from './git-history-contribution';
import { GIT_HISTORY_ID, GIT_HISTORY_MAX_COUNT, GIT_HISTORY_LABEL } from './git-history-contribution';
import { GitFileStatus, Git, GitFileChange, Repository } from '../../common';
import { FileSystem } from '@theia/filesystem/lib/common';
import { GitDiffContribution } from '../diff/git-diff-contribution';
Expand Down Expand Up @@ -69,10 +69,10 @@ export class GitHistoryWidget extends GitNavigableListWidget<GitHistoryListNode>
@inject(WidgetManager) protected readonly widgetManager: WidgetManager,
@inject(GitDiffContribution) protected readonly diffContribution: GitDiffContribution) {
super();
this.id = GIT_HISTORY;
this.id = GIT_HISTORY_ID;
this.scrollContainer = 'git-history-list-container';
this.title.label = 'Git History';
this.title.caption = 'Git History';
this.title.label = GIT_HISTORY_LABEL;
this.title.caption = GIT_HISTORY_LABEL;
this.title.iconClass = 'fa git-history-tab-icon';
this.addClass('theia-git');
this.resetState();
Expand Down

0 comments on commit 1d0d011

Please sign in to comment.