///
import type { Event } from '@difizen/mana-common';
import { URI } from '@difizen/mana-common';
import { Emitter, Disposable } from '@difizen/mana-common';
import { ApplicationContribution } from '@difizen/mana-core';
import type { Contribution } from '@difizen/mana-syringe';
import { Syringe } from '@difizen/mana-syringe';
export type ResourceLabelFormatter = {
scheme: string;
authority?: string;
priority?: boolean;
formatting: ResourceLabelFormatting;
};
export type ResourceLabelFormatting = {
label: string;
separator: '/' | '\\' | '';
normalizeDriveLetter?: boolean;
authorityPrefix?: string;
};
export declare const LabelProviderContribution: Syringe.DefinedToken;
/**
* A {@link LabelProviderContribution} determines how specific elements/nodes are displayed in the workbench.
* Mana views use a common {@link LabelProvider} to determine the label and/or an icon for elements shown in the UI. This includes elements in lists
* and trees, but also view specific locations like headers. The common {@link LabelProvider} collects all {@links LabelProviderContribution} and delegates
* to the contribution with the highest priority. This is determined via calling the {@link LabelProviderContribution.canHandle} function, so contributions
* define which elements they are responsible for.
* As arbitrary views can consume LabelProviderContributions, they must be generic for the covered element type, not view specific. Label providers and
* contributions can be used for arbitrary element and node types, e.g. for markers or domain-specific elements.
*/
export interface LabelProviderContribution {
/**
* Determines whether this contribution can handle the given element and with what priority.
* All contributions are ordered by the returned number if greater than zero. The highest number wins.
* If two or more contributions return the same positive number one of those will be used. It is undefined which one.
*/
canHandle: (element: Record) => number;
/**
* returns an icon class for the given element.
*/
getIcon?: (element: T) => string | undefined;
/**
* returns a short name for the given element.
*/
getName?: (element: T) => string | undefined;
/**
* returns a long name for the given element.
*/
getLongName?: (element: T) => string | undefined;
/**
* returns an icon component for the given element.
*/
getIconComponent?: (element: T) => React.ReactNode;
/**
* returns an name component for the given element.
*/
getNameComponent?: (element: T) => React.ReactNode;
/**
* returns an description component for the given element.
*/
getDescriptionComponent?: (element: T) => React.ReactNode;
/**
* Emit when something has changed that may result in this label provider returning a different
* value for one or more properties (name, icon etc).
*/
readonly onDidChange?: Event;
/**
* Checks whether the given element is affected by the given change event.
* Contributions delegating to the label provider can use this hook
* to perform a recursive check.
*/
affects?: (element: T, event: DidChangeLabelEvent) => boolean;
}
export type DidChangeLabelEvent = {
affects: (element: Record) => boolean;
};
export type URIIconReference = {
kind: 'uriIconReference';
id: 'file' | 'folder';
uri?: URI | undefined;
};
export declare namespace URIIconReference {
function is(element: any | undefined): element is URIIconReference;
function create(id: URIIconReference['id'], uri?: URI): URIIconReference;
}
export declare class DefaultUriLabelProviderContribution implements LabelProviderContribution> {
protected formatters: ResourceLabelFormatter[];
protected readonly onDidChangeEmitter: Emitter;
protected homePath: string | undefined;
init(): void;
canHandle(element: Record): number;
getIcon(element: Record): string;
get defaultFolderIcon(): string;
get defaultFileIcon(): string;
protected getFileIcon(uri: URI): string | undefined;
getName(element: Record): string | undefined;
getLongName(element: Record): string | undefined;
protected getUri(element: URI | URIIconReference): URI | undefined;
registerFormatter(formatter: ResourceLabelFormatter): Disposable;
get onDidChange(): Event;
private fireOnDidChange;
private readonly labelMatchingRegexp;
protected formatUri(resource: URI, formatting: ResourceLabelFormatting): string;
private hasDriveLetter;
protected findFormatting(resource: URI): ResourceLabelFormatting | undefined;
}
/**
* The {@link LabelProvider} determines how elements/nodes are displayed in the workbench. For any element, it can determine a short label, a long label
* and an icon. The {@link LabelProvider} is to be used in lists, trees and tables, but also view specific locations like headers.
* The common {@link LabelProvider} can be extended/adapted via {@link LabelProviderContribution}s. For every element, the {@links LabelProvider} will determine the
* {@link LabelProviderContribution} with the hightest priority and delegate to it. Mana registers default {@link LabelProviderContribution} for common types, e.g.
* the {@link DefaultUriLabelProviderContribution} for elements that have a URI.
* Using the {@link LabelProvider} across the workbench ensures a common look and feel for elements across multiple views. To adapt the way how specific
* elements/nodes are rendered, use a {@link LabelProviderContribution} rather than adapting or sub classing the {@link LabelProvider}. This way, your adaptation
* is applied to all views in Mana that use the {@link LabelProvider}
*/
export declare class LabelProvider implements ApplicationContribution {
protected readonly onDidChangeEmitter: Emitter;
protected readonly contributionProvider: Contribution.Provider;
constructor(contributionProvider: Contribution.Provider);
/**
* Start listening to contributions.
*
* Don't call this method directly!
* It's called by the frontend application during initialization.
*/
initialize(): void;
protected affects(element: Record, event: DidChangeLabelEvent): boolean;
get onDidChange(): Event;
/**
* Return a default file icon for the current icon theme.
*/
get fileIcon(): string;
/**
* Return a default folder icon for the current icon theme.
*/
get folderIcon(): string;
/**
* Get the icon class from the list of available {@link LabelProviderContribution} for the given element.
* @return the icon class
*/
getIcon(element: Record): string;
/**
* Get a short name from the list of available {@link LabelProviderContribution} for the given element.
* @return the short name
*/
getName(element: Record): string;
/**
* Get a long name from the list of available {@link LabelProviderContribution} for the given element.
* @return the long name
*/
getLongName(element: Record): string;
/**
* Get a icon component from the list of available {@link LabelProviderContribution} for the given element.
* @return the icon component
*/
getIconCompomponent(element: Record): React.ReactNode;
/**
* Get a name component from the list of available {@link LabelProviderContribution} for the given element.
* @return the name component
*/
getNameComponent(element: Record): React.ReactNode;
/**
* Get a description component from the list of available {@link LabelProviderContribution} for the given element.
* @return the description component
*/
getDescriptionComponent(element: Record): React.ReactNode;
protected findContribution(element: Record): LabelProviderContribution[];
}
//# sourceMappingURL=label-provider.d.ts.map