forked from jupyterlab/jupyter-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement toggling the AI completer via statusbar item
also adds the icon for provider re-using jupyternaut icon
- Loading branch information
1 parent
ec1c0e0
commit b757e2f
Showing
6 changed files
with
301 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { Popup, showPopup } from '@jupyterlab/statusbar'; | ||
import React from 'react'; | ||
import { VDomModel, VDomRenderer } from '@jupyterlab/ui-components'; | ||
import { CommandRegistry } from '@lumino/commands'; | ||
import { MenuSvg, RankedMenu, IRankedMenu } from '@jupyterlab/ui-components'; | ||
import { Jupyternaut } from '../icons'; | ||
import { IJupyternautStatus } from '../tokens'; | ||
|
||
/** | ||
* StatusBar item to display menu for toggling the completion. | ||
*/ | ||
export class JupyternautStatus | ||
extends VDomRenderer<VDomModel> | ||
implements IJupyternautStatus | ||
{ | ||
constructor(options: JupyternautStatus.IOptions) { | ||
super(new VDomModel()); | ||
this._commandRegistry = options.commandRegistry; | ||
this._items = []; | ||
|
||
this.addClass('jp-mod-highlighted'); | ||
this.title.caption = 'Open Jupyternaut status menu'; | ||
this.node.addEventListener('click', this._handleClick); | ||
} | ||
|
||
addItem(item: IRankedMenu.IItemOptions): void { | ||
this._items.push(item); | ||
} | ||
|
||
hasItems(): boolean { | ||
return this._items.length !== 0; | ||
} | ||
|
||
/** | ||
* Render the status item. | ||
*/ | ||
render(): JSX.Element | null { | ||
if (!this.model) { | ||
return null; | ||
} | ||
return <Jupyternaut top={'2px'} width={'16px'} stylesheet={'statusBar'} />; | ||
} | ||
|
||
dispose(): void { | ||
this.node.removeEventListener('click', this._handleClick); | ||
super.dispose(); | ||
} | ||
|
||
/** | ||
* Create a menu for viewing status and changing options. | ||
*/ | ||
private _handleClick = () => { | ||
if (this._popup) { | ||
this._popup.dispose(); | ||
} | ||
if (this._menu) { | ||
this._menu.dispose(); | ||
} | ||
this._menu = new RankedMenu({ | ||
commands: this._commandRegistry, | ||
renderer: MenuSvg.defaultRenderer | ||
}); | ||
for (const item of this._items) { | ||
this._menu.addItem(item); | ||
} | ||
this._popup = showPopup({ | ||
body: this._menu, | ||
anchor: this, | ||
align: 'left' | ||
}); | ||
}; | ||
|
||
private _items: IRankedMenu.IItemOptions[]; | ||
private _commandRegistry: CommandRegistry; | ||
private _menu: RankedMenu | null = null; | ||
private _popup: Popup | null = null; | ||
} | ||
|
||
/** | ||
* A namespace for JupyternautStatus statics. | ||
*/ | ||
export namespace JupyternautStatus { | ||
/** | ||
* Options for the JupyternautStatus item. | ||
*/ | ||
export interface IOptions { | ||
/** | ||
* The application command registry. | ||
*/ | ||
commandRegistry: CommandRegistry; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.