vscode#QuickInputButton TypeScript Examples

The following examples show how to use vscode#QuickInputButton. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: multiStepInput.ts    From cloudmusic-vscode with MIT License 6 votes vote down vote up
pickButtons: {
  forward: QuickInputButton;
  previous: QuickInputButton;
  next: QuickInputButton;
  close: QuickInputButton;
} = {
  forward: {
    iconPath: new ThemeIcon("arrow-right"),
    tooltip: i18n.word.forward,
  },
  previous: {
    iconPath: new ThemeIcon("arrow-up"),
    tooltip: i18n.word.previousPage,
  },
  next: {
    iconPath: new ThemeIcon("arrow-down"),
    tooltip: i18n.word.nextPage,
  },
  close: {
    iconPath: new ThemeIcon("close"),
    tooltip: i18n.word.close,
  },
}
Example #2
Source File: extension.ts    From vscode-file-browser with GNU Lesser General Public License v3.0 6 votes vote down vote up
onDidTriggerButton(button: QuickInputButton) {
        if (button === this.stepInButton) {
            this.stepIn();
        } else if (button === this.stepOutButton) {
            this.stepOut();
        } else if (button === this.actionsButton) {
            this.actions();
        }
    }
Example #3
Source File: multiStepInput.ts    From cloudmusic-vscode with MIT License 5 votes vote down vote up
showQuickPick<T extends QuickPickItem>({
    title,
    step,
    totalSteps,
    items,
    // activeItems,
    placeholder,
    changeCallback,
    canSelectMany,
    previous,
    next,
  }: QuickPickParameters<T> & QuickPickOption): Promise<
    readonly T[] | T | ButtonAction
  > {
    const disposables: Disposable[] = [];

    return new Promise<readonly T[] | T | ButtonAction>((resolve, reject) => {
      const input = window.createQuickPick<T>();
      input.canSelectMany = !!canSelectMany;
      input.matchOnDescription = true;
      input.matchOnDetail = true;
      input.ignoreFocusOut = true;
      input.title = title;
      input.step = step;
      input.totalSteps = Math.max(
        totalSteps || 1,
        this._step,
        this._steps.length
      );
      input.placeholder = placeholder;
      input.items = items;
      /* if (activeItems) {
            input.activeItems = activeItems;
          } */
      const button: QuickInputButton[] = [];
      if (previous) button.push(pickButtons.previous);
      if (next) button.push(pickButtons.next);
      input.buttons = [
        ...(this._step > 1 ? [QuickInputButtons.Back] : []),
        ...button,
        ...(this._step < this._steps.length ? [pickButtons.forward] : []),
        pickButtons.close,
      ];
      disposables.push(
        input.onDidTriggerButton((item) => {
          switch (item) {
            case QuickInputButtons.Back:
              reject(InputFlowAction.back);
              break;
            case pickButtons.forward:
              reject(InputFlowAction.forward);
              break;
            case pickButtons.previous:
              resolve(ButtonAction.previous);
              break;
            case pickButtons.next:
              resolve(ButtonAction.next);
              break;
            default:
              input.hide();
          }
        }),
        input.onDidAccept(() =>
          resolve(canSelectMany ? input.selectedItems : input.selectedItems[0])
        ),
        input.onDidHide(() => reject(InputFlowAction.cancel))
      );
      if (changeCallback)
        disposables.push(
          input.onDidChangeValue((value) => changeCallback(input, value))
        );
      if (this._current) this._current.dispose();
      this._current = input;
      this._current.show();
    }).finally(() => disposables.forEach((d) => void d.dispose()));
  }
Example #4
Source File: extension.ts    From vscode-file-browser with GNU Lesser General Public License v3.0 5 votes vote down vote up
actionsButton: QuickInputButton = {
        iconPath: new ThemeIcon("ellipsis"),
        tooltip: "Actions on selected file",
    };
Example #5
Source File: extension.ts    From vscode-file-browser with GNU Lesser General Public License v3.0 5 votes vote down vote up
stepOutButton: QuickInputButton = {
        iconPath: new ThemeIcon("arrow-left"),
        tooltip: "Step out of folder",
    };
Example #6
Source File: extension.ts    From vscode-file-browser with GNU Lesser General Public License v3.0 5 votes vote down vote up
stepInButton: QuickInputButton = {
        iconPath: new ThemeIcon("arrow-right"),
        tooltip: "Step into folder",
    };
Example #7
Source File: LookupV3QuickPickView.ts    From dendron with GNU Affero General Public License v3.0 4 votes vote down vote up
private onTriggerButton = (btn: QuickInputButton) => {
    const btnType = (btn as IDendronQuickInputButton).type;

    switch (btnType) {
      case LookupSelectionTypeEnum.selection2Items:
        if (
          this.getButton(LookupSelectionTypeEnum.selection2Items)?.canToggle
        ) {
          this._viewState.selectionState.value =
            this._viewState.selectionState.value ===
            LookupSelectionTypeEnum.selection2Items
              ? LookupSelectionTypeEnum.none
              : LookupSelectionTypeEnum.selection2Items;
        }
        break;

      case LookupSelectionTypeEnum.selection2link:
        if (this.getButton(LookupSelectionTypeEnum.selection2link)?.canToggle) {
          this._viewState.selectionState.value =
            this._viewState.selectionState.value ===
            LookupSelectionTypeEnum.selection2link
              ? LookupSelectionTypeEnum.none
              : LookupSelectionTypeEnum.selection2link;
        }
        break;

      case LookupSelectionTypeEnum.selectionExtract:
        if (
          this.getButton(LookupSelectionTypeEnum.selectionExtract)?.canToggle
        ) {
          this._viewState.selectionState.value =
            this._viewState.selectionState.value ===
            LookupSelectionTypeEnum.selectionExtract
              ? LookupSelectionTypeEnum.none
              : LookupSelectionTypeEnum.selectionExtract;
        }
        break;
      case "selectVault": {
        if (this.getButton("selectVault")?.canToggle) {
          this._viewState.vaultSelectionMode.value =
            this._viewState.vaultSelectionMode.value ===
            VaultSelectionMode.alwaysPrompt
              ? VaultSelectionMode.smart
              : VaultSelectionMode.alwaysPrompt;
        }
        break;
      }
      case "multiSelect": {
        if (this.getButton("multiSelect")?.canToggle) {
          this._viewState.isMultiSelectEnabled.value =
            !this._viewState.isMultiSelectEnabled.value;
        }
        break;
      }
      case "copyNoteLink": {
        if (this.getButton("copyNoteLink")?.canToggle) {
          this._viewState.isCopyNoteLinkEnabled.value =
            !this._viewState.isCopyNoteLinkEnabled.value;
        }
        break;
      }
      case "directChildOnly": {
        if (this.getButton("directChildOnly")?.canToggle) {
          this._viewState.isApplyDirectChildFilter.value =
            !this._viewState.isApplyDirectChildFilter.value;
        }
        break;
      }
      case LookupNoteTypeEnum.journal: {
        if (this.getButton(LookupNoteTypeEnum.journal)?.canToggle) {
          this._viewState.nameModifierMode.value =
            this._viewState.nameModifierMode.value ===
            LookupNoteTypeEnum.journal
              ? LookupNoteTypeEnum.none
              : LookupNoteTypeEnum.journal;
        }
        break;
      }
      case LookupNoteTypeEnum.scratch: {
        if (this.getButton(LookupNoteTypeEnum.scratch)?.canToggle) {
          this._viewState.nameModifierMode.value =
            this._viewState.nameModifierMode.value ===
            LookupNoteTypeEnum.scratch
              ? LookupNoteTypeEnum.none
              : LookupNoteTypeEnum.scratch;
        }
        break;
      }
      case LookupNoteTypeEnum.task: {
        if (this.getButton(LookupNoteTypeEnum.task)?.canToggle) {
          this._viewState.nameModifierMode.value =
            this._viewState.nameModifierMode.value === LookupNoteTypeEnum.task
              ? LookupNoteTypeEnum.none
              : LookupNoteTypeEnum.task;
        }
        break;
      }
      case "horizontal": {
        if (this.getButton("horizontal")?.canToggle) {
          this._viewState.isSplitHorizontally.value =
            !this._viewState.isSplitHorizontally.value;
        }
        break;
      }
      default:
        break;
    }

    AnalyticsUtils.track(LookupEvents.LookupModifierToggledByUser, {
      command: this._providerId,
      type: (btn as IDendronQuickInputButton).type,
      pressed: (btn as IDendronQuickInputButton).pressed,
    });
  };
Example #8
Source File: completeTask.ts    From vscode-todo-md with MIT License 4 votes vote down vote up
export async function completeTask() {
	// TODO: refactor this file
	// Show Quick Pick to complete a task
	const document = await getActiveOrDefaultDocument();
	// TODO: should this be tree?
	const notCompletedTasks = defaultSortTasks($state.tasks.filter(task => !task.done)).map(task => ({
		label: formatTask(task),
		ln: task.lineNumber,
	}));
	const qp = window.createQuickPick();
	qp.title = 'Complete a task';
	qp.placeholder = 'Choose a task to complete';

	const revealTaskInlineButton: QuickInputButton = {
		iconPath: new ThemeIcon('go-to-file'),
		tooltip: 'Reveal task',
	};
	const followLinkInlineButton: QuickInputButton = {
		iconPath: new ThemeIcon('link-external'),
		tooltip: 'Follow link',
	};
	const completeTaskInlineButton: QuickInputButton = {
		iconPath: new ThemeIcon('check'),
		tooltip: 'Complete task',
	};

	qp.items = notCompletedTasks.map(notCompletedTask => ({
		...notCompletedTask,
		buttons: [
			revealTaskInlineButton,
			followLinkInlineButton,
			completeTaskInlineButton,
		],
	}));

	let activeQuickPickItem: typeof notCompletedTasks[0];
	qp.onDidChangeActive(e => {
		// @ts-ignore
		activeQuickPickItem = e[0];
	});
	qp.onDidTriggerItemButton(async e => {
		// @ts-ignore
		const task = getTaskAtLineExtension(e.item.ln);
		if (!task) {
			return;
		}
		if (e.button.tooltip === followLinkInlineButton.tooltip) {
			followLinks(task.links);
		} else if (e.button.tooltip === revealTaskInlineButton.tooltip) {
			revealTask(task.lineNumber);
		} else if (e.button.tooltip === completeTaskInlineButton.tooltip) {
			// @ts-ignore
			await toggleDoneAtLine(await getActiveOrDefaultDocument(), e.item.ln);
			await updateState();
			qp.items = defaultSortTasks($state.tasks.filter(t => !t.done)).map(t => ({
				label: formatTask(t),
				ln: t.lineNumber,
			})).map(notCompletedTask => ({
				...notCompletedTask,
				buttons: [
					revealTaskInlineButton,
					followLinkInlineButton,
					completeTaskInlineButton,
				],
			}));
			return;
		}
		qp.hide();
		qp.dispose();
	});
	qp.onDidAccept(async e => {
		const task = getTaskAtLineExtension(activeQuickPickItem.ln);
		if (!task) {
			return;
		}
		if (task.count) {
			await incrementCountForTask(document, task.lineNumber, task);
		} else {
			await toggleDoneAtLine(document, task.lineNumber);
		}
		await updateState();
		updateAllTreeViews();
		qp.dispose();
	});
	qp.show();
}