Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
1d8a10fe
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1d8a10fe
编写于
2月 19, 2018
作者:
T
Till Salinger
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
improved code based on code review feedback
上级
b7cc9709
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
47 deletion
+30
-47
src/vs/workbench/parts/files/electron-browser/fileActions.ts
src/vs/workbench/parts/files/electron-browser/fileActions.ts
+15
-27
src/vs/workbench/parts/files/electron-browser/views/explorerViewer.ts
...ench/parts/files/electron-browser/views/explorerViewer.ts
+15
-20
未找到文件。
src/vs/workbench/parts/files/electron-browser/fileActions.ts
浏览文件 @
1d8a10fe
...
...
@@ -1336,14 +1336,11 @@ export function validateFileName(parent: IFileStat, name: string, allowOverwriti
return
nls
.
localize
(
'
emptyFileNameError
'
,
"
A file or folder name must be provided.
"
);
}
const
names
:
string
[]
=
trimTrailingSlashes
(
name
)
// prevents empty last array element after split
.
split
(
/
[\\/]
/
);
const
names
:
string
[]
=
name
.
split
(
/
[\\/]
/
).
filter
(
part
=>
!!
part
);
// Do not allow to overwrite existing file
if
(
!
allowOverwriting
)
{
let
p
=
parent
;
const
alreadyExisting
=
names
.
every
((
folderName
)
=>
{
let
{
exists
,
child
}
=
alreadyExists
(
p
,
folderName
);
...
...
@@ -1365,8 +1362,10 @@ export function validateFileName(parent: IFileStat, name: string, allowOverwriti
return
nls
.
localize
(
'
invalidFileNameError
'
,
"
The name **{0}** is not valid as a file or folder name. Please choose a different name.
"
,
trimLongName
(
name
));
}
// Max length restriction (on Windows)
if
(
isWindows
)
{
if
(
windowsMaxLengthRestrictionReached
(
name
,
parent
))
{
const
fullPathLength
=
name
.
length
+
parent
.
resource
.
fsPath
.
length
+
1
/* path segment */
;
if
(
fullPathLength
>
255
)
{
return
nls
.
localize
(
'
filePathTooLongError
'
,
"
The name **{0}** results in a path that is too long. Please choose a shorter name.
"
,
trimLongName
(
name
));
}
}
...
...
@@ -1374,39 +1373,28 @@ export function validateFileName(parent: IFileStat, name: string, allowOverwriti
return
null
;
}
function
windowsMaxLengthRestrictionReached
(
name
:
string
,
parent
:
IFileStat
):
boolean
{
const
fullPathLength
=
name
.
length
+
parent
.
resource
.
fsPath
.
length
+
1
/* path segment */
;
return
fullPathLength
>
255
;
}
function
trimTrailingSlashes
(
str
):
string
|
undefined
{
if
(
!
str
)
{
return
str
;
}
return
str
.
replace
(
/
[\\/]
*$/
,
''
);
}
function
alreadyExists
(
parent
:
IFileStat
,
name
:
string
):
{
exists
:
boolean
,
child
:
IFileStat
|
undefined
}
{
let
foundDup
Child
:
IFileStat
;
let
duplicate
Child
:
IFileStat
;
if
(
parent
.
children
)
{
let
exists
:
boolean
=
parent
.
children
.
some
((
c
)
=>
{
let
found
=
compareFolderNames
(
c
.
name
,
name
);
if
(
found
)
{
foundDupChild
=
c
;
}
let
found
:
boolean
;
if
(
isLinux
)
{
found
=
c
.
name
===
name
;
}
else
{
found
=
c
.
name
.
toLowerCase
()
===
name
.
toLowerCase
();
}
if
(
found
)
{
duplicateChild
=
c
;
}
return
found
;
});
return
{
exists
,
child
:
foundDup
Child
};
return
{
exists
,
child
:
duplicate
Child
};
}
return
{
exists
:
false
,
child
:
undefined
};
}
function
compareFolderNames
(
name1
:
string
,
name2
:
string
):
boolean
{
if
(
isLinux
)
{
return
name1
===
name2
;
}
return
name1
.
toLowerCase
()
===
name2
.
toLowerCase
();
}
function
trimLongName
(
name
:
string
):
string
{
if
(
name
&&
name
.
length
>
255
)
{
return
`
${
name
.
substr
(
0
,
255
)}
...`
;
...
...
src/vs/workbench/parts/files/electron-browser/views/explorerViewer.ts
浏览文件 @
1d8a10fe
...
...
@@ -296,7 +296,6 @@ export class FileRenderer implements IRenderer {
},
0
);
});
const
initialRelPath
:
string
=
relative
(
stat
.
root
.
resource
.
fsPath
,
stat
.
parent
.
resource
.
fsPath
);
const
toDispose
=
[
inputBox
,
DOM
.
addStandardDisposableListener
(
inputBox
.
inputElement
,
DOM
.
EventType
.
KEY_DOWN
,
(
e
:
IKeyboardEvent
)
=>
{
...
...
@@ -309,7 +308,8 @@ export class FileRenderer implements IRenderer {
}
}),
DOM
.
addStandardDisposableListener
(
inputBox
.
inputElement
,
DOM
.
EventType
.
KEY_UP
,
(
e
:
IKeyboardEvent
)
=>
{
displayCurrentPath
(
inputBox
,
initialRelPath
,
fileKind
);
const
initialRelPath
:
string
=
relative
(
stat
.
root
.
resource
.
fsPath
,
stat
.
parent
.
resource
.
fsPath
);
this
.
displayCurrentPath
(
inputBox
,
initialRelPath
,
fileKind
);
}),
DOM
.
addDisposableListener
(
inputBox
.
inputElement
,
DOM
.
EventType
.
BLUR
,
()
=>
{
done
(
inputBox
.
isInputValid
(),
true
);
...
...
@@ -318,29 +318,24 @@ export class FileRenderer implements IRenderer {
styler
];
}
}
function
displayCurrentPath
(
inputBox
:
InputBox
,
initialRelPath
:
string
,
fileKind
:
FileKind
)
{
const
value
=
inputBox
.
value
;
if
(
inputBox
.
validate
())
{
if
(
value
&&
value
.
search
(
/
[\\/]
/
)
!==
-
1
)
{
// only show if there's a slash
const
newPath
=
replaceWithNativeSep
(
paths
.
join
(
initialRelPath
,
value
));
const
fileType
:
string
=
FileKind
[
fileKind
].
toLowerCase
();
inputBox
.
showMessage
({
type
:
MessageType
.
INFO
,
content
:
nls
.
localize
(
'
constructedPath
'
,
"
Create **{0}** in **{1}**
"
,
fileType
,
newPath
),
formatContent
:
true
});
private
displayCurrentPath
(
inputBox
:
InputBox
,
initialRelPath
:
string
,
fileKind
:
FileKind
)
{
if
(
inputBox
.
validate
())
{
const
value
=
inputBox
.
value
;
if
(
value
&&
value
.
search
(
/
[\\/]
/
)
!==
-
1
)
{
// only show if there's a slash
const
newPath
=
paths
.
normalize
(
paths
.
join
(
initialRelPath
,
value
),
true
);
const
fileType
:
string
=
FileKind
[
fileKind
].
toLowerCase
();
inputBox
.
showMessage
({
type
:
MessageType
.
INFO
,
content
:
nls
.
localize
(
'
constructedPath
'
,
"
Create **{0}** in **{1}**
"
,
fileType
,
newPath
),
formatContent
:
true
});
}
}
}
}
function
replaceWithNativeSep
(
str
:
string
)
{
if
(
!
str
)
{
return
str
;
}
return
str
.
replace
(
/
[\\/]
/g
,
paths
.
nativeSep
);
}
// Explorer Accessibility Provider
export
class
FileAccessibilityProvider
implements
IAccessibilityProvider
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录