@@ -7,8 +7,8 @@ import { Event } from 'vs/base/common/event';
7
7
import { Disposable } from 'vs/base/common/lifecycle' ;
8
8
import { IContextKeyService , IContextKey , setConstant as setConstantContextKey } from 'vs/platform/contextkey/common/contextkey' ;
9
9
import { InputFocusedContext , IsMacContext , IsLinuxContext , IsWindowsContext , IsWebContext , IsMacNativeContext , IsDevelopmentContext , IsIOSContext , ProductQualityContext , IsMobileContext } from 'vs/platform/contextkey/common/contextkeys' ;
10
- import { SplitEditorsVertically , InEditorZenModeContext , ActiveEditorCanRevertContext , ActiveEditorGroupLockedContext , ActiveEditorCanSplitInGroupContext , SideBySideEditorActiveContext , AuxiliaryBarVisibleContext , SideBarVisibleContext , PanelAlignmentContext , PanelMaximizedContext , PanelVisibleContext , ActiveEditorContext , EditorsVisibleContext , TextCompareEditorVisibleContext , TextCompareEditorActiveContext , ActiveEditorGroupEmptyContext , MultipleEditorGroupsContext , EmbedderIdentifierContext , EditorTabsVisibleContext , IsCenteredLayoutContext , ActiveEditorGroupIndexContext , ActiveEditorGroupLastContext , ActiveEditorReadonlyContext , EditorAreaVisibleContext , ActiveEditorAvailableEditorIdsContext , DirtyWorkingCopiesContext , EmptyWorkspaceSupportContext , EnterMultiRootWorkspaceSupportContext , HasWebFileSystemAccess , IsFullscreenContext , OpenFolderWorkspaceSupportContext , RemoteNameContext , VirtualWorkspaceContext , WorkbenchStateContext , WorkspaceFolderCountContext , PanelPositionContext , TemporaryWorkspaceContext } from 'vs/workbench/common/contextkeys' ;
11
- import { TEXT_DIFF_EDITOR_ID , EditorInputCapabilities , SIDE_BY_SIDE_EDITOR_ID , DEFAULT_EDITOR_ASSOCIATION } from 'vs/workbench/common/editor' ;
10
+ import { SplitEditorsVertically , InEditorZenModeContext , ActiveEditorCanRevertContext , ActiveEditorGroupLockedContext , ActiveEditorCanSplitInGroupContext , SideBySideEditorActiveContext , AuxiliaryBarVisibleContext , SideBarVisibleContext , PanelAlignmentContext , PanelMaximizedContext , PanelVisibleContext , ActiveEditorContext , EditorsVisibleContext , TextCompareEditorVisibleContext , TextCompareEditorActiveContext , ActiveEditorGroupEmptyContext , MultipleEditorGroupsContext , EmbedderIdentifierContext , EditorTabsVisibleContext , IsCenteredLayoutContext , ActiveEditorGroupIndexContext , ActiveEditorGroupLastContext , ActiveEditorReadonlyContext , EditorAreaVisibleContext , ActiveEditorAvailableEditorIdsContext , DirtyWorkingCopiesContext , EmptyWorkspaceSupportContext , EnterMultiRootWorkspaceSupportContext , HasWebFileSystemAccess , IsFullscreenContext , OpenFolderWorkspaceSupportContext , RemoteNameContext , VirtualWorkspaceContext , WorkbenchStateContext , WorkspaceFolderCountContext , PanelPositionContext , TemporaryWorkspaceContext , ActiveEditorCanToggleReadonlyContext } from 'vs/workbench/common/contextkeys' ;
11
+ import { TEXT_DIFF_EDITOR_ID , EditorInputCapabilities , SIDE_BY_SIDE_EDITOR_ID , DEFAULT_EDITOR_ASSOCIATION , EditorResourceAccessor , SideBySideEditor } from 'vs/workbench/common/editor' ;
12
12
import { trackFocus , addDisposableListener , EventType } from 'vs/base/browser/dom' ;
13
13
import { preferredSideBySideGroupDirection , GroupDirection , IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService' ;
14
14
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
@@ -25,18 +25,21 @@ import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/b
25
25
import { Schemas } from 'vs/base/common/network' ;
26
26
import { WebFileSystemAccess } from 'vs/platform/files/browser/webFileSystemAccess' ;
27
27
import { IProductService } from 'vs/platform/product/common/productService' ;
28
+ import { FileSystemProviderCapabilities , IFileService } from 'vs/platform/files/common/files' ;
28
29
29
30
export class WorkbenchContextKeysHandler extends Disposable {
30
31
private inputFocusedContext : IContextKey < boolean > ;
31
32
32
33
private dirtyWorkingCopiesContext : IContextKey < boolean > ;
33
34
34
35
private activeEditorContext : IContextKey < string | null > ;
35
- private activeEditorIsReadonly : IContextKey < boolean > ;
36
36
private activeEditorCanRevert : IContextKey < boolean > ;
37
37
private activeEditorCanSplitInGroup : IContextKey < boolean > ;
38
38
private activeEditorAvailableEditorIds : IContextKey < string > ;
39
39
40
+ private activeEditorIsReadonly : IContextKey < boolean > ;
41
+ private activeEditorCanToggleReadonly : IContextKey < boolean > ;
42
+
40
43
private activeEditorGroupEmpty : IContextKey < boolean > ;
41
44
private activeEditorGroupIndex : IContextKey < number > ;
42
45
private activeEditorGroupLast : IContextKey < boolean > ;
@@ -84,7 +87,8 @@ export class WorkbenchContextKeysHandler extends Disposable {
84
87
@IEditorGroupsService private readonly editorGroupService : IEditorGroupsService ,
85
88
@IWorkbenchLayoutService private readonly layoutService : IWorkbenchLayoutService ,
86
89
@IPaneCompositePartService private readonly paneCompositeService : IPaneCompositePartService ,
87
- @IWorkingCopyService private readonly workingCopyService : IWorkingCopyService
90
+ @IWorkingCopyService private readonly workingCopyService : IWorkingCopyService ,
91
+ @IFileService private readonly fileService : IFileService
88
92
) {
89
93
super ( ) ;
90
94
@@ -119,6 +123,7 @@ export class WorkbenchContextKeysHandler extends Disposable {
119
123
// Editors
120
124
this . activeEditorContext = ActiveEditorContext . bindTo ( this . contextKeyService ) ;
121
125
this . activeEditorIsReadonly = ActiveEditorReadonlyContext . bindTo ( this . contextKeyService ) ;
126
+ this . activeEditorCanToggleReadonly = ActiveEditorCanToggleReadonlyContext . bindTo ( this . contextKeyService ) ;
122
127
this . activeEditorCanRevert = ActiveEditorCanRevertContext . bindTo ( this . contextKeyService ) ;
123
128
this . activeEditorCanSplitInGroup = ActiveEditorCanSplitInGroupContext . bindTo ( this . contextKeyService ) ;
124
129
this . activeEditorAvailableEditorIds = ActiveEditorAvailableEditorIdsContext . bindTo ( this . contextKeyService ) ;
@@ -289,22 +294,26 @@ export class WorkbenchContextKeysHandler extends Disposable {
289
294
290
295
if ( activeEditorPane ) {
291
296
this . activeEditorContext . set ( activeEditorPane . getId ( ) ) ;
292
- this . activeEditorIsReadonly . set ( activeEditorPane . input . hasCapability ( EditorInputCapabilities . Readonly ) ) ;
293
297
this . activeEditorCanRevert . set ( ! activeEditorPane . input . hasCapability ( EditorInputCapabilities . Untitled ) ) ;
294
298
this . activeEditorCanSplitInGroup . set ( activeEditorPane . input . hasCapability ( EditorInputCapabilities . CanSplitInGroup ) ) ;
295
299
296
300
const activeEditorResource = activeEditorPane . input . resource ;
297
301
const editors = activeEditorResource ? this . editorResolverService . getEditors ( activeEditorResource ) . map ( editor => editor . id ) : [ ] ;
298
- // Non text editor untitled files cannot be easily serialized between extensions
299
- // so instead we disable this context key to prevent common commands that act on the active editor
300
302
if ( activeEditorResource ?. scheme === Schemas . untitled && activeEditorPane . input . editorId !== DEFAULT_EDITOR_ASSOCIATION . id ) {
303
+ // Non text editor untitled files cannot be easily serialized between extensions
304
+ // so instead we disable this context key to prevent common commands that act on the active editor
301
305
this . activeEditorAvailableEditorIds . set ( '' ) ;
302
306
} else {
303
307
this . activeEditorAvailableEditorIds . set ( editors . join ( ',' ) ) ;
304
308
}
309
+
310
+ this . activeEditorIsReadonly . set ( activeEditorPane . input . hasCapability ( EditorInputCapabilities . Readonly ) ) ;
311
+ const primaryEditorResource = EditorResourceAccessor . getOriginalUri ( activeEditorPane . input , { supportSideBySide : SideBySideEditor . PRIMARY } ) ;
312
+ this . activeEditorCanToggleReadonly . set ( ! ! primaryEditorResource && this . fileService . hasProvider ( primaryEditorResource ) && ! this . fileService . hasCapability ( primaryEditorResource , FileSystemProviderCapabilities . Readonly ) ) ;
305
313
} else {
306
314
this . activeEditorContext . reset ( ) ;
307
315
this . activeEditorIsReadonly . reset ( ) ;
316
+ this . activeEditorCanToggleReadonly . reset ( ) ;
308
317
this . activeEditorCanRevert . reset ( ) ;
309
318
this . activeEditorCanSplitInGroup . reset ( ) ;
310
319
this . activeEditorAvailableEditorIds . reset ( ) ;
0 commit comments