Skip to content

Commit

Permalink
GH-165: FileIcons added; if changes on a new file get discarded the f…
Browse files Browse the repository at this point in the history
…ile gets deleted

Signed-off-by: Jan Bicker <jan.bicker@typefox.io>
  • Loading branch information
jbicker committed Sep 28, 2017
1 parent f6dca77 commit bf3bf66
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
37 changes: 16 additions & 21 deletions packages/git/src/browser/git-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import { GitFileChange, GitFileStatus, Repository, WorkingDirectoryStatus } from
import { GitWatcher, GitStatusChangeEvent } from '../common/git-watcher';
import { GIT_RESOURCE_SCHEME } from './git-resource';
import { GitRepositoryProvider } from './git-repository-provider';
import { MessageService, ResourceProvider, Disposable } from '@theia/core';
import { MessageService, ResourceProvider, Disposable, CommandService } from '@theia/core';
import URI from '@theia/core/lib/common/uri';
import { VirtualRenderer, VirtualWidget, ContextMenuRenderer, OpenerService, open } from '@theia/core/lib/browser';
import { h } from '@phosphor/virtualdom/lib';
import { DiffUriHelper } from '@theia/editor/lib/browser/editor-utility';
import { FileIconProvider } from '@theia/filesystem/lib/browser/icons/file-icons';
import { WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands';

@injectable()
export class GitWidget extends VirtualWidget {
Expand All @@ -40,7 +42,9 @@ export class GitWidget extends VirtualWidget {
@inject(OpenerService) protected readonly openerService: OpenerService,
@inject(ContextMenuRenderer) protected readonly contextMenuRenderer: ContextMenuRenderer,
@inject(ResourceProvider) protected readonly resourceProvider: ResourceProvider,
@inject(MessageService) protected readonly messageService: MessageService) {
@inject(MessageService) protected readonly messageService: MessageService,
@inject(FileIconProvider) protected readonly iconProvider: FileIconProvider,
@inject(CommandService) protected readonly commandService: CommandService) {
super();
this.id = 'theia-gitContainer';
this.title.label = 'Git';
Expand Down Expand Up @@ -201,12 +205,7 @@ export class GitWidget extends VirtualWidget {
title: 'Unstage Changes',
onclick: async event => {
const repo = await this.gitRepositoryProvider.getSelected();
this.git.rm(repo, change.uri)
.then(() => {
this.git.status(this.repository).then(status => {
this.updateView(status);
});
});
this.git.rm(repo, change.uri);
}
}, h.i({ className: 'fa fa-minus' })));
} else {
Expand All @@ -216,25 +215,19 @@ export class GitWidget extends VirtualWidget {
onclick: async event => {
const repo = await this.gitRepositoryProvider.getSelected();
const options: Git.Options.Checkout.WorkingTreeFile = { paths: change.uri };
this.git.checkout(repo, options)
.then(() => {
this.git.status(this.repository).then(status => {
this.updateView(status);
});
});
if (change.status === GitFileStatus.New) {
this.commandService.executeCommand(WorkspaceCommands.FILE_DELETE, new URI(change.uri));
} else {
this.git.checkout(repo, options);
}
}
}, h.i({ className: 'fa fa-undo' })));
btns.push(h.a({
className: 'button',
title: 'Stage Changes',
onclick: async event => {
const repo = await this.gitRepositoryProvider.getSelected();
this.git.add(repo, change.uri)
.then(() => {
this.git.status(this.repository).then(status => {
this.updateView(status);
});
});
this.git.add(repo, change.uri);
}
}, h.i({ className: 'fa fa-plus' })));
}
Expand All @@ -259,6 +252,8 @@ export class GitWidget extends VirtualWidget {

protected renderGitItem(change: GitFileChange): h.Child {
const changeUri: URI = new URI(change.uri);
const fileIcon = this.iconProvider.getFileIconForURI(changeUri);
const iconSpan = h.span({ className: fileIcon });
const nameSpan = h.span({ className: 'name' }, changeUri.displayName + ' ');
const pathSpan = h.span({ className: 'path' }, this.getRepositoryRelativePath(changeUri.path.dir.toString()));
const nameAndPathDiv = h.div({
Expand Down Expand Up @@ -294,7 +289,7 @@ export class GitWidget extends VirtualWidget {
}
open(this.openerService, uri);
}
}, nameSpan, pathSpan);
}, iconSpan, nameSpan, pathSpan);
const buttonsDiv = this.renderGitItemButtons(change);
const staged = change.staged ? 'staged ' : '';
const statusDiv = h.div({ className: 'status ' + staged + GitFileStatus[change.status].toLowerCase() }, this.getStatusChar(change.status, change.staged));
Expand Down
11 changes: 7 additions & 4 deletions packages/workspace/src/browser/workspace-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,20 @@ export class FileSystemCommandHandler implements CommandHandler {
protected readonly handler: UriCommandHandler
) { }

protected getUri(): URI | undefined {
protected getUri(...args: any[]): URI | undefined {
if (args && args[0] instanceof URI) {
return args[0];
}
return UriSelection.getUri(this.selectionService.selection);
}

execute(...args: any[]): object | undefined {
const uri = this.getUri();
const uri = this.getUri(...args);
return uri ? this.handler.execute(uri, ...args) : undefined;
}

isVisible(...args: any[]): boolean {
const uri = this.getUri();
const uri = this.getUri(...args);
if (uri) {
if (this.handler.isVisible) {
return this.handler.isVisible(uri, ...args);
Expand All @@ -242,7 +245,7 @@ export class FileSystemCommandHandler implements CommandHandler {
}

isEnabled(...args: any[]): boolean {
const uri = this.getUri();
const uri = this.getUri(...args);
if (uri) {
if (this.handler.isEnabled) {
return this.handler.isEnabled(uri, ...args);
Expand Down

0 comments on commit bf3bf66

Please sign in to comment.