Skip to content

Commit 8ab70f4

Browse files
author
Akos Kitta
committed
fixed save-as. added sketchload
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent 528f415 commit 8ab70f4

19 files changed

+360
-114
lines changed

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,11 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
260260
}
261261

262262
protected async openSketchFiles(uri: string): Promise<void> {
263-
const uris = await this.sketchService.getSketchFiles(uri);
264-
for (const uri of uris) {
263+
const sketch = await this.sketchService.loadSketch(uri);
264+
await this.editorManager.open(new URI(sketch.mainFileUri));
265+
for (const uri of [...sketch.otherSketchFileUris, ...sketch.additionalFileUris]) {
265266
await this.editorManager.open(new URI(uri));
266267
}
267-
if (uris.length) {
268-
await this.editorManager.open(new URI(uris[0])); // Make sure the sketch file has the focus.
269-
}
270268
}
271269

272270
registerColors(colors: ColorRegistry): void {
@@ -313,6 +311,24 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
313311
hc: 'activityBar.inactiveForeground'
314312
},
315313
description: 'Background color of the toolbar items when hovering over them. Such as Upload, Verify, etc.'
314+
},
315+
{
316+
id: 'arduino.output.background',
317+
defaults: {
318+
dark: 'editorWidget.background',
319+
light: 'editorWidget.background',
320+
hc: 'editorWidget.background'
321+
},
322+
description: 'Background color of the Output view.'
323+
},
324+
{
325+
id: 'arduino.output.foreground',
326+
defaults: {
327+
dark: 'editorWidget.foreground',
328+
light: 'editorWidget.foreground',
329+
hc: 'editorWidget.foreground'
330+
},
331+
description: 'Color of the text in the Output view.'
316332
}
317333
);
318334
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ArduinoLanguageGrammarContribution } from './language/arduino-language-
1515
import { LibraryService, LibraryServicePath } from '../common/protocol/library-service';
1616
import { BoardsService, BoardsServicePath, BoardsServiceClient } from '../common/protocol/boards-service';
1717
import { SketchesService, SketchesServicePath } from '../common/protocol/sketches-service';
18+
import { SketchesServiceClientImpl } from '../common/protocol/sketches-service-client-impl';
1819
import { CoreService, CoreServicePath, CoreServiceClient } from '../common/protocol/core-service';
1920
import { BoardsListWidget } from './boards/boards-list-widget';
2021
import { BoardsListWidgetFrontendContribution } from './boards/boards-widget-frontend-contribution';
@@ -151,6 +152,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
151152

152153
// Sketch list service
153154
bind(SketchesService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, SketchesServicePath)).inSingletonScope();
155+
bind(SketchesServiceClientImpl).toSelf().inSingletonScope();
154156

155157
// Config service
156158
bind(ConfigService).toDynamicValue(context => {

arduino-ide-extension/src/browser/contributions/close-sketch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ export class CloseSketch extends SketchContribution {
1515
registerCommands(registry: CommandRegistry): void {
1616
registry.registerCommand(CloseSketch.Commands.CLOSE_SKETCH, {
1717
execute: async () => {
18-
const sketch = await this.currentSketch();
18+
const sketch = await this.sketchServiceClient.currentSketch();
1919
if (!sketch) {
2020
return;
2121
}
2222
const isTemp = await this.sketchService.isTemp(sketch);
23-
const uri = await this.currentSketchFile();
23+
const uri = await this.sketchServiceClient.currentSketchFile();
2424
if (!uri) {
2525
return;
2626
}

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

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { inject, injectable, interfaces } from 'inversify';
22
import URI from '@theia/core/lib/common/uri';
33
import { ILogger } from '@theia/core/lib/common/logger';
4-
import { notEmpty } from '@theia/core/lib/common/objects';
54
import { FileSystem } from '@theia/filesystem/lib/common';
65
import { LabelProvider } from '@theia/core/lib/browser/label-provider';
76
import { MessageService } from '@theia/core/lib/common/message-service';
@@ -11,8 +10,9 @@ import { MenuModelRegistry, MenuContribution } from '@theia/core/lib/common/menu
1110
import { KeybindingRegistry, KeybindingContribution } from '@theia/core/lib/browser/keybinding';
1211
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
1312
import { Command, CommandRegistry, CommandContribution, CommandService } from '@theia/core/lib/common/command';
14-
import { SketchesService, ConfigService, FileSystemExt, Sketch } from '../../common/protocol';
1513
import { EditorMode } from '../editor-mode';
14+
import { SketchesServiceClientImpl } from '../../common/protocol/sketches-service-client-impl';
15+
import { SketchesService, ConfigService, FileSystemExt, Sketch } from '../../common/protocol';
1616

1717
export { Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, TabBarToolbarRegistry, URI, Sketch, open };
1818

@@ -69,30 +69,8 @@ export abstract class SketchContribution extends Contribution {
6969
@inject(OpenerService)
7070
protected readonly openerService: OpenerService;
7171

72-
protected async currentSketch(): Promise<Sketch | undefined> {
73-
const sketches = (await Promise.all(this.workspaceService.tryGetRoots().map(({ uri }) => this.sketchService.getSketchFolder(uri)))).filter(notEmpty);
74-
if (!sketches.length) {
75-
return;
76-
}
77-
if (sketches.length > 1) {
78-
console.log(`Multiple sketch folders were found in the workspace. Falling back to the first one. Sketch folders: ${JSON.stringify(sketches)}`);
79-
}
80-
return sketches[0];
81-
}
82-
83-
protected async currentSketchFile(): Promise<string | undefined> {
84-
const sketch = await this.currentSketch();
85-
if (sketch) {
86-
const uri = new URI(sketch.uri).resolve(`${sketch.name}.ino`).toString();
87-
const exists = await this.fileSystem.exists(uri);
88-
if (!exists) {
89-
this.messageService.warn(`Could not find sketch file: ${uri}`);
90-
return undefined;
91-
}
92-
return uri;
93-
}
94-
return undefined;
95-
}
72+
@inject(SketchesServiceClientImpl)
73+
protected readonly sketchServiceClient: SketchesServiceClientImpl;
9674

9775
}
9876

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

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,33 +151,29 @@ ${value}
151151
registerKeybindings(registry: KeybindingRegistry): void {
152152
registry.registerKeybinding({
153153
command: EditContributions.Commands.COPY_FOR_FORUM.id,
154-
keybinding: 'CtrlCmd+Shift+C'
154+
keybinding: 'CtrlCmd+Shift+C',
155+
when: 'editorFocus'
155156
});
156157
registry.registerKeybinding({
157158
command: EditContributions.Commands.COPY_FOR_GITHUB.id,
158-
keybinding: 'CtrlCmd+Alt+C'
159+
keybinding: 'CtrlCmd+Alt+C',
160+
when: 'editorFocus'
159161
});
160162
registry.registerKeybinding({
161163
command: EditContributions.Commands.GO_TO_LINE.id,
162-
keybinding: 'CtrlCmd+L'
164+
keybinding: 'CtrlCmd+L',
165+
when: 'editorFocus'
163166
});
164167

165168
registry.registerKeybinding({
166169
command: EditContributions.Commands.TOGGLE_COMMENT.id,
167-
keybinding: 'CtrlCmd+/'
168-
});
169-
registry.registerKeybinding({
170-
command: EditContributions.Commands.INDENT_LINES.id,
171-
keybinding: 'Tab'
172-
});
173-
registry.registerKeybinding({
174-
command: EditContributions.Commands.OUTDENT_LINES.id,
175-
keybinding: 'Shift+Tab'
170+
keybinding: 'CtrlCmd+/',
171+
when: 'editorFocus'
176172
});
177173

178174
registry.registerKeybinding({
179175
command: EditContributions.Commands.INCREASE_FONT_SIZE.id,
180-
keybinding: 'CtrlCmd+=' // TODO: compare with the Java IDE. It uses `⌘+`. There is no `+` on EN_US.
176+
keybinding: 'CtrlCmd+='
181177
});
182178
registry.registerKeybinding({
183179
command: EditContributions.Commands.DECREASE_FONT_SIZE.id,
@@ -213,8 +209,15 @@ ${value}
213209
}
214210

215211
protected async currentValue(): Promise<string | undefined> {
216-
const currentEditor = await this.current()
217-
return currentEditor?.getValue();
212+
const currentEditor = await this.current();
213+
if (currentEditor) {
214+
const selection = currentEditor.getSelection();
215+
if (!selection || selection.isEmpty()) {
216+
return currentEditor.getValue();
217+
}
218+
return currentEditor.getModel()?.getValueInRange(selection);
219+
}
220+
return undefined;
218221
}
219222

220223
protected async run(commandId: string): Promise<any> {

arduino-ide-extension/src/browser/contributions/open-sketch-external.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class OpenSketchExternal extends SketchContribution {
2828
}
2929

3030
protected async openExternal(): Promise<void> {
31-
const uri = await this.currentSketchFile();
31+
const uri = await this.sketchServiceClient.currentSketchFile();
3232
if (uri) {
3333
const exists = this.fileSystem.exists(uri);
3434
if (exists) {

arduino-ide-extension/src/browser/contributions/save-as-sketch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class SaveAsSketch extends SketchContribution {
3232
* Resolves `true` if the sketch was successfully saved as something.
3333
*/
3434
async saveAs({ execOnlyIfTemp, openAfterMove }: SaveAsSketch.Options = SaveAsSketch.Options.DEFAULT): Promise<boolean> {
35-
const sketch = await this.currentSketch();
35+
const sketch = await this.sketchServiceClient.currentSketch();
3636
if (!sketch) {
3737
return false;
3838
}

arduino-ide-extension/src/browser/contributions/sketch-control.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class SketchControl extends SketchContribution {
2626
isVisible: widget => this.shell.getWidgets('main').indexOf(widget) !== -1,
2727
execute: async () => {
2828
this.toDisposeBeforeCreateNewContextMenu.dispose();
29-
const sketch = await this.currentSketch();
29+
const sketch = await this.sketchServiceClient.currentSketch();
3030
if (!sketch) {
3131
return;
3232
}
@@ -40,8 +40,8 @@ export class SketchControl extends SketchContribution {
4040
return;
4141
}
4242

43-
const uris = await this.sketchService.getSketchFiles(sketch.uri);
44-
// TODO: order them! The Java IDE orders them by tab index. Use the shell and the editor manager to achieve it.
43+
const { mainFileUri, otherSketchFileUris, additionalFileUris } = await this.sketchService.loadSketch(sketch.uri);
44+
const uris = [mainFileUri, ...otherSketchFileUris, ...additionalFileUris];
4545
for (let i = 0; i < uris.length; i++) {
4646
const uri = new URI(uris[i]);
4747
const command = { id: `arduino-focus-file--${uri.toString()}` };

arduino-ide-extension/src/browser/contributions/upload-sketch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class UploadSketch extends SketchContribution {
7373
}
7474

7575
async uploadSketch(usingProgrammer: boolean = false): Promise<void> {
76-
const uri = await this.currentSketchFile();
76+
const uri = await this.sketchServiceClient.currentSketchFile();
7777
if (!uri) {
7878
return;
7979
}

arduino-ide-extension/src/browser/contributions/verify-sketch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class VerifySketch extends SketchContribution {
5757
}
5858

5959
async verifySketch(): Promise<void> {
60-
const uri = await this.currentSketchFile();
60+
const uri = await this.sketchServiceClient.currentSketchFile();
6161
if (!uri) {
6262
return;
6363
}

arduino-ide-extension/src/browser/data/arduino.color-theme.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@
108108
"secondaryButton.hoverBackground": "#dae3e3",
109109
"arduino.branding.primary": "#00979d",
110110
"arduino.branding.secondary": "#b5c8c9",
111-
"arduino.foreground": "#edf1f1"
111+
"arduino.foreground": "#edf1f1",
112+
"arduino.output.background": "#000000",
113+
"arduino.output.foreground": "#ffffff"
112114
},
113115
"type": "light",
114116
"name": "Arduino"

arduino-ide-extension/src/browser/style/main.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,12 @@
155155
border: 1px solid var(--theia-arduino-toolbar-background);
156156
padding: 2px 0px 2px 9px;
157157
}
158+
159+
#outputView .monaco-editor .lines-content.monaco-editor-background {
160+
background-color: var(--theia-arduino-output-background);
161+
}
162+
163+
.monaco-editor {
164+
/* #outputView .monaco-editor .inputarea.ime-input { */
165+
color: var(--theia-arduino-output-foreground);
166+
}

arduino-ide-extension/src/browser/theia/editor/editor-manager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export class EditorManager extends TheiaEditorManager {
1717
const { editor } = widget;
1818
if (editor instanceof MonacoEditor) {
1919
const codeEditor = editor.getControl();
20-
codeEditor.updateOptions({ readOnly });
20+
const lineNumbersMinChars = 2;
21+
const overviewRulerLanes = 0;
22+
codeEditor.updateOptions({ readOnly, lineNumbersMinChars, overviewRulerLanes });
2123
}
2224
}
2325
return widget;

arduino-ide-extension/src/browser/theia/workspace/workspace-service.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { ApplicationServer } from '@theia/core/lib/common/application-protocol';
77
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
88
import { FocusTracker, Widget } from '@theia/core/lib/browser';
99
import { WorkspaceService as TheiaWorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
10-
import { EditorMode } from '../../editor-mode';
1110
import { ConfigService } from '../../../common/protocol/config-service';
1211
import { SketchesService } from '../../../common/protocol/sketches-service';
1312
import { ArduinoWorkspaceRootResolver } from '../../arduino-workspace-resolver';
@@ -24,9 +23,6 @@ export class WorkspaceService extends TheiaWorkspaceService {
2423
@inject(LabelProvider)
2524
protected readonly labelProvider: LabelProvider;
2625

27-
@inject(EditorMode)
28-
protected readonly editorMode: EditorMode;
29-
3026
@inject(MessageService)
3127
protected readonly messageService: MessageService;
3228

@@ -82,13 +78,7 @@ export class WorkspaceService extends TheiaWorkspaceService {
8278
if (!exists) {
8379
return false;
8480
}
85-
// The workspace root location must exist. However, when opening a workspace root in pro-mode,
86-
// the workspace root must not be a sketch folder. It can be the default sketch directory, or any other directories, for instance.
87-
if (this.editorMode.proMode) {
88-
return true;
89-
}
90-
const sketchFolder = await this.sketchService.isSketchFolder(uri);
91-
return sketchFolder;
81+
return this.sketchService.isSketchFolder(uri);
9282
}
9383

9484
protected onCurrentWidgetChange({ newValue }: FocusTracker.IChangedArgs<Widget>): void {

arduino-ide-extension/src/browser/tool-output/client-service-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class ToolOutputServiceClientImpl implements ToolOutputServiceClient {
1212
onNewOutput(tool: string, text: string): void {
1313
const name = `Arduino: ${tool}`;
1414
// Zen-mode: we do not reveal the output for daemon messages.
15-
const show = tool === 'daemon' ? Promise.resolve() : this.commandService.executeCommand(OutputCommands.SHOW.id, { name, options: { preserveFocus: false } });
15+
const show = tool === 'daemon22' ? Promise.resolve() : this.commandService.executeCommand(OutputCommands.SHOW.id, { name, options: { preserveFocus: false } });
1616
show.then(() => this.commandService.executeCommand(OutputCommands.APPEND.id, { name, text }));
1717
}
1818

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { inject, injectable } from 'inversify';
2+
import URI from '@theia/core/lib/common/uri';
3+
import { notEmpty } from '@theia/core/lib/common/objects';
4+
import { FileSystem } from '@theia/filesystem/lib/common';
5+
import { MessageService } from '@theia/core/lib/common/message-service';
6+
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
7+
import { Sketch, SketchesService } from '../../common/protocol';
8+
9+
@injectable()
10+
export class SketchesServiceClientImpl {
11+
12+
@inject(FileSystem)
13+
protected readonly fileSystem: FileSystem;
14+
15+
@inject(MessageService)
16+
protected readonly messageService: MessageService;
17+
18+
@inject(SketchesService)
19+
protected readonly sketchService: SketchesService;
20+
21+
@inject(WorkspaceService)
22+
protected readonly workspaceService: WorkspaceService;
23+
24+
async currentSketch(): Promise<Sketch | undefined> {
25+
const sketches = (await Promise.all(this.workspaceService.tryGetRoots().map(({ uri }) => this.sketchService.getSketchFolder(uri)))).filter(notEmpty);
26+
if (!sketches.length) {
27+
return undefined;
28+
}
29+
if (sketches.length > 1) {
30+
console.log(`Multiple sketch folders were found in the workspace. Falling back to the first one. Sketch folders: ${JSON.stringify(sketches)}`);
31+
}
32+
return sketches[0];
33+
}
34+
35+
async currentSketchFile(): Promise<string | undefined> {
36+
const sketch = await this.currentSketch();
37+
if (sketch) {
38+
const uri = new URI(sketch.uri).resolve(`${sketch.name}.ino`).toString();
39+
const exists = await this.fileSystem.exists(uri);
40+
if (!exists) {
41+
this.messageService.warn(`Could not find sketch file: ${uri}`);
42+
return undefined;
43+
}
44+
return uri;
45+
}
46+
return undefined;
47+
}
48+
49+
}

arduino-ide-extension/src/common/protocol/sketches-service.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ export interface SketchesService {
88
*/
99
getSketches(uri?: string): Promise<Sketch[]>;
1010

11-
getSketchFiles(uri: string): Promise<string[]>;
11+
/**
12+
* This is the TS implementation of `SketchLoad` from the CLI and should be replaced with a gRPC call eventually.
13+
* See: https://github.com/arduino/arduino-cli/issues/837
14+
* Based on: https://github.com/arduino/arduino-cli/blob/eef3705c4afcba4317ec38b803d9ffce5dd59a28/arduino/builder/sketch.go#L100-L215
15+
*/
16+
loadSketch(uri: string): Promise<Sketch>;
1217

1318
/**
1419
* Creates a new sketch folder in the temp location.
@@ -40,7 +45,10 @@ export interface SketchesService {
4045

4146
export interface Sketch {
4247
readonly name: string;
43-
readonly uri: string;
48+
readonly uri: string; // `LocationPath`
49+
readonly mainFileUri: string; // `MainFile`
50+
readonly otherSketchFileUris: string[]; // `OtherSketchFiles`
51+
readonly additionalFileUris: string[]; // `AdditionalFiles`
4452
}
4553
export namespace Sketch {
4654
export function is(arg: any): arg is Sketch {

0 commit comments

Comments
 (0)