This is an automated email from the ASF dual-hosted git repository. jhorvath pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
commit a91aa552ce9f91f4a392a2652f120f1739686cb0 Author: Ondřej Douda <ondrej.do...@oracle.com> AuthorDate: Thu Jun 22 14:35:26 2023 +0200 Fields names changes. --- .../vscode/src/propertiesView/controlTypes.ts | 44 +++++++++++----------- .../src/propertiesView/propertiesHtmlBuilder.ts | 36 +++++++++--------- .../vscode/src/propertiesView/propertiesView.ts | 22 ++++------- .../vscode/src/propertiesView/script.ts | 10 ++--- 4 files changed, 54 insertions(+), 58 deletions(-) diff --git a/java/java.lsp.server/vscode/src/propertiesView/controlTypes.ts b/java/java.lsp.server/vscode/src/propertiesView/controlTypes.ts index e6561aa4a5..9e1be2dcd3 100644 --- a/java/java.lsp.server/vscode/src/propertiesView/controlTypes.ts +++ b/java/java.lsp.server/vscode/src/propertiesView/controlTypes.ts @@ -8,40 +8,42 @@ import { EnumType, Typed } from "../typesUtil"; export type ID = number; -export const PropTypes = { +export const PropertyTypes = { String: "java.lang.String", Boolean: "java.lang.Boolean", Properties: "java.util.Properties", Unknown: "unknown", } as const;// unfortunate but necessary duplication -export type PropTypeMap = { +export type PropertyTypeMap = { "java.lang.String": string; "java.lang.Boolean": boolean; "java.util.Properties": Record<string, string>; "unknown": unknown }; -export type Property<T extends keyof PropTypeMap = keyof PropTypeMap> = T extends T ? { - propPref: boolean; - propDispName: string; - propShortName: string; - propWrite: boolean; - propHidden: boolean; - propExpert: boolean; - propType: T; - propValue: PropTypeMap[T]; - propName: string; +export type Property<T extends keyof PropertyTypeMap = keyof PropertyTypeMap> = T extends T ? { + preferred: boolean; + displayName: string; + shortName: string; + htmlName?: string; + write: boolean; + hidden: boolean; + expert: boolean; + type: T; + value: PropertyTypeMap[T]; + name: string; } : never; // Distributive type export type Properties = { - propPref: boolean; - propDispName: string; - propShortName: string; - propHidden: boolean; - propExpert: boolean; - propName: string; - props: Property[]; + preferred: boolean; + displayName: string; + shortName: string; + htmlName?: string; + hidden: boolean; + expert: boolean; + name: string; + properties: Property[]; }; -export type MessageProp = { +export type PropertyMessage = { name: string; value: string | boolean | Record<string, string>; }; @@ -63,7 +65,7 @@ export type ErrMessage = MessageCommon<typeof CommandKey.Error> & { stack?: string; }; export type SaveMessage = MessageCommon<typeof CommandKey.Save> & { - properties: MessageProp[]; + properties: PropertyMessage[]; }; export type CancelMessage = MessageCommon<typeof CommandKey.Cancel>; export type Message = InfoMessage | ErrMessage | SaveMessage | CancelMessage; \ No newline at end of file diff --git a/java/java.lsp.server/vscode/src/propertiesView/propertiesHtmlBuilder.ts b/java/java.lsp.server/vscode/src/propertiesView/propertiesHtmlBuilder.ts index 616d82cf05..de7c28256c 100644 --- a/java/java.lsp.server/vscode/src/propertiesView/propertiesHtmlBuilder.ts +++ b/java/java.lsp.server/vscode/src/propertiesView/propertiesHtmlBuilder.ts @@ -5,7 +5,7 @@ * Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. */ import * as vscode from 'vscode'; -import { PropTypes, Properties, Property } from "./controlTypes"; +import { PropertyTypes, Properties, Property } from "./controlTypes"; export function makeHtmlForProperties(name: string, nonce: string, scriptUri: vscode.Uri, properties: Properties): string { return `<!DOCTYPE html> @@ -46,7 +46,7 @@ function wrapToTable(name: string, content: string, separator: string = ":"): st function makePropertiesTable(properties: Properties): string { let html = ""; - for (const prop of properties.props) { + for (const prop of properties.properties) { html += makePropAccess(prop); } return html; @@ -54,47 +54,47 @@ function makePropertiesTable(properties: Properties): string { function makePropAccess(prop: Property): string { let out: string; - switch (prop.propType) { - case PropTypes.String: + switch (prop.type) { + case PropertyTypes.String: out = makeStringAccess(prop); break; - case PropTypes.Boolean: + case PropertyTypes.Boolean: out = makeBoolAccess(prop); break; - case PropTypes.Properties: + case PropertyTypes.Properties: out = makePropertiesAccess(prop); break; default: - out = prop.propValue + ""; + out = prop.value + ""; break; } - return wrapToTable(prop.propDispName, out) + '\n'; + return wrapToTable(prop.displayName, out) + '\n'; } -function makeStringAccess(prop: Property<typeof PropTypes.String>) { - return `<vscode-text-field name="input" id="${prop.propName}" value="${encode(prop.propValue)}" ${prop.propWrite ? "" : "disabled"}></vscode-text-field>`; +function makeStringAccess(prop: Property<typeof PropertyTypes.String>) { + return `<vscode-text-field name="input" id="${prop.name}" value="${encode(prop.value)}" ${prop.write ? "" : "disabled"}></vscode-text-field>`; } -function makeBoolAccess(prop: Property<typeof PropTypes.Boolean>) { - return `<vscode-checkbox name="input" id="${prop.propName}" ${prop.propWrite ? "" : "disabled"} ${prop.propValue ? "checked" : ""}></vscode-checkbox>`; +function makeBoolAccess(prop: Property<typeof PropertyTypes.Boolean>) { + return `<vscode-checkbox name="input" id="${prop.name}" ${prop.write ? "" : "disabled"} ${prop.value ? "checked" : ""}></vscode-checkbox>`; } -function makePropertiesAccess(prop: Property<typeof PropTypes.Properties>) { - return `<details><summary><b>${prop.propDispName}</b></summary><table name="input" id="${prop.propName}"> +function makePropertiesAccess(prop: Property<typeof PropertyTypes.Properties>) { + return `<details><summary><b>${prop.displayName}</b></summary><table name="input" id="${prop.name}"> ${makePropTable(prop)} </table></details>`; } -function makePropTable(prop: Property<typeof PropTypes.Properties>) { +function makePropTable(prop: Property<typeof PropertyTypes.Properties>) { let out = ""; - for (const key in prop.propValue) { + for (const key in prop.value) { out += makePropRow(prop, key) + '\n'; } return out; } -function makePropRow(prop: Property<typeof PropTypes.Properties>, key: string) { - return wrapToTable(asTextField(key, prop.propWrite, "name"), asTextField(prop.propValue[key], prop.propWrite, "value"), " = "); +function makePropRow(prop: Property<typeof PropertyTypes.Properties>, key: string) { + return wrapToTable(asTextField(key, prop.write, "name"), asTextField(prop.value[key], prop.write, "value"), " = "); } function asTextField(value: string, enabled: boolean, name: string) { diff --git a/java/java.lsp.server/vscode/src/propertiesView/propertiesView.ts b/java/java.lsp.server/vscode/src/propertiesView/propertiesView.ts index 49518d3d64..f195e62eee 100644 --- a/java/java.lsp.server/vscode/src/propertiesView/propertiesView.ts +++ b/java/java.lsp.server/vscode/src/propertiesView/propertiesView.ts @@ -6,10 +6,9 @@ */ import * as vscode from 'vscode'; -import { CommandKey, ID, Message, MessageProp, Properties, Property, PropTypes } from './controlTypes'; +import { CommandKey, ID, Message, PropertyMessage, Properties, Property, PropertyTypes } from './controlTypes'; import { assertNever, isRecord, isString, IsType } from '../typesUtil'; import { makeHtmlForProperties } from './propertiesHtmlBuilder'; -import { fstat } from 'fs'; export class PropertiesView { private static readonly COMMAND_PREFIX = "java."; @@ -31,11 +30,6 @@ export class PropertiesView { if (!node) return; const id = node.id; - const p: Property={ - propDispName:"",propExpert:false,propHidden:false,propName:"",propPref:false,propShortName:"",propWrite:false, - propType:'java.lang.Boolean', - propValue:'' - } // If we already have a panel, show it. const current = PropertiesView.panels[id]; try { @@ -123,14 +117,14 @@ export class PropertiesView { return new Map<String, Properties>(Object.entries(resp)); // TODO - validate cast } - private save(properties: MessageProp[]) { + private save(properties: PropertyMessage[]) { if (!this.properties) return; for (const prop of properties) - this.mergeProps(prop, this.properties?.props); + this.mergeProps(prop, this.properties?.properties); const msg: Record<string, Properties> = {}; - msg[this.properties.propName] = this.properties; + msg[this.properties.name] = this.properties; vscode.commands.executeCommand(PropertiesView.COMMAND_SET_NODE_PROPERTIES, this.id, msg) .then(done => { @@ -151,10 +145,10 @@ export class PropertiesView { vscode.window.showErrorMessage("Saving of properties failed.", { modal: true, detail: out }); } - private mergeProps(prop: MessageProp, props?: Property[]): void { - const p = props?.find(p => p.propName === prop.name); - if (p && Object.values(PropTypes).includes(p.propType)) - p.propValue = prop.value; + private mergeProps(prop: PropertyMessage, props?: Property[]): void { + const p = props?.find(p => p.name === prop.name); + if (p && Object.values(PropertyTypes).includes(p.type)) + p.value = prop.value; } private processMessage(message: Message) { diff --git a/java/java.lsp.server/vscode/src/propertiesView/script.ts b/java/java.lsp.server/vscode/src/propertiesView/script.ts index 1f800f5b5d..475fdef694 100644 --- a/java/java.lsp.server/vscode/src/propertiesView/script.ts +++ b/java/java.lsp.server/vscode/src/propertiesView/script.ts @@ -6,7 +6,7 @@ */ import { provideVSCodeDesignSystem, vsCodeButton, vsCodeTextField, vsCodeDivider, vsCodeCheckbox, Button, TextField, Checkbox } from "@vscode/webview-ui-toolkit"; import { isError, asClass, isClass } from "../typesUtil"; -import { CommandKey, Message, MessageProp } from "./controlTypes"; +import { CommandKey, Message, PropertyMessage } from "./controlTypes"; provideVSCodeDesignSystem().register(vsCodeButton(), vsCodeTextField(), vsCodeDivider(), vsCodeCheckbox()); @@ -42,8 +42,8 @@ function sendMessage(message: Message) { vscode.postMessage(message); } -function getProperties(): MessageProp[] { - const out: MessageProp[] = []; +function getProperties(): PropertyMessage[] { + const out: PropertyMessage[] = []; const elements = document.getElementsByName("input"); for (let i = 0; i < elements.length; ++i) { const element = elements.item(i); @@ -53,7 +53,7 @@ function getProperties(): MessageProp[] { return out; } -function getProperty(element: HTMLElement): MessageProp { +function getProperty(element: HTMLElement): PropertyMessage { if (isClass(TextField, element)) { return makeProperty(element.value, element?.id); } else if (isClass(Checkbox, element)) { @@ -64,7 +64,7 @@ function getProperty(element: HTMLElement): MessageProp { throw new Error("Unknown HTML Element type."); } -function makeProperty(value: string | boolean | Record<string, string>, name?: string): MessageProp { +function makeProperty(value: string | boolean | Record<string, string>, name?: string): PropertyMessage { if (name) return { name: name, value: value }; throw new Error("HTML Element have no ID."); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists