forked from eclipse-theia/theia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extension-manager] preserve extension widgets between sessions
Signed-off-by: Anton Kosiakov <anton.kosyakov@typefox.io>
- Loading branch information
Showing
10 changed files
with
159 additions
and
90 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
49 changes: 0 additions & 49 deletions
49
packages/extension-manager/src/browser/extension-detail-widget-service.ts
This file was deleted.
Oops, something went wrong.
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
44 changes: 44 additions & 0 deletions
44
packages/extension-manager/src/browser/extension-open-handler.ts
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,44 @@ | ||
/* | ||
* Copyright (C) 2017 TypeFox 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 { injectable, inject } from "inversify"; | ||
import URI from "@theia/core/lib/common/uri"; | ||
import { OpenHandler, WidgetManager, FrontendApplication } from "@theia/core/lib/browser"; | ||
import { ExtensionUri } from "./extension-uri"; | ||
import { ExtensionWidgetOptions } from './extension-widget-factory'; | ||
import { ExtensionDetailWidget } from './extension-detail-widget'; | ||
|
||
@injectable() | ||
export class ExtensionOpenHandler implements OpenHandler { | ||
|
||
readonly id = ExtensionUri.scheme; | ||
|
||
constructor( | ||
@inject(FrontendApplication) protected readonly app: FrontendApplication, | ||
@inject(WidgetManager) protected readonly widgetManager: WidgetManager | ||
) { } | ||
|
||
canHandle(uri: URI): number { | ||
try { | ||
ExtensionUri.toExtensionName(uri); | ||
return 500; | ||
} catch { | ||
return 0; | ||
} | ||
} | ||
|
||
async open(uri: URI): Promise<ExtensionDetailWidget> { | ||
const options: ExtensionWidgetOptions = { | ||
name: ExtensionUri.toExtensionName(uri) | ||
}; | ||
const widget = await this.widgetManager.getOrCreateWidget<ExtensionDetailWidget>(ExtensionUri.scheme, options); | ||
this.app.shell.addToMainArea(widget); | ||
this.app.shell.activateMain(widget.id); | ||
return widget; | ||
} | ||
|
||
} |
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,21 @@ | ||
/* | ||
* Copyright (C) 2017 TypeFox 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 URI from "@theia/core/lib/common/uri"; | ||
|
||
export namespace ExtensionUri { | ||
export const scheme = 'extension'; | ||
export function toUri(extensionName: string): URI { | ||
return new URI('').withScheme(scheme).withFragment(extensionName); | ||
} | ||
export function toExtensionName(uri: URI): string { | ||
if (uri.scheme === scheme) { | ||
return uri.fragment; | ||
} | ||
throw new Error('The given uri is not an extension URI, uri: ' + uri); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/extension-manager/src/browser/extension-widget-factory.ts
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,37 @@ | ||
/* | ||
* Copyright (C) 2017 TypeFox 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 { injectable, inject } from "inversify"; | ||
import { WidgetFactory, FrontendApplication } from "@theia/core/lib/browser"; | ||
import { ExtensionManager } from '../common'; | ||
import { ExtensionUri } from "./extension-uri"; | ||
import { ExtensionDetailWidget } from './extension-detail-widget'; | ||
|
||
export class ExtensionWidgetOptions { | ||
readonly name: string; | ||
} | ||
|
||
@injectable() | ||
export class ExtensionWidgetFactory implements WidgetFactory { | ||
|
||
readonly id = ExtensionUri.scheme; | ||
|
||
constructor( | ||
@inject(FrontendApplication) protected readonly app: FrontendApplication, | ||
@inject(ExtensionManager) protected readonly extensionManager: ExtensionManager | ||
) { } | ||
|
||
async createWidget(options: ExtensionWidgetOptions): Promise<ExtensionDetailWidget> { | ||
const extension = await this.extensionManager.resolve(options.name); | ||
const widget = new ExtensionDetailWidget(extension); | ||
widget.id = 'extension:' + options.name; | ||
widget.title.closable = true; | ||
widget.title.label = options.name; | ||
return widget; | ||
} | ||
|
||
} |
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