Skip to content

Commit

Permalink
feat: implement the base launch UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricbet committed Apr 11, 2023
1 parent 9dda754 commit 80e38a7
Show file tree
Hide file tree
Showing 13 changed files with 338 additions and 22 deletions.
16 changes: 14 additions & 2 deletions packages/components/src/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import classNames from 'classnames';
import React from 'react';

import { Dropdown } from '../dropdown';
import { Placement } from '../dropdown/dropdown';
import { Icon, DefaultIconKeys, getIcon } from '../icon';
import './style.less';

Expand All @@ -27,6 +28,8 @@ interface MoreActionProps {
more?: boolean;
moreIconClass?: string;
menu?: React.ReactNode;
moreVisible?: boolean;
placement?: Placement;
onVisibleChange?: (visible: boolean) => void;
}

Expand Down Expand Up @@ -95,6 +98,8 @@ export const Button = React.memo(
more,
moreIconClass,
menu,
moreVisible,
placement,
title,
onVisibleChange,
...otherProps
Expand Down Expand Up @@ -127,9 +132,16 @@ export const Button = React.memo(

const iconNode = iconClass ? <Icon iconClass={iconClass} disabled={disabled} /> : null;

if (more) {
if (menu) {
return (
<Dropdown className={'kt-menu'} overlay={menu} trigger={['click']} onVisibleChange={onVisibleChange}>
<Dropdown
visible={moreVisible}
className={'kt-menu'}
overlay={menu}
trigger={['click']}
onVisibleChange={onVisibleChange}
placement={placement}
>
<button
{...otherProps}
disabled={disabled}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { tuple } from '../utils/type';
import { warning } from '../utils/warning';

const Placements = tuple('topLeft', 'topCenter', 'topRight', 'bottomLeft', 'bottomCenter', 'bottomRight');
type Placement = (typeof Placements)[number];
export type Placement = (typeof Placements)[number];

type OverlayFunc = () => React.ReactNode;

Expand Down
12 changes: 12 additions & 0 deletions packages/core-browser/src/menu/next/menu.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ export class SeparatorMenuItemNode extends MenuNode {
}
}

// 只展示 label 的 menu node
export class LabelMenuItemNode extends MenuNode {
static readonly ID = 'menu.item.node.label';

constructor(label: string) {
super({
id: LabelMenuItemNode.ID,
label,
});
}
}

export interface IMenu extends IDisposable {
/**
* menu-id
Expand Down
2 changes: 1 addition & 1 deletion packages/debug/src/browser/debug-configuration-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class DebugConfigurationManager {
if (!uri) {
uri = await this.doCreate(model);
}
return this.workbenchEditorService.open(uri, {
return this.workbenchEditorService.open(uri.withScheme('launch_view_scheme'), {
disableNavigate: true,
});
}
Expand Down
6 changes: 3 additions & 3 deletions packages/debug/src/browser/debug-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import * as monaco from '@opensumi/monaco-editor-core/esm/vs/editor/editor.api';

import {
IDebugSessionManager,
launchSchemaUri,
DEBUG_CONTAINER_ID,
DEBUG_WATCH_ID,
DEBUG_VARIABLES_ID,
Expand All @@ -53,6 +52,7 @@ import {
TSourceBrekpointProperties,
DEBUG_COMMANDS,
IDebugModelManager,
launchDefaultSchemaUri,
} from '../common';

import {
Expand All @@ -67,7 +67,7 @@ import { DebugContextKey } from './contextkeys/debug-contextkey.service';
import { DebugConfigurationManager } from './debug-configuration-manager';
import { DebugPreferences, debugPreferencesSchema } from './debug-preferences';
import { DebugProgressService } from './debug-progress.service';
import { launchSchema } from './debug-schema-updater';
import { launchSchema } from './debug-schema-manager';
import { DebugSession } from './debug-session';
import { DebugSessionManager } from './debug-session-manager';
import { DebugEditorContribution } from './editor/debug-editor-contribution';
Expand Down Expand Up @@ -610,7 +610,7 @@ export class DebugContribution
}

registerSchema(registry: IJSONSchemaRegistry) {
registry.registerSchema(`${launchSchemaUri}/default`, launchSchema, ['launch.json']);
registry.registerSchema(launchDefaultSchemaUri, launchSchema, ['launch.json']);
}

registerKeybindings(keybindings: KeybindingRegistry) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Injectable, Autowired } from '@opensumi/di';
import { objects, IJSONSchema, IJSONSchemaRegistry } from '@opensumi/ide-core-browser';

import { launchSchemaUri } from '../common';
import { launchExtensionSchemaUri, launchSchemaUri } from '../common';
import { DebugServer, IDebugServer } from '../common/debug-service';

import { DebugConfigurationManager } from './debug-configuration-manager';

const { deepClone } = objects;

@Injectable()
export class DebugSchemaUpdater {
export class DebugSchemaManager {
@Autowired(IDebugServer)
protected readonly debug: DebugServer;

Expand All @@ -19,7 +19,7 @@ export class DebugSchemaUpdater {
@Autowired(DebugConfigurationManager)
private config: DebugConfigurationManager;

async update(): Promise<void> {
public async update(): Promise<void> {
const debuggers = this.config.getDebuggers();
const schema = { ...deepClone(launchSchema) };
const items = schema!.properties!.configurations.items as IJSONSchema;
Expand All @@ -38,7 +38,8 @@ export class DebugSchemaUpdater {
items.defaultSnippets.push(...configurationSnippets);
}
}
this.schemaRegistry.registerSchema(`${launchSchemaUri}/extension`, schema, ['launch.json']);

this.schemaRegistry.registerSchema(launchExtensionSchemaUri, schema, ['launch.json']);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,80 @@
import { PreferenceContribution, PreferenceSchema, Domain, PreferenceConfiguration } from '@opensumi/ide-core-browser';
import { Autowired, Injectable } from '@opensumi/di';
import {
PreferenceContribution,
PreferenceSchema,
Domain,
PreferenceConfiguration,
URI,
MaybePromise,
localize,
getIcon,
} from '@opensumi/ide-core-browser';
import {
BrowserEditorContribution,
EditorComponentRegistry,
EditorOpenType,
IResource,
IResourceProvider,
ResourceService,
} from '@opensumi/ide-editor/lib/browser';

import { launchPreferencesSchema } from './launch-preferences';
import { LaunchViewContainer } from './launch.view';

const LAUNCH_VIEW_SCHEME = 'launch_view_scheme';
const LAUNCH_VIEW_COMPONENT_ID = 'launch-view';

@Injectable()
export class LaunchResourceProvider implements IResourceProvider {
readonly scheme: string = LAUNCH_VIEW_SCHEME;

provideResource(uri: URI): MaybePromise<IResource<any>> {
// 获取文件类型 getFileType: (path: string) => string
return {
supportsRevive: true,
name: localize('menu-bar.title.debug'),
icon: getIcon('debug'),
uri,
};
}

provideResourceSubname(resource: IResource, groupResources: IResource[]): string | null {
return null;
}

async shouldCloseResource(resource: IResource, openedResources: IResource[][]): Promise<boolean> {
return true;
}
}

@Domain(PreferenceContribution, PreferenceConfiguration, BrowserEditorContribution)
export class LaunchPreferencesContribution
implements PreferenceContribution, PreferenceConfiguration, BrowserEditorContribution
{
@Autowired(LaunchResourceProvider)
private readonly prefResourceProvider: LaunchResourceProvider;

@Domain(PreferenceContribution, PreferenceConfiguration)
export class LaunchPreferencesContribution implements PreferenceContribution, PreferenceConfiguration {
schema: PreferenceSchema = launchPreferencesSchema;
name = 'launch';

registerResource(resourceService: ResourceService): void {
resourceService.registerResourceProvider(this.prefResourceProvider);
}

registerEditorComponent(editorComponentRegistry: EditorComponentRegistry): void {
editorComponentRegistry.registerEditorComponent({
component: LaunchViewContainer,
uid: LAUNCH_VIEW_COMPONENT_ID,
scheme: LAUNCH_VIEW_SCHEME,
});

editorComponentRegistry.registerEditorComponentResolver(LAUNCH_VIEW_SCHEME, (_, __, resolve) => {
resolve([
{
type: EditorOpenType.component,
componentId: LAUNCH_VIEW_COMPONENT_ID,
},
]);
});
}
}
91 changes: 91 additions & 0 deletions packages/debug/src/browser/preferences/launch.module.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
@base-font-size: 14px;
@small-base-font-size: 12px;

.launch_container {
height: 100%;
font-size: @base-font-size;
overflow: hidden;
padding: 16px 16px 0 16px;
box-sizing: border-box;
min-width: 500px;

.launch_panel {
height: 100%;
margin-top: 8px;

.launch_indexes_container {
height: 100%;
margin-right: 16px;
.not_configuration_content {
text-align: center;
font-size: @small-base-font-size;
}
.configuration_items_box {
height: calc(100% - 40px) !important;
.configuration_item {
height: 22px;
display: flex;
align-items: center;
cursor: pointer;
flex-direction: row;
padding: 4px;
&:hover {
background: var(--list-hoverBackground);
color: var(--list-hoverForeground);
}
&.selected {
background: var(--list-activeSelectionBackground);
color: var(--list-activeSelectionForeground);
}

.configuration_wrapper {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 1;
}

.configuration_description {
display: inline;
font-size: 12px;
}
}
}
.foot_box {
position: relative;
z-index: 1;
.button {
width: 100%;
}
}
}
}
}

.devider {
box-sizing: border-box;
font-size: 14px;
font-variant: tabular-nums;
list-style: none;
font-feature-settings: 'tnum';
position: relative;
margin: 0 3px;
display: inline-block;
vertical-align: middle;
&:after {
content: '';
display: block;
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
border-top: 0;
border-left: 1px solid var(--editorGroup-border);
pointer-events: none;
transform: translateX(1.5px);
}
&:hover:after {
border-color: transparent;
}
}
Loading

0 comments on commit 80e38a7

Please sign in to comment.