Skip to content

Commit 7077303

Browse files
author
Akos Kitta
committed
Hid the Explorer. Disabled new folder in workspace
when not in `pro-mode`. Closes arduino/arduino-pro-ide#84. Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent acd9bf1 commit 7077303

File tree

6 files changed

+48
-29
lines changed

6 files changed

+48
-29
lines changed

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

+26-16
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import { OutlineViewContribution } from '@theia/outline-view/lib/browser/outline
5353
import { ProblemContribution } from '@theia/markers/lib/browser/problem/problem-contribution';
5454
import { ScmContribution } from '@theia/scm/lib/browser/scm-contribution';
5555
import { SearchInWorkspaceFrontendContribution } from '@theia/search-in-workspace/lib/browser/search-in-workspace-frontend-contribution';
56+
import { FileNavigatorCommands } from '@theia/navigator/lib/browser/navigator-contribution';
5657

5758
export namespace ArduinoMenus {
5859
export const SKETCH = [...MAIN_MENU_BAR, '3_sketch'];
@@ -66,11 +67,11 @@ export namespace ArduinoToolbarContextMenu {
6667
export const EXAMPLE_SKETCHES_GROUP: MenuPath = [...OPEN_SKETCH_PATH, '3_examples'];
6768
}
6869

69-
export namespace ArduinoAdvancedMode {
70-
export const LS_ID = 'arduino-advanced-mode';
71-
export const TOGGLED: boolean = (() => {
72-
const advancedModeStr = window.localStorage.getItem(LS_ID);
73-
return advancedModeStr === 'true';
70+
export namespace EditorMode {
71+
export const PRO_MODE_KEY = 'arduino-advanced-mode';
72+
export const IN_PRO_MODE: boolean = (() => {
73+
const value = window.localStorage.getItem(PRO_MODE_KEY);
74+
return value === 'true';
7475
})();
7576
}
7677

@@ -135,7 +136,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
135136
protected readonly menuRegistry: MenuModelRegistry;
136137

137138
@inject(CommandRegistry)
138-
protected readonly commands: CommandRegistry;
139+
protected readonly commandRegistry: CommandRegistry;
139140

140141
@inject(StatusBar)
141142
protected readonly statusBar: StatusBar;
@@ -181,6 +182,13 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
181182
// This is a hack. Otherwise, the backend services won't bind.
182183
await this.workspaceServiceExt.roots();
183184

185+
if (!EditorMode.IN_PRO_MODE) {
186+
const { ADD_FOLDER, REMOVE_FOLDER, SAVE_WORKSPACE_AS } = WorkspaceCommands;
187+
for (const command of [ADD_FOLDER, REMOVE_FOLDER, SAVE_WORKSPACE_AS]) {
188+
this.commandRegistry.unregisterCommand(command);
189+
}
190+
}
191+
184192
const updateStatusBar = (config: BoardsConfig.Config) => {
185193
this.statusBar.setElement('arduino-selected-board', {
186194
alignment: StatusBarAlignment.RIGHT,
@@ -239,7 +247,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
239247
id: BoardsToolBarItem.TOOLBAR_ID,
240248
render: () => <BoardsToolBarItem
241249
key='boardsToolbarItem'
242-
commands={this.commands}
250+
commands={this.commandRegistry}
243251
boardsServiceClient={this.boardsServiceClient}
244252
boardService={this.boardsService} />,
245253
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left'
@@ -255,7 +263,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
255263
id: ArduinoCommands.TOGGLE_ADVANCED_MODE.id,
256264
command: ArduinoCommands.TOGGLE_ADVANCED_MODE.id,
257265
tooltip: 'Toggle Advanced Mode',
258-
text: (ArduinoAdvancedMode.TOGGLED ? '$(toggle-on)' : '$(toggle-off)'),
266+
text: (EditorMode.IN_PRO_MODE ? '$(toggle-on)' : '$(toggle-off)'),
259267
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right'
260268
});
261269
}
@@ -338,7 +346,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
338346
});
339347
}
340348
} else {
341-
this.commands.executeCommand(ArduinoCommands.OPEN_FILE_NAVIGATOR.id);
349+
this.commandRegistry.executeCommand(ArduinoCommands.OPEN_FILE_NAVIGATOR.id);
342350
}
343351
}
344352
});
@@ -385,9 +393,9 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
385393
})
386394
registry.registerCommand(ArduinoCommands.TOGGLE_ADVANCED_MODE, {
387395
execute: async () => {
388-
const oldState = ArduinoAdvancedMode.TOGGLED;
396+
const oldState = EditorMode.IN_PRO_MODE;
389397
const inAdvancedMode = !oldState;
390-
window.localStorage.setItem(ArduinoAdvancedMode.LS_ID, String(inAdvancedMode));
398+
window.localStorage.setItem(EditorMode.PRO_MODE_KEY, String(inAdvancedMode));
391399
if (!inAdvancedMode) {
392400
// Close all widget that is neither editor nor `Output`.
393401
for (const area of ['left', 'right', 'bottom', 'main'] as Array<ApplicationShell.Area>) {
@@ -401,12 +409,12 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
401409
window.location.reload(true);
402410
},
403411
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right',
404-
isToggled: () => ArduinoAdvancedMode.TOGGLED
412+
isToggled: () => EditorMode.IN_PRO_MODE
405413
})
406414
}
407415

408416
registerMenus(registry: MenuModelRegistry) {
409-
if (!ArduinoAdvancedMode.TOGGLED) {
417+
if (!EditorMode.IN_PRO_MODE) {
410418
// If are not in pro-mode, we have to disable the context menu for the tabs.
411419
// Such as `Close`, `Close All`, etc.
412420
for (const command of [
@@ -415,7 +423,9 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
415423
CommonCommands.CLOSE_RIGHT_TABS,
416424
CommonCommands.CLOSE_ALL_TABS,
417425
CommonCommands.COLLAPSE_PANEL,
418-
CommonCommands.TOGGLE_MAXIMIZED
426+
CommonCommands.TOGGLE_MAXIMIZED,
427+
FileNavigatorCommands.REVEAL_IN_NAVIGATOR
428+
419429
]) {
420430
registry.unregisterMenuAction(command);
421431
}
@@ -478,8 +488,8 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
478488
const command: Command = {
479489
id: 'openSketch' + sketch.name
480490
}
481-
this.commands.registerCommand(command, {
482-
execute: () => this.commands.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch)
491+
this.commandRegistry.registerCommand(command, {
492+
execute: () => this.commandRegistry.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch)
483493
});
484494

485495
registry.registerMenuAction(ArduinoToolbarContextMenu.WS_SKETCHES_GROUP, {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { LanguageGrammarDefinitionContribution } from '@theia/monaco/lib/browser
1010
import { LanguageClientContribution } from '@theia/languages/lib/browser';
1111
import { ArduinoLanguageClientContribution } from './language/arduino-language-client-contribution';
1212
import { LibraryListWidget } from './library/library-list-widget';
13-
import { ArduinoFrontendContribution, ArduinoAdvancedMode } from './arduino-frontend-contribution';
13+
import { ArduinoFrontendContribution, EditorMode } from './arduino-frontend-contribution';
1414
import { ArduinoLanguageGrammarContribution } from './language/arduino-language-grammar-contribution';
1515
import { LibraryService, LibraryServicePath } from '../common/protocol/library-service';
1616
import { BoardsService, BoardsServicePath, BoardsServiceClient } from '../common/protocol/boards-service';
@@ -199,7 +199,7 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
199199
themeService.register(...ArduinoTheme.themes);
200200

201201
// Customizing default Theia layout
202-
if (!ArduinoAdvancedMode.TOGGLED) {
202+
if (!EditorMode.IN_PRO_MODE) {
203203
unbind(OutlineViewContribution);
204204
bind(OutlineViewContribution).to(SilentOutlineViewContribution).inSingletonScope();
205205
unbind(ProblemContribution);
@@ -220,7 +220,7 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
220220
bind(SearchInWorkspaceFrontendContribution).to(SilentSearchInWorkspaceContribution).inSingletonScope();
221221
} else {
222222
// We use this CSS class on the body to modify the visibility of the close button for the editors and views.
223-
document.body.classList.add(ArduinoAdvancedMode.LS_ID);
223+
document.body.classList.add(EditorMode.PRO_MODE_KEY);
224224
}
225225
unbind(FrontendApplication);
226226
bind(FrontendApplication).to(ArduinoFrontendApplication).inSingletonScope();

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service
44
import { ConfigService } from '../common/protocol/config-service';
55
import { SketchesService } from '../common/protocol/sketches-service';
66
import { ArduinoWorkspaceRootResolver } from './arduino-workspace-resolver';
7-
import { ArduinoAdvancedMode } from './arduino-frontend-contribution';
7+
import { EditorMode as EditorMode } from './arduino-frontend-contribution';
88

99
@injectable()
1010
export class ArduinoWorkspaceService extends WorkspaceService {
@@ -18,7 +18,7 @@ export class ArduinoWorkspaceService extends WorkspaceService {
1818
@inject(LabelProvider)
1919
protected readonly labelProvider: LabelProvider;
2020

21-
async getDefaultWorkspacePath(): Promise<string | undefined> {
21+
async getDefaultWorkspaceUri(): Promise<string | undefined> {
2222
const [hash, recentWorkspaces, recentSketches] = await Promise.all([
2323
window.location.hash,
2424
this.sketchService.getSketches().then(sketches => sketches.map(({ uri }) => uri)),
@@ -36,7 +36,8 @@ export class ArduinoWorkspaceService extends WorkspaceService {
3636
await this.server.setMostRecentlyUsedWorkspace(uri);
3737
return toOpen.uri;
3838
}
39-
return (await this.sketchService.createNewSketch()).uri;
39+
const { sketchDirUri } = (await this.configService.getConfiguration());
40+
return (await this.sketchService.createNewSketch(sketchDirUri)).uri;
4041
}
4142

4243
private async isValid(uri: string): Promise<boolean> {
@@ -46,7 +47,7 @@ export class ArduinoWorkspaceService extends WorkspaceService {
4647
}
4748
// The workspace root location must exist. However, when opening a workspace root in pro-mode,
4849
// the workspace root must not be a sketch folder. It can be the default sketch directory, or any other directories, for instance.
49-
if (!ArduinoAdvancedMode.TOGGLED) {
50+
if (EditorMode.IN_PRO_MODE) {
5051
return true;
5152
}
5253
const sketchFolder = await this.sketchService.isSketchFolder(uri);

arduino-ide-extension/src/browser/customization/arduino-frontend-application.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { injectable, inject } from 'inversify';
22
import { FileSystem } from '@theia/filesystem/lib/common/filesystem';
33
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
44
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
5-
import { ArduinoFrontendContribution, ArduinoAdvancedMode } from '../arduino-frontend-contribution';
5+
import { ArduinoFrontendContribution, EditorMode } from '../arduino-frontend-contribution';
66

77
@injectable()
88
export class ArduinoFrontendApplication extends FrontendApplication {
@@ -21,7 +21,7 @@ export class ArduinoFrontendApplication extends FrontendApplication {
2121
// If not in PRO mode, we open the sketch file with all the related files.
2222
// Otherwise, we reuse the workbench's restore functionality and we do not open anything at all.
2323
// TODO: check `otherwise`. Also, what if we check for opened editors, instead of blindly opening them?
24-
if (!ArduinoAdvancedMode.TOGGLED) {
24+
if (!EditorMode.IN_PRO_MODE) {
2525
this.workspaceService.roots.then(roots => {
2626
for (const root of roots) {
2727
this.fileSystem.exists(root.uri).then(exists => {

arduino-ide-extension/src/browser/customization/silent-navigator-contribution.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import { injectable } from 'inversify';
1+
import { injectable, postConstruct } from 'inversify';
22
import { FileNavigatorContribution } from '@theia/navigator/lib/browser/navigator-contribution';
33
import { FrontendApplication } from '@theia/core/lib/browser';
44

55
@injectable()
66
export class SilentNavigatorContribution extends FileNavigatorContribution {
77

8+
@postConstruct()
9+
protected async init(): Promise<void> {
10+
// @ts-ignore
11+
delete this.toggleCommand; // The `Explorer` should not be accessible via command or keybinding.
12+
return super.init();
13+
}
14+
815
async initializeLayout(app: FrontendApplication): Promise<void> {
916
}
1017

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ export interface SketchesService {
88
getSketches(uri?: string): Promise<Sketch[]>
99
getSketchFiles(uri: string): Promise<string[]>
1010
/**
11-
* Creates a new sketch folder in the `parentUri` location. If `parentUri` is not specified,
12-
* it falls back to the default `sketchDirUri` from the CLI.
11+
* Creates a new sketch folder in the `parentUri` location.
12+
* Normally, `parentUri` is the client's workspace root, or the default `sketchDirUri` from the CLI.
13+
* Note, `parentUri` and `sketchDirUri` can be the same.
1314
*/
14-
createNewSketch(parentUri?: string): Promise<Sketch>
15+
createNewSketch(parentUri: string): Promise<Sketch>
1516
isSketchFolder(uri: string): Promise<boolean>
1617
}
1718

0 commit comments

Comments
 (0)