Skip to content

Commit

Permalink
Adds keep open button to Git commands
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Sep 11, 2019
1 parent c42fa63 commit 4c1cefd
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 25 deletions.
4 changes: 4 additions & 0 deletions images/dark/icon-pin-small-selected.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions images/light/icon-pin-small-selected.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 75 additions & 25 deletions src/commands/gitCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ export type GitCommandsCommandArgs =
@command()
export class GitCommandsCommand extends Command {
private readonly GitQuickInputButtons = class {
static readonly CloseOnFocusOut: QuickInputButton = {
iconPath: {
dark: Container.context.asAbsolutePath('images/dark/icon-pin-small.svg') as any,
light: Container.context.asAbsolutePath('images/light/icon-pin-small.svg') as any
},
tooltip: 'Keep Open'
};

static readonly KeepOpen: QuickInputButton = {
iconPath: {
dark: Container.context.asAbsolutePath('images/dark/icon-pin-small-selected.svg') as any,
light: Container.context.asAbsolutePath('images/light/icon-pin-small-selected.svg') as any
},
tooltip: 'Keep Open'
};

static readonly WillConfirm: QuickInputButton = {
iconPath: {
dark: Container.context.asAbsolutePath('images/dark/icon-check.svg') as any,
Expand Down Expand Up @@ -139,6 +155,15 @@ export class GitCommandsCommand extends Command {
return;
}

if (
e === this.GitQuickInputButtons.CloseOnFocusOut ||
e === this.GitQuickInputButtons.KeepOpen
) {
await this.toggleKeepOpen(input, commandsStep.command);

return;
}

if (step.onDidClickButton !== undefined) {
step.onDidClickButton(input, e);
input.buttons = this.getButtons(step, commandsStep.command);
Expand Down Expand Up @@ -201,6 +226,8 @@ export class GitCommandsCommand extends Command {

if (e === this.GitQuickInputButtons.WillConfirmForced) return;
if (
e === this.GitQuickInputButtons.CloseOnFocusOut ||
e === this.GitQuickInputButtons.KeepOpen ||
e === this.GitQuickInputButtons.WillConfirm ||
e === this.GitQuickInputButtons.WillSkipConfirm
) {
Expand All @@ -212,7 +239,19 @@ export class GitCommandsCommand extends Command {
command = active;
}

await this.toggleConfirmation(quickpick, command);
if (
e === this.GitQuickInputButtons.WillConfirm ||
e === this.GitQuickInputButtons.WillSkipConfirm
) {
await this.toggleConfirmation(quickpick, command);
}

if (
e === this.GitQuickInputButtons.CloseOnFocusOut ||
e === this.GitQuickInputButtons.KeepOpen
) {
await this.toggleKeepOpen(quickpick, command);
}

return;
}
Expand Down Expand Up @@ -289,20 +328,7 @@ export class GitCommandsCommand extends Command {
const command = quickpick.activeItems[0];
if (!QuickCommandBase.is(command)) return;

const buttons: QuickInputButton[] = [];
if (command.canSkipConfirm) {
if (command.skipConfirmKey !== undefined) {
buttons.push(
command.confirm()
? this.GitQuickInputButtons.WillConfirm
: this.GitQuickInputButtons.WillSkipConfirm
);
}
} else {
buttons.push(this.GitQuickInputButtons.WillConfirmForced);
}

quickpick.buttons = buttons;
quickpick.buttons = this.getButtons(undefined, command);
}),
quickpick.onDidAccept(async () => {
let items = quickpick.selectedItems;
Expand Down Expand Up @@ -412,12 +438,18 @@ export class GitCommandsCommand extends Command {
}

private getButtons(step: QuickInputStep | QuickPickStep | undefined, command?: QuickCommandBase) {
if (command === undefined) return [];

const buttons: QuickInputButton[] = [];

if (step !== undefined) {
if (step.buttons !== undefined) return step.buttons;
if (step.buttons !== undefined) {
buttons.push(
...step.buttons,
configuration.get('gitCommands', 'closeOnFocusOut')
? this.GitQuickInputButtons.CloseOnFocusOut
: this.GitQuickInputButtons.KeepOpen
);
return buttons;
}

buttons.push(QuickInputButtons.Back);

Expand All @@ -426,15 +458,24 @@ export class GitCommandsCommand extends Command {
}
}

if (!command.canConfirm) return buttons;
if (command.canSkipConfirm) {
buttons.push(
command.confirm() ? this.GitQuickInputButtons.WillConfirm : this.GitQuickInputButtons.WillSkipConfirm
);
} else {
buttons.push(this.GitQuickInputButtons.WillConfirmForced);
if (command !== undefined && command.canConfirm) {
if (command.canSkipConfirm) {
buttons.push(
command.confirm()
? this.GitQuickInputButtons.WillConfirm
: this.GitQuickInputButtons.WillSkipConfirm
);
} else {
buttons.push(this.GitQuickInputButtons.WillConfirmForced);
}
}

buttons.push(
configuration.get('gitCommands', 'closeOnFocusOut')
? this.GitQuickInputButtons.CloseOnFocusOut
: this.GitQuickInputButtons.KeepOpen
);

return buttons;
}

Expand Down Expand Up @@ -472,6 +513,15 @@ export class GitCommandsCommand extends Command {

input.buttons = this.getButtons(command.value, command);
}

private async toggleKeepOpen(input: InputBox | QuickPick<QuickPickItem>, command: QuickCommandBase | undefined) {
const closeOnFocusOut = !configuration.get('gitCommands', 'closeOnFocusOut');

input.ignoreFocusOut = !closeOnFocusOut;
void (await configuration.updateEffective('gitCommands', 'closeOnFocusOut', closeOnFocusOut));

input.buttons = this.getButtons(command && command.value, command);
}
}

class PickCommandStep implements QuickPickStep {
Expand Down

0 comments on commit 4c1cefd

Please sign in to comment.