Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add localization for empty navigator #12795

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/browser/widgets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './widget';
export * from './react-renderer';
export * from './react-widget';
export * from './extractable-widget';
export * from './static-html-renderer';
29 changes: 29 additions & 0 deletions packages/core/src/browser/widgets/static-html-renderer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// *****************************************************************************
// Copyright (C) 2023 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import * as React from 'react';

export interface StaticHtmlProps {
element: HTMLElement
}

export class StaticHtml extends React.Component<StaticHtmlProps> {

override render(): React.ReactNode {
return <div ref={element => element?.appendChild(this.props.element)} />;
}

}
22 changes: 10 additions & 12 deletions packages/navigator/src/browser/navigator-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { injectable, inject, postConstruct } from '@theia/core/shared/inversify'
import { Message } from '@theia/core/shared/@phosphor/messaging';
import URI from '@theia/core/lib/common/uri';
import { CommandService } from '@theia/core/lib/common';
import { Key, TreeModel, ContextMenuRenderer, ExpandableTreeNode, TreeProps, TreeNode } from '@theia/core/lib/browser';
import { Key, TreeModel, ContextMenuRenderer, ExpandableTreeNode, TreeProps, TreeNode, StaticHtml } from '@theia/core/lib/browser';
import { DirNode } from '@theia/filesystem/lib/browser';
import { WorkspaceService, WorkspaceCommands } from '@theia/workspace/lib/browser';
import { WorkspaceNode, WorkspaceRootNode } from './navigator-tree';
Expand All @@ -28,6 +28,7 @@ import * as React from '@theia/core/shared/react';
import { NavigatorContextKeyService } from './navigator-context-key-service';
import { nls } from '@theia/core/lib/common/nls';
import { AbstractNavigatorTreeWidget } from './abstract-navigator-tree-widget';
import { MarkdownRenderer } from '@theia/core/lib/browser/markdown-rendering/markdown-renderer';

export const FILE_NAVIGATOR_ID = 'files';
export const LABEL = nls.localizeByDefault('No Folder Opened');
Expand All @@ -39,6 +40,7 @@ export class FileNavigatorWidget extends AbstractNavigatorTreeWidget {
@inject(CommandService) protected readonly commandService: CommandService;
@inject(NavigatorContextKeyService) protected readonly contextKeyService: NavigatorContextKeyService;
@inject(WorkspaceService) protected readonly workspaceService: WorkspaceService;
@inject(MarkdownRenderer) protected readonly markdownRenderer: MarkdownRenderer;

constructor(
@inject(TreeProps) props: TreeProps,
Expand Down Expand Up @@ -175,17 +177,13 @@ export class FileNavigatorWidget extends AbstractNavigatorTreeWidget {
* Instead of displaying an empty navigator tree, this will show a button to add more folders.
*/
protected renderEmptyMultiRootWorkspace(): React.ReactNode {
// TODO: @msujew Implement a markdown renderer and use vscode/explorerViewlet/noFolderHelp
return <div className='theia-navigator-container'>
<div className='center'>You have not yet added a folder to the workspace.</div>
<div className='open-workspace-button-container'>
<button className='theia-button open-workspace-button' title='Add a folder to your workspace'
onClick={this.addFolder}
onKeyUp={this.keyUpHandler}>
Add Folder
</button>
</div>
</div>;
const openFolder = nls.localizeByDefault('Open Folder');
const addRootFolderButton = `[${openFolder}](command:${WorkspaceCommands.ADD_FOLDER.id})`;
const content = this.markdownRenderer.render({
value: nls.localizeByDefault('You have not yet added a folder to the workspace.\n{0}', addRootFolderButton),
isTrusted: true
});
return <StaticHtml element={content.element} />;
}

protected isEmptyMultiRootWorkspace(model: TreeModel): boolean {
Expand Down