Reworks more commands deal with context

This commit is contained in:
Eric Amodio
2017-06-27 01:19:39 -04:00
parent 9179b70875
commit 1751987868
5 changed files with 220 additions and 144 deletions

View File

@@ -1,7 +1,7 @@
'use strict'; 'use strict';
import { commands, TextEditor, Uri, window } from 'vscode'; import { commands, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorTracker } from '../activeEditorTracker'; import { ActiveEditorTracker } from '../activeEditorTracker';
import { ActiveEditorCommand, Commands, getCommandUri } from './common'; import { ActiveEditorCommand, CommandContext, Commands, getCommandUri } from './common';
import { TextEditorComparer, UriComparer } from '../comparers'; import { TextEditorComparer, UriComparer } from '../comparers';
import { BuiltInCommands } from '../constants'; import { BuiltInCommands } from '../constants';
import { GitService } from '../gitService'; import { GitService } from '../gitService';
@@ -18,7 +18,23 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand {
super(Commands.CloseUnchangedFiles); super(Commands.CloseUnchangedFiles);
} }
async execute(editor: TextEditor, uri?: Uri, args: CloseUnchangedFilesCommandArgs = {}) { async run(context: CommandContext, args: CloseUnchangedFilesCommandArgs = {}): Promise<any> {
// Since we can change the args and they could be cached -- make a copy
switch (context.type) {
case 'uri':
return this.execute(context.editor, context.uri, { ...args });
case 'scm-states':
return undefined;
case 'scm-groups':
// const group = context.scmResourceGroups[0];
// args.uris = group.resourceStates.map(_ => _.resourceUri);
return this.execute(undefined, undefined, { ...args });
default:
return this.execute(context.editor, undefined, { ...args });
}
}
async execute(editor: TextEditor | undefined, uri?: Uri, args: CloseUnchangedFilesCommandArgs = {}) {
uri = getCommandUri(uri, editor); uri = getCommandUri(uri, editor);
try { try {

View File

@@ -1,6 +1,6 @@
'use strict'; 'use strict';
import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode'; import { commands, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, getCommandUri } from './common'; import { ActiveEditorCommand, CommandContext, Commands, getCommandUri } from './common';
import { BuiltInCommands, GlyphChars } from '../constants'; import { BuiltInCommands, GlyphChars } from '../constants';
import { GitService, GitUri } from '../gitService'; import { GitService, GitUri } from '../gitService';
import { Logger } from '../logger'; import { Logger } from '../logger';
@@ -21,7 +21,22 @@ export class DiffWithBranchCommand extends ActiveEditorCommand {
super(Commands.DiffWithBranch); super(Commands.DiffWithBranch);
} }
async execute(editor: TextEditor, uri?: Uri, args: DiffWithBranchCommandArgs = {}): Promise<any> { async run(context: CommandContext, args: DiffWithBranchCommandArgs = {}): Promise<any> {
// Since we can change the args and they could be cached -- make a copy
switch (context.type) {
case 'uri':
return this.execute(context.editor, context.uri, { ...args });
case 'scm-states':
const resource = context.scmResourceStates[0];
return this.execute(undefined, resource.resourceUri, { ...args });
case 'scm-groups':
return undefined;
default:
return this.execute(context.editor, undefined, { ...args });
}
}
async execute(editor: TextEditor | undefined, uri?: Uri, args: DiffWithBranchCommandArgs = {}): Promise<any> {
uri = getCommandUri(uri, editor); uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined; if (uri === undefined) return undefined;

View File

@@ -1,6 +1,6 @@
'use strict'; 'use strict';
import { TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode'; import { TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, getCommandUri, openEditor } from './common'; import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, openEditor } from './common';
import { GitService } from '../gitService'; import { GitService } from '../gitService';
import { Logger } from '../logger'; import { Logger } from '../logger';
import { Messages } from '../messages'; import { Messages } from '../messages';
@@ -15,7 +15,23 @@ export class OpenChangedFilesCommand extends ActiveEditorCommand {
super(Commands.OpenChangedFiles); super(Commands.OpenChangedFiles);
} }
async execute(editor: TextEditor, uri?: Uri, args: OpenChangedFilesCommandArgs = {}) { async run(context: CommandContext, args: OpenChangedFilesCommandArgs = {}): Promise<any> {
// Since we can change the args and they could be cached -- make a copy
switch (context.type) {
case 'uri':
return this.execute(context.editor, context.uri, { ...args });
case 'scm-states':
return undefined;
case 'scm-groups':
// const group = context.scmResourceGroups[0];
// args.uris = group.resourceStates.map(_ => _.resourceUri);
return this.execute(undefined, undefined, { ...args });
default:
return this.execute(context.editor, undefined, { ...args });
}
}
async execute(editor: TextEditor | undefined, uri?: Uri, args: OpenChangedFilesCommandArgs = {}) {
uri = getCommandUri(uri, editor); uri = getCommandUri(uri, editor);
try { try {

View File

@@ -1,7 +1,7 @@
'use strict'; 'use strict';
import { Arrays } from '../system'; import { Arrays } from '../system';
import { commands, Range, TextEditor, Uri, window } from 'vscode'; import { commands, Range, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, Commands, getCommandUri } from './common'; import { ActiveEditorCommand, CommandContext, Commands, getCommandUri } from './common';
import { GitService, GitUri } from '../gitService'; import { GitService, GitUri } from '../gitService';
import { Logger } from '../logger'; import { Logger } from '../logger';
import { OpenInRemoteCommandArgs } from './openInRemote'; import { OpenInRemoteCommandArgs } from './openInRemote';
@@ -12,7 +12,21 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
super(Commands.OpenFileInRemote); super(Commands.OpenFileInRemote);
} }
async execute(editor: TextEditor, uri?: Uri) { async run(context: CommandContext): Promise<any> {
switch (context.type) {
case 'uri':
return this.execute(context.editor, context.uri);
case 'scm-states':
const resource = context.scmResourceStates[0];
return this.execute(undefined, resource.resourceUri);
case 'scm-groups':
return undefined;
default:
return this.execute(context.editor, undefined);
}
}
async execute(editor: TextEditor | undefined, uri?: Uri) {
uri = getCommandUri(uri, editor); uri = getCommandUri(uri, editor);
if (uri === undefined) return undefined; if (uri === undefined) return undefined;

View File

@@ -1,7 +1,7 @@
'use strict'; 'use strict';
import { Strings } from '../system'; import { Strings } from '../system';
import { commands, Range, TextEditor, Uri, window } from 'vscode'; import { commands, Range, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCachedCommand, Commands, getCommandUri } from './common'; import { ActiveEditorCachedCommand, CommandContext, Commands, getCommandUri } from './common';
import { GlyphChars } from '../constants'; import { GlyphChars } from '../constants';
import { GitLog, GitService, GitUri } from '../gitService'; import { GitLog, GitService, GitUri } from '../gitService';
import { Logger } from '../logger'; import { Logger } from '../logger';
@@ -25,7 +25,22 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand {
super(Commands.ShowQuickFileHistory); super(Commands.ShowQuickFileHistory);
} }
async execute(editor: TextEditor, uri?: Uri, args: ShowQuickFileHistoryCommandArgs = {}) { async run(context: CommandContext, args: ShowQuickFileHistoryCommandArgs = {}): Promise<any> {
// Since we can change the args and they could be cached -- make a copy
switch (context.type) {
case 'uri':
return this.execute(context.editor, context.uri, { ...args });
case 'scm-states':
const resource = context.scmResourceStates[0];
return this.execute(undefined, resource.resourceUri, { ...args });
case 'scm-groups':
return undefined;
default:
return this.execute(context.editor, undefined, { ...args });
}
}
async execute(editor: TextEditor | undefined, uri?: Uri, args: ShowQuickFileHistoryCommandArgs = {}) {
uri = getCommandUri(uri, editor); uri = getCommandUri(uri, editor);
if (uri === undefined) return commands.executeCommand(Commands.ShowQuickCurrentBranchHistory); if (uri === undefined) return commands.executeCommand(Commands.ShowQuickCurrentBranchHistory);