Skip to content

Commit 5abfc2c

Browse files
author
Akos Kitta
committed
chopped up the FE contribution
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent b6df6b5 commit 5abfc2c

14 files changed

+513
-170
lines changed

arduino-ide-extension/src/browser/arduino-commands.ts

-27
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,17 @@ export namespace ArduinoCommands {
2424
id: 'arduino-toggle-compile-for-debug'
2525
};
2626

27-
export const SHOW_OPEN_CONTEXT_MENU: Command = {
28-
id: 'arduino-show-open-context-menu',
29-
label: 'Open Sketch',
30-
category
31-
};
32-
3327
export const OPEN_FILE_NAVIGATOR: Command = {
3428
id: 'arduino-open-file-navigator'
3529
};
3630

37-
export const OPEN_SKETCH: Command = {
38-
id: 'arduino-open-file'
39-
};
40-
4131
/**
4232
* Unlike `OPEN_SKETCH`, it opens all files from a sketch folder. (ino, cpp, etc...)
4333
*/
4434
export const OPEN_SKETCH_FILES: Command = {
4535
id: 'arduino-open-sketch-files'
4636
};
4737

48-
export const SAVE_SKETCH: Command = {
49-
id: 'arduino-save-sketch'
50-
};
51-
52-
export const SAVE_SKETCH_AS: Command = {
53-
id: 'arduino-save-sketch-as'
54-
};
55-
56-
export const NEW_SKETCH: Command = {
57-
id: 'arduino-new-sketch',
58-
label: 'New Sketch',
59-
category
60-
};
61-
export const NEW_SKETCH_TOOLBAR: Command = {
62-
id: 'arduino-new-sketch-toolbar'
63-
};
64-
6538
export const OPEN_BOARDS_DIALOG: Command = {
6639
id: 'arduino-open-boards-dialog'
6740
};

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

+14-139
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
import * as React from 'react';
2-
import * as dateFormat from 'dateformat';
3-
import { remote } from 'electron';
42
import { injectable, inject, postConstruct } from 'inversify';
53
import URI from '@theia/core/lib/common/uri';
64
import { EditorWidget } from '@theia/editor/lib/browser/editor-widget';
75
import { MessageService } from '@theia/core/lib/common/message-service';
86
import { CommandContribution, CommandRegistry, Command, CommandHandler } from '@theia/core/lib/common/command';
97
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
10-
import { BoardsService, BoardsServiceClient, CoreService, Sketch, SketchesService, ToolOutputServiceClient } from '../common/protocol';
8+
import { BoardsService, BoardsServiceClient, CoreService, SketchesService, ToolOutputServiceClient } from '../common/protocol';
119
import { ArduinoCommands } from './arduino-commands';
1210
import { BoardsServiceClientImpl } from './boards/boards-service-client-impl';
1311
import { WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands';
14-
import { SelectionService, MenuContribution, MenuModelRegistry, MAIN_MENU_BAR, MenuPath, notEmpty } from '@theia/core';
12+
import { SelectionService, MenuContribution, MenuModelRegistry, MAIN_MENU_BAR, MenuPath } from '@theia/core';
1513
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
1614
import { EditorManager, EditorMainMenu } from '@theia/editor/lib/browser';
1715
import {
18-
ContextMenuRenderer, Widget, StatusBar, StatusBarAlignment, FrontendApplicationContribution,
16+
ContextMenuRenderer, StatusBar, StatusBarAlignment, FrontendApplicationContribution,
1917
FrontendApplication, KeybindingContribution, KeybindingRegistry, OpenerService, open
2018
} from '@theia/core/lib/browser';
2119
import { OpenFileDialogProps, FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
2220
import { FileSystem, FileStat } from '@theia/filesystem/lib/common';
2321
import { CommonCommands, CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution';
24-
import { FileSystemCommands } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution';
25-
import { FileDownloadCommands } from '@theia/filesystem/lib/browser/download/file-download-command-contribution';
2622
import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu';
2723
import { TerminalMenus } from '@theia/terminal/lib/browser/terminal-frontend-contribution';
2824
import { MaybePromise } from '@theia/core/lib/common/types';
@@ -47,6 +43,7 @@ import { ConfigService } from '../common/protocol/config-service';
4743
import { BoardsConfigStore } from './boards/boards-config-store';
4844
import { MainMenuManager } from './menu/main-menu-manager';
4945
import { FileSystemExt } from '../common/protocol/filesystem-ext';
46+
import { OpenSketch } from './contributions/open-sketch';
5047

5148
export namespace ArduinoMenus {
5249
export const SKETCH = [...MAIN_MENU_BAR, '3_sketch'];
@@ -209,24 +206,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
209206
tooltip: 'Upload',
210207
priority: 2
211208
});
212-
registry.registerItem({
213-
id: ArduinoCommands.NEW_SKETCH.id,
214-
command: ArduinoCommands.NEW_SKETCH_TOOLBAR.id,
215-
tooltip: 'New',
216-
priority: 4 // Note: priority 3 was reserved by debug.
217-
});
218-
registry.registerItem({
219-
id: ArduinoCommands.SHOW_OPEN_CONTEXT_MENU.id,
220-
command: ArduinoCommands.SHOW_OPEN_CONTEXT_MENU.id,
221-
tooltip: 'Open',
222-
priority: 5
223-
});
224-
registry.registerItem({
225-
id: ArduinoCommands.SAVE_SKETCH.id,
226-
command: ArduinoCommands.SAVE_SKETCH.id,
227-
tooltip: 'Save',
228-
priority: 6
229-
});
230209
registry.registerItem({
231210
id: BoardsToolBarItem.TOOLBAR_ID,
232211
render: () => <BoardsToolBarItem
@@ -308,101 +287,16 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
308287
execute: this.upload.bind(this)
309288
});
310289

311-
registry.registerCommand(ArduinoCommands.SHOW_OPEN_CONTEXT_MENU, {
312-
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
313-
execute: async (widget: Widget, target: EventTarget) => {
314-
if (this.wsSketchCount) {
315-
const el = (target as HTMLElement).parentElement;
316-
if (el) {
317-
this.contextMenuRenderer.render(ArduinoToolbarContextMenu.OPEN_SKETCH_PATH, {
318-
x: el.getBoundingClientRect().left,
319-
y: el.getBoundingClientRect().top + el.offsetHeight
320-
});
321-
}
322-
} else {
323-
this.commandRegistry.executeCommand(ArduinoCommands.OPEN_FILE_NAVIGATOR.id);
324-
}
325-
}
326-
});
327-
328290
registry.registerCommand(ArduinoCommands.OPEN_FILE_NAVIGATOR, {
329291
execute: () => this.doOpenFile()
330292
});
331293

332-
registry.registerCommand(ArduinoCommands.OPEN_SKETCH, {
333-
execute: async (sketch: Sketch) => {
334-
this.workspaceService.open(new URI(sketch.uri));
335-
}
336-
});
337-
338294
registry.registerCommand(ArduinoCommands.OPEN_SKETCH_FILES, {
339295
execute: async (uri: string) => {
340296
this.openSketchFiles(uri);
341297
}
342298
});
343299

344-
registry.registerCommand(ArduinoCommands.SAVE_SKETCH, {
345-
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
346-
execute: (sketch: Sketch) => {
347-
registry.executeCommand(CommonCommands.SAVE_ALL.id);
348-
}
349-
});
350-
351-
registry.registerCommand(ArduinoCommands.SAVE_SKETCH_AS, {
352-
execute: async ({ execOnlyIfTemp }: { execOnlyIfTemp: boolean } = { execOnlyIfTemp: false }) => {
353-
const sketches = (await Promise.all(this.workspaceService.tryGetRoots().map(({ uri }) => this.sketchService.getSketchFolder(uri)))).filter(notEmpty);
354-
if (!sketches.length) {
355-
return;
356-
}
357-
if (sketches.length > 1) {
358-
console.log(`Multiple sketch folders were found in the workspace. Falling back to the first one. Sketch folders: ${JSON.stringify(sketches)}`);
359-
}
360-
const sketch = sketches[0];
361-
const isTemp = await this.sketchService.isTemp(sketch);
362-
if (!isTemp && !!execOnlyIfTemp) {
363-
return;
364-
}
365-
366-
// If target does not exist, propose a `directories.user`/${sketch.name} path
367-
// If target exists, propose `directories.user`/${sketch.name}_copy_${yyyymmddHHMMss}
368-
const sketchDirUri = new URI((await this.configService.getConfiguration()).sketchDirUri);
369-
const exists = await this.fileSystem.exists(sketchDirUri.resolve(sketch.name).toString());
370-
const defaultUri = exists
371-
? sketchDirUri.resolve(sketchDirUri.resolve(`${sketch.name}_copy_${dateFormat(new Date(), 'yyyymmddHHMMss')}`).toString())
372-
: sketchDirUri.resolve(sketch.name);
373-
const defaultPath = await this.fileSystem.getFsPath(defaultUri.toString())!;
374-
const { filePath, canceled } = await remote.dialog.showSaveDialog({ title: 'Save sketch folder as...', defaultPath });
375-
if (!filePath || canceled) {
376-
return;
377-
}
378-
const destinationUri = await this.fileSystemExt.getUri(filePath);
379-
if (!destinationUri) {
380-
return;
381-
}
382-
const workspaceUri = await this.sketchService.copy(sketch, { destinationUri });
383-
if (workspaceUri) {
384-
this.workspaceService.open(new URI(workspaceUri));
385-
}
386-
}
387-
});
388-
389-
registry.registerCommand(ArduinoCommands.NEW_SKETCH, {
390-
execute: async () => {
391-
try {
392-
const sketch = await this.sketchService.createNewSketch();
393-
this.workspaceService.open(new URI(sketch.uri));
394-
} catch (e) {
395-
await this.messageService.error(e.toString());
396-
}
397-
}
398-
});
399-
registry.registerCommand(ArduinoCommands.NEW_SKETCH_TOOLBAR, {
400-
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
401-
execute: async () => {
402-
return registry.executeCommand(ArduinoCommands.NEW_SKETCH.id);
403-
}
404-
});
405-
406300
registry.registerCommand(ArduinoCommands.OPEN_BOARDS_DIALOG, {
407301
execute: async () => {
408302
const boardsConfig = await this.boardsConfigDialog.open();
@@ -516,17 +410,18 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
516410
CommonCommands.TOGGLE_MAXIMIZED,
517411
FileNavigatorCommands.REVEAL_IN_NAVIGATOR
518412
]) {
519-
registry.unregisterMenuAction(command);
413+
if (command) { }
414+
// registry.unregisterMenuAction(command);
520415
}
521416

522-
registry.unregisterMenuAction(FileSystemCommands.UPLOAD);
523-
registry.unregisterMenuAction(FileDownloadCommands.DOWNLOAD);
417+
// registry.unregisterMenuAction(FileSystemCommands.UPLOAD);
418+
// registry.unregisterMenuAction(FileDownloadCommands.DOWNLOAD);
524419

525-
registry.unregisterMenuAction(WorkspaceCommands.OPEN_FOLDER);
526-
registry.unregisterMenuAction(WorkspaceCommands.OPEN_WORKSPACE);
527-
registry.unregisterMenuAction(WorkspaceCommands.OPEN_RECENT_WORKSPACE);
528-
registry.unregisterMenuAction(WorkspaceCommands.SAVE_WORKSPACE_AS);
529-
registry.unregisterMenuAction(WorkspaceCommands.CLOSE);
420+
// registry.unregisterMenuAction(WorkspaceCommands.OPEN_FOLDER);
421+
// registry.unregisterMenuAction(WorkspaceCommands.OPEN_WORKSPACE);
422+
// registry.unregisterMenuAction(WorkspaceCommands.OPEN_RECENT_WORKSPACE);
423+
// registry.unregisterMenuAction(WorkspaceCommands.SAVE_WORKSPACE_AS);
424+
// registry.unregisterMenuAction(WorkspaceCommands.CLOSE);
530425

531426
registry.getMenu(MAIN_MENU_BAR).removeNode(this.getMenuId(MonacoMenus.SELECTION));
532427
registry.getMenu(MAIN_MENU_BAR).removeNode(this.getMenuId(EditorMainMenu.GO));
@@ -549,10 +444,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
549444
label: 'Upload',
550445
order: '3'
551446
});
552-
registry.registerMenuAction(ArduinoToolbarContextMenu.OPEN_GROUP, {
553-
commandId: ArduinoCommands.OPEN_FILE_NAVIGATOR.id,
554-
label: 'Open...'
555-
});
556447

557448
registry.registerSubmenu(ArduinoMenus.TOOLS, 'Tools');
558449

@@ -561,18 +452,10 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
561452
label: 'Advanced Mode'
562453
});
563454

564-
registry.registerMenuAction([...CommonMenus.FILE, '0_new_sketch'], {
565-
commandId: ArduinoCommands.NEW_SKETCH.id
566-
});
567-
568455
registry.registerMenuAction([...CommonMenus.FILE_SETTINGS_SUBMENU, '3_settings_cli'], {
569456
commandId: ArduinoCommands.OPEN_CLI_CONFIG.id
570457
});
571458

572-
registry.registerMenuAction(CommonMenus.FILE_SAVE, {
573-
commandId: ArduinoCommands.SAVE_SKETCH_AS.id,
574-
label: 'Save As...'
575-
});
576459
}
577460

578461
protected getMenuId(menuPath: string[]): string {
@@ -591,14 +474,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
591474
command: ArduinoCommands.UPLOAD.id,
592475
keybinding: 'CtrlCmd+Alt+U'
593476
});
594-
keybindings.registerKeybinding({
595-
command: ArduinoCommands.NEW_SKETCH.id,
596-
keybinding: 'CtrlCmd+N'
597-
});
598-
keybindings.registerKeybinding({
599-
command: ArduinoCommands.SAVE_SKETCH_AS.id,
600-
keybinding: 'CtrlCmd+Shift+S'
601-
});
602477
}
603478

604479
protected async registerSketchesInMenu(registry: MenuModelRegistry): Promise<void> {
@@ -609,7 +484,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
609484
id: 'openSketch' + sketch.name
610485
}
611486
this.commandRegistry.registerCommand(command, {
612-
execute: () => this.commandRegistry.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch)
487+
execute: () => this.commandRegistry.executeCommand(OpenSketch.Commands.OPEN_SKETCH.id, sketch)
613488
});
614489

615490
registry.registerMenuAction(ArduinoToolbarContextMenu.WS_SKETCHES_GROUP, {

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

+12
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ import { ILogger } from '@theia/core';
7979
import { FileSystemExt, FileSystemExtPath } from '../common/protocol/filesystem-ext';
8080
import { WorkspaceFrontendContribution, FileMenuContribution } from '@theia/workspace/lib/browser';
8181
import { ArduinoWorkspaceFrontendContribution, ArduinoFileMenuContribution } from './customization/arduino-workspace-frontend-contribution';
82+
import { Contribution } from './contributions/contribution';
83+
import { NewSketch } from './contributions/new-sketch';
84+
import { OpenSketch } from './contributions/open-sketch';
85+
import { CloseSketch } from './contributions/close-sketch';
86+
import { SaveAsSketch } from './contributions/save-as-sketch';
87+
import { SaveSketch } from './contributions/save-sketch';
8288

8389
const ElementQueries = require('css-element-queries/src/ElementQueries');
8490

@@ -298,4 +304,10 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
298304

299305
// File-system extension
300306
bind(FileSystemExt).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, FileSystemExtPath)).inSingletonScope();
307+
308+
Contribution.configure(bind, NewSketch);
309+
Contribution.configure(bind, OpenSketch);
310+
Contribution.configure(bind, CloseSketch);
311+
Contribution.configure(bind, SaveSketch);
312+
Contribution.configure(bind, SaveAsSketch);
301313
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { injectable } from 'inversify';
2+
import { WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands';
3+
import { ArduinoMenus } from '../menu/arduino-menus';
4+
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry } from './contribution';
5+
import { SaveAsSketch } from './save-as-sketch';
6+
7+
@injectable()
8+
export class CloseSketch extends SketchContribution {
9+
10+
registerCommands(registry: CommandRegistry): void {
11+
registry.registerCommand(CloseSketch.Commands.CLOSE_SKETCH, {
12+
execute: async () => {
13+
const sketch = await this.getCurrentSketch();
14+
if (!sketch) {
15+
return;
16+
}
17+
const isTemp = await this.sketchService.isTemp(sketch);
18+
if (isTemp) {
19+
await this.commandService.executeCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH.id, { openAfterMove: false, execOnlyIfTemp: true });
20+
await this.commandService.executeCommand(WorkspaceCommands.CLOSE.id);
21+
}
22+
}
23+
});
24+
}
25+
26+
registerMenus(registry: MenuModelRegistry): void {
27+
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
28+
commandId: CloseSketch.Commands.CLOSE_SKETCH.id,
29+
label: 'Close',
30+
order: '5'
31+
});
32+
}
33+
34+
registerKeybindings(registry: KeybindingRegistry): void {
35+
registry.registerKeybinding({
36+
command: CloseSketch.Commands.CLOSE_SKETCH.id,
37+
keybinding: 'CtrlCmd+W' // TODO: Windows binding?
38+
});
39+
}
40+
41+
}
42+
43+
export namespace CloseSketch {
44+
export namespace Commands {
45+
export const CLOSE_SKETCH: Command = {
46+
id: 'arduino-close-sketch'
47+
};
48+
}
49+
}

0 commit comments

Comments
 (0)