-
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.
Add editor life cycle methods: open, save and close (#31)
eclipse-che/che#9435 add editor life cycle methods: open, save and close Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
- Loading branch information
Showing
10 changed files
with
979 additions
and
726 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
55 changes: 55 additions & 0 deletions
55
packages/plugin-ext/src/main/browser/editor/untitled-resource.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,55 @@ | ||
/* | ||
* 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 { ResourceResolver, Resource } from "@theia/core"; | ||
import URI from "@theia/core/lib/common/uri"; | ||
import { injectable } from "inversify"; | ||
import { Schemes } from "../../../common/uri-components"; | ||
import { UriComponents } from "../../../common/uri-components"; | ||
|
||
const resources = new Map<string, UntitledResource>(); | ||
let index = 0; | ||
@injectable() | ||
export class UntitledResourceResolver implements ResourceResolver { | ||
resolve(uri: URI): Resource | Promise<Resource> { | ||
if (uri.scheme === Schemes.Untitled) { | ||
return resources.get(uri.toString())!; | ||
} | ||
throw new Error(`scheme ${uri.scheme} is not '${Schemes.Untitled}'`); | ||
} | ||
} | ||
|
||
export class UntitledResource implements Resource { | ||
|
||
constructor(public uri: URI, private content?: string) { | ||
resources.set(this.uri.toString(), this); | ||
} | ||
|
||
readContents(options?: { encoding?: string | undefined; } | undefined): Promise<string> { | ||
return Promise.resolve(this.content ? this.content : ''); | ||
} | ||
|
||
dispose(): void { | ||
resources.delete(this.uri.toString()); | ||
} | ||
} | ||
|
||
export function createUntitledResource(content?: string, language?: string): UriComponents { | ||
let extension; | ||
if (language) { | ||
for (const lang of monaco.languages.getLanguages()) { | ||
if (lang.id === language) { | ||
if (lang.extensions) { | ||
extension = lang.extensions[0]; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
const resource = new UntitledResource(new URI().withScheme(Schemes.Untitled).withPath(`/Untitled-${index++}${extension ? extension : ''}`), content); | ||
return monaco.Uri.parse(resource.uri.toString()); | ||
} |
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
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
Oops, something went wrong.