Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
5b16b26e
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,发现更多精彩内容 >>
提交
5b16b26e
编写于
9月 13, 2016
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
less direct use of TextFileEditorModel
上级
a6b89e14
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
41 addition
and
34 deletion
+41
-34
src/vs/editor/browser/standalone/simpleServices.ts
src/vs/editor/browser/standalone/simpleServices.ts
+11
-3
src/vs/platform/editor/common/editor.ts
src/vs/platform/editor/common/editor.ts
+2
-0
src/vs/workbench/common/editor/untitledEditorInput.ts
src/vs/workbench/common/editor/untitledEditorInput.ts
+2
-2
src/vs/workbench/parts/files/browser/editors/textFileEditor.ts
...s/workbench/parts/files/browser/editors/textFileEditor.ts
+4
-10
src/vs/workbench/parts/files/common/editors/textFileEditorModelManager.ts
.../parts/files/common/editors/textFileEditorModelManager.ts
+7
-7
src/vs/workbench/parts/files/common/files.ts
src/vs/workbench/parts/files/common/files.ts
+4
-0
src/vs/workbench/parts/files/common/textFileService.ts
src/vs/workbench/parts/files/common/textFileService.ts
+11
-12
未找到文件。
src/vs/editor/browser/standalone/simpleServices.ts
浏览文件 @
5b16b26e
...
...
@@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
{
EventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
{
Schemas
}
from
'
vs/base/common/network
'
;
import
Severity
from
'
vs/base/common/severity
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
...
...
@@ -56,13 +55,18 @@ export class SimpleEditor implements IEditor {
}
}
export
class
SimpleModel
extends
EventEmitter
implements
ITextEditorModel
{
export
class
SimpleModel
implements
ITextEditorModel
{
private
model
:
editorCommon
.
IModel
;
private
_onDispose
:
Emitter
<
void
>
;
constructor
(
model
:
editorCommon
.
IModel
)
{
super
();
this
.
model
=
model
;
this
.
_onDispose
=
new
Emitter
<
void
>
();
}
public
get
onDispose
():
Event
<
void
>
{
return
this
.
_onDispose
.
event
;
}
public
load
():
TPromise
<
SimpleModel
>
{
...
...
@@ -72,6 +76,10 @@ export class SimpleModel extends EventEmitter implements ITextEditorModel {
public
get
textEditorModel
():
editorCommon
.
IModel
{
return
this
.
model
;
}
public
dispose
():
void
{
this
.
_onDispose
.
fire
();
}
}
export
interface
IOpenEditorDelegate
{
...
...
src/vs/platform/editor/common/editor.ts
浏览文件 @
5b16b26e
...
...
@@ -28,6 +28,8 @@ export interface IEditorService {
export
interface
IEditorModel
{
onDispose
:
Event
<
void
>
;
/**
* Loads the model.
*/
...
...
src/vs/workbench/common/editor/untitledEditorInput.ts
浏览文件 @
5b16b26e
...
...
@@ -9,7 +9,7 @@ import URI from 'vs/base/common/uri';
import
{
isUnspecific
,
guessMimeTypes
,
MIME_TEXT
,
suggestFilename
}
from
'
vs/base/common/mime
'
;
import
labels
=
require
(
'
vs/base/common/labels
'
);
import
paths
=
require
(
'
vs/base/common/paths
'
);
import
{
UntitledEditorInput
as
AbstractUntitledEditorInput
,
E
ditorModel
,
E
ncodingMode
,
ConfirmResult
}
from
'
vs/workbench/common/editor
'
;
import
{
UntitledEditorInput
as
AbstractUntitledEditorInput
,
EncodingMode
,
ConfirmResult
}
from
'
vs/workbench/common/editor
'
;
import
{
UntitledEditorModel
}
from
'
vs/workbench/common/editor/untitledEditorModel
'
;
import
{
IInstantiationService
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
ILifecycleService
}
from
'
vs/platform/lifecycle/common/lifecycle
'
;
...
...
@@ -131,7 +131,7 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput {
}
}
public
resolve
(
refresh
?:
boolean
):
TPromise
<
EditorModel
>
{
public
resolve
(
refresh
?:
boolean
):
TPromise
<
Untitled
EditorModel
>
{
// Use Cached Model
if
(
this
.
cachedModel
)
{
...
...
src/vs/workbench/parts/files/browser/editors/textFileEditor.ts
浏览文件 @
5b16b26e
...
...
@@ -15,10 +15,9 @@ import {IEditorViewState} from 'vs/editor/common/editorCommon';
import
{
Action
}
from
'
vs/base/common/actions
'
;
import
{
Scope
}
from
'
vs/workbench/common/memento
'
;
import
{
IEditorOptions
}
from
'
vs/editor/common/editorCommon
'
;
import
{
VIEWLET_ID
,
TEXT_FILE_EDITOR_ID
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
VIEWLET_ID
,
TEXT_FILE_EDITOR_ID
,
ITextFileEditorModel
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
BaseTextEditor
}
from
'
vs/workbench/browser/parts/editor/textEditor
'
;
import
{
EditorOptions
,
TextEditorOptions
,
EditorModel
}
from
'
vs/workbench/common/editor
'
;
import
{
TextFileEditorModel
}
from
'
vs/workbench/parts/files/common/editors/textFileEditorModel
'
;
import
{
EditorOptions
,
TextEditorOptions
}
from
'
vs/workbench/common/editor
'
;
import
{
BinaryEditorModel
}
from
'
vs/workbench/common/editor/binaryEditorModel
'
;
import
{
FileEditorInput
}
from
'
vs/workbench/parts/files/common/editors/fileEditorInput
'
;
import
{
ExplorerViewlet
}
from
'
vs/workbench/parts/files/browser/explorerViewlet
'
;
...
...
@@ -117,7 +116,7 @@ export class TextFileEditor extends BaseTextEditor {
}
// Different Input (Reload)
return
this
.
editorService
.
resolveEditorModel
(
input
,
true
/* Reload */
).
then
(
(
resolvedModel
:
EditorModel
)
=>
{
return
this
.
editorService
.
resolveEditorModel
(
input
,
true
/* Reload */
).
then
(
resolvedModel
=>
{
// There is a special case where the text editor has to handle binary file editor input: if a file with application/unknown
// mime has been resolved and cached before, it maybe an actual instance of BinaryEditorModel. In this case our text
...
...
@@ -126,13 +125,8 @@ export class TextFileEditor extends BaseTextEditor {
return
this
.
openAsBinary
(
input
,
options
);
}
// Assert Model interface
if
(
!
(
resolvedModel
instanceof
TextFileEditorModel
))
{
return
TPromise
.
wrapError
<
void
>
(
'
Invalid editor input. Text file editor requires a model instance of TextFileEditorModel.
'
);
}
// Check Model state
const
textFileModel
=
<
TextFileEditorModel
>
resolvedModel
;
const
textFileModel
=
<
I
TextFileEditorModel
>
resolvedModel
;
const
hasInput
=
!!
this
.
getInput
();
const
modelDisposed
=
textFileModel
.
isDisposed
();
...
...
src/vs/workbench/parts/files/common/editors/textFileEditorModelManager.ts
浏览文件 @
5b16b26e
...
...
@@ -32,8 +32,8 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager {
private
mapResourceToDisposeListener
:
{
[
resource
:
string
]:
IDisposable
;
};
private
mapResourceToStateChangeListener
:
{
[
resource
:
string
]:
IDisposable
;
};
private
mapResourceToModel
:
{
[
resource
:
string
]:
TextFileEditorModel
;
};
private
mapResourceToPendingModelLoaders
:
{
[
resource
:
string
]:
TPromise
<
TextFileEditorModel
>
};
private
mapResourceToModel
:
{
[
resource
:
string
]:
I
TextFileEditorModel
;
};
private
mapResourceToPendingModelLoaders
:
{
[
resource
:
string
]:
TPromise
<
I
TextFileEditorModel
>
};
constructor
(
@
ILifecycleService
private
lifecycleService
:
ILifecycleService
,
...
...
@@ -162,11 +162,11 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager {
return
this
.
_onModelEncodingChanged
.
event
;
}
public
get
(
resource
:
URI
):
TextFileEditorModel
{
public
get
(
resource
:
URI
):
I
TextFileEditorModel
{
return
this
.
mapResourceToModel
[
resource
.
toString
()];
}
public
loadOrCreate
(
resource
:
URI
,
encoding
:
string
,
refresh
?:
boolean
):
TPromise
<
TextFileEditorModel
>
{
public
loadOrCreate
(
resource
:
URI
,
encoding
:
string
,
refresh
?:
boolean
):
TPromise
<
I
TextFileEditorModel
>
{
// Return early if model is currently being loaded
const
pendingLoad
=
this
.
mapResourceToPendingModelLoaders
[
resource
.
toString
()];
...
...
@@ -174,7 +174,7 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager {
return
pendingLoad
;
}
let
modelPromise
:
TPromise
<
TextFileEditorModel
>
;
let
modelPromise
:
TPromise
<
I
TextFileEditorModel
>
;
// Model exists
let
model
=
this
.
get
(
resource
);
...
...
@@ -238,13 +238,13 @@ export class TextFileEditorModelManager implements ITextFileEditorModelManager {
});
}
public
getAll
(
resource
?:
URI
):
TextFileEditorModel
[]
{
public
getAll
(
resource
?:
URI
):
I
TextFileEditorModel
[]
{
return
Object
.
keys
(
this
.
mapResourceToModel
)
.
filter
(
r
=>
!
resource
||
resource
.
toString
()
===
r
)
.
map
(
r
=>
this
.
mapResourceToModel
[
r
]);
}
public
add
(
resource
:
URI
,
model
:
TextFileEditorModel
):
void
{
public
add
(
resource
:
URI
,
model
:
I
TextFileEditorModel
):
void
{
const
knownModel
=
this
.
mapResourceToModel
[
resource
.
toString
()];
if
(
knownModel
===
model
)
{
return
;
// already cached
...
...
src/vs/workbench/parts/files/common/files.ts
浏览文件 @
5b16b26e
...
...
@@ -274,6 +274,8 @@ export interface ITextFileEditorModelManager {
export
interface
ITextFileEditorModel
extends
ITextEditorModel
,
IEncodingSupport
{
onDidStateChange
:
Event
<
StateChange
>
;
getResource
():
URI
;
getLastSaveAttemptTime
():
number
;
...
...
@@ -282,6 +284,8 @@ export interface ITextFileEditorModel extends ITextEditorModel, IEncodingSupport
getState
():
ModelState
;
updatePreferredEncoding
(
encoding
:
string
):
void
;
save
(
overwriteReadonly
?:
boolean
,
overwriteEncoding
?:
boolean
):
TPromise
<
void
>
;
revert
():
TPromise
<
void
>
;
...
...
src/vs/workbench/parts/files/common/textFileService.ts
浏览文件 @
5b16b26e
...
...
@@ -9,8 +9,7 @@ import URI from 'vs/base/common/uri';
import
paths
=
require
(
'
vs/base/common/paths
'
);
import
errors
=
require
(
'
vs/base/common/errors
'
);
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
TextFileEditorModel
}
from
'
vs/workbench/parts/files/common/editors/textFileEditorModel
'
;
import
{
IResult
,
ITextFileOperationResult
,
ITextFileService
,
IRawTextContent
,
IAutoSaveConfiguration
,
AutoSaveMode
,
ITextFileEditorModelManager
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
IResult
,
ITextFileOperationResult
,
ITextFileService
,
IRawTextContent
,
IAutoSaveConfiguration
,
AutoSaveMode
,
ITextFileEditorModelManager
,
ITextFileEditorModel
}
from
'
vs/workbench/parts/files/common/files
'
;
import
{
ConfirmResult
}
from
'
vs/workbench/common/editor
'
;
import
{
ILifecycleService
}
from
'
vs/platform/lifecycle/common/lifecycle
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
...
...
@@ -329,11 +328,11 @@ export abstract class TextFileService implements ITextFileService {
});
}
private
getFileModels
(
resources
?:
URI
[]):
TextFileEditorModel
[];
private
getFileModels
(
resource
?:
URI
):
TextFileEditorModel
[];
private
getFileModels
(
arg1
?:
any
):
TextFileEditorModel
[]
{
private
getFileModels
(
resources
?:
URI
[]):
I
TextFileEditorModel
[];
private
getFileModels
(
resource
?:
URI
):
I
TextFileEditorModel
[];
private
getFileModels
(
arg1
?:
any
):
I
TextFileEditorModel
[]
{
if
(
Array
.
isArray
(
arg1
))
{
const
models
:
TextFileEditorModel
[]
=
[];
const
models
:
I
TextFileEditorModel
[]
=
[];
(
<
URI
[]
>
arg1
).
forEach
(
resource
=>
{
models
.
push
(...
this
.
getFileModels
(
resource
));
});
...
...
@@ -344,9 +343,9 @@ export abstract class TextFileService implements ITextFileService {
return
this
.
_models
.
getAll
(
<
URI
>
arg1
);
}
private
getDirtyFileModels
(
resources
?:
URI
[]):
TextFileEditorModel
[];
private
getDirtyFileModels
(
resource
?:
URI
):
TextFileEditorModel
[];
private
getDirtyFileModels
(
arg1
?:
any
):
TextFileEditorModel
[]
{
private
getDirtyFileModels
(
resources
?:
URI
[]):
I
TextFileEditorModel
[];
private
getDirtyFileModels
(
resource
?:
URI
):
I
TextFileEditorModel
[];
private
getDirtyFileModels
(
arg1
?:
any
):
I
TextFileEditorModel
[]
{
return
this
.
getFileModels
(
arg1
).
filter
(
model
=>
model
.
isDirty
());
}
...
...
@@ -381,7 +380,7 @@ export abstract class TextFileService implements ITextFileService {
private
doSaveAs
(
resource
:
URI
,
target
?:
URI
):
TPromise
<
URI
>
{
// Retrieve text model from provided resource if any
let
modelPromise
:
TPromise
<
TextFileEditorModel
|
UntitledEditorModel
>
=
TPromise
.
as
(
null
);
let
modelPromise
:
TPromise
<
I
TextFileEditorModel
|
UntitledEditorModel
>
=
TPromise
.
as
(
null
);
if
(
resource
.
scheme
===
'
file
'
)
{
modelPromise
=
TPromise
.
as
(
this
.
_models
.
get
(
resource
));
}
else
if
(
resource
.
scheme
===
'
untitled
'
)
{
...
...
@@ -411,11 +410,11 @@ export abstract class TextFileService implements ITextFileService {
});
}
private
doSaveTextFileAs
(
sourceModel
:
TextFileEditorModel
|
UntitledEditorModel
,
resource
:
URI
,
target
:
URI
):
TPromise
<
void
>
{
private
doSaveTextFileAs
(
sourceModel
:
I
TextFileEditorModel
|
UntitledEditorModel
,
resource
:
URI
,
target
:
URI
):
TPromise
<
void
>
{
// create the target file empty if it does not exist already
return
this
.
fileService
.
resolveFile
(
target
).
then
(
stat
=>
stat
,
()
=>
null
).
then
(
stat
=>
stat
||
this
.
fileService
.
createFile
(
target
)).
then
(
stat
=>
{
// resolve a model for the file (which can be binary if the file is not a text file)
return
this
.
editorService
.
resolveEditorModel
({
resource
:
target
}).
then
((
targetModel
:
TextFileEditorModel
)
=>
{
return
this
.
editorService
.
resolveEditorModel
({
resource
:
target
}).
then
((
targetModel
:
I
TextFileEditorModel
)
=>
{
// binary model: delete the file and run the operation again
if
(
targetModel
instanceof
BinaryEditorModel
)
{
return
this
.
fileService
.
del
(
target
).
then
(()
=>
this
.
doSaveTextFileAs
(
sourceModel
,
resource
,
target
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录