-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notebook selected cell status bar item and center selected cell c…
…ommand (#14046) Signed-off-by: Jonah Iden <jonah.iden@typefox.io>
- Loading branch information
1 parent
7c0ed59
commit d34c0b3
Showing
6 changed files
with
127 additions
and
14 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
77 changes: 77 additions & 0 deletions
77
packages/notebook/src/browser/contributions/notebook-status-bar-contribution.ts
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,77 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2024 TypeFox and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import { inject, injectable } from '@theia/core/shared/inversify'; | ||
import { FrontendApplicationContribution, StatusBar, StatusBarAlignment } from '@theia/core/lib/browser'; | ||
import { Disposable } from '@theia/core/lib/common'; | ||
import { NotebookEditorWidgetService } from '../service/notebook-editor-widget-service'; | ||
import { NotebookEditorWidget } from '../notebook-editor-widget'; | ||
import { nls } from '@theia/core'; | ||
import { NotebookCommands } from './notebook-actions-contribution'; | ||
|
||
export const NOTEBOOK_CELL_SELECTION_STATUS_BAR_ID = 'notebook-cell-selection-position'; | ||
|
||
@injectable() | ||
export class NotebookStatusBarContribution implements FrontendApplicationContribution { | ||
|
||
@inject(StatusBar) protected readonly statusBar: StatusBar; | ||
@inject(NotebookEditorWidgetService) protected readonly editorWidgetService: NotebookEditorWidgetService; | ||
|
||
protected currentCellSelectionListener: Disposable | undefined; | ||
protected lastFocusedEditor: NotebookEditorWidget | undefined; | ||
|
||
onStart(): void { | ||
this.editorWidgetService.onDidChangeFocusedEditor(editor => { | ||
this.currentCellSelectionListener?.dispose(); | ||
this.currentCellSelectionListener = editor?.model?.onDidChangeSelectedCell(() => | ||
this.updateStatusbar(editor) | ||
); | ||
editor?.onDidDispose(() => { | ||
this.lastFocusedEditor = undefined; | ||
this.updateStatusbar(); | ||
}); | ||
this.updateStatusbar(editor); | ||
this.lastFocusedEditor = editor; | ||
}); | ||
if (this.editorWidgetService.focusedEditor) { | ||
this.updateStatusbar(); | ||
} | ||
} | ||
|
||
protected async updateStatusbar(editor?: NotebookEditorWidget): Promise<void> { | ||
if ((!editor && !this.lastFocusedEditor?.isVisible) || editor?.model?.cells.length === 0) { | ||
this.statusBar.removeElement(NOTEBOOK_CELL_SELECTION_STATUS_BAR_ID); | ||
return; | ||
} | ||
|
||
await editor?.ready; | ||
if (!editor?.model) { | ||
return; | ||
} | ||
|
||
const selectedCellIndex = editor.model.selectedCell ? editor.model.cells.indexOf(editor.model.selectedCell) + 1 : ''; | ||
|
||
this.statusBar.setElement(NOTEBOOK_CELL_SELECTION_STATUS_BAR_ID, { | ||
text: nls.localizeByDefault('Cell {0} of {1}', selectedCellIndex, editor.model.cells.length), | ||
alignment: StatusBarAlignment.RIGHT, | ||
priority: 100, | ||
command: NotebookCommands.CENTER_ACTIVE_CELL.id, | ||
arguments: [editor] | ||
}); | ||
|
||
} | ||
|
||
} |
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
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