Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 763fde0

Browse filesBrowse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
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>
1 parent 0e7b0c9 commit 763fde0
Copy full SHA for 763fde0

File tree

5 files changed

+115
-39
lines changed
Filter options

5 files changed

+115
-39
lines changed

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

Copy file name to clipboardExpand all lines: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts
+6-3Lines changed: 6 additions & 3 deletions
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

Copy file name to clipboardExpand all lines: arduino-ide-extension/src/browser/contributions/debug.ts
+24-4Lines changed: 24 additions & 4 deletions
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)
@@ -83,10 +101,10 @@ export class Debug extends SketchContribution {
83101
* If `undefined`, debugging is enabled. Otherwise, the human-readable reason why it's disabled.
84102
*/
85103
private _message?: string = noBoardSelected; // Initial pessimism.
86-
private didChangeMessageEmitter = new Emitter<string | undefined>();
87-
private onDidChangeMessage = this.didChangeMessageEmitter.event;
104+
private readonly didChangeMessageEmitter = new Emitter<string | undefined>();
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(
+9-32Lines changed: 9 additions & 32 deletions
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

Copy file name to clipboardExpand all lines: arduino-ide-extension/src/browser/theia/debug/debug-configuration-widget.tsx
+19Lines changed: 19 additions & 0 deletions
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
}
+57Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
19+
private readonly statusMessageWidget = new Widget();
20+
private readonly messageNode = document.createElement('div');
21+
22+
@postConstruct()
23+
protected override init(): void {
24+
super.init();
25+
this.messageNode.classList.add('status-message', 'noselect');
26+
this.statusMessageWidget.node.appendChild(this.messageNode);
27+
this.updateState();
28+
this.toDisposeOnDetach.pushAll([
29+
this.debugStatusMessageSource.onDidChangeMessage((message) =>
30+
this.updateState(message)
31+
),
32+
this.statusMessageWidget,
33+
]);
34+
}
35+
36+
private updateState(message = this.debugStatusMessageSource.message): void {
37+
requestAnimationFrame(() => {
38+
this.messageNode.textContent = message ?? '';
39+
const enabled = !message;
40+
updateVisibility(enabled, this.toolbar, this.sessionWidget);
41+
if (this.layout instanceof PanelLayout) {
42+
if (enabled) {
43+
this.layout.removeWidget(this.statusMessageWidget);
44+
} else {
45+
this.layout.insertWidget(0, this.statusMessageWidget);
46+
}
47+
}
48+
this.title.iconClass = enabled ? codicon('debug-alt') : 'fa fa-ban'; // TODO: find a better icon?
49+
});
50+
}
51+
}
52+
53+
function updateVisibility(visible: boolean, ...widgets: Widget[]): void {
54+
widgets.forEach((widget) =>
55+
visible ? widget.removeClass('hidden') : widget.addClass('hidden')
56+
);
57+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.