Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
aa19069e
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,发现更多精彩内容 >>
提交
aa19069e
编写于
2月 14, 2018
作者:
T
Till Salinger
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add multi-path creation from file explorer
上级
00f2d8ed
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
75 addition
and
9 deletion
+75
-9
src/vs/workbench/parts/files/electron-browser/fileActions.ts
src/vs/workbench/parts/files/electron-browser/fileActions.ts
+49
-9
src/vs/workbench/services/files/test/node/fileService.test.ts
...vs/workbench/services/files/test/node/fileService.test.ts
+26
-0
未找到文件。
src/vs/workbench/parts/files/electron-browser/fileActions.ts
浏览文件 @
aa19069e
...
...
@@ -498,7 +498,8 @@ export abstract class BaseCreateAction extends BaseRenameAction {
return
validateFileName
(
parent
,
name
,
false
);
}
return
super
.
validateFileName
(
parent
,
name
);
console
.
log
(
'
The other validateFilename function was called!
'
);
return
super
.
validateFileName
(
parent
,
name
);
// TODO: when is this called?
}
}
...
...
@@ -1325,31 +1326,42 @@ export class CopyPathAction extends Action {
}
}
export
function
validateFileName
(
parent
:
IFileStat
,
name
:
string
,
allowOverwriting
:
boolean
=
false
):
string
{
export
function
validateFileName
(
parent
:
IFileStat
,
name
:
string
,
allowOverwriting
:
boolean
=
false
,
isFile
:
boolean
=
false
):
string
{
// TODO: param file or folder?
// Produce a well formed file name
name
=
getWellFormedFileName
(
name
);
// Name not provided
if
(
!
name
||
name
.
length
===
0
||
/^
\s
+$/
.
test
(
name
))
{
if
(
!
name
||
name
.
length
===
0
||
/^
\s
+$/
.
test
(
name
))
{
// TODO: replace with strings.isFalsyOrWhitespace?
return
nls
.
localize
(
'
emptyFileNameError
'
,
"
A file or folder name must be provided.
"
);
}
// if () --> is file && trailing slash --> return
const
names
:
string
[]
=
trimTrailingSlashes
(
name
)
// prevents empty last array element after split
.
split
(
/
[\\/]
/
);
// Do not allow to overwrite existing file
if
(
!
allowOverwriting
)
{
if
(
parent
.
children
&&
parent
.
children
.
some
((
c
)
=>
{
if
(
isLinux
)
{
return
c
.
name
===
name
;
let
p
=
parent
;
const
alreadyExisting
=
names
.
every
((
folderName
)
=>
{
let
{
exists
,
child
}
=
alreadyExists
(
p
,
folderName
);
if
(
!
exists
)
{
return
false
;
}
else
{
p
=
child
;
return
true
;
}
});
return
c
.
name
.
toLowerCase
()
===
name
.
toLowerCase
();
}))
{
if
(
alreadyExisting
)
{
return
nls
.
localize
(
'
fileNameExistsError
'
,
"
A file or folder **{0}** already exists at this location. Please choose a different name.
"
,
name
);
}
}
// Invalid File name
if
(
!
paths
.
isValidBasename
(
name
))
{
if
(
names
.
some
((
folderName
)
=>
!
paths
.
isValidBasename
(
folderName
)
))
{
return
nls
.
localize
(
'
invalidFileNameError
'
,
"
The name **{0}** is not valid as a file or folder name. Please choose a different name.
"
,
trimLongName
(
name
));
}
...
...
@@ -1364,6 +1376,34 @@ export function validateFileName(parent: IFileStat, name: string, allowOverwriti
return
null
;
}
function
trimTrailingSlashes
(
str
):
string
|
undefined
{
if
(
!
str
)
{
return
str
;
}
return
str
.
replace
(
/
[\\/]
*$/
,
''
);
}
function
alreadyExists
(
parent
:
IFileStat
,
name
:
string
):
{
exists
:
boolean
,
child
:
IFileStat
|
undefined
}
{
let
foundDupChild
:
IFileStat
;
if
(
parent
.
children
)
{
let
exists
:
boolean
=
parent
.
children
.
some
((
c
)
=>
{
let
found
=
compareFolderNames
(
c
.
name
,
name
);
if
(
found
)
{
foundDupChild
=
c
;
}
return
found
;
});
return
{
exists
,
child
:
foundDupChild
};
}
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/services/files/test/node/fileService.test.ts
浏览文件 @
aa19069e
...
...
@@ -136,6 +136,32 @@ suite('FileService', () => {
},
error
=>
onError
(
error
,
done
));
});
test
(
'
createFolder: creating multiple folders at once
'
,
function
(
done
:
()
=>
void
)
{
let
event
:
FileOperationEvent
;
const
toDispose
=
service
.
onAfterOperation
(
e
=>
{
event
=
e
;
});
const
multiFolderPaths
=
'
a/couple/of/folders
'
;
service
.
resolveFile
(
uri
.
file
(
testDir
)).
done
(
parent
=>
{
const
resource
=
uri
.
file
(
path
.
join
(
parent
.
resource
.
fsPath
,
multiFolderPaths
));
return
service
.
createFolder
(
resource
).
then
(
f
=>
{
// assert.equal(f.name, multiFolderPaths);
assert
.
equal
(
fs
.
existsSync
(
f
.
resource
.
fsPath
),
true
);
assert
.
ok
(
event
);
assert
.
equal
(
event
.
resource
.
fsPath
,
resource
.
fsPath
);
assert
.
equal
(
event
.
operation
,
FileOperation
.
CREATE
);
assert
.
equal
(
event
.
target
.
resource
.
fsPath
,
resource
.
fsPath
);
assert
.
equal
(
event
.
target
.
isDirectory
,
true
);
toDispose
.
dispose
();
done
();
});
},
error
=>
onError
(
error
,
done
));
});
test
(
'
touchFile
'
,
function
(
done
:
()
=>
void
)
{
service
.
touchFile
(
uri
.
file
(
path
.
join
(
testDir
,
'
test.txt
'
))).
done
(
s
=>
{
assert
.
equal
(
s
.
name
,
'
test.txt
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录