Merge branch 'tht13-stageShortcut'

This commit is contained in:
Joao Moreno 2016-06-09 16:25:43 +02:00
commit 9d6a8347e5
2 changed files with 131 additions and 6 deletions

View file

@ -28,7 +28,7 @@ import {IFileService} from 'vs/platform/files/common/files';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import wbar = require('vs/workbench/common/actionRegistry');
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
import { OpenChangeAction, OpenFileAction, SyncAction, PullAction, PushAction, PublishAction, StartGitBranchAction, StartGitCheckoutAction, InputCommitAction, UndoLastCommitAction } from './gitActions';
import { OpenChangeAction, OpenFileAction, SyncAction, PullAction, PushAction, PublishAction, StartGitBranchAction, StartGitCheckoutAction, InputCommitAction, UndoLastCommitAction, BaseStageAction, BaseUnstageAction } from './gitActions';
import paths = require('vs/base/common/paths');
import URI from 'vs/base/common/uri';
@ -244,6 +244,122 @@ class OpenInEditorAction extends baseeditor.EditorInputAction {
}
}
export class WorkbenchStageAction extends BaseStageAction {
static ID = 'workbench.action.git.stage';
static LABEL = nls.localize('workbenchStage', "Stage");
private contextService: IWorkspaceContextService;
constructor(
id = WorkbenchStageAction.ID,
label = WorkbenchStageAction.LABEL,
@IGitService gitService: IGitService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IWorkspaceContextService contextService: IWorkspaceContextService
) {
super(id, label, '', gitService, editorService);
this.contextService = contextService;
this.onGitServiceChange();
}
protected updateEnablement(): void {
if (this.contextService) {
this.enabled = this.isEnabled();
} else {
this.enabled = super.isEnabled();
}
}
isEnabled():boolean {
if (!super.isEnabled()) {
return false;
}
const editor = this.editorService.getActiveEditor();
if (!editor || !(editor instanceof baseeditor.BaseEditor)) {
return false;
}
return true;
}
run(context?: any): TPromise<void> {
const input = this.editorService.getActiveEditor().input;
let fileStatus: IFileStatus;
if (gitei.isGitEditorInput(input)) {
const gitInput = input as gitei.GitDiffEditorInput;
fileStatus = gitInput.getFileStatus();
} else {
fileStatus = getStatus(this.gitService, this.contextService, input as WorkbenchEditorCommon.IFileEditorInput);
}
if (!fileStatus) {
return TPromise.as<void>(null);
}
return super.run(fileStatus);
}
}
export class WorkbenchUnstageAction extends BaseUnstageAction {
static ID = 'workbench.action.git.unstage';
static LABEL = nls.localize('workbenchUnstage', "Unstage");
private contextService: IWorkspaceContextService;
constructor(
id = WorkbenchUnstageAction.ID,
label = WorkbenchUnstageAction.LABEL,
@IGitService gitService: IGitService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IWorkspaceContextService contextService: IWorkspaceContextService
) {
super(id, label, '', gitService, editorService);
this.contextService = contextService;
this.onGitServiceChange();
}
protected updateEnablement(): void {
if (this.contextService) {
this.enabled = this.isEnabled();
} else {
this.enabled = super.isEnabled();
}
}
isEnabled():boolean {
if (!super.isEnabled()) {
return false;
}
const editor = this.editorService.getActiveEditor();
if (!editor || !(editor instanceof baseeditor.BaseEditor)) {
return false;
}
return true;
}
run(context?: any): TPromise<void> {
const input = this.editorService.getActiveEditor().input;
let fileStatus: IFileStatus;
if (gitei.isGitEditorInput(input)) {
const gitInput = input as gitei.GitDiffEditorInput;
fileStatus = gitInput.getFileStatus();
} else {
fileStatus = getStatus(this.gitService, this.contextService, input as WorkbenchEditorCommon.IFileEditorInput);
}
if (!fileStatus) {
return TPromise.as<void>(null);
}
return super.run(fileStatus);
}
}
export class StageRangesAction extends baseeditor.EditorInputAction {
private gitService: IGitService;
private editorService: IWorkbenchEditorService;
@ -480,3 +596,5 @@ workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(StartGi
workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(StartGitCheckoutAction, StartGitCheckoutAction.ID, StartGitCheckoutAction.LABEL), 'Git: Checkout', category);
workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(InputCommitAction, InputCommitAction.ID, InputCommitAction.LABEL), 'Git: Commit', category);
workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(UndoLastCommitAction, UndoLastCommitAction.ID, UndoLastCommitAction.LABEL), 'Git: Undo Last Commit', category);
workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(WorkbenchStageAction, WorkbenchStageAction.ID, WorkbenchStageAction.LABEL), 'Git: Stage', category);
workbenchActionRegistry.registerWorkbenchAction(new SyncActionDescriptor(WorkbenchUnstageAction, WorkbenchUnstageAction.ID, WorkbenchUnstageAction.LABEL), 'Git: Unstage', category);

View file

@ -212,7 +212,7 @@ export class RefreshAction extends GitAction {
}
export abstract class BaseStageAction extends GitAction {
private editorService: IWorkbenchEditorService;
protected editorService: IWorkbenchEditorService;
constructor(id: string, label: string, className: string, gitService: IGitService, editorService: IWorkbenchEditorService) {
super(id, label, className, gitService);
@ -283,7 +283,10 @@ export class StageAction extends BaseStageAction {
static ID = 'workbench.action.git.stage';
static LABEL = nls.localize('stageChanges', "Stage");
constructor(@IGitService gitService: IGitService, @IWorkbenchEditorService editorService: IWorkbenchEditorService) {
constructor(
@IGitService gitService: IGitService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService
) {
super(StageAction.ID, StageAction.LABEL, 'git-action stage', gitService, editorService);
}
}
@ -485,7 +488,7 @@ export class GlobalUndoAction extends BaseUndoAction {
export abstract class BaseUnstageAction extends GitAction {
private editorService: IWorkbenchEditorService;
protected editorService: IWorkbenchEditorService;
constructor(id: string, label: string, className: string, gitService: IGitService, editorService: IWorkbenchEditorService) {
super(id, label, className, gitService);
@ -559,9 +562,13 @@ export abstract class BaseUnstageAction extends GitAction {
export class UnstageAction extends BaseUnstageAction {
static ID = 'workbench.action.git.unstage';
static LABEL = nls.localize('unstage', "Unstage");
constructor(@IGitService gitService: IGitService, @IWorkbenchEditorService editorService: IWorkbenchEditorService) {
super(UnstageAction.ID, nls.localize('unstage', "Unstage"), 'git-action unstage', gitService, editorService);
constructor(
@IGitService gitService: IGitService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService
) {
super(UnstageAction.ID, UnstageAction.LABEL, 'git-action unstage', gitService, editorService);
}
}