Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git history #1176

Merged
merged 1 commit into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/core/src/browser/style/variables-bright.useable.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ all of MD as it is not optimized for dense, information rich UIs.
--theia-ui-button-color-disabled: var(--theia-accent-color5);
--theia-ui-button-font-color-disabled: var(--theia-ui-font-color3);

/* expand/collapse element */
--theia-ui-expand-button-color: var(--theia-accent-color4);
--theia-ui-expand-button-font-color: var(--theia-ui-font-color1);

/* dialogs */
--theia-ui-dialog-header-color: var(--theia-brand-color1);
--theia-ui-dialog-header-font-color: var(--theia-inverse-ui-font-color1);
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/browser/style/variables-dark.useable.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ all of MD as it is not optimized for dense, information rich UIs.
--theia-ui-button-color-disabled: var(--theia-accent-color5);
--theia-ui-button-font-color-disabled: var(--theia-ui-font-color3);

/* dialogs */
/* expand/collapse element */
--theia-ui-expand-button-color: black;
--theia-ui-expand-button-font-color: var(--theia-ui-font-color1);

/* dialogs */
--theia-ui-dialog-header-color: var(--theia-brand-color0);
--theia-ui-dialog-header-font-color: var(--theia-ui-font-color1);
--theia-ui-dialog-color: var(--theia-layout-color1);
Expand Down
17 changes: 11 additions & 6 deletions packages/editor/src/browser/diff-uris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export namespace DiffUris {
@injectable()
export class DiffUriLabelProviderContribution implements LabelProviderContribution {

constructor( @inject(LabelProvider) protected labelProvider: LabelProvider) { }
constructor(@inject(LabelProvider) protected labelProvider: LabelProvider) { }

canHandle(element: object): number {
if (element instanceof URI && DiffUris.isDiffUri(element)) {
Expand All @@ -60,12 +60,17 @@ export class DiffUriLabelProviderContribution implements LabelProviderContributi

getName(uri: URI): string {
const [left, right] = DiffUris.decode(uri);
const leftLongName = this.labelProvider.getName(left);
const rightLongName = this.labelProvider.getName(right);
if (leftLongName === rightLongName) {
return leftLongName;

if (left.path.toString() === right.path.toString() && left.query && right.query) {
return `${left.displayName}: ${left.query} <-> ${right.query}`;
} else {
const leftLongName = this.labelProvider.getName(left);
const rightLongName = this.labelProvider.getName(right);
if (leftLongName === rightLongName) {
return leftLongName;
}
return `${leftLongName} <-> ${rightLongName}`;
}
return `${leftLongName} <-> ${rightLongName}`;
}

getIcon(uri: URI): string {
Expand Down
22 changes: 2 additions & 20 deletions packages/git/src/browser/diff/git-diff-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class GitDiffWidget extends GitBaseWidget implements StatefulWidget {
@inject(GitRepositoryProvider) protected repositoryProvider: GitRepositoryProvider,
@inject(LabelProvider) protected labelProvider: LabelProvider,
@inject(OpenerService) protected openerService: OpenerService) {
super();
super(repositoryProvider, labelProvider);
this.id = GIT_DIFF;
this.title.label = "Diff";

Expand Down Expand Up @@ -71,24 +71,6 @@ export class GitDiffWidget extends GitBaseWidget implements StatefulWidget {
}
}

protected relativePath(uri: URI | string): string {
const parsedUri = typeof uri === 'string' ? new URI(uri) : uri;
const repo = this.repositoryProvider.selectedRepository;
if (repo) {
return this.getRepositoryRelativePath(repo, parsedUri);
} else {
return this.labelProvider.getLongName(parsedUri);
}
}

protected computeCaption(fileChange: GitFileChange): string {
let result = `${this.relativePath(fileChange.uri)} - ${this.getStatusCaption(fileChange.status, true)}`;
if (fileChange.oldUri) {
result = `${this.relativePath(fileChange.oldUri)} -> ${result}`;
}
return result;
}

storeState(): object {
const { fileChangeNodes, options } = this;
return {
Expand Down Expand Up @@ -143,7 +125,7 @@ export class GitDiffWidget extends GitBaseWidget implements StatefulWidget {
const fileChangeElement: h.Child = this.renderGitItem(fileChange);
files.push(fileChangeElement);
}
return h.div({ className: "commitFileListContainer" }, ...files);
return h.div({ className: "listContainer" }, ...files);
}

protected renderGitItem(change: GitFileChangeNode): h.Child {
Expand Down
33 changes: 27 additions & 6 deletions packages/git/src/browser/git-base-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
*/

import { VirtualWidget } from "@theia/core/lib/browser";
import { GitFileStatus, Repository } from '../common';
import { GitFileStatus, Repository, GitFileChange } from '../common';
import URI from "@theia/core/lib/common/uri";
import { GitRepositoryProvider } from "./git-repository-provider";
import { LabelProvider } from "@theia/core/lib/browser/label-provider";

export class GitBaseWidget extends VirtualWidget {

constructor(
protected readonly repositoryProvider: GitRepositoryProvider,
protected readonly labelProvider: LabelProvider) {
super();
}

protected getStatusCaption(status: GitFileStatus, staged: boolean): string {
switch (status) {
case GitFileStatus.New: return staged ? 'Added' : 'Unstaged';
Expand All @@ -23,13 +31,26 @@ export class GitBaseWidget extends VirtualWidget {
return '';
}

/**
* Returns the repository relative path of the given uri.
* @param repository
* @param uri
*/
protected getRepositoryRelativePath(repository: Repository, uri: URI) {
const repositoryUri = new URI(repository.localUri);
return uri.toString().substr(repositoryUri.toString().length + 1);
}

protected relativePath(uri: URI | string): string {
const parsedUri = typeof uri === 'string' ? new URI(uri) : uri;
const repo = this.repositoryProvider.selectedRepository;
if (repo) {
return this.getRepositoryRelativePath(repo, parsedUri);
} else {
return this.labelProvider.getLongName(parsedUri);
}
}

protected computeCaption(fileChange: GitFileChange): string {
let result = `${this.relativePath(fileChange.uri)} - ${this.getStatusCaption(fileChange.status, true)}`;
if (fileChange.oldUri) {
result = `${this.relativePath(fileChange.oldUri)} -> ${result}`;
}
return result;
}
}
5 changes: 4 additions & 1 deletion packages/git/src/browser/git-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import { Git, GitPath } from '../common/git';
import { ContainerModule } from 'inversify';
import { bindGitDiffModule } from './diff/git-diff-frontend-module';
import { WebSocketConnectionProvider, FrontendApplicationContribution, WidgetFactory, KeybindingContribution } from '@theia/core/lib/browser';
import { bindGitHistoryModule } from './history/git-history-frontend-module';
import { WebSocketConnectionProvider, FrontendApplicationContribution, WidgetFactory } from '@theia/core/lib/browser';
import { KeybindingContribution } from '@theia/core/lib/browser/keybinding';
import { GitCommandHandlers } from './git-command';
import { CommandContribution, MenuContribution, ResourceResolver } from "@theia/core/lib/common";
import { GitWatcher, GitWatcherPath, GitWatcherServer, GitWatcherServerProxy, ReconnectingGitWatcherServer } from '../common/git-watcher';
Expand All @@ -24,6 +26,7 @@ import '../../src/browser/style/index.css';

export default new ContainerModule(bind => {
bindGitDiffModule(bind);
bindGitHistoryModule(bind);
bind(GitWatcherServerProxy).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, GitWatcherPath)).inSingletonScope();
bind(GitWatcherServer).to(ReconnectingGitWatcherServer).inSingletonScope();
bind(GitWatcher).toSelf().inSingletonScope();
Expand Down
11 changes: 9 additions & 2 deletions packages/git/src/browser/git-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export interface GitFileChangeNode extends GitFileChange {
readonly description: string;
readonly caption?: string;
readonly extraIconClassName?: string;
readonly commitSha?: string;
selected?: boolean;
}

export namespace GitFileChangeNode {
export function is(node: any): node is GitFileChangeNode {
return 'uri' in node && 'status' in node && 'description' in node && 'label' in node && 'icon' in node;
}
}

@injectable()
Expand All @@ -53,7 +61,7 @@ export class GitWidget extends GitBaseWidget {
@inject(LabelProvider) protected readonly labelProvider: LabelProvider,
@inject(CommandService) protected readonly commandService: CommandService,
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService) {
super();
super(repositoryProvider, labelProvider);
this.id = 'theia-gitContainer';
this.title.label = 'Git';

Expand Down Expand Up @@ -386,5 +394,4 @@ export class GitWidget extends GitBaseWidget {
const message = error instanceof Error ? error.message : error;
this.messageService.error(message);
}

}
86 changes: 86 additions & 0 deletions packages/git/src/browser/history/git-history-contribution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (C) 2018 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import { MenuModelRegistry, CommandRegistry, Command, SelectionService } from "@theia/core";
import { AbstractViewContribution } from "@theia/core/lib/browser";
import { injectable, inject } from "inversify";
import { NAVIGATOR_CONTEXT_MENU } from "@theia/navigator/lib/browser/navigator-menu";
import { UriCommandHandler, FileSystemCommandHandler } from "@theia/workspace/lib/browser/workspace-commands";
import { GitHistoryWidget } from './git-history-widget';
import { Git } from "../../common";

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'
};
}

export const GIT_HISTORY = 'git-history';
export const GIT_HISTORY_MAX_COUNT = 100;
@injectable()
export class GitHistoryContribution extends AbstractViewContribution<GitHistoryWidget> {

constructor(
@inject(SelectionService) protected readonly selectionService: SelectionService) {
super({
widgetId: GIT_HISTORY,
widgetName: 'Git History',
defaultWidgetOptions: {
area: 'left',
rank: 400
},
toggleCommandId: GitHistoryCommands.OPEN_BRANCH_HISTORY.id,
toggleKeybinding: 'alt+h'
});
}

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

super.registerMenus(menus);
}

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(GitHistoryCommands.OPEN_FILE_HISTORY, this.newFileHandler({
execute: async uri => {
const options: Git.Options.Log = {
uri: uri.toString(),
maxCount: GIT_HISTORY_MAX_COUNT,
shortSha: true
};
this.showWidget(options);
}
}));
commands.registerCommand(GitHistoryCommands.OPEN_BRANCH_HISTORY, {
execute: () => {
this.showWidget({
maxCount: GIT_HISTORY_MAX_COUNT,
shortSha: true
});
}
});
}

async showWidget(options?: Git.Options.Log) {
const widget = await this.widget;
await widget.setContent(options);
this.openView({
toggle: true,
activate: true
});
}

protected newFileHandler(handler: UriCommandHandler): FileSystemCommandHandler {
return new FileSystemCommandHandler(this.selectionService, handler);
}
}
32 changes: 32 additions & 0 deletions packages/git/src/browser/history/git-history-frontend-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2018 TypeFox and others.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*/

import { GitHistoryContribution, GIT_HISTORY } from "./git-history-contribution";
import { interfaces } from "inversify";
import { CommandContribution, MenuContribution } from "@theia/core";
import { KeybindingContribution } from "@theia/core/lib/browser/keybinding";
import { WidgetFactory } from "@theia/core/lib/browser";
import { GitHistoryWidget } from "./git-history-widget";

import '../../../src/browser/style/history.css';

export function bindGitHistoryModule(bind: interfaces.Bind) {

bind(GitHistoryWidget).toSelf();
bind(WidgetFactory).toDynamicValue(ctx => ({
id: GIT_HISTORY,
createWidget: () => ctx.container.get<GitHistoryWidget>(GitHistoryWidget)
}));

bind(GitHistoryContribution).toSelf().inSingletonScope();
for (const identifier of [CommandContribution, MenuContribution, KeybindingContribution]) {
bind(identifier).toDynamicValue(ctx =>
ctx.container.get(GitHistoryContribution)
).inSingletonScope();
}

}
Loading