Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
540a57ef
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,发现更多精彩内容 >>
提交
540a57ef
编写于
5月 12, 2018
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
grid - adopt IOpenEditorEvent
上级
d3082d70
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
90 addition
and
86 deletion
+90
-86
src/vs/platform/editor/common/editor.ts
src/vs/platform/editor/common/editor.ts
+0
-11
src/vs/workbench/browser/parts/editor/editorPart.ts
src/vs/workbench/browser/parts/editor/editorPart.ts
+2
-2
src/vs/workbench/browser/parts/editor2/nextEditorGroupView.ts
...vs/workbench/browser/parts/editor2/nextEditorGroupView.ts
+2
-2
src/vs/workbench/common/editor.ts
src/vs/workbench/common/editor.ts
+25
-14
src/vs/workbench/parts/files/electron-browser/fileActions.ts
src/vs/workbench/parts/files/electron-browser/fileActions.ts
+2
-2
src/vs/workbench/parts/preferences/common/preferencesContribution.ts
...bench/parts/preferences/common/preferencesContribution.ts
+5
-7
src/vs/workbench/services/editor/browser/nextEditorService.ts
...vs/workbench/services/editor/browser/nextEditorService.ts
+15
-10
src/vs/workbench/services/editor/common/nextEditorService.ts
src/vs/workbench/services/editor/common/nextEditorService.ts
+7
-6
src/vs/workbench/services/group/common/nextEditorGroupsService.ts
...orkbench/services/group/common/nextEditorGroupsService.ts
+2
-2
src/vs/workbench/services/preferences/browser/preferencesService.ts
...kbench/services/preferences/browser/preferencesService.ts
+25
-26
src/vs/workbench/services/preferences/common/preferences.ts
src/vs/workbench/services/preferences/common/preferences.ts
+5
-4
未找到文件。
src/vs/platform/editor/common/editor.ts
浏览文件 @
540a57ef
...
...
@@ -22,17 +22,6 @@ export interface IEditorService {
openEditor
(
input
:
IResourceInput
,
sideBySide
?:
boolean
):
TPromise
<
IEditor
>
;
}
export
interface
IEditorInputWithOptions
{
editor
:
IEditorInput
;
options
?:
IEditorOptions
;
}
export
function
isEditorInputWithOptions
(
obj
:
any
):
obj
is
IEditorInputWithOptions
{
const
editorInputWithOptions
=
obj
as
IEditorInputWithOptions
;
return
!!
editorInputWithOptions
&&
!!
editorInputWithOptions
.
editor
;
}
export
interface
IEditorModel
{
onDispose
:
Event
<
void
>
;
...
...
src/vs/workbench/browser/parts/editor/editorPart.ts
浏览文件 @
540a57ef
...
...
@@ -947,11 +947,11 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService
}
// Editor opening event (can be prevented and overridden)
const
event
=
new
EditorOpeningEvent
(
input
,
options
,
position
);
const
event
=
new
EditorOpeningEvent
(
null
,
input
,
options
);
this
.
_onEditorOpening
.
fire
(
event
);
const
prevented
=
event
.
isPrevented
();
if
(
prevented
)
{
return
prevented
();
return
prevented
()
as
any
;
}
// Open through UI
...
...
src/vs/workbench/browser/parts/editor2/nextEditorGroupView.ts
浏览文件 @
540a57ef
...
...
@@ -582,11 +582,11 @@ export class NextEditorGroupView extends Themable implements INextEditorGroupVie
openEditor
(
editor
:
EditorInput
,
options
?:
EditorOptions
):
Thenable
<
void
>
{
// Editor opening event allows for prevention
const
event
=
new
EditorOpeningEvent
(
editor
,
options
,
this
.
_group
.
id
);
// TODO@grid position => group ID
const
event
=
new
EditorOpeningEvent
(
this
,
editor
,
options
);
this
.
_onWillOpenEditor
.
fire
(
event
);
const
prevented
=
event
.
isPrevented
();
if
(
prevented
)
{
return
prevented
()
.
then
(()
=>
void
0
);
// TODO@grid do we need the BaseEditor return type still in the event?
return
prevented
()
;
}
// Proceed with opening
...
...
src/vs/workbench/common/editor.ts
浏览文件 @
540a57ef
...
...
@@ -11,7 +11,7 @@ import * as types from 'vs/base/common/types';
import
URI
from
'
vs/base/common/uri
'
;
import
{
IDisposable
,
dispose
,
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
IEditor
,
IEditorViewState
,
ScrollType
}
from
'
vs/editor/common/editorCommon
'
;
import
{
IEditorInput
,
IEditorModel
,
IEditorOptions
,
ITextEditorOptions
,
IBaseResourceInput
,
Position
,
Verbosity
,
I
Editor
as
IBaseEditor
,
I
RevertOptions
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IEditorInput
,
IEditorModel
,
IEditorOptions
,
ITextEditorOptions
,
IBaseResourceInput
,
Position
,
Verbosity
,
IRevertOptions
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IInstantiationService
,
IConstructorSignature0
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
RawContextKey
,
ContextKeyExpr
}
from
'
vs/platform/contextkey/common/contextkey
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
...
...
@@ -274,9 +274,9 @@ export abstract class EditorInput implements IEditorInput {
}
export
interface
IEditorOpeningEvent
{
input
:
IEditorInput
;
editor
:
IEditorInput
;
options
?:
IEditorOptions
;
position
:
Position
;
group
:
INextEditorGroup
;
/**
* Allows to prevent the opening of an editor by providing a callback
...
...
@@ -285,32 +285,32 @@ export interface IEditorOpeningEvent {
* to return a promise that resolves to NULL to prevent the opening
* altogether.
*/
prevent
(
callback
:
()
=>
T
Promise
<
IBaseEditor
>
):
void
;
prevent
(
callback
:
()
=>
T
henable
<
any
>
):
void
;
}
export
class
EditorOpeningEvent
implements
IEditorOpeningEvent
{
private
override
:
()
=>
T
Promise
<
IBaseEditor
>
;
private
override
:
()
=>
T
henable
<
any
>
;
constructor
(
private
_
input
:
IEditorInput
,
private
_options
:
IEditorOptions
,
private
_position
:
Position
)
{
constructor
(
private
_
group
:
INextEditorGroup
,
private
_editor
:
IEditorInput
,
private
_options
:
IEditorOptions
)
{
}
public
get
input
():
IEditorInput
{
return
this
.
_
input
;
public
get
group
():
INextEditorGroup
{
return
this
.
_
group
;
}
public
get
options
():
IEditorOptions
{
return
this
.
_
options
;
public
get
editor
():
IEditorInput
{
return
this
.
_
editor
;
}
public
get
position
():
Position
{
return
this
.
_
position
;
public
get
options
():
IEditorOptions
{
return
this
.
_
options
;
}
public
prevent
(
callback
:
()
=>
T
Promise
<
IBaseEditor
>
):
void
{
public
prevent
(
callback
:
()
=>
T
henable
<
any
>
):
void
{
this
.
override
=
callback
;
}
public
isPrevented
():
()
=>
T
Promise
<
IBaseEditor
>
{
public
isPrevented
():
()
=>
T
henable
<
any
>
{
return
this
.
override
;
}
}
...
...
@@ -519,6 +519,17 @@ export class EditorModel extends Disposable implements IEditorModel {
}
}
export
interface
IEditorInputWithOptions
{
editor
:
IEditorInput
;
options
?:
IEditorOptions
;
}
export
function
isEditorInputWithOptions
(
obj
:
any
):
obj
is
IEditorInputWithOptions
{
const
editorInputWithOptions
=
obj
as
IEditorInputWithOptions
;
return
!!
editorInputWithOptions
&&
!!
editorInputWithOptions
.
editor
;
}
/**
* The editor options is the base class of options that can be passed in when opening an editor.
*/
...
...
src/vs/workbench/parts/files/electron-browser/fileActions.ts
浏览文件 @
540a57ef
...
...
@@ -1104,13 +1104,13 @@ export class GlobalCompareResourcesAction extends Action {
// Compare with next editor that opens
const
unbind
=
once
(
this
.
editorGroupService
.
onEditorOpening
)(
e
=>
{
const
resource
=
e
.
input
.
getResource
();
const
resource
=
e
.
editor
.
getResource
();
if
(
resource
)
{
e
.
prevent
(()
=>
{
return
this
.
editorService
.
openEditor
({
leftResource
:
activeResource
,
rightResource
:
resource
});
})
.
then
(()
=>
void
0
)
;
});
}
});
...
...
src/vs/workbench/parts/preferences/common/preferencesContribution.ts
浏览文件 @
540a57ef
...
...
@@ -60,7 +60,7 @@ export class PreferencesContribution implements IWorkbenchContribution {
}
private
onEditorOpening
(
event
:
IEditorOpeningEvent
):
void
{
const
resource
=
event
.
input
.
getResource
();
const
resource
=
event
.
editor
.
getResource
();
if
(
!
resource
||
resource
.
scheme
!==
'
file
'
||
// require a file path opening
!
endsWith
(
resource
.
fsPath
,
'
settings.json
'
)
||
// file must end in settings.json
...
...
@@ -72,15 +72,13 @@ export class PreferencesContribution implements IWorkbenchContribution {
// If the file resource was already opened before in the group, do not prevent
// the opening of that resource. Otherwise we would have the same settings
// opened twice (https://github.com/Microsoft/vscode/issues/36447)
const
stacks
=
this
.
editorGroupService
.
getStacksModel
();
const
group
=
stacks
.
groupAt
(
event
.
position
);
if
(
group
&&
group
.
contains
(
event
.
input
))
{
if
(
event
.
group
.
isOpened
(
event
.
editor
))
{
return
;
}
// Global User Settings File
if
(
resource
.
fsPath
===
this
.
environmentService
.
appSettingsPath
)
{
return
event
.
prevent
(()
=>
this
.
preferencesService
.
openGlobalSettings
(
event
.
options
,
event
.
position
));
return
event
.
prevent
(()
=>
this
.
preferencesService
.
openGlobalSettings
(
event
.
options
,
event
.
group
));
}
// Single Folder Workspace Settings File
...
...
@@ -88,7 +86,7 @@ export class PreferencesContribution implements IWorkbenchContribution {
if
(
state
===
WorkbenchState
.
FOLDER
)
{
const
folders
=
this
.
workspaceService
.
getWorkspace
().
folders
;
if
(
resource
.
fsPath
===
folders
[
0
].
toResource
(
FOLDER_SETTINGS_PATH
).
fsPath
)
{
return
event
.
prevent
(()
=>
this
.
preferencesService
.
openWorkspaceSettings
(
event
.
options
,
event
.
position
));
return
event
.
prevent
(()
=>
this
.
preferencesService
.
openWorkspaceSettings
(
event
.
options
,
event
.
group
));
}
}
...
...
@@ -97,7 +95,7 @@ export class PreferencesContribution implements IWorkbenchContribution {
const
folders
=
this
.
workspaceService
.
getWorkspace
().
folders
;
for
(
let
i
=
0
;
i
<
folders
.
length
;
i
++
)
{
if
(
resource
.
fsPath
===
folders
[
i
].
toResource
(
FOLDER_SETTINGS_PATH
).
fsPath
)
{
return
event
.
prevent
(()
=>
this
.
preferencesService
.
openFolderSettings
(
folders
[
i
].
uri
,
event
.
options
,
event
.
position
));
return
event
.
prevent
(()
=>
this
.
preferencesService
.
openFolderSettings
(
folders
[
i
].
uri
,
event
.
options
,
event
.
group
));
}
}
}
...
...
src/vs/workbench/services/editor/browser/nextEditorService.ts
浏览文件 @
540a57ef
...
...
@@ -6,8 +6,8 @@
'
use strict
'
;
import
{
IInstantiationService
,
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IEditorInput
,
IResourceInput
,
IUntitledResourceInput
,
IResourceDiffInput
,
IResourceSideBySideInput
,
IEditor
,
ITextEditorOptions
,
IEditorOptions
,
IEditorInputWithOptions
,
isEditorInputWithOptions
}
from
'
vs/platform/editor/common/editor
'
;
import
{
GroupIdentifier
,
IFileEditorInput
,
IEditorInputFactoryRegistry
,
Extensions
as
EditorExtensions
,
IFileInputFactory
,
EditorInput
,
SideBySideEditorInput
,
EditorOptions
,
TextEditorOptions
,
IEditorOpeningEvent
}
from
'
vs/workbench/common/editor
'
;
import
{
IEditorInput
,
IResourceInput
,
IUntitledResourceInput
,
IResourceDiffInput
,
IResourceSideBySideInput
,
IEditor
,
ITextEditorOptions
,
IEditorOptions
}
from
'
vs/platform/editor/common/editor
'
;
import
{
GroupIdentifier
,
IFileEditorInput
,
IEditorInputFactoryRegistry
,
Extensions
as
EditorExtensions
,
IFileInputFactory
,
EditorInput
,
SideBySideEditorInput
,
IEditorInputWithOptions
,
isEditorInputWithOptions
,
EditorOptions
,
TextEditorOptions
,
IEditorOpeningEvent
}
from
'
vs/workbench/common/editor
'
;
import
{
ResourceEditorInput
}
from
'
vs/workbench/common/editor/resourceEditorInput
'
;
import
{
DataUriEditorInput
}
from
'
vs/workbench/common/editor/dataUriEditorInput
'
;
import
{
Registry
}
from
'
vs/platform/registry/common/platform
'
;
...
...
@@ -163,9 +163,9 @@ export class NextEditorService extends Disposable implements INextEditorService
//#region openEditor()
openEditor
(
editor
:
IEditorInput
,
options
?:
IEditorOptions
,
group
?:
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
>
;
openEditor
(
editor
:
IResourceEditor
,
group
?:
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
>
;
openEditor
(
editor
:
IEditorInput
|
IResourceEditor
,
optionsOrGroup
?:
IEditorOptions
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
,
group
?:
GroupIdentifier
):
Thenable
<
IEditor
>
{
openEditor
(
editor
:
IEditorInput
,
options
?:
IEditorOptions
,
group
?:
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
>
;
openEditor
(
editor
:
IResourceEditor
,
group
?:
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
>
;
openEditor
(
editor
:
IEditorInput
|
IResourceEditor
,
optionsOrGroup
?:
IEditorOptions
|
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
,
group
?:
GroupIdentifier
):
Thenable
<
IEditor
>
{
// Typed Editor Support
if
(
editor
instanceof
EditorInput
)
{
...
...
@@ -189,7 +189,7 @@ export class NextEditorService extends Disposable implements INextEditorService
const
typedInput
=
this
.
createInput
(
textInput
);
if
(
typedInput
)
{
const
editorOptions
=
TextEditorOptions
.
from
(
textInput
);
const
targetGroup
=
this
.
findTargetGroup
(
typedInput
,
editorOptions
,
optionsOrGroup
as
GroupIdentifier
);
const
targetGroup
=
this
.
findTargetGroup
(
typedInput
,
editorOptions
,
optionsOrGroup
as
INextEditorGroup
|
GroupIdentifier
);
return
targetGroup
.
openEditor
(
typedInput
,
editorOptions
).
then
(()
=>
targetGroup
.
activeControl
);
}
...
...
@@ -197,9 +197,14 @@ export class NextEditorService extends Disposable implements INextEditorService
return
TPromise
.
wrap
<
IEditor
>
(
null
);
}
private
findTargetGroup
(
input
:
IEditorInput
,
options
?:
IEditorOptions
,
group
?:
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
INextEditorGroup
{
private
findTargetGroup
(
input
:
IEditorInput
,
options
?:
IEditorOptions
,
group
?:
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
INextEditorGroup
{
let
targetGroup
:
INextEditorGroup
;
// Group: Instance of Group
if
(
group
&&
typeof
group
!==
'
number
'
)
{
return
group
;
}
// Group: Active Group
if
(
group
===
ACTIVE_GROUP
)
{
targetGroup
=
this
.
nextEditorGroupsService
.
activeGroup
;
...
...
@@ -271,9 +276,9 @@ export class NextEditorService extends Disposable implements INextEditorService
//#region openEditors()
openEditors
(
editors
:
IEditorInputWithOptions
[],
group
?:
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
[]
>
;
openEditors
(
editors
:
IResourceEditor
[],
group
?:
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
[]
>
;
openEditors
(
editors
:
(
IEditorInputWithOptions
|
IResourceEditor
)[],
group
?:
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
[]
>
{
openEditors
(
editors
:
IEditorInputWithOptions
[],
group
?:
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
[]
>
;
openEditors
(
editors
:
IResourceEditor
[],
group
?:
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
[]
>
;
openEditors
(
editors
:
(
IEditorInputWithOptions
|
IResourceEditor
)[],
group
?:
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
[]
>
{
// Convert to typed editors and options
const
typedEditors
:
IEditorInputWithOptions
[]
=
[];
...
...
src/vs/workbench/services/editor/common/nextEditorService.ts
浏览文件 @
540a57ef
...
...
@@ -6,10 +6,11 @@
'
use strict
'
;
import
{
createDecorator
,
ServiceIdentifier
,
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IEditorInput
,
IResourceInput
,
IUntitledResourceInput
,
IResourceDiffInput
,
IResourceSideBySideInput
,
IEditor
,
IEditorOptions
,
IEditorInputWithOptions
}
from
'
vs/platform/editor/common/editor
'
;
import
{
GroupIdentifier
,
IEditorOpeningEvent
}
from
'
vs/workbench/common/editor
'
;
import
{
IEditorInput
,
IResourceInput
,
IUntitledResourceInput
,
IResourceDiffInput
,
IResourceSideBySideInput
,
IEditor
,
IEditorOptions
}
from
'
vs/platform/editor/common/editor
'
;
import
{
GroupIdentifier
,
IEditorOpeningEvent
,
IEditorInputWithOptions
}
from
'
vs/workbench/common/editor
'
;
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
IEditor
as
ICodeEditor
}
from
'
vs/editor/common/editorCommon
'
;
import
{
INextEditorGroup
}
from
'
vs/workbench/services/group/common/nextEditorGroupsService
'
;
export
const
INextEditorService
=
createDecorator
<
INextEditorService
>
(
'
nextEditorService
'
);
...
...
@@ -90,7 +91,7 @@ export interface INextEditorService {
* active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side
* of the currently active group.
*/
openEditor
(
editor
:
IEditorInput
,
options
?:
IEditorOptions
,
group
?:
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
>
;
openEditor
(
editor
:
IEditorInput
,
options
?:
IEditorOptions
,
group
?:
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
>
;
/**
* Open an editor in an editor group.
...
...
@@ -100,7 +101,7 @@ export interface INextEditorService {
* active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side
* of the currently active group.
*/
openEditor
(
editor
:
IResourceEditor
,
group
?:
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
>
;
openEditor
(
editor
:
IResourceEditor
,
group
?:
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
IEditor
>
;
/**
* Open editors in an editor group.
...
...
@@ -110,8 +111,8 @@ export interface INextEditorService {
* active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side
* of the currently active group.
*/
openEditors
(
editors
:
IEditorInputWithOptions
[],
group
?:
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
ReadonlyArray
<
IEditor
>>
;
openEditors
(
editors
:
IResourceEditor
[],
group
?:
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
ReadonlyArray
<
IEditor
>>
;
openEditors
(
editors
:
IEditorInputWithOptions
[],
group
?:
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
ReadonlyArray
<
IEditor
>>
;
openEditors
(
editors
:
IResourceEditor
[],
group
?:
INextEditorGroup
|
GroupIdentifier
|
SIDE_GROUP_TYPE
|
ACTIVE_GROUP_TYPE
):
Thenable
<
ReadonlyArray
<
IEditor
>>
;
/**
* Find out if the provided editor (or resource of an editor) is opened in any group.
...
...
src/vs/workbench/services/group/common/nextEditorGroupsService.ts
浏览文件 @
540a57ef
...
...
@@ -7,8 +7,8 @@
import
{
Event
}
from
'
vs/base/common/event
'
;
import
{
createDecorator
,
ServiceIdentifier
,
ServicesAccessor
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
GroupIdentifier
,
IEditorOpeningEvent
}
from
'
vs/workbench/common/editor
'
;
import
{
IEditorInput
,
IEditor
,
IEditorOptions
,
IEditorInputWithOptions
,
Direction
}
from
'
vs/platform/editor/common/editor
'
;
import
{
GroupIdentifier
,
IEditorOpeningEvent
,
IEditorInputWithOptions
}
from
'
vs/workbench/common/editor
'
;
import
{
IEditorInput
,
IEditor
,
IEditorOptions
,
Direction
}
from
'
vs/platform/editor/common/editor
'
;
export
const
INextEditorGroupsService
=
createDecorator
<
INextEditorGroupsService
>
(
'
nextEditorGroupsService
'
);
...
...
src/vs/workbench/services/preferences/browser/preferencesService.ts
浏览文件 @
540a57ef
...
...
@@ -39,6 +39,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import
{
INotificationService
}
from
'
vs/platform/notification/common/notification
'
;
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
{
INextEditorService
}
from
'
vs/workbench/services/editor/common/nextEditorService
'
;
import
{
INextEditorGroup
,
INextEditorGroupsService
}
from
'
vs/workbench/services/group/common/nextEditorGroupsService
'
;
const
emptyEditableSettingsContent
=
'
{
\n
}
'
;
...
...
@@ -61,6 +62,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic
@
IWorkbenchEditorService
private
editorService
:
IWorkbenchEditorService
,
@
INextEditorService
private
nextEditorService
:
INextEditorService
,
@
IEditorGroupService
private
editorGroupService
:
IEditorGroupService
,
@
INextEditorGroupsService
private
nextEditorGroupService
:
INextEditorGroupsService
,
@
IFileService
private
fileService
:
IFileService
,
@
IWorkspaceConfigurationService
private
configurationService
:
IWorkspaceConfigurationService
,
@
INotificationService
private
notificationService
:
INotificationService
,
...
...
@@ -181,30 +183,30 @@ export class PreferencesService extends Disposable implements IPreferencesServic
return
this
.
openOrSwitchSettings
(
target
,
resource
);
}
openGlobalSettings
(
options
?:
IEditorOptions
,
position
?:
EditorPosition
):
TPromise
<
IEditor
>
{
return
this
.
openOrSwitchSettings
(
ConfigurationTarget
.
USER
,
this
.
userSettingsResource
,
options
,
position
);
openGlobalSettings
(
options
?:
IEditorOptions
,
group
?:
INextEditorGroup
):
TPromise
<
IEditor
>
{
return
this
.
openOrSwitchSettings
(
ConfigurationTarget
.
USER
,
this
.
userSettingsResource
,
options
,
group
);
}
openSettings2
():
TPromise
<
IEditor
>
{
return
this
.
editorService
.
openEditor
(
this
.
instantiationService
.
createInstance
(
SettingsEditor2Input
),
{
pinned
:
true
}).
then
(()
=>
null
);
}
openWorkspaceSettings
(
options
?:
IEditorOptions
,
position
?:
EditorPosition
):
TPromise
<
IEditor
>
{
openWorkspaceSettings
(
options
?:
IEditorOptions
,
group
?:
INextEditorGroup
):
TPromise
<
IEditor
>
{
if
(
this
.
contextService
.
getWorkbenchState
()
===
WorkbenchState
.
EMPTY
)
{
this
.
notificationService
.
info
(
nls
.
localize
(
'
openFolderFirst
'
,
"
Open a folder first to create workspace settings
"
));
return
TPromise
.
as
(
null
);
}
return
this
.
openOrSwitchSettings
(
ConfigurationTarget
.
WORKSPACE
,
this
.
workspaceSettingsResource
,
options
,
position
);
return
this
.
openOrSwitchSettings
(
ConfigurationTarget
.
WORKSPACE
,
this
.
workspaceSettingsResource
,
options
,
group
);
}
openFolderSettings
(
folder
:
URI
,
options
?:
IEditorOptions
,
position
?:
EditorPosition
):
TPromise
<
IEditor
>
{
return
this
.
openOrSwitchSettings
(
ConfigurationTarget
.
WORKSPACE_FOLDER
,
this
.
getEditableSettingsURI
(
ConfigurationTarget
.
WORKSPACE_FOLDER
,
folder
),
options
,
position
);
openFolderSettings
(
folder
:
URI
,
options
?:
IEditorOptions
,
group
?:
INextEditorGroup
):
TPromise
<
IEditor
>
{
return
this
.
openOrSwitchSettings
(
ConfigurationTarget
.
WORKSPACE_FOLDER
,
this
.
getEditableSettingsURI
(
ConfigurationTarget
.
WORKSPACE_FOLDER
,
folder
),
options
,
group
);
}
switchSettings
(
target
:
ConfigurationTarget
,
resource
:
URI
):
TPromise
<
void
>
{
const
activeEditor
=
this
.
editorService
.
getActiveEditor
();
if
(
activeEditor
&&
activeEditor
.
input
instanceof
PreferencesEditorInput
)
{
return
this
.
doSwitchSettings
(
target
,
resource
,
activeEditor
.
input
,
activeEditor
.
position
).
then
(()
=>
null
);
return
this
.
doSwitchSettings
(
target
,
resource
,
activeEditor
.
input
,
null
).
then
(()
=>
null
);
}
else
{
return
this
.
doOpenSettings
(
target
,
resource
).
then
(()
=>
null
);
}
...
...
@@ -247,17 +249,15 @@ export class PreferencesService extends Disposable implements IPreferencesServic
});
}
private
openOrSwitchSettings
(
configurationTarget
:
ConfigurationTarget
,
resource
:
URI
,
options
?:
IEditorOptions
,
position
?:
EditorPosition
):
TPromise
<
IEditor
>
{
const
activeGroup
=
this
.
editorGroupService
.
getStacksModel
().
activeGroup
;
const
positionToReplace
=
position
!==
void
0
?
position
:
activeGroup
?
this
.
editorGroupService
.
getStacksModel
().
positionOfGroup
(
activeGroup
)
:
EditorPosition
.
ONE
;
const
editorInput
=
this
.
getActiveSettingsEditorInput
(
positionToReplace
);
private
openOrSwitchSettings
(
configurationTarget
:
ConfigurationTarget
,
resource
:
URI
,
options
?:
IEditorOptions
,
group
:
INextEditorGroup
=
this
.
nextEditorGroupService
.
activeGroup
):
TPromise
<
IEditor
>
{
const
editorInput
=
this
.
getActiveSettingsEditorInput
(
group
);
if
(
editorInput
&&
editorInput
.
master
.
getResource
().
fsPath
!==
resource
.
fsPath
)
{
return
this
.
doSwitchSettings
(
configurationTarget
,
resource
,
editorInput
,
positionToReplace
);
return
this
.
doSwitchSettings
(
configurationTarget
,
resource
,
editorInput
,
group
);
}
return
this
.
doOpenSettings
(
configurationTarget
,
resource
,
options
,
position
);
return
this
.
doOpenSettings
(
configurationTarget
,
resource
,
options
,
group
);
}
private
doOpenSettings
(
configurationTarget
:
ConfigurationTarget
,
resource
:
URI
,
options
?:
IEditorOptions
,
position
?:
EditorPosition
):
TPromise
<
IEditor
>
{
private
doOpenSettings
(
configurationTarget
:
ConfigurationTarget
,
resource
:
URI
,
options
?:
IEditorOptions
,
group
?:
INextEditorGroup
):
TPromise
<
IEditor
>
{
const
openDefaultSettings
=
!!
this
.
configurationService
.
getValue
(
DEFAULT_SETTINGS_EDITOR_SETTING
);
return
this
.
getOrCreateEditableSettingsEditorInput
(
configurationTarget
,
resource
)
.
then
(
editableSettingsEditorInput
=>
{
...
...
@@ -271,30 +271,29 @@ export class PreferencesService extends Disposable implements IPreferencesServic
const
defaultPreferencesEditorInput
=
this
.
instantiationService
.
createInstance
(
DefaultPreferencesEditorInput
,
this
.
getDefaultSettingsResource
(
configurationTarget
));
const
preferencesEditorInput
=
new
PreferencesEditorInput
(
this
.
getPreferencesEditorInputName
(
configurationTarget
,
resource
),
editableSettingsEditorInput
.
getDescription
(),
defaultPreferencesEditorInput
,
<
EditorInput
>
editableSettingsEditorInput
);
this
.
lastOpenedSettingsInput
=
preferencesEditorInput
;
return
this
.
nextEditorService
.
openEditor
(
preferencesEditorInput
,
options
/*, TODO@grid position */
);
return
this
.
nextEditorService
.
openEditor
(
preferencesEditorInput
,
options
,
group
);
}
return
this
.
nextEditorService
.
openEditor
(
editableSettingsEditorInput
,
options
/*, TODO@grid position */
);
return
this
.
nextEditorService
.
openEditor
(
editableSettingsEditorInput
,
options
,
group
);
});
}
private
doSwitchSettings
(
target
:
ConfigurationTarget
,
resource
:
URI
,
input
:
PreferencesEditorInput
,
position
?:
EditorPosition
):
TPromise
<
IEditor
>
{
private
doSwitchSettings
(
target
:
ConfigurationTarget
,
resource
:
URI
,
input
:
PreferencesEditorInput
,
group
:
INextEditorGroup
):
TPromise
<
IEditor
>
{
return
this
.
getOrCreateEditableSettingsEditorInput
(
target
,
this
.
getEditableSettingsURI
(
target
,
resource
))
.
then
(
toInput
=>
{
const
replaceWith
=
new
PreferencesEditorInput
(
this
.
getPreferencesEditorInputName
(
target
,
resource
),
toInput
.
getDescription
(),
this
.
instantiationService
.
createInstance
(
DefaultPreferencesEditorInput
,
this
.
getDefaultSettingsResource
(
target
)),
toInput
);
return
this
.
editorService
.
replaceEditors
([{
toReplace
:
input
,
replaceWith
}],
position
).
then
(
editors
=>
{
return
group
.
replaceEditors
([{
editor
:
input
,
replacement
:
replaceWith
}]).
then
(()
=>
{
this
.
lastOpenedSettingsInput
=
replaceWith
;
return
editors
[
0
]
;
return
group
.
activeControl
;
});
});
}
private
getActiveSettingsEditorInput
(
position
?:
EditorPosition
):
PreferencesEditorInput
{
const
stacksModel
=
this
.
editorGroupService
.
getStacksModel
();
const
group
=
position
!==
void
0
?
stacksModel
.
groupAt
(
position
)
:
stacksModel
.
activeGroup
;
return
group
&&
<
PreferencesEditorInput
>
group
.
getEditors
().
filter
(
e
=>
e
instanceof
PreferencesEditorInput
)[
0
];
private
getActiveSettingsEditorInput
(
group
:
INextEditorGroup
=
this
.
nextEditorGroupService
.
activeGroup
):
PreferencesEditorInput
{
return
<
PreferencesEditorInput
>
group
.
editors
.
filter
(
e
=>
e
instanceof
PreferencesEditorInput
)[
0
];
}
private
getConfigurationTargetFromSettingsResource
(
resource
:
URI
):
ConfigurationTarget
{
...
...
src/vs/workbench/services/preferences/common/preferences.ts
浏览文件 @
540a57ef
...
...
@@ -6,7 +6,7 @@
import
URI
from
'
vs/base/common/uri
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
createDecorator
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
{
IEditor
,
Position
,
IEditorOptions
}
from
'
vs/platform/editor/common/editor
'
;
import
{
IEditor
,
IEditorOptions
}
from
'
vs/platform/editor/common/editor
'
;
import
{
ITextModel
}
from
'
vs/editor/common/model
'
;
import
{
IRange
}
from
'
vs/editor/common/core/range
'
;
import
{
IWorkspaceContextService
}
from
'
vs/platform/workspace/common/workspace
'
;
...
...
@@ -16,6 +16,7 @@ import { Event } from 'vs/base/common/event';
import
{
IStringDictionary
}
from
'
vs/base/common/collections
'
;
import
{
ILocalExtension
}
from
'
vs/platform/extensionManagement/common/extensionManagement
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
INextEditorGroup
}
from
'
vs/workbench/services/group/common/nextEditorGroupsService
'
;
export
interface
ISettingsGroup
{
id
:
string
;
...
...
@@ -143,9 +144,9 @@ export interface IPreferencesService {
openRawDefaultSettings
():
TPromise
<
void
>
;
openSettings
():
TPromise
<
IEditor
>
;
openSettings2
():
TPromise
<
IEditor
>
;
openGlobalSettings
(
options
?:
IEditorOptions
,
position
?:
Position
):
TPromise
<
IEditor
>
;
openWorkspaceSettings
(
options
?:
IEditorOptions
,
position
?:
Position
):
TPromise
<
IEditor
>
;
openFolderSettings
(
folder
:
URI
,
options
?:
IEditorOptions
,
position
?:
Position
):
TPromise
<
IEditor
>
;
openGlobalSettings
(
options
?:
IEditorOptions
,
group
?:
INextEditorGroup
):
TPromise
<
IEditor
>
;
openWorkspaceSettings
(
options
?:
IEditorOptions
,
group
?:
INextEditorGroup
):
TPromise
<
IEditor
>
;
openFolderSettings
(
folder
:
URI
,
options
?:
IEditorOptions
,
group
?:
INextEditorGroup
):
TPromise
<
IEditor
>
;
switchSettings
(
target
:
ConfigurationTarget
,
resource
:
URI
):
TPromise
<
void
>
;
openGlobalKeybindingSettings
(
textual
:
boolean
):
TPromise
<
void
>
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录