UNPKG

@jupyterlab/git

Version:

A JupyterLab extension for version control using git

246 lines (245 loc) 7.99 kB
import { ISettingRegistry } from '@jupyterlab/settingregistry'; import { CommandRegistry } from '@lumino/commands'; import { TranslationBundle } from '@jupyterlab/translation'; import * as React from 'react'; import { GitExtension } from '../model'; import { ContextCommandIDs, Git } from '../tokens'; export interface IFileListState { selectedFiles: Git.IStatusFile[]; lastClickedFile: Git.IStatusFile | null; markedFiles: Git.IStatusFile[]; } export interface IFileListProps { /** * Modified files */ files: Git.IStatusFile[]; /** * Git extension model */ model: GitExtension; /** * Jupyter App commands registry */ commands: CommandRegistry; /** * Extension settings */ settings: ISettingRegistry.ISettings; /** * The application language translator. */ trans: TranslationBundle; } export type ContextCommands = Record<NonNullable<Git.Status>, ContextCommandIDs[]>; export declare const CONTEXT_COMMANDS: ContextCommands; export declare class FileList extends React.Component<IFileListProps, IFileListState> { constructor(props: IFileListProps); componentDidMount(): void; componentWillUnmount(): void; /** * Open the context menu on the advanced view * * @param selectedFile The file on which the context menu is opened * @param event The click event */ openContextMenu: (selectedFile: Git.IStatusFile, event: React.MouseEvent) => void; /** * Open the context menu on the simple view * * @param selectedFile The file on which the context menu is opened * @param event The click event */ openSimpleContextMenu: (selectedFile: Git.IStatusFile, event: React.MouseEvent) => void; /** Reset all staged files */ resetAllStagedFiles: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => Promise<void>; /** Reset staged selected files */ resetSelectedFiles: (file: Git.IStatusFile) => void; /** If the clicked file is selected, open all selected files. * If the clicked file is not selected, open the clicked file only. */ openSelectedFiles: (clickedFile: Git.IStatusFile) => void; /** Add all unstaged files */ addAllUnstagedFiles: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => Promise<void>; /** Discard changes in all unstaged files */ discardAllUnstagedFiles: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => Promise<void>; /** Discard changes in all unstaged and staged files */ discardAllChanges: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => Promise<void>; /** Add a specific unstaged file */ addFile: (...file: string[]) => Promise<void>; /** Discard changes in a specific unstaged or staged file */ discardChanges: (file: Git.IStatusFile) => void; /** Add all untracked files */ addAllUntrackedFiles: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => Promise<void>; addAllMarkedFiles: () => Promise<void>; /** * Select files into state.selectedFiles * @param file The current cliced-on file * @param options Selection options */ setSelection: (file: Git.IStatusFile, options?: { singleton?: boolean; group?: boolean; }) => void; /** * Mark files from the latest selected to this one * * @param file The current clicked-on file */ markUntilFile: (file: Git.IStatusFile) => void; /** * Set mark status from select-all button * * @param files Files to toggle */ toggleAllFiles: (files: Git.IStatusFile[]) => void; private _selectOnlyOneFile; /** * Toggle selection status of a file * @param file The clicked file */ private _toggleFile; /** * Select a list of files * @param files List of files to select */ private _selectFiles; /** * Deselect a list of file * @param files List of file to deselect */ private _deselectFiles; /** * Handle shift-click behaviour for file selection * @param file The shift-clicked file */ private _selectUntilFile; pullFromRemote: (event?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => Promise<void>; get markedFiles(): Git.IStatusFile[]; /** * Render the modified files */ render(): JSX.Element; /** * Test if a file is selected * @param candidate file to test */ private _isSelectedFile; /** * Render an unmerged file * * Note: This is actually a React.FunctionComponent but defined as * a private method as it needs access to FileList properties. * * @param rowProps Row properties */ private _renderUnmergedRow; private _renderUnmerged; /** * Render a staged file * * Note: This is actually a React.FunctionComponent but defined as * a private method as it needs access to FileList properties. * * @param rowProps Row properties */ private _renderStagedRow; /** * Render the staged files list. * * @param files The staged files * @param height The height of the HTML element */ private _renderStaged; /** * Render a changed file * * Note: This is actually a React.FunctionComponent but defined as * a private method as it needs access to FileList properties. * * @param rowProps Row properties */ private _renderChangedRow; /** * Render the changed files list * * @param files Changed files * @param height Height of the HTML element */ private _renderChanged; /** * Render a untracked file. * * Note: This is actually a React.FunctionComponent but defined as * a private method as it needs access to FileList properties. * * @param rowProps Row properties */ private _renderUntrackedRow; /** * Render the untracked files list. * * @param files Untracked files * @param height Height of the HTML element */ private _renderUntracked; /** * Render the remote changed list. * * Note: This is actually a React.FunctionComponent but defined as * a private method as it needs access to FileList properties. * * @param rowProps Row properties */ private _renderRemoteChangedRow; /** * Render the a file that has changed on remote to files list. * * @param files Untracked files * @param height Height of the HTML element */ private _renderRemoteChanged; /** * Render a modified file in simple mode. * * Note: This is actually a React.FunctionComponent but defined as * a private method as it needs access to FileList properties. * * @param rowProps Row properties */ private _renderSimpleStageRow; /** * Render the modified files in simple mode. * * @param files Modified files * @param height Height of the HTML element */ private _renderSimpleStage; /** * Creates a button element which, depending on the settings, is used * to either request a diff of the file, or open the file * * @param path File path of interest * @param currentRef the ref to diff against the git 'HEAD' ref */ private _createDiffButton; /** * Returns a callback which opens a diff of the file * * @param file File to open diff for * @param currentRef the ref to diff against the git 'HEAD' ref */ private _openDiffViews; /** * Determine if files in simple staging are all marked * @returns True if files are all marked */ private _areFilesAllMarked; /** * Callback invoked upon clicking a button to stash the dirty files. * * @param event - event object * @returns a promise which resolves upon stashing the latest changes */ private _onStashClick; }