Skip to content

Commit 94233a1

Browse files
authored
Merge pull request #80 from bcmi-labs/0.3.0-rc
All in on PR for 0.0.3
2 parents 7fb3276 + 4e683b2 commit 94233a1

File tree

68 files changed

+2698
-2043
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+2698
-2043
lines changed

.vscode/settings.json

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
11
{
2-
"typescript.tsdk": "node_modules/typescript/lib"
3-
}
2+
"tslint.enable": true,
3+
"tslint.configFile": "./tslint.json",
4+
"editor.formatOnSave": true,
5+
"files.exclude": {
6+
"**/lib": false
7+
},
8+
"editor.insertSpaces": true,
9+
"editor.detectIndentation": false,
10+
"[typescript]": {
11+
"editor.tabSize": 4
12+
},
13+
"[json]": {
14+
"editor.tabSize": 2
15+
},
16+
"[jsonc]": {
17+
"editor.tabSize": 2
18+
},
19+
"files.insertFinalNewline": true,
20+
"typescript.tsdk": "node_modules/typescript/lib"
21+
}

arduino-ide-extension/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "arduino-ide-extension",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "An extension for Theia building the Arduino IDE",
55
"license": "MIT",
66
"engines": {
@@ -58,7 +58,7 @@
5858
"rimraf": "^2.6.1",
5959
"shelljs": "^0.8.3",
6060
"tslint": "^5.5.0",
61-
"typescript": "2.9.1",
61+
"typescript": "3.5.3",
6262
"uuid": "^3.2.1",
6363
"yargs": "^11.1.0"
6464
},

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

+103-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { injectable, inject, postConstruct } from 'inversify';
33
import URI from '@theia/core/lib/common/uri';
44
import { EditorWidget } from '@theia/editor/lib/browser/editor-widget';
55
import { MessageService } from '@theia/core/lib/common/message-service';
6-
import { CommandContribution, CommandRegistry, Command } from '@theia/core/lib/common/command';
6+
import { CommandContribution, CommandRegistry, Command, CommandHandler } from '@theia/core/lib/common/command';
77
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
88
import { BoardsService } from '../common/protocol/boards-service';
99
import { ArduinoCommands } from './arduino-commands';
@@ -22,9 +22,11 @@ import {
2222
OpenerService,
2323
Widget,
2424
StatusBar,
25-
ShellLayoutRestorer,
2625
StatusBarAlignment,
27-
QuickOpenService
26+
QuickOpenService,
27+
ApplicationShell,
28+
FrontendApplicationContribution,
29+
FrontendApplication
2830
} from '@theia/core/lib/browser';
2931
import { OpenFileDialogProps, FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
3032
import { FileSystem, FileStat } from '@theia/filesystem/lib/common';
@@ -44,6 +46,14 @@ import { ConfigService } from '../common/protocol/config-service';
4446
import { MonitorConnection } from './monitor/monitor-connection';
4547
import { MonitorViewContribution } from './monitor/monitor-view-contribution';
4648
import { ArduinoWorkspaceService } from './arduino-workspace-service';
49+
import { FileNavigatorContribution } from '@theia/navigator/lib/browser/navigator-contribution';
50+
import { OutlineViewContribution } from '@theia/outline-view/lib/browser/outline-view-contribution';
51+
import { ProblemContribution } from '@theia/markers/lib/browser/problem/problem-contribution';
52+
import { ScmContribution } from '@theia/scm/lib/browser/scm-contribution';
53+
import { SearchInWorkspaceFrontendContribution } from '@theia/search-in-workspace/lib/browser/search-in-workspace-frontend-contribution';
54+
import { FileNavigatorCommands } from '@theia/navigator/lib/browser/navigator-contribution';
55+
import { ArduinoShellLayoutRestorer } from './shell/arduino-shell-layout-restorer';
56+
import { EditorMode } from './editor-mode';
4757

4858
export namespace ArduinoMenus {
4959
export const SKETCH = [...MAIN_MENU_BAR, '3_sketch'];
@@ -57,16 +67,8 @@ export namespace ArduinoToolbarContextMenu {
5767
export const EXAMPLE_SKETCHES_GROUP: MenuPath = [...OPEN_SKETCH_PATH, '3_examples'];
5868
}
5969

60-
export namespace ArduinoAdvancedMode {
61-
export const LS_ID = 'arduino-advanced-mode';
62-
export const TOGGLED: boolean = (() => {
63-
const advancedModeStr = window.localStorage.getItem(LS_ID);
64-
return advancedModeStr === 'true';
65-
})();
66-
}
67-
6870
@injectable()
69-
export class ArduinoFrontendContribution implements TabBarToolbarContribution, CommandContribution, MenuContribution {
71+
export class ArduinoFrontendContribution implements FrontendApplicationContribution, TabBarToolbarContribution, CommandContribution, MenuContribution {
7072

7173
@inject(MessageService)
7274
protected readonly messageService: MessageService;
@@ -126,13 +128,13 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
126128
protected readonly menuRegistry: MenuModelRegistry;
127129

128130
@inject(CommandRegistry)
129-
protected readonly commands: CommandRegistry;
131+
protected readonly commandRegistry: CommandRegistry;
130132

131133
@inject(StatusBar)
132134
protected readonly statusBar: StatusBar;
133135

134-
@inject(ShellLayoutRestorer)
135-
protected readonly layoutRestorer: ShellLayoutRestorer;
136+
@inject(ArduinoShellLayoutRestorer)
137+
protected readonly layoutRestorer: ArduinoShellLayoutRestorer;
136138

137139
@inject(QuickOpenService)
138140
protected readonly quickOpenService: QuickOpenService;
@@ -146,8 +148,29 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
146148
@inject(MonitorConnection)
147149
protected readonly monitorConnection: MonitorConnection;
148150

149-
protected boardsToolbarItem: BoardsToolBarItem | null;
150-
protected wsSketchCount: number = 0;
151+
@inject(ApplicationShell)
152+
protected readonly shell: ApplicationShell;
153+
154+
@inject(FileNavigatorContribution)
155+
protected readonly fileNavigatorContributions: FileNavigatorContribution;
156+
157+
@inject(OutlineViewContribution)
158+
protected readonly outlineContribution: OutlineViewContribution;
159+
160+
@inject(ProblemContribution)
161+
protected readonly problemContribution: ProblemContribution;
162+
163+
@inject(ScmContribution)
164+
protected readonly scmContribution: ScmContribution;
165+
166+
@inject(SearchInWorkspaceFrontendContribution)
167+
protected readonly siwContribution: SearchInWorkspaceFrontendContribution;
168+
169+
@inject(EditorMode)
170+
protected readonly editorMode: EditorMode;
171+
172+
protected application: FrontendApplication;
173+
protected wsSketchCount: number = 0; // TODO: this does not belong here, does it?
151174

152175
@postConstruct()
153176
protected async init(): Promise<void> {
@@ -171,6 +194,22 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
171194
]).then(([{ boards }, { ports }]) => this.boardsServiceClient.tryReconnect(boards, ports));
172195
}
173196

197+
onStart(app: FrontendApplication): void {
198+
this.application = app;
199+
// Initialize all `pro-mode` widgets. This is a NOOP if in normal mode.
200+
for (const viewContribution of [
201+
this.fileNavigatorContributions,
202+
this.outlineContribution,
203+
this.problemContribution,
204+
this.scmContribution,
205+
this.siwContribution] as Array<FrontendApplicationContribution>) {
206+
207+
if (viewContribution.initializeLayout) {
208+
viewContribution.initializeLayout(this.application);
209+
}
210+
}
211+
}
212+
174213
registerToolbarItems(registry: TabBarToolbarRegistry): void {
175214
registry.registerItem({
176215
id: ArduinoCommands.VERIFY.id,
@@ -196,8 +235,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
196235
id: BoardsToolBarItem.TOOLBAR_ID,
197236
render: () => <BoardsToolBarItem
198237
key='boardsToolbarItem'
199-
ref={ref => this.boardsToolbarItem = ref}
200-
commands={this.commands}
238+
commands={this.commandRegistry}
201239
boardsServiceClient={this.boardsServiceClient}
202240
boardService={this.boardsService} />,
203241
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left'
@@ -213,12 +251,48 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
213251
id: ArduinoCommands.TOGGLE_ADVANCED_MODE.id,
214252
command: ArduinoCommands.TOGGLE_ADVANCED_MODE.id,
215253
tooltip: 'Toggle Advanced Mode',
216-
text: (ArduinoAdvancedMode.TOGGLED ? '$(toggle-on)' : '$(toggle-off)'),
254+
text: (this.editorMode.proMode ? '$(toggle-on)' : '$(toggle-off)'),
217255
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right'
218256
});
219257
}
220258

221259
registerCommands(registry: CommandRegistry): void {
260+
// TODO: use proper API https://github.com/eclipse-theia/theia/pull/6599
261+
const allHandlers: { [id: string]: CommandHandler[] } = (registry as any)._handlers;
262+
// Make sure to reveal the `Explorer` before executing `New File` and `New Folder`.
263+
for (const command of [WorkspaceCommands.NEW_FILE, WorkspaceCommands.NEW_FOLDER]) {
264+
const { id } = command;
265+
const handlers = allHandlers[id].slice();
266+
registry.unregisterCommand(id);
267+
registry.registerCommand(command);
268+
for (const handler of handlers) {
269+
const wrapper: CommandHandler = {
270+
execute: (...args: any[]) => {
271+
this.fileNavigatorContributions.openView({ reveal: true }).then(() => handler.execute(args));
272+
},
273+
isVisible: (...args: any[]) => {
274+
return handler.isVisible!(args);
275+
},
276+
isEnabled: (args: any[]) => {
277+
return handler.isEnabled!(args);
278+
},
279+
isToggled: (args: any[]) => {
280+
return handler.isToggled!(args);
281+
}
282+
};
283+
if (!handler.isEnabled) {
284+
delete wrapper.isEnabled;
285+
}
286+
if (!handler.isToggled) {
287+
delete wrapper.isToggled;
288+
}
289+
if (!handler.isVisible) {
290+
delete wrapper.isVisible;
291+
}
292+
registry.registerHandler(id, wrapper);
293+
}
294+
}
295+
222296
registry.registerCommand(ArduinoCommands.VERIFY, {
223297
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
224298
isEnabled: widget => true,
@@ -296,7 +370,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
296370
});
297371
}
298372
} else {
299-
this.commands.executeCommand(ArduinoCommands.OPEN_FILE_NAVIGATOR.id);
373+
this.commandRegistry.executeCommand(ArduinoCommands.OPEN_FILE_NAVIGATOR.id);
300374
}
301375
}
302376
});
@@ -342,18 +416,14 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
342416
}
343417
})
344418
registry.registerCommand(ArduinoCommands.TOGGLE_ADVANCED_MODE, {
345-
execute: () => {
346-
const oldModeState = ArduinoAdvancedMode.TOGGLED;
347-
window.localStorage.setItem(ArduinoAdvancedMode.LS_ID, oldModeState ? 'false' : 'true');
348-
registry.executeCommand('reset.layout');
349-
},
419+
execute: () => this.editorMode.toggle(),
350420
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right',
351-
isToggled: () => ArduinoAdvancedMode.TOGGLED
421+
isToggled: () => this.editorMode.proMode
352422
})
353423
}
354424

355425
registerMenus(registry: MenuModelRegistry) {
356-
if (!ArduinoAdvancedMode.TOGGLED) {
426+
if (!this.editorMode.proMode) {
357427
// If are not in pro-mode, we have to disable the context menu for the tabs.
358428
// Such as `Close`, `Close All`, etc.
359429
for (const command of [
@@ -362,16 +432,15 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
362432
CommonCommands.CLOSE_RIGHT_TABS,
363433
CommonCommands.CLOSE_ALL_TABS,
364434
CommonCommands.COLLAPSE_PANEL,
365-
CommonCommands.TOGGLE_MAXIMIZED
435+
CommonCommands.TOGGLE_MAXIMIZED,
436+
FileNavigatorCommands.REVEAL_IN_NAVIGATOR
366437
]) {
367438
registry.unregisterMenuAction(command);
368439
}
369440

370441
registry.unregisterMenuAction(FileSystemCommands.UPLOAD);
371442
registry.unregisterMenuAction(FileDownloadCommands.DOWNLOAD);
372443

373-
registry.unregisterMenuAction(WorkspaceCommands.NEW_FOLDER);
374-
375444
registry.unregisterMenuAction(WorkspaceCommands.OPEN_FOLDER);
376445
registry.unregisterMenuAction(WorkspaceCommands.OPEN_WORKSPACE);
377446
registry.unregisterMenuAction(WorkspaceCommands.OPEN_RECENT_WORKSPACE);
@@ -425,8 +494,8 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
425494
const command: Command = {
426495
id: 'openSketch' + sketch.name
427496
}
428-
this.commands.registerCommand(command, {
429-
execute: () => this.commands.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch)
497+
this.commandRegistry.registerCommand(command, {
498+
execute: () => this.commandRegistry.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch)
430499
});
431500

432501
registry.registerMenuAction(ArduinoToolbarContextMenu.WS_SKETCHES_GROUP, {
@@ -466,7 +535,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
466535
if (destinationFile && !destinationFile.isDirectory) {
467536
const message = await this.validate(destinationFile);
468537
if (!message) {
469-
await this.workspaceService.open(destinationFileUri);
538+
this.workspaceService.open(destinationFileUri);
470539
return destinationFileUri;
471540
} else {
472541
this.messageService.warn(message);

0 commit comments

Comments
 (0)