mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-09 10:28:32 +00:00
feat: disable debug widget if unsupported by board
Remove the 'Add configuration...' select option from the debug widget. Closes #14 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { SelectOption } from '@theia/core/lib/browser/widgets/select-component';
|
||||
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
||||
import { nls } from '@theia/core/lib/common/nls';
|
||||
import { injectable } from '@theia/core/shared/inversify';
|
||||
@@ -51,6 +52,24 @@ class DebugConfigurationSelect extends TheiaDebugConfigurationSelect {
|
||||
);
|
||||
}
|
||||
|
||||
protected override renderOptions(): SelectOption[] {
|
||||
const options = super.renderOptions();
|
||||
const addConfiguration = options[options.length - 1];
|
||||
const separator = options[options.length - 2];
|
||||
// Remove "Add configuration..." and the preceding separator options.
|
||||
// They're expected to be the last two items.
|
||||
if (
|
||||
addConfiguration.value ===
|
||||
TheiaDebugConfigurationSelect.ADD_CONFIGURATION &&
|
||||
separator.separator
|
||||
) {
|
||||
options.splice(options.length - 2, 2);
|
||||
return options;
|
||||
}
|
||||
// Something is unexpected with the select options.
|
||||
return options;
|
||||
}
|
||||
|
||||
override componentWillUnmount(): void {
|
||||
this.toDisposeOnUnmount.dispose();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import {
|
||||
codicon,
|
||||
PanelLayout,
|
||||
Widget,
|
||||
} from '@theia/core/lib/browser/widgets/widget';
|
||||
import {
|
||||
inject,
|
||||
injectable,
|
||||
postConstruct,
|
||||
} from '@theia/core/shared/inversify';
|
||||
import { DebugWidget as TheiaDebugWidget } from '@theia/debug/lib/browser/view/debug-widget';
|
||||
import { DebugDisabledStatusMessageSource } from '../../contributions/debug';
|
||||
|
||||
@injectable()
|
||||
export class DebugWidget extends TheiaDebugWidget {
|
||||
@inject(DebugDisabledStatusMessageSource)
|
||||
private readonly debugStatusMessageSource: DebugDisabledStatusMessageSource;
|
||||
|
||||
private readonly statusMessageWidget = new Widget();
|
||||
private readonly messageNode = document.createElement('div');
|
||||
|
||||
@postConstruct()
|
||||
protected override init(): void {
|
||||
super.init();
|
||||
this.messageNode.classList.add('status-message', 'noselect');
|
||||
this.statusMessageWidget.node.appendChild(this.messageNode);
|
||||
this.updateState();
|
||||
this.toDisposeOnDetach.pushAll([
|
||||
this.debugStatusMessageSource.onDidChangeMessage((message) =>
|
||||
this.updateState(message)
|
||||
),
|
||||
this.statusMessageWidget,
|
||||
]);
|
||||
}
|
||||
|
||||
private updateState(message = this.debugStatusMessageSource.message): void {
|
||||
requestAnimationFrame(() => {
|
||||
this.messageNode.textContent = message ?? '';
|
||||
const enabled = !message;
|
||||
updateVisibility(enabled, this.toolbar, this.sessionWidget);
|
||||
if (this.layout instanceof PanelLayout) {
|
||||
if (enabled) {
|
||||
this.layout.removeWidget(this.statusMessageWidget);
|
||||
} else {
|
||||
this.layout.insertWidget(0, this.statusMessageWidget);
|
||||
}
|
||||
}
|
||||
this.title.iconClass = enabled ? codicon('debug-alt') : 'fa fa-ban'; // TODO: find a better icon?
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function updateVisibility(visible: boolean, ...widgets: Widget[]): void {
|
||||
widgets.forEach((widget) =>
|
||||
visible ? widget.removeClass('hidden') : widget.addClass('hidden')
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user