Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
4928801c
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,发现更多精彩内容 >>
提交
4928801c
编写于
10月 13, 2016
作者:
D
Daniel Imms
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Get untitled files restoring from backup
上级
86e1c202
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
60 addition
and
14 deletion
+60
-14
src/vs/platform/backup/common/backup.ts
src/vs/platform/backup/common/backup.ts
+2
-1
src/vs/workbench/common/backup.ts
src/vs/workbench/common/backup.ts
+14
-1
src/vs/workbench/common/editor/untitledEditorInput.ts
src/vs/workbench/common/editor/untitledEditorInput.ts
+14
-2
src/vs/workbench/common/editor/untitledEditorModel.ts
src/vs/workbench/common/editor/untitledEditorModel.ts
+1
-1
src/vs/workbench/common/options.ts
src/vs/workbench/common/options.ts
+1
-0
src/vs/workbench/electron-browser/workbench.ts
src/vs/workbench/electron-browser/workbench.ts
+15
-1
src/vs/workbench/services/files/node/fileService.ts
src/vs/workbench/services/files/node/fileService.ts
+1
-3
src/vs/workbench/services/untitled/common/untitledEditorService.ts
...rkbench/services/untitled/common/untitledEditorService.ts
+12
-5
未找到文件。
src/vs/platform/backup/common/backup.ts
浏览文件 @
4928801c
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
Uri
from
'
vs/base/common/uri
'
;
export
const
IBackupService
=
createDecorator
<
IBackupService
>
(
'
backupService
'
);
...
...
@@ -20,5 +20,6 @@ export interface IBackupService {
registerBackupFile
(
resource
:
Uri
):
void
;
deregisterBackupFile
(
resource
:
Uri
):
void
;
getBackupFiles
(
workspace
:
string
):
string
[];
getBackupUntitledFiles
(
workspace
:
string
):
string
[];
getBackupResource
(
resource
:
Uri
):
Uri
;
}
src/vs/workbench/common/backup.ts
浏览文件 @
4928801c
...
...
@@ -62,9 +62,22 @@ export class BackupService implements IBackupService {
return
this
.
fileContent
.
folderWorkspaces
[
workspace
]
||
[];
}
public
getBackupUntitledFiles
(
workspace
:
string
):
string
[]
{
const
workspaceHash
=
crypto
.
createHash
(
'
md5
'
).
update
(
this
.
workspaceResource
.
fsPath
).
digest
(
'
hex
'
);
const
untitledDir
=
path
.
join
(
this
.
environmentService
.
userDataPath
,
'
Backups
'
,
workspaceHash
,
'
untitled
'
);
try
{
const
untitledFiles
=
fs
.
readdirSync
(
untitledDir
).
map
(
file
=>
path
.
join
(
untitledDir
,
file
));
console
.
log
(
'
untitledFiles
'
,
untitledFiles
);
return
untitledFiles
;
}
catch
(
ex
)
{
console
.
log
(
'
untitled backups do not exist
'
);
return
[];
}
}
public
getBackupResource
(
resource
:
Uri
):
Uri
{
le
t
workspaceHash
=
crypto
.
createHash
(
'
md5
'
).
update
(
this
.
workspaceResource
.
fsPath
).
digest
(
'
hex
'
);
cons
t
workspaceHash
=
crypto
.
createHash
(
'
md5
'
).
update
(
this
.
workspaceResource
.
fsPath
).
digest
(
'
hex
'
);
const
backupName
=
crypto
.
createHash
(
'
md5
'
).
update
(
resource
.
fsPath
).
digest
(
'
hex
'
);
const
backupPath
=
path
.
join
(
this
.
environmentService
.
userDataPath
,
'
Backups
'
,
workspaceHash
,
resource
.
scheme
,
backupName
);
console
.
log
(
'
getBackupResource
'
+
Uri
.
file
(
backupPath
));
...
...
src/vs/workbench/common/editor/untitledEditorInput.ts
浏览文件 @
4928801c
...
...
@@ -19,6 +19,9 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
ITextFileService
}
from
'
vs/workbench/services/textfile/common/textfiles
'
;
// TODO: This file cannot depend on native node modules
import
fs
=
require
(
'
fs
'
);
/**
* An editor input to be used for untitled text buffers.
*/
...
...
@@ -28,6 +31,7 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
public
static
SCHEMA
:
string
=
'
untitled
'
;
private
resource
:
URI
;
private
restoreResource
:
URI
;
private
hasAssociatedFilePath
:
boolean
;
private
modeId
:
string
;
private
cachedModel
:
UntitledEditorModel
;
...
...
@@ -46,7 +50,7 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
@
ITextFileService
private
textFileService
:
ITextFileService
)
{
super
();
console
.
log
(
'
UntitledEditorInput constructor
'
,
resource
,
hasAssociatedFilePath
,
modeId
);
this
.
resource
=
resource
;
this
.
hasAssociatedFilePath
=
hasAssociatedFilePath
;
this
.
modeId
=
modeId
;
...
...
@@ -66,6 +70,10 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
return
this
.
resource
;
}
public
setRestoreResource
(
resource
:
URI
):
void
{
this
.
restoreResource
=
resource
;
}
public
getName
():
string
{
return
this
.
hasAssociatedFilePath
?
paths
.
basename
(
this
.
resource
.
fsPath
)
:
this
.
resource
.
fsPath
;
}
...
...
@@ -140,7 +148,11 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
}
private
createModel
():
UntitledEditorModel
{
const
content
=
''
;
let
content
=
''
;
if
(
this
.
restoreResource
)
{
// TODO: This loading should probably go through fileService, fs cannot be a dependency in common/
content
=
fs
.
readFileSync
(
this
.
restoreResource
.
fsPath
,
'
utf8
'
);
}
const
model
=
this
.
instantiationService
.
createInstance
(
UntitledEditorModel
,
content
,
this
.
modeId
,
this
.
resource
,
this
.
hasAssociatedFilePath
);
// re-emit some events from the model
...
...
src/vs/workbench/common/editor/untitledEditorModel.ts
浏览文件 @
4928801c
...
...
@@ -46,7 +46,7 @@ export class UntitledEditorModel extends StringEditorModel implements IEncodingS
super
(
value
,
modeId
,
resource
,
modeService
,
modelService
);
this
.
hasAssociatedFilePath
=
hasAssociatedFilePath
;
this
.
dirty
=
hasAssociatedFilePath
;
// untitled associated to file path are dirty right away
this
.
dirty
=
hasAssociatedFilePath
||
value
!==
''
;
// untitled associated to file path are dirty right away
this
.
_onDidChangeDirty
=
new
Emitter
<
void
>
();
this
.
_onDidChangeEncoding
=
new
Emitter
<
void
>
();
...
...
src/vs/workbench/common/options.ts
浏览文件 @
4928801c
...
...
@@ -24,4 +24,5 @@ export interface IOptions {
filesToDiff
?:
IResourceInput
[];
filesToRestore
?:
IResourceInput
[];
untitledFilesToRestore
?:
IResourceInput
[];
}
\ No newline at end of file
src/vs/workbench/electron-browser/workbench.ts
浏览文件 @
4928801c
...
...
@@ -176,8 +176,16 @@ export class Workbench implements IPartService {
options
.
filesToRestore
=
this
.
backupService
.
getBackupFiles
(
workspace
.
resource
.
fsPath
).
map
(
filePath
=>
{
return
{
resource
:
Uri
.
file
(
filePath
),
options
:
{
pinned
:
true
}
};
});
options
.
untitledFilesToRestore
=
this
.
backupService
.
getBackupUntitledFiles
(
workspace
.
resource
.
fsPath
).
map
(
untitledFilePath
=>
{
return
{
resource
:
Uri
.
from
({
path
:
untitledFilePath
,
scheme
:
'
untitled
'
}),
options
:
{
pinned
:
true
}
};
});
this
.
hasFilesToCreateOpenOrDiff
=
(
options
.
filesToCreate
&&
options
.
filesToCreate
.
length
>
0
)
||
(
options
.
filesToOpen
&&
options
.
filesToOpen
.
length
>
0
)
||
(
options
.
filesToDiff
&&
options
.
filesToDiff
.
length
>
0
)
||
(
options
.
filesToRestore
.
length
>
0
);
this
.
hasFilesToCreateOpenOrDiff
=
(
options
.
filesToCreate
&&
options
.
filesToCreate
.
length
>
0
)
||
(
options
.
filesToOpen
&&
options
.
filesToOpen
.
length
>
0
)
||
(
options
.
filesToDiff
&&
options
.
filesToDiff
.
length
>
0
)
||
(
options
.
filesToRestore
.
length
>
0
)
||
(
options
.
untitledFilesToRestore
.
length
>
0
);
this
.
toDispose
=
[];
this
.
toShutdown
=
[];
...
...
@@ -305,6 +313,7 @@ export class Workbench implements IPartService {
const
filesToCreate
=
wbopt
.
filesToCreate
||
[];
const
filesToOpen
=
wbopt
.
filesToOpen
||
[];
const
filesToRestore
=
wbopt
.
filesToRestore
||
[];
const
untitledFilesToRestore
=
wbopt
.
untitledFilesToRestore
||
[];
const
filesToDiff
=
wbopt
.
filesToDiff
;
// Files to diff is exclusive
...
...
@@ -323,9 +332,14 @@ export class Workbench implements IPartService {
inputs
.
push
(...
filesToCreate
.
map
(
resourceInput
=>
this
.
untitledEditorService
.
createOrGet
(
resourceInput
.
resource
)));
options
.
push
(...
filesToCreate
.
map
(
r
=>
null
));
// fill empty options for files to create because we dont have options there
// Files to restore
inputs
.
push
(...
untitledFilesToRestore
.
map
(
resourceInput
=>
this
.
untitledEditorService
.
createOrGet
(
null
,
null
,
resourceInput
.
resource
)));
options
.
push
(...
untitledFilesToRestore
.
map
(
r
=>
null
));
// fill empty options for files to create because we dont have options there
// Files to open
let
filesToOpenInputPromise
=
filesToOpen
.
map
(
resourceInput
=>
this
.
editorService
.
createInput
(
resourceInput
));
let
filesToRestoreInputPromise
=
filesToRestore
.
map
(
resourceInput
=>
this
.
editorService
.
createInput
(
resourceInput
,
true
));
return
TPromise
.
join
<
EditorInput
>
(
filesToOpenInputPromise
.
concat
(
filesToRestoreInputPromise
)).
then
((
inputsToOpen
)
=>
{
inputs
.
push
(...
inputsToOpen
);
options
.
push
(...
filesToOpen
.
concat
(
filesToRestore
).
map
(
resourceInput
=>
TextEditorOptions
.
from
(
resourceInput
)));
...
...
src/vs/workbench/services/files/node/fileService.ts
浏览文件 @
4928801c
...
...
@@ -459,10 +459,8 @@ export class FileService implements IFileService {
public
backupFile
(
resource
:
uri
,
content
:
string
):
TPromise
<
IFileStat
>
{
if
(
resource
.
scheme
===
'
file
'
)
{
// TODO: Persist hash -> file map on disk (json file?)
this
.
backupService
.
registerBackupFile
(
resource
);
}
this
.
backupService
.
registerBackupFile
(
resource
);
const
backupResource
=
this
.
getBackupPath
(
resource
);
console
.
log
(
`Backing up to
${
backupResource
.
fsPath
}
`
);
return
this
.
updateContent
(
backupResource
,
content
);
...
...
src/vs/workbench/services/untitled/common/untitledEditorService.ts
浏览文件 @
4928801c
...
...
@@ -6,6 +6,7 @@
import
URI
from
'
vs/base/common/uri
'
;
import
{
createDecorator
,
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IBackupService
}
from
'
vs/platform/backup/common/backup
'
;
import
arrays
=
require
(
'
vs/base/common/arrays
'
);
import
{
UntitledEditorInput
}
from
'
vs/workbench/common/editor/untitledEditorInput
'
;
import
Event
,
{
Emitter
,
once
}
from
'
vs/base/common/event
'
;
...
...
@@ -58,7 +59,7 @@ export interface IUntitledEditorService {
* It is valid to pass in a file resource. In that case the path will be used as identifier.
* The use case is to be able to create a new file with a specific path with VSCode.
*/
createOrGet
(
resource
?:
URI
,
modeId
?:
string
):
UntitledEditorInput
;
createOrGet
(
resource
?:
URI
,
modeId
?:
string
,
restoreResource
?:
URI
):
UntitledEditorInput
;
/**
* A check to find out if a untitled resource has a file path associated or not.
...
...
@@ -76,7 +77,10 @@ export class UntitledEditorService implements IUntitledEditorService {
private
_onDidChangeDirty
:
Emitter
<
URI
>
;
private
_onDidChangeEncoding
:
Emitter
<
URI
>
;
constructor
(
@
IInstantiationService
private
instantiationService
:
IInstantiationService
)
{
constructor
(
@
IBackupService
private
backupService
:
IBackupService
,
@
IInstantiationService
private
instantiationService
:
IInstantiationService
)
{
this
.
_onDidChangeDirty
=
new
Emitter
<
URI
>
();
this
.
_onDidChangeEncoding
=
new
Emitter
<
URI
>
();
}
...
...
@@ -130,7 +134,7 @@ export class UntitledEditorService implements IUntitledEditorService {
.
map
((
i
)
=>
i
.
getResource
());
}
public
createOrGet
(
resource
?:
URI
,
modeId
?:
string
):
UntitledEditorInput
{
public
createOrGet
(
resource
?:
URI
,
modeId
?:
string
,
restoreResource
?:
URI
):
UntitledEditorInput
{
let
hasAssociatedFilePath
=
false
;
if
(
resource
)
{
hasAssociatedFilePath
=
(
resource
.
scheme
===
'
file
'
);
...
...
@@ -147,10 +151,10 @@ export class UntitledEditorService implements IUntitledEditorService {
}
// Create new otherwise
return
this
.
doCreate
(
resource
,
hasAssociatedFilePath
,
modeId
);
return
this
.
doCreate
(
resource
,
hasAssociatedFilePath
,
modeId
,
restoreResource
);
}
private
doCreate
(
resource
?:
URI
,
hasAssociatedFilePath
?:
boolean
,
modeId
?:
string
):
UntitledEditorInput
{
private
doCreate
(
resource
?:
URI
,
hasAssociatedFilePath
?:
boolean
,
modeId
?:
string
,
restoreResource
?:
URI
):
UntitledEditorInput
{
if
(
!
resource
)
{
// Create new taking a resource URI that is not already taken
...
...
@@ -162,6 +166,9 @@ export class UntitledEditorService implements IUntitledEditorService {
}
const
input
=
this
.
instantiationService
.
createInstance
(
UntitledEditorInput
,
resource
,
hasAssociatedFilePath
,
modeId
);
if
(
restoreResource
)
{
input
.
setRestoreResource
(
restoreResource
);
}
const
dirtyListener
=
input
.
onDidChangeDirty
(()
=>
{
this
.
_onDidChangeDirty
.
fire
(
resource
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录