-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vitaliy Gulyy <vgulyy@redhat.com>
- Loading branch information
1 parent
aa7754c
commit c53854c
Showing
6 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import { WorkspaceExt, MAIN_RPC_CONTEXT } from "../../api/plugin-api"; | ||
import { RPCProtocol } from "../../api/rpc-protocol"; | ||
import { WorkspaceService } from "@theia/workspace/lib/browser"; | ||
import Uri from 'vscode-uri'; | ||
import { WorkspaceFoldersChangeEvent, WorkspaceFolder } from "@theia/plugin"; | ||
import { Path } from "@theia/core/lib/common/path"; | ||
|
||
export class WorkspaceMain { | ||
|
||
private proxy: WorkspaceExt; | ||
|
||
private workspaceRoot: Uri | undefined; | ||
|
||
constructor(rpc: RPCProtocol, workspaceService: WorkspaceService) { | ||
this.proxy = rpc.getProxy(MAIN_RPC_CONTEXT.WORKSPACE_EXT); | ||
|
||
workspaceService.root.then((root) => { | ||
if (root) { | ||
this.workspaceRoot = Uri.parse(root.uri); | ||
const workspacePath = new Path(this.workspaceRoot.path); | ||
|
||
const folder: WorkspaceFolder = { | ||
uri: this.workspaceRoot, | ||
name: workspacePath.base, | ||
index: 0 | ||
} as WorkspaceFolder; | ||
|
||
this.proxy.$onWorkspaceFoldersChanged({ | ||
added: [folder], | ||
removed: [] | ||
} as WorkspaceFoldersChangeEvent); | ||
} else { | ||
this.proxy.$onWorkspaceFoldersChanged({ | ||
added: [], | ||
removed: [] | ||
} as WorkspaceFoldersChangeEvent); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import { WorkspaceFolder, WorkspaceFoldersChangeEvent } from "@theia/plugin"; | ||
import { Event, Emitter } from "@theia/core/lib/common/event"; | ||
import { WorkspaceExt } from "../api/plugin-api"; | ||
import { RPCProtocol } from "../api/rpc-protocol"; | ||
import { Path } from "@theia/core/lib/common/path"; | ||
|
||
export class WorkspaceExtImpl implements WorkspaceExt { | ||
|
||
private workspaceFoldersChangedEmitter = new Emitter<WorkspaceFoldersChangeEvent>(); | ||
public readonly onDidChangeWorkspaceFolders: Event<WorkspaceFoldersChangeEvent> = this.workspaceFoldersChangedEmitter.event; | ||
|
||
private folders: WorkspaceFolder[] | undefined; | ||
|
||
constructor(rpc: RPCProtocol) { | ||
} | ||
|
||
get workspaceFolders(): WorkspaceFolder[] | undefined { | ||
return this.folders; | ||
} | ||
|
||
get rootPath(): string | undefined { | ||
if (this.workspaceFolders) { | ||
return this.workspaceFolders[0].uri.path; | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
get name(): string | undefined { | ||
if (this.workspaceFolders) { | ||
return new Path(this.workspaceFolders[0].uri.path).base; | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
$onWorkspaceFoldersChanged(event: WorkspaceFoldersChangeEvent): void { | ||
this.folders = event.added; | ||
this.workspaceFoldersChangedEmitter.fire(event); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters