Skip to content

Commit d346172

Browse files
author
Akos Kitta
committed
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 <[email protected]>
1 parent 0e7b0c9 commit d346172

File tree

5 files changed

+112
-38
lines changed

5 files changed

+112
-38
lines changed

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ import { TabBarRenderer } from './theia/core/tab-bars';
180180
import { EditorCommandContribution } from './theia/editor/editor-command';
181181
import { NavigatorTabBarDecorator as TheiaNavigatorTabBarDecorator } from '@theia/navigator/lib/browser/navigator-tab-bar-decorator';
182182
import { NavigatorTabBarDecorator } from './theia/navigator/navigator-tab-bar-decorator';
183-
import { Debug } from './contributions/debug';
183+
import { Debug, DebugDisabledStatusMessageSource } from './contributions/debug';
184184
import { Sketchbook } from './contributions/sketchbook';
185185
import { DebugFrontendApplicationContribution } from './theia/debug/debug-frontend-application-contribution';
186186
import { DebugFrontendApplicationContribution as TheiaDebugFrontendApplicationContribution } from '@theia/debug/lib/browser/debug-frontend-application-contribution';
@@ -365,7 +365,8 @@ import { AutoSelectProgrammer } from './contributions/auto-select-programmer';
365365
import { HostedPluginSupport } from './hosted/hosted-plugin-support';
366366
import { DebugSessionManager as TheiaDebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager';
367367
import { DebugSessionManager } from './theia/debug/debug-session-manager';
368-
import { DebugWidget } from '@theia/debug/lib/browser/view/debug-widget';
368+
import { DebugWidget as TheiaDebugWidget } from '@theia/debug/lib/browser/view/debug-widget';
369+
import { DebugWidget } from './theia/debug/debug-widget';
369370
import { DebugViewModel } from '@theia/debug/lib/browser/view/debug-view-model';
370371
import { DebugSessionWidget } from '@theia/debug/lib/browser/view/debug-session-widget';
371372
import { DebugConfigurationWidget } from './theia/debug/debug-configuration-widget';
@@ -771,6 +772,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
771772
bindContributionProvider(bind, StartupTaskProvider);
772773
bind(StartupTaskProvider).toService(BoardsServiceProvider); // to reuse the boards config in another window
773774

775+
bind(DebugDisabledStatusMessageSource).toService(Debug);
776+
774777
// Disabled the quick-pick customization from Theia when multiple formatters are available.
775778
// Use the default VS Code behavior, and pick the first one. In the IDE2, clang-format has `exclusive` selectors.
776779
bind(MonacoFormattingConflictsContribution).toSelf().inSingletonScope();
@@ -874,7 +877,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
874877
// Customized debug widget with its customized config <select> to update it programmatically.
875878
bind(WidgetFactory)
876879
.toDynamicValue(({ container }) => ({
877-
id: DebugWidget.ID,
880+
id: TheiaDebugWidget.ID,
878881
createWidget: () => {
879882
const child = new Container({ defaultScope: 'Singleton' });
880883
child.parent = container;

arduino-ide-extension/src/browser/contributions/debug.ts

+23-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,26 @@ interface StartDebugParams {
6464
}
6565
type StartDebugResult = boolean;
6666

67+
export const DebugDisabledStatusMessageSource = Symbol(
68+
'DebugDisabledStatusMessageSource'
69+
);
70+
export interface DebugDisabledStatusMessageSource {
71+
/**
72+
* `undefined` if debugging is enabled (for the currently selected board + programmer + config options).
73+
* Otherwise, it's the human readable message why it's disabled.
74+
*/
75+
get message(): string | undefined;
76+
/**
77+
* Emits an event when {@link message} changes.
78+
*/
79+
get onDidChangeMessage(): Event<string | undefined>;
80+
}
81+
6782
@injectable()
68-
export class Debug extends SketchContribution {
83+
export class Debug
84+
extends SketchContribution
85+
implements DebugDisabledStatusMessageSource
86+
{
6987
@inject(HostedPluginSupport)
7088
private readonly hostedPluginSupport: HostedPluginSupport;
7189
@inject(NotificationCenter)
@@ -84,9 +102,9 @@ export class Debug extends SketchContribution {
84102
*/
85103
private _message?: string = noBoardSelected; // Initial pessimism.
86104
private didChangeMessageEmitter = new Emitter<string | undefined>();
87-
private onDidChangeMessage = this.didChangeMessageEmitter.event;
105+
readonly onDidChangeMessage = this.didChangeMessageEmitter.event;
88106

89-
private get message(): string | undefined {
107+
get message(): string | undefined {
90108
return this._message;
91109
}
92110
private set message(message: string | undefined) {
@@ -349,6 +367,8 @@ export namespace Debug {
349367
}
350368

351369
/**
370+
* Resolves with the FQBN to use for the `debug --info --programmer p --fqbn $FQBN` command. Otherwise, rejects.
371+
*
352372
* (non-API)
353373
*/
354374
export async function isDebugEnabled(
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,13 @@
1-
/* TODO: remove after https://github.com/eclipse-theia/theia/pull/9256/ */
2-
3-
/* To fix colors in Theia. */
4-
.theia-debug-hover-title.number,
5-
.theia-debug-console-variable.number {
6-
color: var(--theia-variable-number-variable-color);
7-
}
8-
.theia-debug-hover-title.boolean,
9-
.theia-debug-console-variable.boolean {
10-
color: var(--theia-variable-boolean-variable-color);
11-
}
12-
.theia-debug-hover-title.string,
13-
.theia-debug-console-variable.string {
14-
color: var(--theia-variable-string-variable-color);
1+
/* Naive way of hiding the debug widget when the debug functionality is disabled https://github.com/arduino/arduino-ide/issues/14 */
2+
.theia-debug-container .debug-toolbar.hidden,
3+
.theia-debug-container .theia-session-container.hidden {
4+
visibility: hidden;
155
}
166

17-
/* To unset the default debug hover dimension. */
18-
.theia-debug-hover {
19-
min-width: unset;
20-
min-height: unset;
21-
width: unset;
22-
height: unset;
23-
}
24-
25-
/* To adjust the left padding in the hover title. */
26-
.theia-debug-hover-title {
27-
padding-left: 5px;
28-
}
7+
.theia-debug-container .status-message {
8+
font-family: "Open Sans";
9+
font-style: normal;
10+
font-size: 12px;
2911

30-
/* Use the default Theia dimensions only iff the expression is complex (`!!expression.hasChildren~) */
31-
.theia-debug-hover.complex-value {
32-
min-width: 324px;
33-
min-height: 324px;
34-
width: 324px;
35-
height: 324px;
12+
padding: 10px;
3613
}

arduino-ide-extension/src/browser/theia/debug/debug-configuration-widget.tsx

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SelectOption } from '@theia/core/lib/browser/widgets/select-component';
12
import { DisposableCollection } from '@theia/core/lib/common/disposable';
23
import { nls } from '@theia/core/lib/common/nls';
34
import { injectable } from '@theia/core/shared/inversify';
@@ -51,6 +52,24 @@ class DebugConfigurationSelect extends TheiaDebugConfigurationSelect {
5152
);
5253
}
5354

55+
protected override renderOptions(): SelectOption[] {
56+
const options = super.renderOptions();
57+
const addConfiguration = options[options.length - 1];
58+
const separator = options[options.length - 2];
59+
// Remove "Add configuration..." and the preceding separator options.
60+
// They're expected to be the last two items.
61+
if (
62+
addConfiguration.value ===
63+
TheiaDebugConfigurationSelect.ADD_CONFIGURATION &&
64+
separator.separator
65+
) {
66+
options.splice(options.length - 2, 2);
67+
return options;
68+
}
69+
// Something is unexpected with the select options.
70+
return options;
71+
}
72+
5473
override componentWillUnmount(): void {
5574
this.toDisposeOnUnmount.dispose();
5675
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {
2+
codicon,
3+
PanelLayout,
4+
Widget,
5+
} from '@theia/core/lib/browser/widgets/widget';
6+
import {
7+
inject,
8+
injectable,
9+
postConstruct,
10+
} from '@theia/core/shared/inversify';
11+
import { DebugWidget as TheiaDebugWidget } from '@theia/debug/lib/browser/view/debug-widget';
12+
import { DebugDisabledStatusMessageSource } from '../../contributions/debug';
13+
14+
@injectable()
15+
export class DebugWidget extends TheiaDebugWidget {
16+
@inject(DebugDisabledStatusMessageSource)
17+
private readonly debugStatusMessageSource: DebugDisabledStatusMessageSource;
18+
private readonly statusMessageWidget: Widget = new Widget();
19+
private readonly messageNode: HTMLDivElement = document.createElement('div');
20+
21+
@postConstruct()
22+
protected override init(): void {
23+
super.init();
24+
this.messageNode.classList.add('status-message', 'noselect');
25+
this.statusMessageWidget.node.appendChild(this.messageNode);
26+
this.updateState();
27+
this.toDisposeOnDetach.push(
28+
this.debugStatusMessageSource.onDidChangeMessage((message) =>
29+
this.updateState(message)
30+
)
31+
);
32+
}
33+
34+
private updateState(message = this.debugStatusMessageSource.message): void {
35+
requestAnimationFrame(() => {
36+
this.messageNode.textContent = message ?? '';
37+
const enabled = !message;
38+
updateVisibility(enabled, this.toolbar, this.sessionWidget);
39+
if (this.layout instanceof PanelLayout) {
40+
if (enabled) {
41+
this.layout.removeWidget(this.statusMessageWidget);
42+
} else {
43+
this.layout.insertWidget(0, this.statusMessageWidget);
44+
}
45+
}
46+
this.title.iconClass = enabled ? codicon('debug-alt') : 'fa fa-ban'; // TODO: find a better icon?
47+
});
48+
}
49+
}
50+
51+
function updateVisibility(visible: boolean, ...widgets: Widget[]): void {
52+
widgets.forEach((widget) =>
53+
visible ? widget.removeClass('hidden') : widget.addClass('hidden')
54+
);
55+
}

0 commit comments

Comments
 (0)