vscode#QuickPick TypeScript Examples

The following examples show how to use vscode#QuickPick. 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: PodControls.ts    From dendron with GNU Affero General Public License v3.0 5 votes vote down vote up
private static getExportConfigChooserQuickPick(): QuickPick<QuickPickItem> {
    const qp = vscode.window.createQuickPick();
    qp.title = "Pick a Pod Configuration or Create a New One";
    qp.matchOnDetail = true;
    qp.matchOnDescription = true;
    qp.ignoreFocusOut = true;

    const items: QuickPickItem[] = [];

    const configs = PodV2ConfigManager.getAllPodConfigs(
      path.join(getExtension().podsDir, "custom")
    );

    configs.forEach((config) => {
      let keybinding;

      try {
        keybinding = KeybindingUtils.getKeybindingForPodIfExists(config.podId);
      } catch (e: any) {
        if (
          e.message &&
          e.message.includes(KeybindingUtils.MULTIPLE_KEYBINDINGS_MSG_FMT)
        ) {
          keybinding = "Multiple Keybindings";
        }
      }

      let description = config.podType.toString();

      if (keybinding) {
        description = description + "  " + keybinding;
      }

      items.push({
        label: config.podId,
        detail: config.description ?? undefined,
        description,
      });
    });

    items.push({
      label: "New Export",
      detail:
        "Create a new export for either one-time use or to save to a new pod configuration",
    });

    qp.items = items;
    return qp;
  }
Example #2
Source File: QuickPickWrapper.ts    From al-objid with MIT License 5 votes vote down vote up
private _quickPick: QuickPick<QuickPickItemWrapper<T>>;
Example #3
Source File: search.ts    From cloudmusic-vscode with MIT License 4 votes vote down vote up
export async function inputKeyword(
  input: MultiStepInput,
  uid: number
): Promise<InputStep> {
  const state = {} as State;

  const items: QuickPickItem[] = [
    { label: state.keyword ?? (await IPC.netease("searchDefault", [uid])) },
    ...(await IPC.netease("searchHotDetail", [uid])).map(
      ({ searchWord, content }) => ({
        label: searchWord,
        description: "$(flame)",
        detail: content,
      })
    ),
  ];

  const updateSuggestions = throttle(
    (that: QuickPick<QuickPickItem>, value) => {
      that.enabled = false;
      that.busy = true;
      IPC.netease("searchSuggest", [uid, value])
        .then((suggestions) => {
          that.items = [
            that.items[0],
            ...suggestions.map((label) => ({ label })),
          ];
        })
        .catch(console.error)
        .finally(() => {
          that.enabled = true;
          that.busy = false;
        });
    },
    256
  );

  const pick = await input.showQuickPick({
    title,
    step: 2,
    totalSteps,
    items,
    placeholder: i18n.sentence.hint.keyword,
    changeCallback: (that, value) => {
      if (value) {
        that.items = [{ label: value }, ...that.items.slice(1)];
        updateSuggestions(that, value);
      } else {
        that.items = items;
      }
    },
  });
  state.keyword = pick.label;

  return (input) => pickType(input);

  async function pickType(input: MultiStepInput): Promise<InputStep> {
    const pick = await input.showQuickPick({
      title,
      step: 3,
      totalSteps,
      items: [
        {
          label: `$(zap) ${i18n.word.single}`,
          type: NeteaseSearchType.single,
        },
        {
          label: `$(circuit-board) ${i18n.word.album}`,
          type: NeteaseSearchType.album,
        },
        {
          label: `$(account) ${i18n.word.artist}`,
          type: NeteaseSearchType.artist,
        },
        {
          label: `$(list-unordered) ${i18n.word.playlist}`,
          type: NeteaseSearchType.playlist,
        },
        {
          label: `$(text-size) ${i18n.word.lyric}`,
          type: NeteaseSearchType.lyric,
        },
      ],
      placeholder: i18n.sentence.hint.search,
    });
    switch (pick.type) {
      case NeteaseSearchType.single:
        return (input) => pickSearchSingle(input, 0);
      case NeteaseSearchType.album:
        return (input) => pickSearchAlbum(input, 0);
      case NeteaseSearchType.artist:
        return (input) => pickSearchArtist(input, 0);
      case NeteaseSearchType.playlist:
        return (input) => pickSearchPlaylist(input, 0);
      case NeteaseSearchType.lyric:
        return (input) => pickSearchLyric(input, 0);
    }
    return (input) => pickSearchSingle(input, 0);
  }

  async function pickSearchSingle(
    input: MultiStepInput,
    offset: number
  ): Promise<InputStep | void> {
    const songs = await IPC.netease("searchSingle", [
      uid,
      state.keyword,
      limit,
      offset,
    ]);
    const pick = await input.showQuickPick({
      title,
      step: 4,
      totalSteps,
      items: pickSongItems(songs),
      canSelectMany: true,
      previous: offset > 0,
      next: songs.length === limit,
    });
    if (pick === ButtonAction.previous)
      return input.stay((input) => pickSearchSingle(input, offset - limit));
    if (pick === ButtonAction.next)
      return input.stay((input) => pickSearchSingle(input, offset + limit));
    if (pick.length === 0) return input.stay();
    if (pick.length === 1) return (input) => pickSong(input, 5, pick[0].item);

    return (input) =>
      pickSongMany(
        input,
        5,
        pick.map(({ item }) => item)
      );
  }

  async function pickSearchAlbum(
    input: MultiStepInput,
    offset: number
  ): Promise<InputStep> {
    const albums = await IPC.netease("searchAlbum", [
      uid,
      state.keyword,
      limit,
      offset,
    ]);
    const pick = await input.showQuickPick({
      title,
      step: 4,
      totalSteps,
      items: pickAlbumItems(albums),
      previous: offset > 0,
      next: albums.length === limit,
    });
    if (pick === ButtonAction.previous)
      return input.stay((input) => pickSearchAlbum(input, offset - limit));
    if (pick === ButtonAction.next)
      return input.stay((input) => pickSearchAlbum(input, offset + limit));
    return (input) => pickAlbum(input, 5, pick.id);
  }

  async function pickSearchArtist(
    input: MultiStepInput,
    offset: number
  ): Promise<InputStep> {
    const artists = await IPC.netease("searchArtist", [
      uid,
      state.keyword,
      limit,
      offset,
    ]);
    const pick = await input.showQuickPick({
      title,
      step: 4,
      totalSteps,
      items: pickArtistItems(artists),
      previous: offset > 0,
      next: artists.length === limit,
    });
    if (pick === ButtonAction.previous)
      return input.stay((input) => pickSearchArtist(input, offset - limit));
    if (pick === ButtonAction.next)
      return input.stay((input) => pickSearchArtist(input, offset + limit));
    return (input) => pickArtist(input, 5, pick.id);
  }

  async function pickSearchPlaylist(
    input: MultiStepInput,
    offset: number
  ): Promise<InputStep> {
    const playlists = await IPC.netease("searchPlaylist", [
      uid,
      state.keyword,
      limit,
      offset,
    ]);
    const pick = await input.showQuickPick({
      title,
      step: 4,
      totalSteps,
      items: pickPlaylistItems(playlists),
      previous: offset > 0,
      next: playlists.length === limit,
    });
    if (pick === ButtonAction.previous)
      return input.stay((input) => pickSearchPlaylist(input, offset - limit));
    if (pick === ButtonAction.next)
      return input.stay((input) => pickSearchPlaylist(input, offset + limit));
    return (input) => pickPlaylist(input, 5, pick.item);
  }

  async function pickSearchLyric(
    input: MultiStepInput,
    offset: number
  ): Promise<InputStep> {
    const songs = await IPC.netease("searchLyric", [
      uid,
      state.keyword,
      limit,
      offset,
    ]);
    const pick = await input.showQuickPick({
      title,
      step: 4,
      totalSteps,
      items: songs.map((item) => ({
        label: `$(zap) ${item.name}`,
        description: item.ar.map(({ name }) => name).join("/"),
        detail: item.lyrics.slice(1).join(", "),
        item,
      })),
      canSelectMany: true,
      previous: offset > 0,
      next: songs.length === limit,
    });
    if (pick === ButtonAction.previous)
      return input.stay((input) => pickSearchLyric(input, offset - limit));
    if (pick === ButtonAction.next)
      return input.stay((input) => pickSearchLyric(input, offset + limit));
    if (pick.length === 0) return input.stay();
    if (pick.length === 1) return (input) => pickSong(input, 5, pick[0].item);

    return (input) =>
      pickSongMany(
        input,
        5,
        pick.map(({ item }) => item)
      );
  }
}