Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
124f4c71
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,体验更适合开发者的 AI 搜索 >>
提交
124f4c71
编写于
7月 10, 2017
作者:
B
Benjamin Pasero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make single-folder case more explicit (rename workspacePath => folderPath)
上级
6da138c8
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
166 addition
and
143 deletion
+166
-143
src/vs/code/electron-main/app.ts
src/vs/code/electron-main/app.ts
+3
-3
src/vs/code/electron-main/window.ts
src/vs/code/electron-main/window.ts
+4
-4
src/vs/code/electron-main/windows.ts
src/vs/code/electron-main/windows.ts
+88
-64
src/vs/code/node/windowsFinder.ts
src/vs/code/node/windowsFinder.ts
+7
-7
src/vs/code/test/node/windowsUtils.test.ts
src/vs/code/test/node/windowsUtils.test.ts
+7
-7
src/vs/platform/backup/common/backup.ts
src/vs/platform/backup/common/backup.ts
+2
-2
src/vs/platform/backup/electron-main/backupMainService.ts
src/vs/platform/backup/electron-main/backupMainService.ts
+25
-25
src/vs/platform/backup/test/electron-main/backupMainService.test.ts
...tform/backup/test/electron-main/backupMainService.test.ts
+13
-13
src/vs/platform/history/electron-main/historyMainService.ts
src/vs/platform/history/electron-main/historyMainService.ts
+5
-5
src/vs/platform/windows/common/windows.ts
src/vs/platform/windows/common/windows.ts
+1
-2
src/vs/platform/windows/electron-main/windows.ts
src/vs/platform/windows/electron-main/windows.ts
+1
-1
src/vs/platform/windows/electron-main/windowsService.ts
src/vs/platform/windows/electron-main/windowsService.ts
+2
-2
src/vs/workbench/electron-browser/main.ts
src/vs/workbench/electron-browser/main.ts
+8
-8
未找到文件。
src/vs/code/electron-main/app.ts
浏览文件 @
124f4c71
...
...
@@ -211,9 +211,9 @@ export class CodeApplication {
// Send to windows
if
(
target
)
{
const
otherWindowsWithTarget
=
this
.
windowsMainService
.
getWindows
().
filter
(
w
=>
w
.
id
!==
windowId
&&
typeof
w
.
opened
Workspace
Path
===
'
string
'
);
const
directTargetMatch
=
otherWindowsWithTarget
.
filter
(
w
=>
isEqual
(
target
,
w
.
opened
Workspace
Path
,
!
platform
.
isLinux
/* ignorecase */
));
const
parentTargetMatch
=
otherWindowsWithTarget
.
filter
(
w
=>
isParent
(
target
,
w
.
opened
Workspace
Path
,
!
platform
.
isLinux
/* ignorecase */
));
const
otherWindowsWithTarget
=
this
.
windowsMainService
.
getWindows
().
filter
(
w
=>
w
.
id
!==
windowId
&&
typeof
w
.
opened
Folder
Path
===
'
string
'
);
const
directTargetMatch
=
otherWindowsWithTarget
.
filter
(
w
=>
isEqual
(
target
,
w
.
opened
Folder
Path
,
!
platform
.
isLinux
/* ignorecase */
));
const
parentTargetMatch
=
otherWindowsWithTarget
.
filter
(
w
=>
isParent
(
target
,
w
.
opened
Folder
Path
,
!
platform
.
isLinux
/* ignorecase */
));
const
targetWindow
=
directTargetMatch
.
length
?
directTargetMatch
[
0
]
:
parentTargetMatch
[
0
];
// prefer direct match over parent match
if
(
targetWindow
)
{
...
...
src/vs/code/electron-main/window.ts
浏览文件 @
124f4c71
...
...
@@ -277,14 +277,14 @@ export class CodeWindow implements ICodeWindow {
return
this
.
_lastFocusTime
;
}
public
get
openedWorkspacePath
():
string
{
return
this
.
currentConfig
?
this
.
currentConfig
.
workspacePath
:
void
0
;
}
public
get
backupPath
():
string
{
return
this
.
currentConfig
?
this
.
currentConfig
.
backupPath
:
void
0
;
}
public
get
openedFolderPath
():
string
{
return
this
.
currentConfig
?
this
.
currentConfig
.
folderPath
:
void
0
;
}
public
get
openedFilePath
():
string
{
return
this
.
currentConfig
&&
this
.
currentConfig
.
filesToOpen
&&
this
.
currentConfig
.
filesToOpen
[
0
]
&&
this
.
currentConfig
.
filesToOpen
[
0
].
filePath
;
}
...
...
src/vs/code/electron-main/windows.ts
浏览文件 @
124f4c71
...
...
@@ -21,7 +21,7 @@ import { ILifecycleService, UnloadReason } from 'vs/platform/lifecycle/electron-
import
{
IConfigurationService
}
from
'
vs/platform/configuration/common/configuration
'
;
import
{
ILogService
}
from
'
vs/platform/log/common/log
'
;
import
{
IWindowSettings
,
OpenContext
,
IPath
,
IWindowConfiguration
}
from
'
vs/platform/windows/common/windows
'
;
import
{
getLastActiveWindow
,
findBestWindowOrFolderForFile
,
findWindowOn
Workspace
}
from
'
vs/code/node/windowsFinder
'
;
import
{
getLastActiveWindow
,
findBestWindowOrFolderForFile
,
findWindowOn
Folder
}
from
'
vs/code/node/windowsFinder
'
;
import
CommonEvent
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
product
from
'
vs/platform/node/product
'
;
import
{
ITelemetryService
,
ITelemetryData
}
from
'
vs/platform/telemetry/common/telemetry
'
;
...
...
@@ -41,17 +41,24 @@ interface INewWindowState extends ISingleWindowState {
hasDefaultState
?:
boolean
;
}
interface
IWindowState
{
interface
I
LegacyWindowState
extends
I
WindowState
{
workspacePath
?:
string
;
}
interface
IWindowState
{
folderPath
?:
string
;
backupPath
:
string
;
uiState
:
ISingleWindowState
;
}
interface
ILegacyWindowsState
extends
IWindowsState
{
openedFolders
?:
IWindowState
[];
}
interface
IWindowsState
{
lastActiveWindow
?:
IWindowState
;
lastPluginDevelopmentHostWindow
?:
IWindowState
;
openedWindows
:
IWindowState
[];
openedFolders
?:
IWindowState
[];
// TODO@Ben deprecated
}
type
RestoreWindowsSetting
=
'
all
'
|
'
folders
'
|
'
one
'
|
'
none
'
;
...
...
@@ -59,7 +66,7 @@ type RestoreWindowsSetting = 'all' | 'folders' | 'one' | 'none';
interface
IOpenBrowserWindowOptions
{
userEnv
?:
IProcessEnvironment
;
cli
?:
ParsedArgs
;
workspace
Path
?:
string
;
folder
Path
?:
string
;
initialStartup
?:
boolean
;
...
...
@@ -70,13 +77,13 @@ interface IOpenBrowserWindowOptions {
forceNewWindow
?:
boolean
;
windowToUse
?:
CodeWindow
;
emptyW
orkspace
BackupFolder
?:
string
;
emptyW
indow
BackupFolder
?:
string
;
}
interface
IWindowToOpen
extends
IPath
{
// the
workspace s
path for a Code instance to open
workspace
Path
?:
string
;
// the
folder
path for a Code instance to open
folder
Path
?:
string
;
// the backup spath for a Code instance to use
backupPath
?:
string
;
...
...
@@ -123,16 +130,33 @@ export class WindowsManager implements IWindowsMainService {
@
IHistoryMainService
private
historyService
:
IHistoryMainService
)
{
this
.
windowsState
=
this
.
storageService
.
getItem
<
IWindowsState
>
(
WindowsManager
.
windowsStateStorageKey
)
||
{
openedWindows
:
[]
};
this
.
fileDialog
=
new
FileDialog
(
environmentService
,
telemetryService
,
storageService
,
this
);
this
.
migrateLegacyWindowState
();
}
private
migrateLegacyWindowState
():
void
{
const
state
:
ILegacyWindowsState
=
this
.
windowsState
;
// TODO@Ben migration from previous openedFolders to new openedWindows property
if
(
Array
.
isArray
(
this
.
windowsState
.
openedFolders
)
&&
this
.
windowsS
tate
.
openedFolders
.
length
>
0
)
{
this
.
windowsState
.
openedWindows
=
this
.
windowsS
tate
.
openedFolders
;
this
.
windowsS
tate
.
openedFolders
=
void
0
;
}
else
if
(
!
this
.
windowsS
tate
.
openedWindows
)
{
this
.
windowsS
tate
.
openedWindows
=
[];
if
(
Array
.
isArray
(
state
.
openedFolders
)
&&
s
tate
.
openedFolders
.
length
>
0
)
{
state
.
openedWindows
=
s
tate
.
openedFolders
;
s
tate
.
openedFolders
=
void
0
;
}
else
if
(
!
s
tate
.
openedWindows
)
{
s
tate
.
openedWindows
=
[];
}
this
.
fileDialog
=
new
FileDialog
(
environmentService
,
telemetryService
,
storageService
,
this
);
// TODO@Ben migration from previous workspacePath in window state to folderPath
const
states
:
ILegacyWindowState
[]
=
[];
states
.
push
(
state
.
lastActiveWindow
);
states
.
push
(
state
.
lastPluginDevelopmentHostWindow
);
states
.
push
(...
state
.
openedWindows
);
states
.
forEach
(
state
=>
{
if
(
state
&&
typeof
state
.
workspacePath
===
'
string
'
)
{
state
.
folderPath
=
state
.
workspacePath
;
state
.
workspacePath
=
void
0
;
}
});
}
public
ready
(
initialUserEnv
:
IProcessEnvironment
):
void
{
...
...
@@ -180,7 +204,7 @@ export class WindowsManager implements IWindowsMainService {
// and then onBeforeQuit(). Using the quit action however will first issue onBeforeQuit()
// and then onBeforeWindowClose().
private
onBeforeQuit
():
void
{
const
currentWindowsState
:
IWindowsState
=
{
const
currentWindowsState
:
I
Legacy
WindowsState
=
{
openedWindows
:
[],
openedFolders
:
[],
// TODO@Ben migration so that old clients do not fail over data (prevents NPEs)
lastPluginDevelopmentHostWindow
:
this
.
windowsState
.
lastPluginDevelopmentHostWindow
,
...
...
@@ -195,14 +219,14 @@ export class WindowsManager implements IWindowsMainService {
}
if
(
activeWindow
)
{
currentWindowsState
.
lastActiveWindow
=
{
workspacePath
:
activeWindow
.
openedWorkspace
Path
,
uiState
:
activeWindow
.
serializeWindowState
(),
backupPath
:
activeWindow
.
backupPath
};
currentWindowsState
.
lastActiveWindow
=
{
folderPath
:
activeWindow
.
openedFolder
Path
,
uiState
:
activeWindow
.
serializeWindowState
(),
backupPath
:
activeWindow
.
backupPath
};
}
}
// 2.) Find extension host window
const
extensionHostWindow
=
WindowsManager
.
WINDOWS
.
filter
(
w
=>
w
.
isExtensionDevelopmentHost
&&
!
w
.
isExtensionTestHost
)[
0
];
if
(
extensionHostWindow
)
{
currentWindowsState
.
lastPluginDevelopmentHostWindow
=
{
workspacePath
:
extensionHostWindow
.
openedWorkspace
Path
,
uiState
:
extensionHostWindow
.
serializeWindowState
(),
backupPath
:
extensionHostWindow
.
backupPath
};
currentWindowsState
.
lastPluginDevelopmentHostWindow
=
{
folderPath
:
extensionHostWindow
.
openedFolder
Path
,
uiState
:
extensionHostWindow
.
serializeWindowState
(),
backupPath
:
extensionHostWindow
.
backupPath
};
}
// 3.) All windows (except extension host) for N >= 2 to support restoreWindows: all or for auto update
...
...
@@ -213,7 +237,7 @@ export class WindowsManager implements IWindowsMainService {
if
(
this
.
getWindowCount
()
>
1
)
{
currentWindowsState
.
openedWindows
=
WindowsManager
.
WINDOWS
.
filter
(
w
=>
!
w
.
isExtensionDevelopmentHost
).
map
(
w
=>
{
return
<
IWindowState
>
{
workspacePath
:
w
.
openedWorkspace
Path
,
folderPath
:
w
.
openedFolder
Path
,
uiState
:
w
.
serializeWindowState
(),
backupPath
:
w
.
backupPath
};
...
...
@@ -231,15 +255,15 @@ export class WindowsManager implements IWindowsMainService {
}
// On Window close, update our stored UI state of this window
const
state
:
IWindowState
=
{
workspacePath
:
win
.
openedWorkspace
Path
,
uiState
:
win
.
serializeWindowState
(),
backupPath
:
win
.
backupPath
};
const
state
:
IWindowState
=
{
folderPath
:
win
.
openedFolder
Path
,
uiState
:
win
.
serializeWindowState
(),
backupPath
:
win
.
backupPath
};
if
(
win
.
isExtensionDevelopmentHost
&&
!
win
.
isExtensionTestHost
)
{
this
.
windowsState
.
lastPluginDevelopmentHostWindow
=
state
;
// do not let test run window state overwrite our extension development state
}
// Any non extension host window with same
workspace
else
if
(
!
win
.
isExtensionDevelopmentHost
&&
!!
win
.
opened
Workspace
Path
)
{
// Any non extension host window with same
folder
else
if
(
!
win
.
isExtensionDevelopmentHost
&&
!!
win
.
opened
Folder
Path
)
{
this
.
windowsState
.
openedWindows
.
forEach
(
o
=>
{
if
(
isEqual
(
o
.
workspacePath
,
win
.
openedWorkspace
Path
,
!
isLinux
/* ignorecase */
))
{
if
(
isEqual
(
o
.
folderPath
,
win
.
openedFolder
Path
,
!
isLinux
/* ignorecase */
))
{
o
.
uiState
=
state
.
uiState
;
}
});
...
...
@@ -260,8 +284,8 @@ export class WindowsManager implements IWindowsMainService {
//
// These are windows to open to show either folders or files (including diffing files or creating them)
//
const
foldersToOpen
=
arrays
.
distinct
(
windowsToOpen
.
filter
(
win
=>
win
.
workspacePath
&&
!
win
.
filePath
).
map
(
win
=>
win
.
workspace
Path
),
folder
=>
isLinux
?
folder
:
folder
.
toLowerCase
());
// prevent duplicates
const
emptyToOpen
=
windowsToOpen
.
filter
(
win
=>
!
win
.
workspace
Path
&&
!
win
.
filePath
&&
!
win
.
backupPath
).
length
;
const
foldersToOpen
=
arrays
.
distinct
(
windowsToOpen
.
filter
(
win
=>
win
.
folderPath
&&
!
win
.
filePath
).
map
(
win
=>
win
.
folder
Path
),
folder
=>
isLinux
?
folder
:
folder
.
toLowerCase
());
// prevent duplicates
const
emptyToOpen
=
windowsToOpen
.
filter
(
win
=>
!
win
.
folder
Path
&&
!
win
.
filePath
&&
!
win
.
backupPath
).
length
;
let
filesToOpen
=
windowsToOpen
.
filter
(
path
=>
!!
path
.
filePath
&&
!
path
.
createFilePath
);
let
filesToCreate
=
windowsToOpen
.
filter
(
path
=>
!!
path
.
filePath
&&
path
.
createFilePath
);
...
...
@@ -279,8 +303,8 @@ export class WindowsManager implements IWindowsMainService {
//
const
hotExitRestore
=
(
openConfig
.
initialStartup
&&
!
openConfig
.
cli
.
extensionDevelopmentPath
);
const
foldersToRestore
=
hotExitRestore
?
this
.
backupService
.
getWorkspaceBackupPaths
()
:
[];
let
emptyToRestore
=
hotExitRestore
?
this
.
backupService
.
getEmptyW
orkspace
BackupPaths
()
:
[];
emptyToRestore
.
push
(...
windowsToOpen
.
filter
(
w
=>
!
w
.
workspacePath
&&
w
.
backupPath
).
map
(
w
=>
path
.
basename
(
w
.
backupPath
)));
// add empty workspace
s with backupPath
let
emptyToRestore
=
hotExitRestore
?
this
.
backupService
.
getEmptyW
indow
BackupPaths
()
:
[];
emptyToRestore
.
push
(...
windowsToOpen
.
filter
(
w
=>
!
w
.
folderPath
&&
w
.
backupPath
).
map
(
w
=>
path
.
basename
(
w
.
backupPath
)));
// add empty window
s with backupPath
emptyToRestore
=
arrays
.
distinct
(
emptyToRestore
);
// prevent duplicates
// Open based on config
...
...
@@ -300,8 +324,8 @@ export class WindowsManager implements IWindowsMainService {
const
recentPaths
:
{
path
:
string
;
isFile
?:
boolean
;
}[]
=
[];
windowsToOpen
.
forEach
(
win
=>
{
if
(
win
.
filePath
||
win
.
workspace
Path
)
{
recentPaths
.
push
({
path
:
win
.
filePath
||
win
.
workspace
Path
,
isFile
:
!!
win
.
filePath
});
if
(
win
.
filePath
||
win
.
folder
Path
)
{
recentPaths
.
push
({
path
:
win
.
filePath
||
win
.
folder
Path
,
isFile
:
!!
win
.
filePath
});
}
});
...
...
@@ -374,7 +398,7 @@ export class WindowsManager implements IWindowsMainService {
userEnv
:
openConfig
.
userEnv
,
cli
:
openConfig
.
cli
,
initialStartup
:
openConfig
.
initialStartup
,
workspace
Path
:
folderToOpen
,
folder
Path
:
folderToOpen
,
filesToOpen
,
filesToCreate
,
filesToDiff
,
...
...
@@ -396,9 +420,9 @@ export class WindowsManager implements IWindowsMainService {
if
(
allFoldersToOpen
.
length
>
0
)
{
// Check for existing instances
const
windowsOn
WorkspacePath
=
arrays
.
coalesce
(
allFoldersToOpen
.
map
(
folderToOpen
=>
findWindowOnWorkspace
(
WindowsManager
.
WINDOWS
,
folderToOpen
)));
if
(
windowsOn
Workspace
Path
.
length
>
0
)
{
const
browserWindow
=
windowsOn
Workspace
Path
[
0
];
const
windowsOn
FolderPath
=
arrays
.
coalesce
(
allFoldersToOpen
.
map
(
folderToOpen
=>
findWindowOnFolder
(
WindowsManager
.
WINDOWS
,
folderToOpen
)));
if
(
windowsOn
Folder
Path
.
length
>
0
)
{
const
browserWindow
=
windowsOn
Folder
Path
[
0
];
browserWindow
.
focus
();
// just focus one of them
const
files
=
{
filesToOpen
,
filesToCreate
,
filesToDiff
};
// copy to object because they get reset shortly after
...
...
@@ -418,7 +442,7 @@ export class WindowsManager implements IWindowsMainService {
// Open remaining ones
allFoldersToOpen
.
forEach
(
folderToOpen
=>
{
if
(
windowsOn
WorkspacePath
.
some
(
win
=>
isEqual
(
win
.
openedWorkspace
Path
,
folderToOpen
,
!
isLinux
/* ignorecase */
)))
{
if
(
windowsOn
FolderPath
.
some
(
win
=>
isEqual
(
win
.
openedFolder
Path
,
folderToOpen
,
!
isLinux
/* ignorecase */
)))
{
return
;
// ignore folders that are already open
}
...
...
@@ -426,7 +450,7 @@ export class WindowsManager implements IWindowsMainService {
userEnv
:
openConfig
.
userEnv
,
cli
:
openConfig
.
cli
,
initialStartup
:
openConfig
.
initialStartup
,
workspace
Path
:
folderToOpen
,
folder
Path
:
folderToOpen
,
filesToOpen
,
filesToCreate
,
filesToDiff
,
...
...
@@ -446,7 +470,7 @@ export class WindowsManager implements IWindowsMainService {
// Handle empty
if
(
emptyToRestore
.
length
>
0
)
{
emptyToRestore
.
forEach
(
emptyW
orkspace
BackupFolder
=>
{
emptyToRestore
.
forEach
(
emptyW
indow
BackupFolder
=>
{
const
browserWindow
=
this
.
openInBrowserWindow
({
userEnv
:
openConfig
.
userEnv
,
cli
:
openConfig
.
cli
,
...
...
@@ -455,7 +479,7 @@ export class WindowsManager implements IWindowsMainService {
filesToCreate
,
filesToDiff
,
forceNewWindow
:
true
,
emptyW
orkspace
BackupFolder
emptyW
indow
BackupFolder
});
usedWindows
.
push
(
browserWindow
);
...
...
@@ -468,7 +492,7 @@ export class WindowsManager implements IWindowsMainService {
});
}
// Only open empty if no empty w
orkspace
s were restored
// Only open empty if no empty w
indow
s were restored
else
if
(
emptyToOpen
>
0
)
{
for
(
let
i
=
0
;
i
<
emptyToOpen
;
i
++
)
{
const
browserWindow
=
this
.
openInBrowserWindow
({
...
...
@@ -561,16 +585,16 @@ export class WindowsManager implements IWindowsMainService {
switch
(
restoreWindows
)
{
// none: we always open an empty w
orkspace
// none: we always open an empty w
indow
case
'
none
'
:
return
[
Object
.
create
(
null
)];
// one: restore last opened folder or empty w
orkspace
// one: restore last opened folder or empty w
indow
case
'
one
'
:
if
(
lastActiveWindow
)
{
// return folder path if it is valid
const
folder
=
lastActiveWindow
.
workspace
Path
;
const
folder
=
lastActiveWindow
.
folder
Path
;
if
(
folder
)
{
const
validatedFolderPath
=
this
.
parsePath
(
folder
);
if
(
validatedFolderPath
)
{
...
...
@@ -578,7 +602,7 @@ export class WindowsManager implements IWindowsMainService {
}
}
// otherwise use backup path to restore empty w
orkspace
s
// otherwise use backup path to restore empty w
indow
s
else
if
(
lastActiveWindow
.
backupPath
)
{
return
[{
backupPath
:
lastActiveWindow
.
backupPath
}];
}
...
...
@@ -591,8 +615,8 @@ export class WindowsManager implements IWindowsMainService {
case
'
folders
'
:
// Windows with Folders
const
lastOpenedFolders
=
this
.
windowsState
.
openedWindows
.
filter
(
w
=>
!!
w
.
workspacePath
).
map
(
o
=>
o
.
workspace
Path
);
const
lastActiveFolder
=
lastActiveWindow
&&
lastActiveWindow
.
workspace
Path
;
const
lastOpenedFolders
=
this
.
windowsState
.
openedWindows
.
filter
(
w
=>
!!
w
.
folderPath
).
map
(
o
=>
o
.
folder
Path
);
const
lastActiveFolder
=
lastActiveWindow
&&
lastActiveWindow
.
folder
Path
;
if
(
lastActiveFolder
)
{
lastOpenedFolders
.
push
(
lastActiveFolder
);
}
...
...
@@ -601,8 +625,8 @@ export class WindowsManager implements IWindowsMainService {
// Windows that were Empty
if
(
restoreWindows
===
'
all
'
)
{
const
lastOpenedEmpty
=
this
.
windowsState
.
openedWindows
.
filter
(
w
=>
!
w
.
workspace
Path
&&
w
.
backupPath
).
map
(
w
=>
w
.
backupPath
);
const
lastActiveEmpty
=
lastActiveWindow
&&
!
lastActiveWindow
.
workspace
Path
&&
lastActiveWindow
.
backupPath
;
const
lastOpenedEmpty
=
this
.
windowsState
.
openedWindows
.
filter
(
w
=>
!
w
.
folder
Path
&&
w
.
backupPath
).
map
(
w
=>
w
.
backupPath
);
const
lastActiveEmpty
=
lastActiveWindow
&&
!
lastActiveWindow
.
folder
Path
&&
lastActiveWindow
.
backupPath
;
if
(
lastActiveEmpty
)
{
lastOpenedEmpty
.
push
(
lastActiveEmpty
);
}
...
...
@@ -617,7 +641,7 @@ export class WindowsManager implements IWindowsMainService {
break
;
}
// Always fallback to empty w
orkspace
// Always fallback to empty w
indow
return
[
Object
.
create
(
null
)];
}
...
...
@@ -662,7 +686,7 @@ export class WindowsManager implements IWindowsMainService {
lineNumber
:
gotoLineMode
?
parsedPath
.
line
:
void
0
,
columnNumber
:
gotoLineMode
?
parsedPath
.
column
:
void
0
}
:
{
workspace
Path
:
candidate
};
{
folder
Path
:
candidate
};
}
}
catch
(
error
)
{
this
.
historyService
.
removeFromRecentPathsList
(
candidate
);
// since file does not seem to exist anymore, remove from recent
...
...
@@ -717,17 +741,17 @@ export class WindowsManager implements IWindowsMainService {
return
;
}
// Fill in previously opened
workspace
unless an explicit path is provided and we are not unit testing
// Fill in previously opened
folder
unless an explicit path is provided and we are not unit testing
if
(
openConfig
.
cli
.
_
.
length
===
0
&&
!
openConfig
.
cli
.
extensionTestsPath
)
{
const
workspaceToOpen
=
this
.
windowsState
.
lastPluginDevelopmentHostWindow
&&
this
.
windowsState
.
lastPluginDevelopmentHostWindow
.
workspace
Path
;
if
(
workspace
ToOpen
)
{
openConfig
.
cli
.
_
=
[
workspace
ToOpen
];
const
folderToOpen
=
this
.
windowsState
.
lastPluginDevelopmentHostWindow
&&
this
.
windowsState
.
lastPluginDevelopmentHostWindow
.
folder
Path
;
if
(
folder
ToOpen
)
{
openConfig
.
cli
.
_
=
[
folder
ToOpen
];
}
}
// Make sure we are not asked to open a path that is already opened
if
(
openConfig
.
cli
.
_
.
length
>
0
)
{
res
=
WindowsManager
.
WINDOWS
.
filter
(
w
=>
w
.
opened
WorkspacePath
&&
openConfig
.
cli
.
_
.
indexOf
(
w
.
openedWorkspace
Path
)
>=
0
);
res
=
WindowsManager
.
WINDOWS
.
filter
(
w
=>
w
.
opened
FolderPath
&&
openConfig
.
cli
.
_
.
indexOf
(
w
.
openedFolder
Path
)
>=
0
);
if
(
res
.
length
)
{
openConfig
.
cli
.
_
=
[];
}
...
...
@@ -745,18 +769,18 @@ export class WindowsManager implements IWindowsMainService {
configuration
.
execPath
=
process
.
execPath
;
configuration
.
userEnv
=
assign
({},
this
.
initialUserEnv
,
options
.
userEnv
||
{});
configuration
.
isInitialStartup
=
options
.
initialStartup
;
configuration
.
workspacePath
=
options
.
workspace
Path
;
configuration
.
folderPath
=
options
.
folder
Path
;
configuration
.
filesToOpen
=
options
.
filesToOpen
;
configuration
.
filesToCreate
=
options
.
filesToCreate
;
configuration
.
filesToDiff
=
options
.
filesToDiff
;
configuration
.
nodeCachedDataDir
=
this
.
environmentService
.
nodeCachedDataDir
;
// if we know the backup folder upfront (for empty w
orkspace
s to restore), we can set it
// if we know the backup folder upfront (for empty w
indow
s to restore), we can set it
// directly here which helps for restoring UI state associated with that window.
// For all other cases we first call into registerWindowForBackupsSync() to set it before
// loading the window.
if
(
options
.
emptyW
orkspace
BackupFolder
)
{
configuration
.
backupPath
=
path
.
join
(
this
.
environmentService
.
backupHome
,
options
.
emptyW
orkspace
BackupFolder
);
if
(
options
.
emptyW
indow
BackupFolder
)
{
configuration
.
backupPath
=
path
.
join
(
this
.
environmentService
.
backupHome
,
options
.
emptyW
indow
BackupFolder
);
}
let
codeWindow
:
CodeWindow
;
...
...
@@ -853,7 +877,7 @@ export class WindowsManager implements IWindowsMainService {
// Register window for backups
if
(
!
configuration
.
extensionDevelopmentPath
)
{
const
backupPath
=
this
.
backupService
.
registerWindowForBackupsSync
(
codeWindow
.
id
,
!
configuration
.
workspacePath
,
options
.
emptyWorkspaceBackupFolder
,
configuration
.
workspace
Path
);
const
backupPath
=
this
.
backupService
.
registerWindowForBackupsSync
(
codeWindow
.
id
,
!
configuration
.
folderPath
,
options
.
emptyWindowBackupFolder
,
configuration
.
folder
Path
);
configuration
.
backupPath
=
backupPath
;
}
...
...
@@ -873,18 +897,18 @@ export class WindowsManager implements IWindowsMainService {
}
// Known Folder - load from stored settings if any
if
(
configuration
.
workspace
Path
)
{
const
stateFor
Workspace
=
this
.
windowsState
.
openedWindows
.
filter
(
o
=>
isEqual
(
o
.
workspacePath
,
configuration
.
workspace
Path
,
!
isLinux
/* ignorecase */
)).
map
(
o
=>
o
.
uiState
);
if
(
stateFor
Workspace
.
length
)
{
return
stateFor
Workspace
[
0
];
if
(
configuration
.
folder
Path
)
{
const
stateFor
Folder
=
this
.
windowsState
.
openedWindows
.
filter
(
o
=>
isEqual
(
o
.
folderPath
,
configuration
.
folder
Path
,
!
isLinux
/* ignorecase */
)).
map
(
o
=>
o
.
uiState
);
if
(
stateFor
Folder
.
length
)
{
return
stateFor
Folder
[
0
];
}
}
// Empty w
orkspace
with backups
// Empty w
indows
with backups
else
if
(
configuration
.
backupPath
)
{
const
stateFor
Workspace
=
this
.
windowsState
.
openedWindows
.
filter
(
o
=>
o
.
backupPath
===
configuration
.
backupPath
).
map
(
o
=>
o
.
uiState
);
if
(
stateFor
Workspace
.
length
)
{
return
stateFor
Workspace
[
0
];
const
stateFor
EmptyWindow
=
this
.
windowsState
.
openedWindows
.
filter
(
o
=>
o
.
backupPath
===
configuration
.
backupPath
).
map
(
o
=>
o
.
uiState
);
if
(
stateFor
EmptyWindow
.
length
)
{
return
stateFor
EmptyWindow
[
0
];
}
}
...
...
src/vs/code/node/windowsFinder.ts
浏览文件 @
124f4c71
...
...
@@ -12,7 +12,7 @@ import * as paths from 'vs/base/common/paths';
import
{
OpenContext
}
from
'
vs/platform/windows/common/windows
'
;
export
interface
ISimpleWindow
{
opened
Workspace
Path
:
string
;
opened
Folder
Path
:
string
;
openedFilePath
?:
string
;
extensionDevelopmentPath
?:
string
;
lastFocusTime
:
number
;
...
...
@@ -34,7 +34,7 @@ export function findBestWindowOrFolderForFile<W extends ISimpleWindow>({ windows
const
folderWithCodeSettings
=
!
reuseWindow
&&
findFolderWithCodeSettings
(
filePath
,
userHome
,
codeSettingsFolder
);
// Return if we found a window that has the parent of the file path opened
if
(
windowOnFilePath
&&
!
(
folderWithCodeSettings
&&
folderWithCodeSettings
.
length
>
windowOnFilePath
.
opened
Workspace
Path
.
length
))
{
if
(
windowOnFilePath
&&
!
(
folderWithCodeSettings
&&
folderWithCodeSettings
.
length
>
windowOnFilePath
.
opened
Folder
Path
.
length
))
{
return
windowOnFilePath
;
}
...
...
@@ -51,9 +51,9 @@ function findWindowOnFilePath<W extends ISimpleWindow>(windows: W[], filePath: s
// From all windows that have the parent of the file opened, return the window
// that has the most specific folder opened ( = longest path wins)
const
windowsOnFilePath
=
windows
.
filter
(
window
=>
typeof
window
.
opened
WorkspacePath
===
'
string
'
&&
paths
.
isEqualOrParent
(
filePath
,
window
.
openedWorkspace
Path
,
!
platform
.
isLinux
/* ignorecase */
));
const
windowsOnFilePath
=
windows
.
filter
(
window
=>
typeof
window
.
opened
FolderPath
===
'
string
'
&&
paths
.
isEqualOrParent
(
filePath
,
window
.
openedFolder
Path
,
!
platform
.
isLinux
/* ignorecase */
));
if
(
windowsOnFilePath
.
length
)
{
return
windowsOnFilePath
.
sort
((
a
,
b
)
=>
-
(
a
.
opened
WorkspacePath
.
length
-
b
.
openedWorkspace
Path
.
length
))[
0
];
return
windowsOnFilePath
.
sort
((
a
,
b
)
=>
-
(
a
.
opened
FolderPath
.
length
-
b
.
openedFolder
Path
.
length
))[
0
];
}
return
null
;
...
...
@@ -105,7 +105,7 @@ export function getLastActiveWindow<W extends ISimpleWindow>(windows: W[]): W {
return
null
;
}
export
function
findWindowOn
Workspace
<
W
extends
ISimpleWindow
>
(
windows
:
W
[],
workspace
Path
:
string
):
W
{
export
function
findWindowOn
Folder
<
W
extends
ISimpleWindow
>
(
windows
:
W
[],
folder
Path
:
string
):
W
{
if
(
windows
.
length
)
{
// Sort the last active window to the front of the array of windows to test
...
...
@@ -119,8 +119,8 @@ export function findWindowOnWorkspace<W extends ISimpleWindow>(windows: W[], wor
// Find it
const
res
=
windowsToTest
.
filter
(
w
=>
{
// match on
workspace
if
(
typeof
w
.
opened
WorkspacePath
===
'
string
'
&&
(
paths
.
isEqual
(
w
.
openedWorkspacePath
,
workspace
Path
,
!
platform
.
isLinux
/* ignorecase */
)))
{
// match on
folder
if
(
typeof
w
.
opened
FolderPath
===
'
string
'
&&
(
paths
.
isEqual
(
w
.
openedFolderPath
,
folder
Path
,
!
platform
.
isLinux
/* ignorecase */
)))
{
return
true
;
}
...
...
src/vs/code/test/node/windowsUtils.test.ts
浏览文件 @
124f4c71
...
...
@@ -22,9 +22,9 @@ function options(custom?: Partial<IBestWindowOrFolderOptions<ISimpleWindow>>): I
};
}
const
vscodeFolderWindow
=
{
lastFocusTime
:
1
,
opened
Workspace
Path
:
path
.
join
(
fixturesFolder
,
'
vscode_folder
'
)
};
const
lastActiveWindow
=
{
lastFocusTime
:
3
,
opened
Workspace
Path
:
null
};
const
noVscodeFolderWindow
=
{
lastFocusTime
:
2
,
opened
Workspace
Path
:
path
.
join
(
fixturesFolder
,
'
no_vscode_folder
'
)
};
const
vscodeFolderWindow
=
{
lastFocusTime
:
1
,
opened
Folder
Path
:
path
.
join
(
fixturesFolder
,
'
vscode_folder
'
)
};
const
lastActiveWindow
=
{
lastFocusTime
:
3
,
opened
Folder
Path
:
null
};
const
noVscodeFolderWindow
=
{
lastFocusTime
:
2
,
opened
Folder
Path
:
path
.
join
(
fixturesFolder
,
'
no_vscode_folder
'
)
};
const
windows
=
[
vscodeFolderWindow
,
lastActiveWindow
,
...
...
@@ -101,7 +101,7 @@ suite('WindowsFinder', () => {
});
test
(
'
Existing window wins over vscode folder if more specific
'
,
()
=>
{
const
window
=
{
lastFocusTime
:
1
,
opened
Workspace
Path
:
path
.
join
(
fixturesFolder
,
'
vscode_folder
'
,
'
nested_folder
'
)
};
const
window
=
{
lastFocusTime
:
1
,
opened
Folder
Path
:
path
.
join
(
fixturesFolder
,
'
vscode_folder
'
,
'
nested_folder
'
)
};
assert
.
equal
(
findBestWindowOrFolderForFile
(
options
({
windows
:
[
window
],
filePath
:
path
.
join
(
fixturesFolder
,
'
vscode_folder
'
,
'
nested_folder
'
,
'
subfolder
'
,
'
file.txt
'
)
...
...
@@ -114,8 +114,8 @@ suite('WindowsFinder', () => {
});
test
(
'
More specific existing window wins
'
,
()
=>
{
const
window
=
{
lastFocusTime
:
2
,
opened
Workspace
Path
:
path
.
join
(
fixturesFolder
,
'
no_vscode_folder
'
)
};
const
nestedFolderWindow
=
{
lastFocusTime
:
1
,
opened
Workspace
Path
:
path
.
join
(
fixturesFolder
,
'
no_vscode_folder
'
,
'
nested_folder
'
)
};
const
window
=
{
lastFocusTime
:
2
,
opened
Folder
Path
:
path
.
join
(
fixturesFolder
,
'
no_vscode_folder
'
)
};
const
nestedFolderWindow
=
{
lastFocusTime
:
1
,
opened
Folder
Path
:
path
.
join
(
fixturesFolder
,
'
no_vscode_folder
'
,
'
nested_folder
'
)
};
assert
.
equal
(
findBestWindowOrFolderForFile
(
options
({
windows
:
[
window
,
nestedFolderWindow
],
filePath
:
path
.
join
(
fixturesFolder
,
'
no_vscode_folder
'
,
'
nested_folder
'
,
'
subfolder
'
,
'
file.txt
'
)
...
...
@@ -123,7 +123,7 @@ suite('WindowsFinder', () => {
});
test
(
'
VSCode folder wins over existing window if more specific
'
,
()
=>
{
const
window
=
{
lastFocusTime
:
1
,
opened
Workspace
Path
:
path
.
join
(
fixturesFolder
,
'
vscode_folder
'
)
};
const
window
=
{
lastFocusTime
:
1
,
opened
Folder
Path
:
path
.
join
(
fixturesFolder
,
'
vscode_folder
'
)
};
assert
.
equal
(
findBestWindowOrFolderForFile
(
options
({
windows
:
[
window
],
filePath
:
path
.
join
(
fixturesFolder
,
'
vscode_folder
'
,
'
nested_vscode_folder
'
,
'
subfolder
'
,
'
file.txt
'
)
...
...
src/vs/platform/backup/common/backup.ts
浏览文件 @
124f4c71
...
...
@@ -16,7 +16,7 @@ export interface IBackupMainService {
_serviceBrand
:
any
;
getWorkspaceBackupPaths
():
string
[];
getEmptyW
orkspace
BackupPaths
():
string
[];
getEmptyW
indow
BackupPaths
():
string
[];
registerWindowForBackupsSync
(
windowId
:
number
,
isEmptyW
orkspace
:
boolean
,
backupFolder
?:
string
,
workspacePath
?:
string
):
string
;
registerWindowForBackupsSync
(
windowId
:
number
,
isEmptyW
indow
:
boolean
,
backupFolder
?:
string
,
workspacePath
?:
string
):
string
;
}
\ No newline at end of file
src/vs/platform/backup/electron-main/backupMainService.ts
浏览文件 @
124f4c71
...
...
@@ -43,25 +43,25 @@ export class BackupMainService implements IBackupMainService {
return
this
.
backups
.
folderWorkspaces
.
slice
(
0
);
// return a copy
}
public
getEmptyW
orkspace
BackupPaths
():
string
[]
{
public
getEmptyW
indow
BackupPaths
():
string
[]
{
return
this
.
backups
.
emptyWorkspaces
.
slice
(
0
);
// return a copy
}
public
registerWindowForBackupsSync
(
windowId
:
number
,
isEmptyW
orkspace
:
boolean
,
backupFolder
?:
string
,
workspacePath
?:
string
):
string
{
public
registerWindowForBackupsSync
(
windowId
:
number
,
isEmptyW
indow
:
boolean
,
backupFolder
?:
string
,
workspacePath
?:
string
):
string
{
// Generate a new folder if this is a new empty workspace
if
(
isEmptyW
orkspace
&&
!
backupFolder
)
{
backupFolder
=
this
.
getRandomEmptyW
orkspace
Id
();
if
(
isEmptyW
indow
&&
!
backupFolder
)
{
backupFolder
=
this
.
getRandomEmptyW
indow
Id
();
}
this
.
pushBackupPathsSync
(
isEmptyW
orkspace
?
backupFolder
:
workspacePath
,
isEmptyWorkspace
);
this
.
pushBackupPathsSync
(
isEmptyW
indow
?
backupFolder
:
workspacePath
,
isEmptyWindow
);
return
path
.
join
(
this
.
backupHome
,
isEmptyW
orkspace
?
backupFolder
:
this
.
getWorkspaceHash
(
workspacePath
));
return
path
.
join
(
this
.
backupHome
,
isEmptyW
indow
?
backupFolder
:
this
.
getWorkspaceHash
(
workspacePath
));
}
private
pushBackupPathsSync
(
workspaceIdentifier
:
string
,
isEmptyW
orkspace
:
boolean
):
string
{
const
array
=
isEmptyW
orkspace
?
this
.
backups
.
emptyWorkspaces
:
this
.
backups
.
folderWorkspaces
;
if
(
this
.
indexOf
(
workspaceIdentifier
,
isEmptyW
orkspace
)
===
-
1
)
{
private
pushBackupPathsSync
(
workspaceIdentifier
:
string
,
isEmptyW
indow
:
boolean
):
string
{
const
array
=
isEmptyW
indow
?
this
.
backups
.
emptyWorkspaces
:
this
.
backups
.
folderWorkspaces
;
if
(
this
.
indexOf
(
workspaceIdentifier
,
isEmptyW
indow
)
===
-
1
)
{
array
.
push
(
workspaceIdentifier
);
this
.
saveSync
();
}
...
...
@@ -69,12 +69,12 @@ export class BackupMainService implements IBackupMainService {
return
workspaceIdentifier
;
}
protected
removeBackupPathSync
(
workspaceIdentifier
:
string
,
isEmptyW
orkspace
:
boolean
):
void
{
const
array
=
isEmptyW
orkspace
?
this
.
backups
.
emptyWorkspaces
:
this
.
backups
.
folderWorkspaces
;
protected
removeBackupPathSync
(
workspaceIdentifier
:
string
,
isEmptyW
indow
:
boolean
):
void
{
const
array
=
isEmptyW
indow
?
this
.
backups
.
emptyWorkspaces
:
this
.
backups
.
folderWorkspaces
;
if
(
!
array
)
{
return
;
}
const
index
=
this
.
indexOf
(
workspaceIdentifier
,
isEmptyW
orkspace
);
const
index
=
this
.
indexOf
(
workspaceIdentifier
,
isEmptyW
indow
);
if
(
index
===
-
1
)
{
return
;
}
...
...
@@ -82,13 +82,13 @@ export class BackupMainService implements IBackupMainService {
this
.
saveSync
();
}
private
indexOf
(
workspaceIdentifier
:
string
,
isEmptyW
orkspace
:
boolean
):
number
{
const
array
=
isEmptyW
orkspace
?
this
.
backups
.
emptyWorkspaces
:
this
.
backups
.
folderWorkspaces
;
private
indexOf
(
workspaceIdentifier
:
string
,
isEmptyW
indow
:
boolean
):
number
{
const
array
=
isEmptyW
indow
?
this
.
backups
.
emptyWorkspaces
:
this
.
backups
.
folderWorkspaces
;
if
(
!
array
)
{
return
-
1
;
}
if
(
isEmptyW
orkspace
)
{
if
(
isEmptyW
indow
)
{
return
array
.
indexOf
(
workspaceIdentifier
);
}
...
...
@@ -140,7 +140,7 @@ export class BackupMainService implements IBackupMainService {
}
private
validateBackupWorkspaces
(
backups
:
IBackupWorkspacesFormat
):
void
{
const
staleBackupWorkspaces
:
{
workspaceIdentifier
:
string
;
backupPath
:
string
;
isEmptyW
orkspace
:
boolean
}[]
=
[];
const
staleBackupWorkspaces
:
{
workspaceIdentifier
:
string
;
backupPath
:
string
;
isEmptyW
indow
:
boolean
}[]
=
[];
// Validate Folder Workspaces
backups
.
folderWorkspaces
.
forEach
(
workspacePath
=>
{
...
...
@@ -151,13 +151,13 @@ export class BackupMainService implements IBackupMainService {
// If the folder has no backups, make sure to delete it
// If the folder has backups, but the target workspace is missing, convert backups to empty ones
if
(
!
hasBackups
||
missingWorkspace
)
{
staleBackupWorkspaces
.
push
({
workspaceIdentifier
:
workspacePath
,
backupPath
,
isEmptyW
orkspace
:
false
});
staleBackupWorkspaces
.
push
({
workspaceIdentifier
:
workspacePath
,
backupPath
,
isEmptyW
indow
:
false
});
if
(
missingWorkspace
)
{
const
identifier
=
this
.
pushBackupPathsSync
(
this
.
getRandomEmptyW
orkspace
Id
(),
true
/* is empty workspace */
);
const
newEmptyW
orkspace
BackupPath
=
path
.
join
(
path
.
dirname
(
backupPath
),
identifier
);
const
identifier
=
this
.
pushBackupPathsSync
(
this
.
getRandomEmptyW
indow
Id
(),
true
/* is empty workspace */
);
const
newEmptyW
indow
BackupPath
=
path
.
join
(
path
.
dirname
(
backupPath
),
identifier
);
try
{
fs
.
renameSync
(
backupPath
,
newEmptyW
orkspace
BackupPath
);
fs
.
renameSync
(
backupPath
,
newEmptyW
indow
BackupPath
);
}
catch
(
ex
)
{
console
.
error
(
`Backup: Could not rename backup folder for missing workspace:
${
ex
.
toString
()}
`
);
...
...
@@ -167,17 +167,17 @@ export class BackupMainService implements IBackupMainService {
}
});
// Validate Empty W
orkspace
s
// Validate Empty W
indow
s
backups
.
emptyWorkspaces
.
forEach
(
backupFolder
=>
{
const
backupPath
=
path
.
join
(
this
.
backupHome
,
backupFolder
);
if
(
!
this
.
hasBackupsSync
(
backupPath
))
{
staleBackupWorkspaces
.
push
({
workspaceIdentifier
:
backupFolder
,
backupPath
,
isEmptyW
orkspace
:
true
});
staleBackupWorkspaces
.
push
({
workspaceIdentifier
:
backupFolder
,
backupPath
,
isEmptyW
indow
:
true
});
}
});
// Clean up stale backups
staleBackupWorkspaces
.
forEach
(
staleBackupWorkspace
=>
{
const
{
backupPath
,
workspaceIdentifier
,
isEmptyW
orkspace
}
=
staleBackupWorkspace
;
const
{
backupPath
,
workspaceIdentifier
,
isEmptyW
indow
}
=
staleBackupWorkspace
;
try
{
extfs
.
delSync
(
backupPath
);
...
...
@@ -185,7 +185,7 @@ export class BackupMainService implements IBackupMainService {
console
.
error
(
`Backup: Could not delete stale backup:
${
ex
.
toString
()}
`
);
}
this
.
removeBackupPathSync
(
workspaceIdentifier
,
isEmptyW
orkspace
);
this
.
removeBackupPathSync
(
workspaceIdentifier
,
isEmptyW
indow
);
});
}
...
...
@@ -220,7 +220,7 @@ export class BackupMainService implements IBackupMainService {
}
}
private
getRandomEmptyW
orkspace
Id
():
string
{
private
getRandomEmptyW
indow
Id
():
string
{
return
(
Date
.
now
()
+
Math
.
round
(
Math
.
random
()
*
1000
)).
toString
();
}
...
...
src/vs/platform/backup/test/electron-main/backupMainService.test.ts
浏览文件 @
124f4c71
...
...
@@ -117,11 +117,11 @@ suite('BackupMainService', () => {
fs
.
mkdirSync
(
fileBackups
);
service
.
registerWindowForBackupsSync
(
1
,
false
,
null
,
fooFile
.
fsPath
);
assert
.
equal
(
service
.
getWorkspaceBackupPaths
().
length
,
1
);
assert
.
equal
(
service
.
getEmptyW
orkspace
BackupPaths
().
length
,
0
);
assert
.
equal
(
service
.
getEmptyW
indow
BackupPaths
().
length
,
0
);
fs
.
writeFileSync
(
path
.
join
(
fileBackups
,
'
backup.txt
'
),
''
);
service
.
loadSync
();
assert
.
equal
(
service
.
getWorkspaceBackupPaths
().
length
,
0
);
assert
.
equal
(
service
.
getEmptyW
orkspace
BackupPaths
().
length
,
1
);
assert
.
equal
(
service
.
getEmptyW
indow
BackupPaths
().
length
,
1
);
done
();
});
...
...
@@ -179,46 +179,46 @@ suite('BackupMainService', () => {
});
test
(
'
getEmptyWorkspaceBackupPaths() should return [] when workspaces.json doesn
\'
t exist
'
,
()
=>
{
assert
.
deepEqual
(
service
.
getEmptyW
orkspace
BackupPaths
(),
[]);
assert
.
deepEqual
(
service
.
getEmptyW
indow
BackupPaths
(),
[]);
});
test
(
'
getEmptyWorkspaceBackupPaths() should return [] when workspaces.json is not properly formed JSON
'
,
()
=>
{
fs
.
writeFileSync
(
backupWorkspacesPath
,
''
);
service
.
loadSync
();
assert
.
deepEqual
(
service
.
getEmptyW
orkspace
BackupPaths
(),
[]);
assert
.
deepEqual
(
service
.
getEmptyW
indow
BackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{]
'
);
service
.
loadSync
();
assert
.
deepEqual
(
service
.
getEmptyW
orkspace
BackupPaths
(),
[]);
assert
.
deepEqual
(
service
.
getEmptyW
indow
BackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
foo
'
);
service
.
loadSync
();
assert
.
deepEqual
(
service
.
getEmptyW
orkspace
BackupPaths
(),
[]);
assert
.
deepEqual
(
service
.
getEmptyW
indow
BackupPaths
(),
[]);
});
test
(
'
getEmptyWorkspaceBackupPaths() should return [] when folderWorkspaces in workspaces.json is absent
'
,
()
=>
{
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{}
'
);
service
.
loadSync
();
assert
.
deepEqual
(
service
.
getEmptyW
orkspace
BackupPaths
(),
[]);
assert
.
deepEqual
(
service
.
getEmptyW
indow
BackupPaths
(),
[]);
});
test
(
'
getEmptyWorkspaceBackupPaths() should return [] when folderWorkspaces in workspaces.json is not a string array
'
,
()
=>
{
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{"emptyWorkspaces":{}}
'
);
service
.
loadSync
();
assert
.
deepEqual
(
service
.
getEmptyW
orkspace
BackupPaths
(),
[]);
assert
.
deepEqual
(
service
.
getEmptyW
indow
BackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{"emptyWorkspaces":{"foo": ["bar"]}}
'
);
service
.
loadSync
();
assert
.
deepEqual
(
service
.
getEmptyW
orkspace
BackupPaths
(),
[]);
assert
.
deepEqual
(
service
.
getEmptyW
indow
BackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{"emptyWorkspaces":{"foo": []}}
'
);
service
.
loadSync
();
assert
.
deepEqual
(
service
.
getEmptyW
orkspace
BackupPaths
(),
[]);
assert
.
deepEqual
(
service
.
getEmptyW
indow
BackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{"emptyWorkspaces":{"foo": "bar"}}
'
);
service
.
loadSync
();
assert
.
deepEqual
(
service
.
getEmptyW
orkspace
BackupPaths
(),
[]);
assert
.
deepEqual
(
service
.
getEmptyW
indow
BackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{"emptyWorkspaces":"foo"}
'
);
service
.
loadSync
();
assert
.
deepEqual
(
service
.
getEmptyW
orkspace
BackupPaths
(),
[]);
assert
.
deepEqual
(
service
.
getEmptyW
indow
BackupPaths
(),
[]);
fs
.
writeFileSync
(
backupWorkspacesPath
,
'
{"emptyWorkspaces":1}
'
);
service
.
loadSync
();
assert
.
deepEqual
(
service
.
getEmptyW
orkspace
BackupPaths
(),
[]);
assert
.
deepEqual
(
service
.
getEmptyW
indow
BackupPaths
(),
[]);
});
});
...
...
src/vs/platform/history/electron-main/historyMainService.ts
浏览文件 @
124f4c71
...
...
@@ -34,7 +34,7 @@ export interface IHistoryMainService {
// methods
addToRecentPathsList
(
paths
:
{
path
:
string
;
isFile
?:
boolean
;
}[]):
void
;
getRecentPathsList
(
workspace
Path
?:
string
,
filesToOpen
?:
IPath
[]):
IRecentPathsList
;
getRecentPathsList
(
folder
Path
?:
string
,
filesToOpen
?:
IPath
[]):
IRecentPathsList
;
removeFromRecentPathsList
(
path
:
string
):
void
;
removeFromRecentPathsList
(
paths
:
string
[]):
void
;
clearRecentPathsList
():
void
;
...
...
@@ -130,7 +130,7 @@ export class HistoryMainService implements IHistoryMainService {
this
.
_onRecentPathsChange
.
fire
();
}
public
getRecentPathsList
(
workspace
Path
?:
string
,
filesToOpen
?:
IPath
[]):
IRecentPathsList
{
public
getRecentPathsList
(
folder
Path
?:
string
,
filesToOpen
?:
IPath
[]):
IRecentPathsList
{
let
files
:
string
[];
let
folders
:
string
[];
...
...
@@ -149,9 +149,9 @@ export class HistoryMainService implements IHistoryMainService {
files
.
unshift
(...
filesToOpen
.
map
(
f
=>
f
.
filePath
));
}
// Add current
workspace
path to beginning if set
if
(
workspace
Path
)
{
folders
.
unshift
(
workspace
Path
);
// Add current
folder
path to beginning if set
if
(
folder
Path
)
{
folders
.
unshift
(
folder
Path
);
}
// Clear those dupes
...
...
src/vs/platform/windows/common/windows.ts
浏览文件 @
124f4c71
...
...
@@ -204,8 +204,7 @@ export interface IWindowConfiguration extends ParsedArgs, IOpenFileRequest {
perfAppReady
?:
number
;
perfWindowLoadTime
?:
number
;
workspacePath
?:
string
;
folderPath
?:
string
;
backupPath
?:
string
;
nodeCachedDataDir
:
string
;
...
...
src/vs/platform/windows/electron-main/windows.ts
浏览文件 @
124f4c71
...
...
@@ -17,7 +17,7 @@ export interface ICodeWindow {
id
:
number
;
win
:
Electron
.
BrowserWindow
;
config
:
IWindowConfiguration
;
opened
Workspace
Path
:
string
;
opened
Folder
Path
:
string
;
lastFocusTime
:
number
;
readyState
:
ReadyState
;
...
...
src/vs/platform/windows/electron-main/windowsService.ts
浏览文件 @
124f4c71
...
...
@@ -160,7 +160,7 @@ export class WindowsService implements IWindowsService, IDisposable {
const
codeWindow
=
this
.
windowsMainService
.
getWindowById
(
windowId
);
if
(
codeWindow
)
{
const
{
files
,
folders
}
=
this
.
historyService
.
getRecentPathsList
(
codeWindow
.
config
.
workspace
Path
,
codeWindow
.
config
.
filesToOpen
);
const
{
files
,
folders
}
=
this
.
historyService
.
getRecentPathsList
(
codeWindow
.
config
.
folder
Path
,
codeWindow
.
config
.
filesToOpen
);
return
TPromise
.
as
({
files
,
folders
});
}
...
...
@@ -273,7 +273,7 @@ export class WindowsService implements IWindowsService, IDisposable {
getWindows
():
TPromise
<
{
id
:
number
;
path
:
string
;
title
:
string
;
}[]
>
{
const
windows
=
this
.
windowsMainService
.
getWindows
();
const
result
=
windows
.
map
(
w
=>
({
path
:
w
.
opened
Workspace
Path
,
title
:
w
.
win
.
getTitle
(),
id
:
w
.
id
,
filename
:
w
.
getRepresentedFilename
()
}));
const
result
=
windows
.
map
(
w
=>
({
path
:
w
.
opened
Folder
Path
,
title
:
w
.
win
.
getTitle
(),
id
:
w
.
id
,
filename
:
w
.
getRepresentedFilename
()
}));
return
TPromise
.
as
(
result
);
}
...
...
src/vs/workbench/electron-browser/main.ts
浏览文件 @
124f4c71
...
...
@@ -148,32 +148,32 @@ function legacyWorkspaceToMultiRootWorkspace(legacyWorkspace: LegacyWorkspace):
}
function
resolveLegacyWorkspace
(
configuration
:
IWindowConfiguration
):
TPromise
<
LegacyWorkspace
>
{
if
(
!
configuration
.
workspace
Path
)
{
if
(
!
configuration
.
folder
Path
)
{
return
TPromise
.
as
(
null
);
}
return
realpath
(
configuration
.
workspacePath
).
then
(
realWorkspace
Path
=>
{
return
realpath
(
configuration
.
folderPath
).
then
(
realFolder
Path
=>
{
// for some weird reason, node adds a trailing slash to UNC paths
// we never ever want trailing slashes as our workspace path unless
// someone opens root ("/").
// See also https://github.com/nodejs/io.js/issues/1765
if
(
paths
.
isUNC
(
real
WorkspacePath
)
&&
strings
.
endsWith
(
realWorkspace
Path
,
paths
.
nativeSep
))
{
real
WorkspacePath
=
strings
.
rtrim
(
realWorkspace
Path
,
paths
.
nativeSep
);
if
(
paths
.
isUNC
(
real
FolderPath
)
&&
strings
.
endsWith
(
realFolder
Path
,
paths
.
nativeSep
))
{
real
FolderPath
=
strings
.
rtrim
(
realFolder
Path
,
paths
.
nativeSep
);
}
// update config
configuration
.
workspacePath
=
realWorkspace
Path
;
configuration
.
folderPath
=
realFolder
Path
;
// resolve ctime of workspace
return
stat
(
real
Workspace
Path
).
then
(
folderStat
=>
new
LegacyWorkspace
(
uri
.
file
(
real
Workspace
Path
),
return
stat
(
real
Folder
Path
).
then
(
folderStat
=>
new
LegacyWorkspace
(
uri
.
file
(
real
Folder
Path
),
platform
.
isLinux
?
folderStat
.
ino
:
folderStat
.
birthtime
.
getTime
()
// On Linux, birthtime is ctime, so we cannot use it! We use the ino instead!
));
},
error
=>
{
errors
.
onUnexpectedError
(
error
);
return
null
;
// treat invalid paths as empty w
orkspace
return
null
;
// treat invalid paths as empty w
indow
});
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录