Skip to content

โœจ Fast, custom cross-platform folder picker and creator for VS Code with icons, validation, and instant navigation. ๐ŸŽจ

License

Notifications You must be signed in to change notification settings

igorskyflyer/npm-vscode-folderpicker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

159 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Icon of FolderPicker

FolderPicker

VS Code Folder Picker โ€ข Crossโ€‘Platform โ€ข Icons & Validation โ€ข Instant Navigation

โœจ Fast, custom cross-platform folder picker and creator for VS Code with icons, validation, and instant navigation. ๐ŸŽจ


๐Ÿ“ƒ Table of Contents


๐Ÿค– Features

  • โœจ Fast Folder Selection
  • ๐ŸŽจ Icons With Clear Visuals
  • โšก Instant Navigation
  • โœ… Path Validation
  • ๐Ÿ› ๏ธ Configurable Buttons
  • ๐ŸŽฏ Custom Handlers & Events
  • ๐Ÿ“‚ Create & Navigate Folders
  • ๐Ÿ”” Error & Action Callbacks

๐ŸŽฏ Motivation

This module powers my New Folder VS Code extension.
It is under active development - expect breaking changes.

The goal

Provide a simple UI/UX for creating new folders when opening a new or blank VS Code instance, since that behavior is not builtโ€‘in.

Why not use showSaveDialog()?

  • Works only if files.simpleDialog.enable is set to true (a global preference that changes the UX for all file/folder dialogs).
  • Limited to creating a singleโ€‘level child folder - no nested/recursive folder creation.

What happened upstream?

The result

I built my own UI and logic to overcome these limitations.
This project is the outcome of that effort.


๐Ÿ•ต๐Ÿผ Usage

Install it by executing any of the following, depending on your preferred package manager:

pnpm add @igorskyflyer/vscode-folderpicker
yarn add @igorskyflyer/vscode-folderpicker
npm i @igorskyflyer/vscode-folderpicker

๐Ÿคน๐Ÿผ API

ResponseSpeed

enum ResponseSpeed

Used for controlling the response speed of the InputBox of the QuickPick. Since v.2.0.0 callbacks for generating Actions are throttled/debounced when necessary and the picker now waits for the user to finish their input before generating available Actions for performance reasons. Throttling is provided by Zep().

Available values are: Instant, Fast, Normal (default), Lazy.

๐Ÿ›‘ CAUTION

Throttling

Setting this property to ResponseSpeed.Instant disables all throttling/debouncing!


showFolderPicker()

showFolderPicker(directory: string, options?: Partial<IFolderPickerOptions>): void

Parameters

directory: string - Initial directory to display in the picker.

options: Partial<IFolderPickerOptions> - Optional configuration to customize behavior and UI.


Options

IFolderPickerOptions

UI/UX

  • [dialogTitle]: string = 'Pick a Folder' - Title text displayed at the top of the dialog. Defaults to 'Pick a Folder'.

  • [showIcons]: boolean = true - Whether to show icons next to folder items. Defaults to true.

Be aware that the term icon is used here descriptively.

This property expects either:

  • a single emoji (e.g. ๐Ÿ“‚), or
  • a VS Code ThemeIcon (string shorthand like '$(gear)' or an object instance new ThemeIcon('gear')).

To see the list of available ThemeIcons, look at the official Visual Studio Code documentation.
See the [Icons] section below.

  • [showConfigButton]: boolean = false - Whether to display a configuration (โš™๏ธ) button in the UI. Defaults to false.

  • [autoNavigate]: boolean = false - Whether to auto navigate to a child folder when creating new child folders. Defaults to false.

  • [responseSpeed]: ResponseSpeed | number = ResponseSpeed.Normal - Controls how quickly the picker responds to user input. Can be a predefined ResponseSpeed or a custom debounce interval in ms. See ResponseSpeed. Defaults to ResponseSpeed.Normal.

  • [ignoreFocusOut]: boolean = false - Whether the picker remains open when focus is lost. Defaults to false.

  • [canPick]: boolean = true - Whether to enable picking of current folder in the Picker. Defaults to true.

Icons

  • [iconFolder]: LabelIcon (string | ThemeIcon) = '' - Icon used for folder entries.

  • [iconFolderUp]: LabelIcon (string | ThemeIcon) = '' - Icon used for the go up (parent folder) action.

  • [iconCreate]: LabelIcon (string | ThemeIcon) = '' - Icon used for the create new folder action.

  • [iconNavigate]: LabelIcon (string | ThemeIcon) = '' - Icon used for navigation actions.

  • [iconPick]: LabelIcon (string | ThemeIcon) = '' - Icon used for the pick action.

  • [iconClear]: LabelIcon (string | ThemeIcon) = '' - Icon used for the clear action.

Behavior

  • [onCreateFolder]: FolderActionCallback - Fired when a new folder is created.

  • [onPickFolder]: FolderActionCallback - Fired when a folder is picked/selected.

  • [onNavigateTo]: FolderActionCallback - Fired when navigating into a folder.

  • [onGoUp]: FolderActionCallback - Fired when navigating up to the parent folder.

  • [onFetch]: FetchCallback - Fired before fetching folder contents.

  • [onFetched]: FetchCallback - Fired after folder contents have been fetched.

  • [onClose]: UICallback - Fired when the picker is closed.

  • [onConfigButton]: UICallback - Fired when the configuration button is pressed. Requires showConfigButton to be set to true.

  • [onError]: ErrorCallback - Fired when an error occurs (always receives an Error).

  • [onUnknownAction]: UnknownActionCallback - Fired for actions not covered by other handlers. Provides full access to the underlying QuickPick.


๐Ÿ—’๏ธ Examples

// some magic code ๐Ÿ”ฎ

import { showFolderPicker } from '@igorskyflyer/vscode-folderpicker'
import { ThemeIcon } from 'vscode'

showFolderPicker('/Users/igor/projects', {
  dialogTitle: 'Select a folder',
  onPickFolder: folderPath => {
    console.log('Picked folder:', folderPath)
  }
})

// even more magic code โœจ

๐Ÿ‘๏ธ Demo

VS Code Folder Picker - Command Palette creating a relative folder in current directory
Figure 1. Command Palette creating a relative folder in the current directory

VS Code Folder Picker - Command Palette creating a folder with absolute path
Figure 2. Command Palette creating a folder with an absolute path

VS Code Folder Picker - Command Palette creating nested recursive folders
Figure 3. Command Palette creating folders recursively in the current directory

VS Code Folder Picker - Command Palette showing invalid folder name error
Figure 4. Invalid folder name supplied in the Command Palette

VS Code Folder Picker - Command Palette navigating to relative folder path
Figure 5. Navigation to relativeโ€‘path folders

VS Code Folder Picker - Command Palette navigating to absolute folder path
Figure 6. Navigation to absoluteโ€‘path folders

VS Code Folder Picker - Command Palette picking a folder
Figure 7. Picking a folder from the Command Palette

๐Ÿ“ Changelog

๐Ÿ“‘ Read about the latest changes in the CHANGELOG.


๐Ÿชช License

Licensed under the MIT license.


๐Ÿ’– Support

I work hard for every project, including this one and your support means a lot to me!
Consider buying me a coffee. โ˜•

Donate to igorskyflyer

Thank you for supporting my efforts! ๐Ÿ™๐Ÿ˜Š

๐Ÿงฌ Related

@igorskyflyer/normalized-string

๐Ÿ’Š NormalizedString provides you with a String type with consistent line-endings, guaranteed. ๐Ÿ“ฎ


@igorskyflyer/valid-path

๐Ÿงฐ Determines whether a given value can be a valid file/directory name. ๐Ÿœ


@igorskyflyer/comment-it

๐Ÿ“œ Formats the provided string as a comment, either a single or a multi line comment for the given programming language. ๐Ÿ’ป


@igorskyflyer/jmap

๐Ÿ•ถ๏ธ Reads a JSON file into a Map. ๐ŸŒป


@igorskyflyer/is-rootdir

๐Ÿ”ผ Checks whether the given path is the root of a drive or filesystem. โ›”


๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Author

Created by Igor Dimitrijeviฤ‡ (@igorskyflyer).

About

โœจ Fast, custom cross-platform folder picker and creator for VS Code with icons, validation, and instant navigation. ๐ŸŽจ

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project