// *****************************************************************************
// Copyright (C) 2020 SAP SE or an SAP affiliate company 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 WITH Classpath-exception-2.0
// *****************************************************************************
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// some code is copied and modified from: https://github.com/microsoft/vscode/blob/573e5145ae3b50523925a6f6315d373e649d1b06/src/vs/base/common/linkedText.ts
import React = require('react');
import { inject, injectable } from 'inversify';
import { CommandRegistry } from '../../common';
import { ContextKeyService } from '../context-key-service';
import { TreeModel } from './tree-model';
import { TreeWidget } from './tree-widget';
import { WindowService } from '../window/window-service';
interface ViewWelcome {
readonly view: string;
readonly content: string;
readonly when?: string;
readonly order: number;
}
interface IItem {
readonly welcomeInfo: ViewWelcome;
visible: boolean;
}
interface ILink {
readonly label: string;
readonly href: string;
readonly title?: string;
}
type LinkedTextItem = string | ILink;
@injectable()
export class TreeViewWelcomeWidget extends TreeWidget {
@inject(CommandRegistry)
protected readonly commands: CommandRegistry;
@inject(ContextKeyService)
protected readonly contextService: ContextKeyService;
@inject(WindowService)
protected readonly windowService: WindowService;
protected viewWelcomeNodes: React.ReactNode[] = [];
protected defaultItem: IItem | undefined;
protected items: IItem[] = [];
get visibleItems(): ViewWelcome[] {
const visibleItems = this.items.filter(v => v.visible);
if (visibleItems.length && this.defaultItem) {
return [this.defaultItem.welcomeInfo];
}
return visibleItems.map(v => v.welcomeInfo);
}
protected override renderTree(model: TreeModel): React.ReactNode {
if (this.shouldShowWelcomeView() && this.visibleItems.length) {
return this.renderViewWelcome();
}
return super.renderTree(model);
}
protected shouldShowWelcomeView(): boolean {
return false;
}
protected renderViewWelcome(): React.ReactNode {
return (