Skip to content

FolderCommandHandler

Command handler for folder-specific commands.

Filters abstract files to only accept TFolder instances. Subclasses override canExecuteFolder and executeFolder.

Import:

import { FolderCommandHandler } from '@mnaoumov/obsidian-lib/command-handlers/folder-command-handler';

Signature:

export class FolderCommandHandler extends AbstractFileCommandHandler

Extends: AbstractFileCommandHandler

Constructor

new FolderCommandHandler(params: AbstractFileCommandHandlerConstructorParams)

Creates a new folder command handler.

Properties

PropertyTypeDescription
iconIconNameThe icon for the command.
(Inherited from AbstractFileCommandHandler)
idstringThe ID of the command.
(Inherited from AbstractFileCommandHandler)
namestringThe display name of the command.
(Inherited from AbstractFileCommandHandler)

Methods

MethodReturnsDescription
buildCommand()CommandBuilds a plain Obsidian Command object with a checkCallback.
(Inherited from AbstractFileCommandHandler)
canExecute()booleanChecks whether the command can execute from the command palette. Uses the active file as the target.
(Inherited from AbstractFileCommandHandler)
canExecuteAbstractFile(abstractFile)booleanFilters to only accept TFolder instances, then delegates to canExecuteFolder.
canExecuteAbstractFile(_abstractFile)booleanChecks whether the command can execute for a single abstract file.
(Inherited from AbstractFileCommandHandler)
canExecuteAbstractFiles(abstractFiles)booleanFilters to only accept TFolder arrays, then delegates to canExecuteFolders.
canExecuteFolder(_folder)booleanChecks whether the command can execute for a single folder.
canExecuteFolders(folders)booleanChecks whether the command can execute for multiple folders. Default implementation checks each folder individually.
execute()Promisable<void>Executes the command from the command palette using the active file.
(Inherited from AbstractFileCommandHandler)
executeAbstractFile(abstractFile)Promisable<void>Delegates to executeFolder.
executeAbstractFiles(abstractFiles)Promisable<void>Delegates to executeFolders.
executeFolder(folder)Promisable<void>Executes the command for a single folder.
executeFolders(folders)Promisable<void>Executes the command for multiple folders. Default implementation executes sequentially.
getActiveFile()null | TAbstractFileGets the active folder, if any, to use as the target when executing from the command palette.
getCommandSwitchesShouldAddCommandToSubmenu()boolean | nullThe submenu answer of the user's command switches.
(Inherited from AbstractFileCommandHandler)
getDefaultShouldAddCommandToSubmenu()booleanGets whether to add the command to a submenu when neither the registration context nor the constructor set a value.
(Inherited from AbstractFileCommandHandler)
isMenuCommand()booleanWhether the command can appear in a context menu: whether the subclass overrides shouldAddToFolderMenu or shouldAddToFoldersMenu, or one of the abstract-file menu hooks this class implements.
isShownInMenus()booleanWhether the user's command switches let this command into the context menus. Always true while no switches are attached.
(Inherited from AbstractFileCommandHandler)
onRegistered(context)Promise<void>Registers file-menu and files-menu event handlers.
(Inherited from AbstractFileCommandHandler)
shouldAddCommandToSubmenu()booleanGets whether to add the command to a submenu.

The registration context wins over the constructor value: a menu surface that already wraps every contributed item in a plugin-titled parent entry forces this off, because a section submenu declared here would make Menu.sort() nest a second plugin-titled entry inside the first.

Next come the user's command switches, when the settings tab component attached them, then the constructor value. When none of those sets a value, getDefaultShouldAddCommandToSubmenu decides. Override that hook, not this method, to supply a fallback such as a plugin setting, so a registration that forces the flag off still wins.
(Inherited from AbstractFileCommandHandler)
shouldAddToAbstractFileMenu(params)booleanFilters to only show menu for TFolder instances.
shouldAddToAbstractFilesMenu(params)booleanFilters to only show menu for TFolder arrays.
shouldAddToCommandPalette()booleanChecks whether the command should appear in the command palette.
(Inherited from AbstractFileCommandHandler)
shouldAddToFolderMenu(params)booleanChecks whether the command should appear in the single-folder context menu.
shouldAddToFoldersMenu(params)booleanChecks whether the command should appear in the multi-folder context menu.