Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
11c2ef63
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,发现更多精彩内容 >>
提交
11c2ef63
编写于
6月 15, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #42640
上级
5f936044
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
123 addition
and
20 deletion
+123
-20
src/vs/workbench/parts/files/electron-browser/fileActions.ts
src/vs/workbench/parts/files/electron-browser/fileActions.ts
+1
-1
src/vs/workbench/services/bulkEdit/electron-browser/bulkEditService.ts
...nch/services/bulkEdit/electron-browser/bulkEditService.ts
+6
-3
src/vs/workbench/services/textfile/common/textFileService.ts
src/vs/workbench/services/textfile/common/textFileService.ts
+52
-0
src/vs/workbench/services/textfile/common/textfiles.ts
src/vs/workbench/services/textfile/common/textfiles.ts
+16
-8
src/vs/workbench/services/textfile/test/textFileService.test.ts
.../workbench/services/textfile/test/textFileService.test.ts
+39
-0
src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts
...bench/test/electron-browser/api/mainThreadEditors.test.ts
+9
-8
未找到文件。
src/vs/workbench/parts/files/electron-browser/fileActions.ts
浏览文件 @
11c2ef63
...
...
@@ -308,7 +308,7 @@ class RenameFileAction extends BaseRenameAction {
renamed
=
this
.
element
.
parent
.
resource
.
with
({
path
:
targetPath
});
}
// Otherwise, a parent of the dirty resource got moved, so we have to reparent more complicated
. Example:
// Otherwise, a parent of the dirty resource got moved, so we have to reparent more complicated
else
{
renamed
=
this
.
element
.
parent
.
resource
.
with
({
path
:
paths
.
join
(
targetPath
,
d
.
path
.
substr
(
this
.
element
.
resource
.
path
.
length
+
1
))
});
}
...
...
src/vs/workbench/services/bulkEdit/electron-browser/bulkEditService.ts
浏览文件 @
11c2ef63
...
...
@@ -25,6 +25,7 @@ import { IProgress, IProgressRunner, emptyProgressRunner } from 'vs/platform/pro
import
{
IEditorService
}
from
'
vs/workbench/services/editor/common/editorService
'
;
import
{
IEnvironmentService
}
from
'
vs/platform/environment/common/environment
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
import
{
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
abstract
class
Recording
{
...
...
@@ -269,6 +270,7 @@ export class BulkEdit {
progress
:
IProgressRunner
,
@
ITextModelService
private
readonly
_textModelService
:
ITextModelService
,
@
IFileService
private
readonly
_fileService
:
IFileService
,
@
ITextFileService
private
readonly
_textFileService
:
ITextFileService
,
@
IEnvironmentService
private
readonly
_environmentService
:
IEnvironmentService
,
@
IWorkspaceContextService
private
readonly
_contextService
:
IWorkspaceContextService
)
{
...
...
@@ -345,9 +347,9 @@ export class BulkEdit {
progress
.
report
(
undefined
);
if
(
edit
.
newUri
&&
edit
.
oldUri
)
{
await
this
.
_
fileService
.
moveFil
e
(
edit
.
oldUri
,
edit
.
newUri
,
false
);
await
this
.
_
textFileService
.
mov
e
(
edit
.
oldUri
,
edit
.
newUri
,
false
);
}
else
if
(
!
edit
.
newUri
&&
edit
.
oldUri
)
{
await
this
.
_
fileService
.
del
(
edit
.
oldUri
,
true
);
await
this
.
_
textFileService
.
delete
(
edit
.
oldUri
,
true
);
}
else
if
(
edit
.
newUri
&&
!
edit
.
oldUri
)
{
await
this
.
_fileService
.
createFile
(
edit
.
newUri
,
undefined
,
{
overwrite
:
false
});
}
...
...
@@ -387,6 +389,7 @@ export class BulkEditService implements IBulkEditService {
@
IEditorService
private
readonly
_editorService
:
IEditorService
,
@
ITextModelService
private
readonly
_textModelService
:
ITextModelService
,
@
IFileService
private
readonly
_fileService
:
IFileService
,
@
ITextFileService
private
readonly
_textFileService
:
ITextFileService
,
@
IEnvironmentService
private
readonly
_environmentService
:
IEnvironmentService
,
@
IWorkspaceContextService
private
readonly
_contextService
:
IWorkspaceContextService
)
{
...
...
@@ -419,7 +422,7 @@ export class BulkEditService implements IBulkEditService {
}
}
const
bulkEdit
=
new
BulkEdit
(
options
.
editor
,
options
.
progress
,
this
.
_textModelService
,
this
.
_fileService
,
this
.
_environmentService
,
this
.
_contextService
);
const
bulkEdit
=
new
BulkEdit
(
options
.
editor
,
options
.
progress
,
this
.
_textModelService
,
this
.
_fileService
,
this
.
_
textFileService
,
this
.
_
environmentService
,
this
.
_contextService
);
bulkEdit
.
add
(
edits
);
return
bulkEdit
.
perform
().
then
(
selection
=>
{
return
{
...
...
src/vs/workbench/services/textfile/common/textFileService.ts
浏览文件 @
11c2ef63
...
...
@@ -701,6 +701,58 @@ export abstract class TextFileService implements ITextFileService {
});
}
public
delete
(
resource
:
URI
,
useTrash
?:
boolean
):
TPromise
<
void
>
{
return
this
.
revert
(
resource
,
{
soft
:
true
}).
then
(()
=>
this
.
fileService
.
del
(
resource
,
useTrash
));
}
public
move
(
source
:
URI
,
target
:
URI
,
overwrite
?:
boolean
):
TPromise
<
void
>
{
// Handle target model if existing
let
handleTargetModelPromise
:
TPromise
<
any
>
=
TPromise
.
as
(
void
0
);
const
targetModel
=
this
.
models
.
get
(
target
);
if
(
targetModel
)
{
if
(
!
overwrite
)
{
return
TPromise
.
wrapError
(
new
Error
(
'
Cannot move file because target file exists and we are not overwriting
'
));
}
// Soft revert the target file since we overwrite
handleTargetModelPromise
=
this
.
revert
(
target
,
{
soft
:
true
});
}
return
handleTargetModelPromise
.
then
(()
=>
{
// Handle source model if existing
let
handleSourceModelPromise
:
TPromise
<
boolean
>
;
const
sourceModel
=
this
.
models
.
get
(
source
);
if
(
sourceModel
&&
sourceModel
.
isDirty
())
{
// Backup to target if the source is dirty
handleSourceModelPromise
=
this
.
backupFileService
.
backupResource
(
target
,
sourceModel
.
createSnapshot
(),
sourceModel
.
getVersionId
()).
then
((()
=>
true
));
}
else
{
handleSourceModelPromise
=
TPromise
.
as
(
false
);
}
return
handleSourceModelPromise
.
then
(
dirty
=>
{
// Soft revert the source file
return
this
.
revert
(
source
,
{
soft
:
true
}).
then
(()
=>
{
// Rename to target
return
this
.
fileService
.
moveFile
(
source
,
target
,
overwrite
).
then
(()
=>
{
// Load if we were dirty before
if
(
dirty
)
{
return
this
.
models
.
loadOrCreate
(
target
).
then
(()
=>
void
0
);
}
return
void
0
;
},
error
=>
{
return
this
.
backupFileService
.
discardResourceBackup
(
target
).
then
(()
=>
TPromise
.
wrapError
(
error
));
});
});
});
});
}
public
getAutoSaveMode
():
AutoSaveMode
{
if
(
this
.
configuredAutoSaveOnFocusChange
)
{
return
AutoSaveMode
.
ON_FOCUS_CHANGE
;
...
...
src/vs/workbench/services/textfile/common/textfiles.ts
浏览文件 @
11c2ef63
...
...
@@ -237,13 +237,16 @@ export interface ITextFileEditorModel extends ITextEditorModel, IEncodingSupport
export
interface
ITextFileService
extends
IDisposable
{
_serviceBrand
:
any
;
onAutoSaveConfigurationChange
:
Event
<
IAutoSaveConfiguration
>
;
onFilesAssociationChange
:
Event
<
void
>
;
readonly
onAutoSaveConfigurationChange
:
Event
<
IAutoSaveConfiguration
>
;
readonly
onFilesAssociationChange
:
Event
<
void
>
;
readonly
isHotExitEnabled
:
boolean
;
/**
* Access to the manager of text file editor models providing further methods to work with them.
*/
models
:
ITextFileEditorModelManager
;
readonly
models
:
ITextFileEditorModelManager
;
/**
* Resolve the contents of a file identified by the resource.
...
...
@@ -307,6 +310,16 @@ export interface ITextFileService extends IDisposable {
*/
revertAll
(
resources
?:
URI
[],
options
?:
IRevertOptions
):
TPromise
<
ITextFileOperationResult
>
;
/**
* Delete a file. If the file is dirty, it will get reverted and then deleted from disk.
*/
delete
(
resource
:
URI
,
useTrash
?:
boolean
):
TPromise
<
void
>
;
/**
* Move a file. If the file is dirty, its contents will be preserved and restored.
*/
move
(
source
:
URI
,
target
:
URI
,
overwrite
?:
boolean
):
TPromise
<
void
>
;
/**
* Brings up the confirm dialog to either save, don't save or cancel.
*
...
...
@@ -324,9 +337,4 @@ export interface ITextFileService extends IDisposable {
* Convinient fast access to the raw configured auto save settings.
*/
getAutoSaveConfiguration
():
IAutoSaveConfiguration
;
/**
* Convinient fast access to the hot exit file setting.
*/
isHotExitEnabled
:
boolean
;
}
src/vs/workbench/services/textfile/test/textFileService.test.ts
浏览文件 @
11c2ef63
...
...
@@ -252,6 +252,45 @@ suite('Files - TextFileService', () => {
});
});
test
(
'
delete - dirty file
'
,
function
()
{
model
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
.
call
(
this
,
'
/path/file.txt
'
),
'
utf8
'
);
(
<
TextFileEditorModelManager
>
accessor
.
textFileService
.
models
).
add
(
model
.
getResource
(),
model
);
const
service
=
accessor
.
textFileService
;
return
model
.
load
().
then
(()
=>
{
model
.
textEditorModel
.
setValue
(
'
foo
'
);
assert
.
ok
(
service
.
isDirty
(
model
.
getResource
()));
return
service
.
delete
(
model
.
getResource
()).
then
(()
=>
{
assert
.
ok
(
!
service
.
isDirty
(
model
.
getResource
()));
});
});
});
test
(
'
move - dirty file
'
,
function
()
{
let
sourceModel
:
TextFileEditorModel
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
.
call
(
this
,
'
/path/file.txt
'
),
'
utf8
'
);
let
targetModel
:
TextFileEditorModel
=
instantiationService
.
createInstance
(
TextFileEditorModel
,
toResource
.
call
(
this
,
'
/path/file_target.txt
'
),
'
utf8
'
);
(
<
TextFileEditorModelManager
>
accessor
.
textFileService
.
models
).
add
(
sourceModel
.
getResource
(),
sourceModel
);
(
<
TextFileEditorModelManager
>
accessor
.
textFileService
.
models
).
add
(
targetModel
.
getResource
(),
targetModel
);
const
service
=
accessor
.
textFileService
;
return
sourceModel
.
load
().
then
(()
=>
{
sourceModel
.
textEditorModel
.
setValue
(
'
foo
'
);
assert
.
ok
(
service
.
isDirty
(
sourceModel
.
getResource
()));
return
service
.
move
(
sourceModel
.
getResource
(),
targetModel
.
getResource
(),
true
).
then
(()
=>
{
assert
.
ok
(
!
service
.
isDirty
(
sourceModel
.
getResource
()));
sourceModel
.
dispose
();
targetModel
.
dispose
();
});
});
});
suite
(
'
Hot Exit
'
,
()
=>
{
suite
(
'
"onExit" setting
'
,
()
=>
{
test
(
'
should hot exit on non-Mac (reason: CLOSE, windows: single, workspace)
'
,
function
()
{
...
...
src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts
浏览文件 @
11c2ef63
...
...
@@ -48,22 +48,23 @@ suite('MainThreadEditors', () => {
deletedResources
.
clear
();
const
fileService
=
new
class
extends
TestFileService
{
async
moveFile
(
from
:
URI
,
target
:
URI
):
TPromise
<
IFileStat
>
{
movedResources
.
set
(
from
,
target
);
return
createMockFileStat
(
target
);
}
async
createFile
(
uri
:
URI
):
TPromise
<
IFileStat
>
{
createdResources
.
add
(
uri
);
return
createMockFileStat
(
uri
);
}
async
del
(
uri
:
URI
):
TPromise
<
any
>
{
deletedResources
.
add
(
uri
);
}
};
const
textFileService
=
new
class
extends
mock
<
ITextFileService
>
()
{
isDirty
()
{
return
false
;
}
delete
(
resource
:
URI
)
{
deletedResources
.
add
(
resource
);
return
TPromise
.
as
(
void
0
);
}
move
(
source
:
URI
,
target
:
URI
)
{
movedResources
.
set
(
source
,
target
);
return
TPromise
.
as
(
void
0
);
}
models
=
<
any
>
{
onModelSaved
:
Event
.
None
,
onModelReverted
:
Event
.
None
,
...
...
@@ -73,7 +74,7 @@ suite('MainThreadEditors', () => {
const
workbenchEditorService
=
new
TestEditorService
();
const
editorGroupService
=
new
TestEditorGroupsService
();
const
bulkEditService
=
new
BulkEditService
(
modelService
,
new
TestEditorService
(),
null
,
fileService
,
TestEnvironmentService
,
new
TestContextService
());
const
bulkEditService
=
new
BulkEditService
(
modelService
,
new
TestEditorService
(),
null
,
fileService
,
textFileService
,
TestEnvironmentService
,
new
TestContextService
());
const
rpcProtocol
=
new
TestRPCProtocol
();
rpcProtocol
.
set
(
ExtHostContext
.
ExtHostDocuments
,
new
class
extends
mock
<
ExtHostDocumentsShape
>
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录