Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
2feb009c
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2feb009c
编写于
11月 17, 2020
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Editors: consider to allow name/description for file based editors (fix #110738)
上级
d19c7c52
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
173 addition
and
33 deletion
+173
-33
src/vs/workbench/common/editor.ts
src/vs/workbench/common/editor.ts
+19
-1
src/vs/workbench/contrib/files/browser/files.contribution.ts
src/vs/workbench/contrib/files/browser/files.contribution.ts
+10
-3
src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts
...workbench/contrib/files/common/editors/fileEditorInput.ts
+54
-1
src/vs/workbench/contrib/files/test/browser/fileEditorInput.test.ts
...kbench/contrib/files/test/browser/fileEditorInput.test.ts
+73
-24
src/vs/workbench/electron-browser/desktop.main.ts
src/vs/workbench/electron-browser/desktop.main.ts
+2
-1
src/vs/workbench/services/editor/browser/editorService.ts
src/vs/workbench/services/editor/browser/editorService.ts
+9
-1
src/vs/workbench/services/history/browser/history.ts
src/vs/workbench/services/history/browser/history.ts
+1
-1
src/vs/workbench/test/browser/parts/editor/editorGroups.test.ts
.../workbench/test/browser/parts/editor/editorGroups.test.ts
+2
-0
src/vs/workbench/test/browser/workbenchTestServices.ts
src/vs/workbench/test/browser/workbenchTestServices.ts
+3
-1
未找到文件。
src/vs/workbench/common/editor.ts
浏览文件 @
2feb009c
...
...
@@ -178,7 +178,7 @@ export interface IFileEditorInputFactory {
/**
* Creates new new editor input capable of showing files.
*/
createFileEditorInput
(
resource
:
URI
,
preferredResource
:
URI
|
undefined
,
encoding
:
string
|
undefined
,
m
ode
:
string
|
undefined
,
instantiationService
:
IInstantiationService
):
IFileEditorInput
;
createFileEditorInput
(
resource
:
URI
,
preferredResource
:
URI
|
undefined
,
preferredName
:
string
|
undefined
,
preferredDescription
:
string
|
undefined
,
preferredEncoding
:
string
|
undefined
,
preferredM
ode
:
string
|
undefined
,
instantiationService
:
IInstantiationService
):
IFileEditorInput
;
/**
* Check if the provided object is a file editor input.
...
...
@@ -704,6 +704,24 @@ export interface IFileEditorInput extends IEditorInput, IEncodingSupport, IModeS
*/
setPreferredResource
(
preferredResource
:
URI
):
void
;
/**
* Sets the preferred name to use for this file input.
*
* Note: for certain file schemes the input may decide to ignore this
* name and use our standard naming. Specifically for schemes we own,
* we do not let others override the name.
*/
setPreferredName
(
name
:
string
):
void
;
/**
* Sets the preferred description to use for this file input.
*
* Note: for certain file schemes the input may decide to ignore this
* description and use our standard naming. Specifically for schemes we own,
* we do not let others override the description.
*/
setPreferredDescription
(
description
:
string
):
void
;
/**
* Sets the preferred encoding to use for this file input.
*/
...
...
src/vs/workbench/contrib/files/browser/files.contribution.ts
浏览文件 @
2feb009c
...
...
@@ -102,8 +102,9 @@ Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
// Register default file input factory
Registry
.
as
<
IEditorInputFactoryRegistry
>
(
EditorInputExtensions
.
EditorInputFactories
).
registerFileEditorInputFactory
({
createFileEditorInput
:
(
resource
,
preferredResource
,
encoding
,
mode
,
instantiationService
):
IFileEditorInput
=>
{
return
instantiationService
.
createInstance
(
FileEditorInput
,
resource
,
preferredResource
,
encoding
,
mode
);
createFileEditorInput
:
(
resource
,
preferredResource
,
preferredName
,
preferredDescription
,
preferredEncoding
,
preferredMode
,
instantiationService
):
IFileEditorInput
=>
{
return
instantiationService
.
createInstance
(
FileEditorInput
,
resource
,
preferredResource
,
preferredName
,
preferredDescription
,
preferredEncoding
,
preferredMode
);
},
isFileEditorInput
:
(
obj
):
obj
is
IFileEditorInput
=>
{
...
...
@@ -114,6 +115,8 @@ Registry.as<IEditorInputFactoryRegistry>(EditorInputExtensions.EditorInputFactor
interface
ISerializedFileEditorInput
{
resourceJSON
:
UriComponents
;
preferredResourceJSON
?:
UriComponents
;
name
?:
string
;
description
?:
string
;
encoding
?:
string
;
modeId
?:
string
;
}
...
...
@@ -132,6 +135,8 @@ class FileEditorInputFactory implements IEditorInputFactory {
const
serializedFileEditorInput
:
ISerializedFileEditorInput
=
{
resourceJSON
:
resource
.
toJSON
(),
preferredResourceJSON
:
isEqual
(
resource
,
preferredResource
)
?
undefined
:
preferredResource
,
// only storing preferredResource if it differs from the resource
name
:
fileEditorInput
.
getPreferredName
(),
description
:
fileEditorInput
.
getPreferredDescription
(),
encoding
:
fileEditorInput
.
getEncoding
(),
modeId
:
fileEditorInput
.
getPreferredMode
()
// only using the preferred user associated mode here if available to not store redundant data
};
...
...
@@ -144,10 +149,12 @@ class FileEditorInputFactory implements IEditorInputFactory {
const
serializedFileEditorInput
:
ISerializedFileEditorInput
=
JSON
.
parse
(
serializedEditorInput
);
const
resource
=
URI
.
revive
(
serializedFileEditorInput
.
resourceJSON
);
const
preferredResource
=
URI
.
revive
(
serializedFileEditorInput
.
preferredResourceJSON
);
const
name
=
serializedFileEditorInput
.
name
;
const
description
=
serializedFileEditorInput
.
description
;
const
encoding
=
serializedFileEditorInput
.
encoding
;
const
mode
=
serializedFileEditorInput
.
modeId
;
const
fileEditorInput
=
accessor
.
get
(
IEditorService
).
createEditorInput
({
resource
,
encoding
,
mode
,
forceFile
:
true
})
as
FileEditorInput
;
const
fileEditorInput
=
accessor
.
get
(
IEditorService
).
createEditorInput
({
resource
,
label
:
name
,
description
,
encoding
,
mode
,
forceFile
:
true
})
as
FileEditorInput
;
if
(
preferredResource
)
{
fileEditorInput
.
setPreferredResource
(
preferredResource
);
}
...
...
src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts
浏览文件 @
2feb009c
...
...
@@ -21,6 +21,7 @@ import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editor
import
{
isEqual
}
from
'
vs/base/common/resources
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
IEditorViewState
}
from
'
vs/editor/common/editorCommon
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
const
enum
ForceOpenAs
{
None
,
...
...
@@ -33,6 +34,8 @@ const enum ForceOpenAs {
*/
export
class
FileEditorInput
extends
AbstractTextResourceEditorInput
implements
IFileEditorInput
{
private
preferredName
:
string
|
undefined
;
private
preferredDescription
:
string
|
undefined
;
private
preferredEncoding
:
string
|
undefined
;
private
preferredMode
:
string
|
undefined
;
...
...
@@ -46,6 +49,8 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements
constructor
(
resource
:
URI
,
preferredResource
:
URI
|
undefined
,
preferredName
:
string
|
undefined
,
preferredDescription
:
string
|
undefined
,
preferredEncoding
:
string
|
undefined
,
preferredMode
:
string
|
undefined
,
@
IInstantiationService
private
readonly
instantiationService
:
IInstantiationService
,
...
...
@@ -61,6 +66,14 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements
this
.
model
=
this
.
textFileService
.
files
.
get
(
resource
);
if
(
preferredName
)
{
this
.
setPreferredName
(
preferredName
);
}
if
(
preferredDescription
)
{
this
.
setPreferredDescription
(
preferredDescription
);
}
if
(
preferredEncoding
)
{
this
.
setPreferredEncoding
(
preferredEncoding
);
}
...
...
@@ -119,7 +132,47 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements
}
getName
():
string
{
return
this
.
decorateLabel
(
super
.
getName
());
return
this
.
preferredName
||
this
.
decorateLabel
(
super
.
getName
());
}
setPreferredName
(
name
:
string
):
void
{
if
(
!
this
.
allowLabelOverride
())
{
return
;
// block for specific schemes we own
}
if
(
this
.
preferredName
!==
name
)
{
this
.
preferredName
=
name
;
this
.
_onDidChangeLabel
.
fire
();
}
}
private
allowLabelOverride
():
boolean
{
return
this
.
resource
.
scheme
!==
Schemas
.
file
&&
this
.
resource
.
scheme
!==
Schemas
.
vscodeRemote
&&
this
.
resource
.
scheme
!==
Schemas
.
userData
;
}
getPreferredName
():
string
|
undefined
{
return
this
.
preferredName
;
}
getDescription
(
verbosity
?:
Verbosity
):
string
|
undefined
{
return
this
.
preferredDescription
||
super
.
getDescription
(
verbosity
);
}
setPreferredDescription
(
description
:
string
):
void
{
if
(
!
this
.
allowLabelOverride
())
{
return
;
// block for specific schemes we own
}
if
(
this
.
preferredDescription
!==
description
)
{
this
.
preferredDescription
=
description
;
this
.
_onDidChangeLabel
.
fire
();
}
}
getPreferredDescription
():
string
|
undefined
{
return
this
.
preferredDescription
;
}
getTitle
(
verbosity
:
Verbosity
):
string
{
...
...
src/vs/workbench/contrib/files/test/browser/fileEditorInput.test.ts
浏览文件 @
2feb009c
...
...
@@ -24,12 +24,16 @@ suite('Files - FileEditorInput', () => {
let
instantiationService
:
IInstantiationService
;
let
accessor
:
TestServiceAccessor
;
function
createFileInput
(
resource
:
URI
,
preferredResource
?:
URI
,
preferredMode
?:
string
,
preferredName
?:
string
,
preferredDescription
?:
string
):
FileEditorInput
{
return
instantiationService
.
createInstance
(
FileEditorInput
,
resource
,
preferredResource
,
preferredName
,
preferredDescription
,
undefined
,
preferredMode
);
}
setup
(()
=>
{
instantiationService
=
workbenchInstantiationService
({
editorService
:
()
=>
{
return
new
class
extends
TestEditorService
{
createEditorInput
(
input
:
IResourceEditorInput
)
{
return
instantiationService
.
createInstance
(
FileEditorInput
,
input
.
resource
,
undefined
,
undefined
,
undefined
);
return
createFileInput
(
input
.
resource
);
}
};
}
...
...
@@ -39,9 +43,9 @@ suite('Files - FileEditorInput', () => {
});
test
(
'
Basics
'
,
async
function
()
{
let
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
),
undefined
,
undefined
,
undefined
);
const
otherInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
foo/bar/otherfile.js
'
),
undefined
,
undefined
,
undefined
);
const
otherInputSame
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
foo/bar/file.js
'
),
undefined
,
undefined
,
undefined
);
let
input
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
)
);
const
otherInput
=
createFileInput
(
toResource
.
call
(
this
,
'
foo/bar/otherfile.js
'
)
);
const
otherInputSame
=
createFileInput
(
toResource
.
call
(
this
,
'
foo/bar/file.js
'
)
);
assert
(
input
.
matches
(
input
));
assert
(
input
.
matches
(
otherInputSame
));
...
...
@@ -56,10 +60,10 @@ suite('Files - FileEditorInput', () => {
assert
.
strictEqual
(
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
).
fsPath
,
input
.
resource
.
fsPath
);
assert
(
input
.
resource
instanceof
URI
);
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar.html
'
),
undefined
,
undefined
,
undefined
);
input
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar.html
'
)
);
const
inputToResolve
:
FileEditorInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
),
undefined
,
undefined
,
undefined
);
const
sameOtherInput
:
FileEditorInput
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
),
undefined
,
undefined
,
undefined
);
const
inputToResolve
:
FileEditorInput
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
)
);
const
sameOtherInput
:
FileEditorInput
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
)
);
let
resolved
=
await
inputToResolve
.
resolve
();
assert
.
ok
(
inputToResolve
.
isResolved
());
...
...
@@ -97,11 +101,11 @@ suite('Files - FileEditorInput', () => {
const
resource
=
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
);
const
preferredResource
=
toResource
.
call
(
this
,
'
/foo/bar/UPDATEFILE.js
'
);
const
inputWithoutPreferredResource
=
instantiationService
.
createInstance
(
FileEditorInput
,
resource
,
undefined
,
undefined
,
undefined
);
const
inputWithoutPreferredResource
=
createFileInput
(
resource
);
assert
.
equal
(
inputWithoutPreferredResource
.
resource
.
toString
(),
resource
.
toString
());
assert
.
equal
(
inputWithoutPreferredResource
.
preferredResource
.
toString
(),
resource
.
toString
());
const
inputWithPreferredResource
=
instantiationService
.
createInstance
(
FileEditorInput
,
resource
,
preferredResource
,
undefined
,
undefined
);
const
inputWithPreferredResource
=
createFileInput
(
resource
,
preferredResource
);
assert
.
equal
(
inputWithPreferredResource
.
resource
.
toString
(),
resource
.
toString
());
assert
.
equal
(
inputWithPreferredResource
.
preferredResource
.
toString
(),
preferredResource
.
toString
());
...
...
@@ -130,7 +134,7 @@ suite('Files - FileEditorInput', () => {
id
:
mode
,
});
const
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
),
undefined
,
undefined
,
mode
);
const
input
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
)
,
undefined
,
mode
);
assert
.
equal
(
input
.
getPreferredMode
(),
mode
);
const
model
=
await
input
.
resolve
()
as
TextFileEditorModel
;
...
...
@@ -140,7 +144,7 @@ suite('Files - FileEditorInput', () => {
assert
.
equal
(
input
.
getPreferredMode
(),
'
text
'
);
assert
.
equal
(
model
.
textEditorModel
!
.
getModeId
(),
PLAINTEXT_MODE_ID
);
const
input2
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
),
undefined
,
undefined
,
undefined
);
const
input2
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/file.js
'
)
);
input2
.
setPreferredMode
(
mode
);
const
model2
=
await
input2
.
resolve
()
as
TextFileEditorModel
;
...
...
@@ -148,10 +152,10 @@ suite('Files - FileEditorInput', () => {
});
test
(
'
matches
'
,
function
()
{
const
input1
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
undefined
,
undefined
,
undefined
);
const
input2
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
undefined
,
undefined
,
undefined
);
const
input3
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/other.js
'
),
undefined
,
undefined
,
undefined
);
const
input2Upper
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/UPDATEFILE.js
'
),
undefined
,
undefined
,
undefined
);
const
input1
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
)
);
const
input2
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
)
);
const
input3
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/other.js
'
)
);
const
input2Upper
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/UPDATEFILE.js
'
)
);
assert
.
strictEqual
(
input1
.
matches
(
null
),
false
);
assert
.
strictEqual
(
input1
.
matches
(
input1
),
true
);
...
...
@@ -162,7 +166,7 @@ suite('Files - FileEditorInput', () => {
});
test
(
'
getEncoding/setEncoding
'
,
async
function
()
{
const
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
undefined
,
undefined
,
undefined
);
const
input
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
)
);
input
.
setEncoding
(
'
utf16
'
,
EncodingMode
.
Encode
);
assert
.
equal
(
input
.
getEncoding
(),
'
utf16
'
);
...
...
@@ -173,7 +177,7 @@ suite('Files - FileEditorInput', () => {
});
test
(
'
save
'
,
async
function
()
{
const
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
undefined
,
undefined
,
undefined
);
const
input
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
)
);
const
resolved
=
await
input
.
resolve
()
as
TextFileEditorModel
;
resolved
.
textEditorModel
!
.
setValue
(
'
changed
'
);
...
...
@@ -185,7 +189,7 @@ suite('Files - FileEditorInput', () => {
});
test
(
'
revert
'
,
async
function
()
{
const
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
undefined
,
undefined
,
undefined
);
const
input
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
)
);
const
resolved
=
await
input
.
resolve
()
as
TextFileEditorModel
;
resolved
.
textEditorModel
!
.
setValue
(
'
changed
'
);
...
...
@@ -201,7 +205,7 @@ suite('Files - FileEditorInput', () => {
});
test
(
'
resolve handles binary files
'
,
async
function
()
{
const
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
undefined
,
undefined
,
undefined
);
const
input
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
)
);
accessor
.
textFileService
.
setResolveTextContentErrorOnce
(
new
TextFileOperationError
(
'
error
'
,
TextFileOperationResult
.
FILE_IS_BINARY
));
...
...
@@ -211,7 +215,7 @@ suite('Files - FileEditorInput', () => {
});
test
(
'
resolve handles too large files
'
,
async
function
()
{
const
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
undefined
,
undefined
,
undefined
);
const
input
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
)
);
accessor
.
textFileService
.
setResolveTextContentErrorOnce
(
new
FileOperationError
(
'
error
'
,
FileOperationResult
.
FILE_TOO_LARGE
));
...
...
@@ -221,7 +225,7 @@ suite('Files - FileEditorInput', () => {
});
test
(
'
attaches to model when created and reports dirty
'
,
async
function
()
{
const
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
undefined
,
undefined
,
undefined
);
const
input
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
)
);
let
listenerCount
=
0
;
const
listener
=
input
.
onDidChangeDirty
(()
=>
{
...
...
@@ -241,7 +245,7 @@ suite('Files - FileEditorInput', () => {
});
test
(
'
force open text/binary
'
,
async
function
()
{
const
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
undefined
,
undefined
,
undefined
);
const
input
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
)
);
input
.
setForceOpenAsBinary
();
let
resolved
=
await
input
.
resolve
();
...
...
@@ -258,7 +262,7 @@ suite('Files - FileEditorInput', () => {
test
(
'
file editor input factory
'
,
async
function
()
{
instantiationService
.
invokeFunction
(
accessor
=>
Registry
.
as
<
IEditorInputFactoryRegistry
>
(
EditorExtensions
.
EditorInputFactories
).
start
(
accessor
));
const
input
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
undefined
,
undefined
,
undefined
);
const
input
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
)
);
const
factory
=
Registry
.
as
<
IEditorInputFactoryRegistry
>
(
EditorExtensions
.
EditorInputFactories
).
getEditorInputFactory
(
input
.
getTypeId
());
if
(
!
factory
)
{
...
...
@@ -276,7 +280,7 @@ suite('Files - FileEditorInput', () => {
assert
.
equal
(
input
.
matches
(
inputDeserialized
),
true
);
const
preferredResource
=
toResource
.
call
(
this
,
'
/foo/bar/UPDATEfile.js
'
);
const
inputWithPreferredResource
=
instantiationService
.
createInstance
(
FileEditorInput
,
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
preferredResource
,
undefined
,
undefined
);
const
inputWithPreferredResource
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
preferredResource
);
const
inputWithPreferredResourceSerialized
=
factory
.
serialize
(
inputWithPreferredResource
);
if
(
!
inputWithPreferredResourceSerialized
)
{
...
...
@@ -287,4 +291,49 @@ suite('Files - FileEditorInput', () => {
assert
.
equal
(
inputWithPreferredResource
.
resource
.
toString
(),
inputWithPreferredResourceDeserialized
.
resource
.
toString
());
assert
.
equal
(
inputWithPreferredResource
.
preferredResource
.
toString
(),
inputWithPreferredResourceDeserialized
.
preferredResource
.
toString
());
});
test
(
'
preferred name/description
'
,
async
function
()
{
// Works with custom file input
const
customFileInput
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
).
with
({
scheme
:
'
test-custom
'
}),
undefined
,
undefined
,
'
My Name
'
,
'
My Description
'
);
let
didChangeLabelCounter
=
0
;
customFileInput
.
onDidChangeLabel
(()
=>
{
didChangeLabelCounter
++
;
});
assert
.
equal
(
customFileInput
.
getName
(),
'
My Name
'
);
assert
.
equal
(
customFileInput
.
getDescription
(),
'
My Description
'
);
customFileInput
.
setPreferredName
(
'
My Name 2
'
);
customFileInput
.
setPreferredDescription
(
'
My Description 2
'
);
assert
.
equal
(
customFileInput
.
getName
(),
'
My Name 2
'
);
assert
.
equal
(
customFileInput
.
getDescription
(),
'
My Description 2
'
);
assert
.
equal
(
didChangeLabelCounter
,
2
);
customFileInput
.
dispose
();
// Disallowed with local file input
const
fileInput
=
createFileInput
(
toResource
.
call
(
this
,
'
/foo/bar/updatefile.js
'
),
undefined
,
undefined
,
'
My Name
'
,
'
My Description
'
);
didChangeLabelCounter
=
0
;
fileInput
.
onDidChangeLabel
(()
=>
{
didChangeLabelCounter
++
;
});
assert
.
notEqual
(
fileInput
.
getName
(),
'
My Name
'
);
assert
.
notEqual
(
fileInput
.
getDescription
(),
'
My Description
'
);
fileInput
.
setPreferredName
(
'
My Name 2
'
);
fileInput
.
setPreferredDescription
(
'
My Description 2
'
);
assert
.
notEqual
(
fileInput
.
getName
(),
'
My Name 2
'
);
assert
.
notEqual
(
fileInput
.
getDescription
(),
'
My Description 2
'
);
assert
.
equal
(
didChangeLabelCounter
,
0
);
fileInput
.
dispose
();
});
});
src/vs/workbench/electron-browser/desktop.main.ts
浏览文件 @
2feb009c
...
...
@@ -339,10 +339,12 @@ class DesktopMain extends Disposable {
}
catch
(
error
)
{
onUnexpectedError
(
error
);
}
return
;
}
private
async
createHash
(
resource
:
URI
):
Promise
<
string
>
{
// Return early the folder is not local
if
(
resource
.
scheme
!==
Schemas
.
file
)
{
return
createHash
(
'
md5
'
).
update
(
resource
.
toString
()).
digest
(
'
hex
'
);
...
...
@@ -397,7 +399,6 @@ class DesktopMain extends Disposable {
return
storageService
;
}
}
}
export
function
main
(
configuration
:
INativeWorkbenchConfiguration
):
Promise
<
void
>
{
...
...
src/vs/workbench/services/editor/browser/editorService.ts
浏览文件 @
2feb009c
...
...
@@ -880,7 +880,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
// File
if
(
resourceEditorInput
.
forceFile
||
this
.
fileService
.
canHandleResource
(
canonicalResource
))
{
return
this
.
fileEditorInputFactory
.
createFileEditorInput
(
canonicalResource
,
preferredResource
,
resourceEditorInput
.
encoding
,
resourceEditorInput
.
mode
,
this
.
instantiationService
);
return
this
.
fileEditorInputFactory
.
createFileEditorInput
(
canonicalResource
,
preferredResource
,
resourceEditorInput
.
label
,
resourceEditorInput
.
description
,
resourceEditorInput
.
encoding
,
resourceEditorInput
.
mode
,
this
.
instantiationService
);
}
// Resource
...
...
@@ -896,6 +896,14 @@ export class EditorService extends Disposable implements EditorServiceImpl {
else
if
(
!
(
cachedInput
instanceof
ResourceEditorInput
))
{
cachedInput
.
setPreferredResource
(
preferredResource
);
if
(
resourceEditorInput
.
label
)
{
cachedInput
.
setPreferredName
(
resourceEditorInput
.
label
);
}
if
(
resourceEditorInput
.
description
)
{
cachedInput
.
setPreferredDescription
(
resourceEditorInput
.
description
);
}
if
(
resourceEditorInput
.
encoding
)
{
cachedInput
.
setPreferredEncoding
(
resourceEditorInput
.
encoding
);
}
...
...
src/vs/workbench/services/history/browser/history.ts
浏览文件 @
2feb009c
...
...
@@ -517,7 +517,7 @@ export class HistoryService extends Disposable implements IHistoryService {
private
preferResourceEditorInput
(
input
:
IEditorInput
):
IEditorInput
|
IResourceEditorInput
{
const
resource
=
EditorResourceAccessor
.
getOriginalUri
(
input
);
if
(
resource
&&
(
resource
.
scheme
===
Schemas
.
file
||
resource
.
scheme
===
Schemas
.
vscodeRemote
||
resource
.
scheme
===
Schemas
.
userData
||
resource
.
scheme
===
this
.
pathService
.
defaultUriScheme
)
)
{
if
(
resource
?.
scheme
===
Schemas
.
file
||
resource
?.
scheme
===
Schemas
.
vscodeRemote
||
resource
?.
scheme
===
Schemas
.
userData
||
resource
?.
scheme
===
this
.
pathService
.
defaultUriScheme
)
{
// for now, only prefer well known schemes that we control to prevent
// issues such as https://github.com/microsoft/vscode/issues/85204
return
{
resource
};
...
...
src/vs/workbench/test/browser/parts/editor/editorGroups.test.ts
浏览文件 @
2feb009c
...
...
@@ -157,6 +157,8 @@ class TestFileEditorInput extends EditorInput implements IFileEditorInput {
}
getTypeId
()
{
return
'
testFileEditorInputForGroups
'
;
}
resolve
():
Promise
<
IEditorModel
>
{
return
Promise
.
resolve
(
null
!
);
}
setPreferredName
(
name
:
string
):
void
{
}
setPreferredDescription
(
description
:
string
):
void
{
}
setPreferredResource
(
resource
:
URI
):
void
{
}
setEncoding
(
encoding
:
string
)
{
}
getEncoding
()
{
return
undefined
;
}
...
...
src/vs/workbench/test/browser/workbenchTestServices.ts
浏览文件 @
2feb009c
...
...
@@ -116,7 +116,7 @@ import { ColorScheme } from 'vs/platform/theme/common/theme';
import
{
Iterable
}
from
'
vs/base/common/iterator
'
;
export
function
createFileEditorInput
(
instantiationService
:
IInstantiationService
,
resource
:
URI
):
FileEditorInput
{
return
instantiationService
.
createInstance
(
FileEditorInput
,
resource
,
undefined
,
undefined
,
undefined
);
return
instantiationService
.
createInstance
(
FileEditorInput
,
resource
,
undefined
,
undefined
,
undefined
,
undefined
,
undefined
);
}
export
interface
ITestInstantiationService
extends
IInstantiationService
{
...
...
@@ -1177,6 +1177,8 @@ export class TestFileEditorInput extends EditorInput implements IFileEditorInput
setPreferredResource
(
resource
:
URI
):
void
{
}
setEncoding
(
encoding
:
string
)
{
}
getEncoding
()
{
return
undefined
;
}
setPreferredName
(
name
:
string
):
void
{
}
setPreferredDescription
(
description
:
string
):
void
{
}
setPreferredEncoding
(
encoding
:
string
)
{
}
setMode
(
mode
:
string
)
{
}
setPreferredMode
(
mode
:
string
)
{
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录