123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- // Copyright (c) Jupyter Development Team.
- // Distributed under the terms of the Modified BSD License.
- import { Menu, Widget } from '@phosphor/widgets';
- import { IJupyterLabMenu, IMenuExtender, JupyterLabMenu } from './labmenu';
- /**
- * An interface for an Edit menu.
- */
- export interface IEditMenu extends IJupyterLabMenu {
- /**
- * A set storing IUndoers for the Edit menu.
- */
- readonly undoers: Set<IEditMenu.IUndoer<Widget>>;
- /**
- * A set storing IClearers for the Edit menu.
- */
- readonly clearers: Set<IEditMenu.IClearer<Widget>>;
- /**
- * A set storing IFindReplacers for the Edit menu.
- */
- readonly findReplacers: Set<IEditMenu.IFindReplacer<Widget>>;
- /**
- * A set storing IGoToLiners for the Edit menu.
- */
- readonly goToLiners: Set<IEditMenu.IGoToLiner<Widget>>;
- }
- /**
- * An extensible Edit menu for the application.
- */
- export class EditMenu extends JupyterLabMenu implements IEditMenu {
- /**
- * Construct the edit menu.
- */
- constructor(options: Menu.IOptions) {
- super(options);
- this.menu.title.label = 'Edit';
- this.undoers = new Set<IEditMenu.IUndoer<Widget>>();
- this.clearers = new Set<IEditMenu.IClearer<Widget>>();
- this.findReplacers = new Set<IEditMenu.IFindReplacer<Widget>>();
- this.goToLiners = new Set<IEditMenu.IGoToLiner<Widget>>();
- }
- /**
- * A set storing IUndoers for the Edit menu.
- */
- readonly undoers: Set<IEditMenu.IUndoer<Widget>>;
- /**
- * A set storing IClearers for the Edit menu.
- */
- readonly clearers: Set<IEditMenu.IClearer<Widget>>;
- /**
- * A set storing IFindReplacers for the Edit menu.
- */
- readonly findReplacers: Set<IEditMenu.IFindReplacer<Widget>>;
- /**
- * A set storing IGoToLiners for the Edit menu.
- */
- readonly goToLiners: Set<IEditMenu.IGoToLiner<Widget>>;
- /**
- * Dispose of the resources held by the edit menu.
- */
- dispose(): void {
- this.undoers.clear();
- this.clearers.clear();
- this.findReplacers.clear();
- super.dispose();
- }
- }
- /**
- * Namespace for IEditMenu
- */
- export namespace IEditMenu {
- /**
- * Interface for an activity that uses Undo/Redo.
- */
- export interface IUndoer<T extends Widget> extends IMenuExtender<T> {
- /**
- * Execute an undo command for the activity.
- */
- undo?: (widget: T) => void;
- /**
- * Execute a redo command for the activity.
- */
- redo?: (widget: T) => void;
- }
- /**
- * Interface for an activity that wants to register a 'Clear...' menu item
- */
- export interface IClearer<T extends Widget> extends IMenuExtender<T> {
- /**
- * A name for the thing to be cleared, used for labeling `clearCurrent`.
- */
- noun?: string;
- /**
- * A plural name for the thing to be cleared, used for labeling `clearAll`.
- */
- pluralNoun?: string;
- /**
- * A function to clear the currently portion of activity.
- */
- clearCurrent?: (widget: T) => void;
- /**
- * A function to clear all of an activity.
- */
- clearAll?: (widget: T) => void;
- }
- /**
- * Interface for an activity that uses Find/Find+Replace.
- */
- export interface IFindReplacer<T extends Widget> extends IMenuExtender<T> {
- /**
- * Execute a find command for the activity.
- */
- find?: (widget: T) => void;
- /**
- * Execute a find/replace command for the activity.
- */
- findAndReplace?: (widget: T) => void;
- }
- /**
- * Interface for an activity that uses Go to Line.
- */
- export interface IGoToLiner<T extends Widget> extends IMenuExtender<T> {
- /**
- * Execute a go to line command for the activity.
- */
- goToLine?: (widget: T) => void;
- }
- }
|