1
- import { LibroSearchToggleCommand , LibroService , LibroView , NotebookCommands } from '@difizen/libro-jupyter/noeditor' ;
1
+ import { LibroSearchToggleCommand , LibroService , NotebookCommands } from '@difizen/libro-jupyter/noeditor' ;
2
2
import { Container , CommandRegistry as LibroCommandRegistry } from '@difizen/mana-app' ;
3
3
4
4
import { Autowired } from '@opensumi/di' ;
5
5
import {
6
6
ClientAppContribution ,
7
+ CommandContribution ,
7
8
CommandRegistry ,
8
9
Domain ,
9
10
IContextKeyService ,
11
+ KeybindingContribution ,
10
12
KeybindingRegistry ,
11
13
KeybindingScope ,
14
+ MaybePromise ,
12
15
} from '@opensumi/ide-core-browser' ;
13
16
import { WorkbenchEditorService } from '@opensumi/ide-editor' ;
14
17
15
18
import { LIBRO_COMPONENTS_SCHEME_ID } from './libro.protocol' ;
16
19
import { ManaContainer } from './mana' ;
17
20
18
- @Domain ( ClientAppContribution )
19
- export class LibroKeybindContribution implements ClientAppContribution {
21
+ @Domain ( ClientAppContribution , KeybindingContribution , CommandContribution )
22
+ export class LibroKeybindContribution implements ClientAppContribution , KeybindingContribution , CommandContribution {
20
23
@Autowired ( IContextKeyService ) contextKeyService : IContextKeyService ;
21
- @Autowired ( KeybindingRegistry ) keybindingRegistry : KeybindingRegistry ;
22
24
@Autowired ( WorkbenchEditorService )
23
25
workbenchEditorService : WorkbenchEditorService ;
24
26
@Autowired ( CommandRegistry )
25
27
protected readonly commandRegistry : CommandRegistry ;
26
28
@Autowired ( ManaContainer )
27
29
private readonly manaContainer : Container ;
28
30
29
- onStart ( ) {
31
+ initialize ( ) : MaybePromise < void > {
30
32
this . registerContextKey ( ) ;
31
- this . registerCommand ( ) ;
32
- this . registerKeybind ( ) ;
33
33
}
34
34
35
35
registerContextKey ( ) {
36
- const notebookFocusContext = this . contextKeyService . createKey < boolean > (
37
- 'libroNotebookFocused' ,
38
- this . hasActiveNotebook ( ) ,
39
- ) ;
36
+ const notebookFocusContext = this . contextKeyService . createKey < boolean > ( 'libroNotebookFocused' , false ) ;
40
37
41
38
this . workbenchEditorService . onActiveResourceChange ( ( e ) => {
42
39
if ( e ?. uri ?. path . ext === `.${ LIBRO_COMPONENTS_SCHEME_ID } ` ) {
@@ -55,45 +52,41 @@ export class LibroKeybindContribution implements ClientAppContribution {
55
52
return this . manaContainer . get ( LibroCommandRegistry ) ;
56
53
}
57
54
58
- hasActiveNotebook ( ) {
59
- return this . libroService . active instanceof LibroView ;
60
- }
61
-
62
- registerCommand ( ) {
63
- this . commandRegistry . registerCommand ( NotebookCommands [ 'EnterCommandMode' ] , {
55
+ registerCommands ( commands : CommandRegistry ) {
56
+ commands . registerCommand ( NotebookCommands [ 'EnterCommandMode' ] , {
64
57
execute : ( ) => {
65
58
this . libroCommandRegistry . executeCommand ( NotebookCommands [ 'EnterCommandMode' ] . id ) ;
66
59
} ,
67
60
} ) ;
68
- this . commandRegistry . registerCommand ( NotebookCommands [ 'RunCell' ] , {
61
+ commands . registerCommand ( NotebookCommands [ 'RunCell' ] , {
69
62
execute : ( ) => {
70
63
this . libroCommandRegistry . executeCommand ( NotebookCommands [ 'RunCell' ] . id ) ;
71
64
} ,
72
65
} ) ;
73
- this . commandRegistry . registerCommand ( NotebookCommands [ 'RunCellAndSelectNext' ] , {
66
+ commands . registerCommand ( NotebookCommands [ 'RunCellAndSelectNext' ] , {
74
67
execute : ( ) => {
75
68
this . libroCommandRegistry . executeCommand ( NotebookCommands [ 'RunCellAndSelectNext' ] . id ) ;
76
69
} ,
77
70
} ) ;
78
- this . commandRegistry . registerCommand ( NotebookCommands [ 'RunCellAndInsertBelow' ] , {
71
+ commands . registerCommand ( NotebookCommands [ 'RunCellAndInsertBelow' ] , {
79
72
execute : ( ) => {
80
73
this . libroCommandRegistry . executeCommand ( NotebookCommands [ 'RunCellAndInsertBelow' ] . id ) ;
81
74
} ,
82
75
} ) ;
83
- this . commandRegistry . registerCommand ( NotebookCommands [ 'SplitCellAntCursor' ] , {
76
+ commands . registerCommand ( NotebookCommands [ 'SplitCellAntCursor' ] , {
84
77
execute : ( ) => {
85
78
this . libroCommandRegistry . executeCommand ( NotebookCommands [ 'SplitCellAntCursor' ] . id ) ;
86
79
} ,
87
80
} ) ;
88
- this . commandRegistry . registerCommand ( LibroSearchToggleCommand . ShowLibroSearch , {
81
+ commands . registerCommand ( LibroSearchToggleCommand . ShowLibroSearch , {
89
82
execute : ( ) => {
90
83
this . libroCommandRegistry . executeCommand ( LibroSearchToggleCommand . ShowLibroSearch . id ) ;
91
84
} ,
92
85
} ) ;
93
86
}
94
87
95
- registerKeybind ( ) {
96
- this . keybindingRegistry . registerKeybindings (
88
+ registerKeybindings ( keybindings : KeybindingRegistry ) : void {
89
+ keybindings . registerKeybindings (
97
90
[
98
91
{
99
92
keybinding : 'f1' ,
0 commit comments