(
this.context,
newEnum as any,
ScpiEnum
)
);
});
this.selectedChanges.updated.forEach(commandDefinition => {
let result = findCommandInScpiSubsystems(
existingSubsystems,
commandDefinition.command.name
);
if (result) {
this.context.updateObject(result.command, {
helpLink: commandDefinition.command.helpLink,
parameters: toJS(
commandDefinition.command.parameters
).map(parameter => {
return {
name: parameter.name,
type: parameter.type.map(type => {
if (type.type === "discrete") {
if (
!scpi.enums.find(
scpiEnum =>
scpiEnum.name ===
type.enumeration
)
) {
return {
type: "discrete"
};
}
}
return type;
}),
isOptional: parameter.isOptional,
description: parameter.description
};
})
});
}
});
this.context.undoManager.setCombineCommands(false);
this.context.backgroundCheckEnabled = true;
};
onCancel = () => {
this.modal.hide();
};
handleTabClick(activeTab: Section, event: any) {
event.preventDefault();
this.activeTab = activeTab;
}
handleSelectAllCheckboxes() {
SECTIONS.forEach(section => {
if (this.selectAllCheckboxDisposers[section]) {
return;
}
let checkbox: HTMLInputElement;
if (section === "added") {
checkbox = this.addedSelectAllCheckbox;
} else if (section === "deleted") {
checkbox = this.deletedSelectAllCheckbox;
} else if (section === "moved") {
checkbox = this.movedSelectAllCheckbox;
} else if (section === "updated") {
checkbox = this.updatedSelectAllCheckbox;
} else {
checkbox = this.newEnumsSelectAllCheckbox;
}
if (!checkbox) {
return;
}
this.selectAllCheckboxDisposers[section] = autorun(() => {
if (this.selectedChanges[section].length == 0) {
checkbox.indeterminate = false;
checkbox.checked = false;
} else if (
this.selectedChanges[section].length ==
this.changes[section].length
) {
checkbox.indeterminate = false;
checkbox.checked = true;
} else {
checkbox.indeterminate = true;
checkbox.checked = false;
}
});
checkbox.addEventListener(
"click",
action((event: any) => {
if (this.selectedChanges[section].length == 0) {
(this.selectedChanges as any)[section] =
this.changes[section].slice();
} else {
this.selectedChanges[section] = [];
}
})
);
});
}
isChangeSelected(
section: Section,
changeDefinition: CommandDefinition | IEnum
) {
let commandDefinitions: any = this.selectedChanges[section];
return commandDefinitions.indexOf(changeDefinition) !== -1;
}
handleSelectCommand(
section: Section,
commandDefinition: CommandDefinition,
event: any
) {
let commandDefinitions: any = this.selectedChanges[section];
if (event.target.checked) {
commandDefinitions.push(commandDefinition);
} else {
let i = commandDefinitions.indexOf(commandDefinition);
commandDefinitions.splice(i, 1);
}
}
render() {
let content;
let buttons;
if (this.error) {
content = {this.error}
;
buttons = [
];
} else if (this.changes) {
if (this.hasChanges) {
let tabs = SECTIONS.filter(
section => this.changes[section].length > 0
).map(section => (
{humanize(section).toUpperCase()}
{this.changes[section].length}
));
let tables = SECTIONS.map(section => {
if (this.changes[section].length === 0) {
return;
}
let thead;
if (section === "added") {
thead = (
|
(this.addedSelectAllCheckbox =
ref!)
}
type="checkbox"
/>{" "}
Command
|
To |
);
} else if (section === "deleted") {
thead = (
|
(this.deletedSelectAllCheckbox =
ref!)
}
type="checkbox"
/>{" "}
Command
|
From |
);
} else if (section === "moved") {
thead = (
|
(this.movedSelectAllCheckbox =
ref!)
}
type="checkbox"
/>{" "}
Command
|
From |
To |
);
} else if (section === "updated") {
thead = (
|
(this.updatedSelectAllCheckbox =
ref!)
}
type="checkbox"
/>{" "}
Command
|
In |
);
} else if (section === "newEnums") {
thead = (
|
(this.newEnumsSelectAllCheckbox =
ref!)
}
type="checkbox"
/>{" "}
Enum
|
Members |
);
}
let tbody = (this.changes[section] as any).map(
(
commandOrNewEnumDefinition:
| CommandDefinition
| IEnum
) => {
let checkbox = (
);
if (section === "newEnums") {
const newEnum =
commandOrNewEnumDefinition as IEnum;
return (
|
{checkbox} {newEnum.name}
|
{newEnum.members
.map(member => member.name)
.join("|")}
|
);
} else {
const commandDefinition =
commandOrNewEnumDefinition as CommandDefinition;
if (
section === "added" ||
section === "deleted" ||
section === "updated"
) {
return (
|
{checkbox}{" "}
{
commandDefinition
.command.name
}
|
{
commandDefinition
.subsystem.name
}
|
);
} else {
// section === "moved"
return (
|
{checkbox}{" "}
{
commandDefinition
.command.name
}
|
{
commandDefinition
.subsystem.name
}
|
{
(
commandDefinition as MovedCommandDefinition
).toSubsystem.name
}
|
);
}
}
}
);
return (
);
});
content = (
);
buttons = [
,
];
} else {
content = (
No changes!
);
buttons = [
];
}
} else {
content = ;
}
let footer;
if (buttons && buttons.length > 0) {
footer = {buttons}
;
}
return (
(this.dialog = ref!)}
className={"modal fade EezStudio_ImportScpiDocDialogDiv"}
tabIndex={-1}
role="dialog"
>
Detected SCPI Command Changes
{content}
{footer}
);
}
}
);
////////////////////////////////////////////////////////////////////////////////
export function showImportScpiDocDialog(projectStore: ProjectStore) {
let el = document.createElement("div");
document.body.appendChild(el);
const root = createRoot(el);
root.render(
{
el.remove();
}}
/>
);
}