This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
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 <[email protected]>
- Loading branch information
1 parent
7d9b311
commit 524ff4c
Showing
17 changed files
with
371 additions
and
221 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
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
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,26 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2021 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
***********************************************************************/ | ||
|
||
import * as theia from '@theia/plugin'; | ||
|
||
export namespace Commands { | ||
export const SHOW_WELCOME: theia.CommandDescription = { | ||
id: 'welcome:show_welcome', | ||
label: 'Welcome: Show Welcome...', | ||
}; | ||
|
||
export const ENABLE_WELCOME: theia.CommandDescription = { | ||
id: 'welcome:enable', | ||
}; | ||
|
||
export const DISABLE_WELCOME: theia.CommandDescription = { | ||
id: 'welcome:disable', | ||
}; | ||
} |
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,39 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2021 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
***********************************************************************/ | ||
|
||
import * as che from '@eclipse-che/plugin'; | ||
|
||
export const WELCOME_ENABLED = 'extensions.welcome'; | ||
|
||
export async function isWelcomeEnabled(): Promise<boolean> { | ||
const workspace = await che.workspace.getCurrentWorkspace(); | ||
// always has a devfile now | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const devfile = workspace.devfile!; | ||
const attributes = devfile.attributes || {}; | ||
const welcome = attributes[WELCOME_ENABLED] || 'true'; | ||
return welcome !== 'false'; | ||
} | ||
|
||
export async function enableWelcome(enable: boolean): Promise<void> { | ||
const workspace = await che.workspace.getCurrentWorkspace(); | ||
// always has a devfile now | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const devfile = workspace.devfile!; | ||
devfile.attributes = devfile.attributes || {}; | ||
devfile.attributes[WELCOME_ENABLED] = '' + enable; | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
await che.workspace.update(workspace.id!, workspace); | ||
} | ||
|
||
export async function isMultiroot(): Promise<boolean> { | ||
const devfile = await che.devfile.get(); | ||
return devfile.metadata?.attributes?.multiRoot !== 'off'; | ||
} |
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,82 @@ | ||
/********************************************************************** | ||
* Copyright (c) 2021 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
***********************************************************************/ | ||
|
||
import * as fs from 'fs-extra'; | ||
import * as path from 'path'; | ||
import * as theia from '@theia/plugin'; | ||
|
||
import { isMultiroot } from './devfile'; | ||
|
||
export class Readme { | ||
processed: string[] = []; | ||
|
||
constructor(protected context: theia.PluginContext) {} | ||
|
||
async seekAndOpen(): Promise<void> { | ||
if (await isMultiroot()) { | ||
this.context.subscriptions.push( | ||
theia.workspace.onDidChangeWorkspaceFolders( | ||
event => this.handleReadmeFiles(event.added), | ||
undefined, | ||
this.context.subscriptions | ||
) | ||
); | ||
} else { | ||
const workspacePlugin = theia.plugins.getPlugin('@eclipse-che.workspace-plugin'); | ||
if (workspacePlugin && workspacePlugin.exports) { | ||
this.context.subscriptions.push( | ||
workspacePlugin.exports.onDidCloneSources( | ||
() => this.handleReadmeFiles(), | ||
undefined, | ||
this.context.subscriptions | ||
) | ||
); | ||
} else { | ||
this.handleReadmeFiles(); | ||
} | ||
} | ||
} | ||
|
||
async handleReadmeFiles(roots?: theia.WorkspaceFolder[]): Promise<void> { | ||
roots = roots ? roots : theia.workspace.workspaceFolders; | ||
if (!roots || roots.length < 1) { | ||
return; | ||
} | ||
|
||
for (const root of roots) { | ||
this.openReadme(root.uri.fsPath); | ||
} | ||
} | ||
|
||
async openReadme(projectPath: string): Promise<void> { | ||
if (this.processed.some(value => value === projectPath)) { | ||
return; | ||
} | ||
|
||
this.processed.push(projectPath); | ||
|
||
const readmePath = path.join(projectPath, 'README.md'); | ||
if (await fs.pathExists(projectPath)) { | ||
const openPath = theia.Uri.parse(`file://${readmePath}?open-handler=code-editor-preview`); | ||
try { | ||
const doc = await theia.workspace.openTextDocument(openPath); | ||
if (doc) { | ||
await theia.window.showTextDocument(doc); | ||
} | ||
} catch (err) { | ||
// Ignore the error. | ||
// `theia.window.showTextDocument` throws an error with message `Failed to show text document` | ||
// But works as expected. | ||
// It's because `?open-handler=code-editor-preview` was added at the end of the URI | ||
// to open preview instead of the editor | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.