forked from eclipse-cdt-cloud/vscode-peripheral-inspector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more edit controls for specific types
- Enumeration Dropdown for fields with enumeration values - Boolean Checkbox edit for non-enums of width 1 Closes eclipse-cdt-cloud#22
- Loading branch information
1 parent
53bb8fe
commit f6ba344
Showing
15 changed files
with
351 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2024 Arm Limited and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the MIT License as outlined in the LICENSE File | ||
********************************************************************************/ | ||
|
||
import { ReactWrapperProps } from '@microsoft/fast-react-wrapper'; | ||
import { Checkbox } from '@vscode/webview-ui-toolkit'; | ||
import { VSCodeCheckbox } from '@vscode/webview-ui-toolkit/react'; | ||
import React from 'react'; | ||
import { CDTTreeItem, CDTTreeTableColumn, EditableBooleanData } from '../types'; | ||
import { AsEditable, AsTreeTableCell, EditableComponentProps, EditableComponentRef } from './TreeTableCell'; | ||
import './boolean-cell.css'; | ||
|
||
export type VSCodeCheckboxComponent = React.Component<ReactWrapperProps<Checkbox, { onChange: unknown; onInput: unknown; }>, unknown, unknown> & Checkbox; | ||
|
||
export interface BooleanCellProps extends EditableComponentProps { | ||
row: CDTTreeItem; | ||
cell: CDTTreeTableColumn; | ||
data: EditableBooleanData; | ||
} | ||
|
||
const BooleanCellComponent = React.forwardRef<EditableComponentRef, BooleanCellProps>(({ row, data, ...props }, ref) => { | ||
const checkboxRef = React.useRef<VSCodeCheckboxComponent>(null); | ||
|
||
React.useImperativeHandle(ref, () => ({ | ||
focus: () => checkboxRef.current?.focus() | ||
})); | ||
|
||
const onChange = () => { | ||
const value = checkboxRef.current?.checked ? '1' : '0'; | ||
props.onSubmitValue(value); | ||
}; | ||
|
||
const onKeyDown = (event: React.KeyboardEvent) => { | ||
if (event.key === 'Escape') { | ||
event.stopPropagation(); | ||
props.onCancelEdit(); | ||
} | ||
}; | ||
|
||
const onBlur = () => { | ||
props.onCancelEdit(); | ||
}; | ||
|
||
return <VSCodeCheckbox | ||
ref={checkboxRef} | ||
className='boolean-cell' | ||
id={`${row.id}-boolean-field`} | ||
checked={data.value === '1'} | ||
onChange={onChange} | ||
onKeyDown={onKeyDown} | ||
onClick={event => event.stopPropagation()} | ||
onBlur={onBlur} | ||
/>; | ||
}); | ||
|
||
export const BooleanCell = AsEditable(AsTreeTableCell(BooleanCellComponent)); |
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,75 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2024 Arm Limited and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the MIT License as outlined in the LICENSE File | ||
********************************************************************************/ | ||
|
||
import { Dropdown, DropdownChangeEvent, DropdownProps } from 'primereact/dropdown'; | ||
import { SelectItem } from 'primereact/selectitem'; | ||
import React from 'react'; | ||
import { CDTTreeItem, CDTTreeTableColumn, EditableEnumData } from '../types'; | ||
import { EditableComponentProps, EditableComponentRef, AsEditable, AsTreeTableCell } from './TreeTableCell'; | ||
import './enum-cell.css'; | ||
import { ChevronDownIcon } from 'primereact/icons/chevrondown'; | ||
|
||
export interface EnumCellProps extends EditableComponentProps { | ||
row: CDTTreeItem; | ||
cell: CDTTreeTableColumn; | ||
data: EditableEnumData; | ||
} | ||
|
||
export type FooterProps = DropdownProps & { focusedOptionIndex?: number }; | ||
|
||
const EnumCellComponent = React.forwardRef<EditableComponentRef, EnumCellProps>(({ row, data, ...props }, ref) => { | ||
const [options] = React.useState<SelectItem[]>(data.options.map(option => ({ label: option.value, title: option.detail }))); | ||
const dropdownRef = React.useRef<Dropdown>(null); | ||
|
||
React.useImperativeHandle(ref, () => ({ | ||
focus: () => dropdownRef.current?.focus() | ||
})); | ||
|
||
const onChange = (event: DropdownChangeEvent) => { | ||
const item = event.value as SelectItem; | ||
if (item.label) { | ||
props.onSubmitValue(item.label); | ||
} | ||
}; | ||
|
||
const onKeyDown = (event: React.KeyboardEvent) => { | ||
if (event.key === 'Escape') { | ||
event.stopPropagation(); | ||
props.onCancelEdit(); | ||
} | ||
}; | ||
|
||
const detailPanel = (params: DropdownProps) => { | ||
const props = params as FooterProps; | ||
const detail = options[props?.focusedOptionIndex ?? - 1]?.title; | ||
return detail; | ||
}; | ||
|
||
const onBlur = () => { | ||
if (!dropdownRef.current?.getOverlay()?.contains(document.activeElement) && !dropdownRef.current?.getElement()?.contains(document.activeElement)) { | ||
// focus lost and overlay/popup is not visible | ||
// props.onCancelEdit(); | ||
} | ||
}; | ||
|
||
return <Dropdown | ||
ref={dropdownRef} | ||
options={options} | ||
className='enum-cell vscode-dropdown' | ||
id={`${row.id}-enum-field`} | ||
value={options.find(option => option.label === data.value)} | ||
onChange={onChange} | ||
onKeyDown={onKeyDown} | ||
onClick={event => event.stopPropagation()} | ||
onBlur={onBlur} | ||
onHide={props.onCancelEdit} | ||
panelFooterTemplate={detailPanel} | ||
dropdownIcon={(opts) => { return <ChevronDownIcon {...opts.iconProps} ref={null} scale={0.7} />; }} | ||
/>; | ||
}); | ||
|
||
export const EnumCell = AsEditable(AsTreeTableCell(EnumCellComponent)); |
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,3 @@ | ||
vscode-checkbox { | ||
margin: 0px; | ||
} |
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,112 @@ | ||
/* Base Dropdown Styling */ | ||
.p-dropdown { | ||
background-color: var(--vscode-settings-dropdownBackground); | ||
color: var(--vscode-settings-dropdownForeground); | ||
border: 1px solid var(--vscode-settings-dropdownBorder); | ||
border-radius: var(--corner-radius); | ||
font-family: var(--vscode-font-family); | ||
width: 100%; | ||
height: 22px; | ||
box-sizing: border-box; | ||
font-size: var(--vscode-font-size); | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.p-dropdown-label { | ||
padding: 2px 6px; | ||
font-size: var(--vscode-font-size); | ||
} | ||
|
||
/* Dropdown Panel Styling */ | ||
.p-dropdown-panel { | ||
background-color: var(--vscode-settings-dropdownBackground); | ||
border: 1px solid var(--vscode-settings-focusedRowBorder); | ||
border-radius: 0; | ||
width: min-content; | ||
font-size: var(--vscode-font-size); | ||
line-height: 1.4em; | ||
} | ||
|
||
/* Dropdown Items Styling */ | ||
.p-dropdown-item { | ||
padding: 0 6px; | ||
display: flex; | ||
align-items: center; | ||
color: var(--vscode-settings-dropdownForeground); | ||
background-color: var(--vscode-settings-dropdownBackground); | ||
height: 22px; | ||
} | ||
|
||
.p-dropdown-item:hover { | ||
background-color: var(--vscode-list-activeSelectionBackground); | ||
} | ||
|
||
.p-dropdown-item.p-highlight { | ||
background-color: var(--vscode-settings-focusedRowBackground) !important; | ||
} | ||
|
||
.p-dropdown-item.p-highlight:hover { | ||
background-color: var(--vscode-list-activeSelectionBackground) !important; | ||
} | ||
|
||
/* Disabled Dropdown Item Styling */ | ||
.p-dropdown-item.p-disabled { | ||
color: var(--vscode-settings-dropdownForeground); | ||
background-color: var(--vscode-settings-dropdownBackground); | ||
} | ||
|
||
/* Adjust Arrow Icon */ | ||
.p-dropdown-trigger { | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 0 6px; | ||
width: auto; | ||
color: var(--vscode-settings-dropdownForeground); | ||
} | ||
|
||
.p-dropdown-trigger:hover { | ||
color: #ffffff; | ||
} | ||
|
||
.p-dropdown .p-dropdown-clearable .p-dropdown-trigger { | ||
padding: 0 6px; | ||
} | ||
|
||
.p-dropdown-trigger .p-icon.p-dropdown-trigger-icon { | ||
transform: scale(0.7, 0.7); | ||
} | ||
|
||
/* Dropdown Footer Styling */ | ||
.p-dropdown-footer { | ||
padding: 4px 6px; | ||
background-color: var(--vscode-settings-dropdownBackground); | ||
color: var(--vscode-settings-dropdownForeground); | ||
border-top: 1px solid var(--vscode-settings-dropdownBorder); | ||
} | ||
|
||
.p-dropdown-footer:first-letter { | ||
text-transform: capitalize; | ||
} | ||
|
||
/* Ensure .p-dropdown-items has no padding */ | ||
.p-dropdown-items { | ||
padding: 0; | ||
} | ||
|
||
/* Focus State */ | ||
.p-focus .p-dropdown, | ||
.p-inputwrapper-focus, | ||
.p-dropdown:focus { | ||
border-color: var(--vscode-settings-focusedRowBorder); | ||
box-shadow: 0 0 0 1px var(--vscode-settings-focusedRowBorder); | ||
} | ||
|
||
.p-focus .p-dropdown-panel, | ||
.p-dropdown-panel:focus { | ||
border-color: var(--vscode-settings-focusedRowBorder); | ||
box-shadow: 0 0 0 1px var(--vscode-settings-focusedRowBorder); | ||
} | ||
|
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.