Skip to content

FileCommandHandler

Command handler for file-specific commands.

Filters abstract files to only accept TFile instances. Subclasses override canExecuteFile and executeFile.

Import:

import { FileCommandHandler } from 'obsidian-dev-utils/obsidian/command-handlers/file-command-handler';

Signature:

export class FileCommandHandler extends AbstractFileCommandHandler

Extends: AbstractFileCommandHandler

Constructor

new FileCommandHandler(params: AbstractFileCommandHandlerConstructorParams)

Creates a new file command handler.

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 TFile instances, then delegates to canExecuteFile.
canExecuteAbstractFile(_abstractFile)booleanChecks whether the command can execute for a single abstract file.
(Inherited from AbstractFileCommandHandler)
canExecuteAbstractFiles(abstractFiles)booleanFilters to only accept TFile arrays, then delegates to canExecuteFiles.
canExecuteFile(_file)booleanChecks whether the command can execute for a single file.
canExecuteFiles(files)booleanChecks whether the command can execute for multiple files. Default implementation checks each file individually.
execute()Promisable<void>Executes the command from the command palette using the active file.
(Inherited from AbstractFileCommandHandler)
executeAbstractFile(abstractFile)Promisable<void>Delegates to executeFile.
executeAbstractFiles(abstractFiles)Promisable<void>Delegates to executeFiles.
executeFile(file)Promisable<void>Executes the command for a single file.
executeFiles(files)Promisable<void>Executes the command for multiple files. Default implementation executes sequentially.
getActiveFile()null | TAbstractFileGets the active file, if any, to use as the target when executing from the command palette.
(Inherited from AbstractFileCommandHandler)
onRegistered(context)Promise<void>Registers file-menu and files-menu event handlers.
(Inherited from AbstractFileCommandHandler)
shouldAddCommandToSubmenu()boolean | undefinedGets whether to add the command to a submenu.
(Inherited from AbstractFileCommandHandler)
shouldAddToAbstractFileMenu(params)booleanFilters to only show menu for TFile instances.
shouldAddToAbstractFilesMenu(params)booleanFilters to only show menu for TFile arrays.
shouldAddToCommandPalette()booleanChecks whether the command should appear in the command palette.
(Inherited from AbstractFileCommandHandler)
shouldAddToFileMenu(params)booleanChecks whether the command should appear in the single-file context menu.
shouldAddToFilesMenu(params)booleanChecks whether the command should appear in the multi-file context menu.