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>
This commit is contained in:
Akos Kitta 2019-11-14 10:23:57 +01:00
parent acd9bf1354
commit 7077303a36
6 changed files with 48 additions and 29 deletions

View File

@ -53,6 +53,7 @@ import { OutlineViewContribution } from '@theia/outline-view/lib/browser/outline
import { ProblemContribution } from '@theia/markers/lib/browser/problem/problem-contribution'; import { ProblemContribution } from '@theia/markers/lib/browser/problem/problem-contribution';
import { ScmContribution } from '@theia/scm/lib/browser/scm-contribution'; import { ScmContribution } from '@theia/scm/lib/browser/scm-contribution';
import { SearchInWorkspaceFrontendContribution } from '@theia/search-in-workspace/lib/browser/search-in-workspace-frontend-contribution'; import { SearchInWorkspaceFrontendContribution } from '@theia/search-in-workspace/lib/browser/search-in-workspace-frontend-contribution';
import { FileNavigatorCommands } from '@theia/navigator/lib/browser/navigator-contribution';
export namespace ArduinoMenus { export namespace ArduinoMenus {
export const SKETCH = [...MAIN_MENU_BAR, '3_sketch']; export const SKETCH = [...MAIN_MENU_BAR, '3_sketch'];
@ -66,11 +67,11 @@ export namespace ArduinoToolbarContextMenu {
export const EXAMPLE_SKETCHES_GROUP: MenuPath = [...OPEN_SKETCH_PATH, '3_examples']; export const EXAMPLE_SKETCHES_GROUP: MenuPath = [...OPEN_SKETCH_PATH, '3_examples'];
} }
export namespace ArduinoAdvancedMode { export namespace EditorMode {
export const LS_ID = 'arduino-advanced-mode'; export const PRO_MODE_KEY = 'arduino-advanced-mode';
export const TOGGLED: boolean = (() => { export const IN_PRO_MODE: boolean = (() => {
const advancedModeStr = window.localStorage.getItem(LS_ID); const value = window.localStorage.getItem(PRO_MODE_KEY);
return advancedModeStr === 'true'; return value === 'true';
})(); })();
} }
@ -135,7 +136,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
protected readonly menuRegistry: MenuModelRegistry; protected readonly menuRegistry: MenuModelRegistry;
@inject(CommandRegistry) @inject(CommandRegistry)
protected readonly commands: CommandRegistry; protected readonly commandRegistry: CommandRegistry;
@inject(StatusBar) @inject(StatusBar)
protected readonly statusBar: StatusBar; protected readonly statusBar: StatusBar;
@ -181,6 +182,13 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
// This is a hack. Otherwise, the backend services won't bind. // This is a hack. Otherwise, the backend services won't bind.
await this.workspaceServiceExt.roots(); await this.workspaceServiceExt.roots();
if (!EditorMode.IN_PRO_MODE) {
const { ADD_FOLDER, REMOVE_FOLDER, SAVE_WORKSPACE_AS } = WorkspaceCommands;
for (const command of [ADD_FOLDER, REMOVE_FOLDER, SAVE_WORKSPACE_AS]) {
this.commandRegistry.unregisterCommand(command);
}
}
const updateStatusBar = (config: BoardsConfig.Config) => { const updateStatusBar = (config: BoardsConfig.Config) => {
this.statusBar.setElement('arduino-selected-board', { this.statusBar.setElement('arduino-selected-board', {
alignment: StatusBarAlignment.RIGHT, alignment: StatusBarAlignment.RIGHT,
@ -239,7 +247,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
id: BoardsToolBarItem.TOOLBAR_ID, id: BoardsToolBarItem.TOOLBAR_ID,
render: () => <BoardsToolBarItem render: () => <BoardsToolBarItem
key='boardsToolbarItem' key='boardsToolbarItem'
commands={this.commands} commands={this.commandRegistry}
boardsServiceClient={this.boardsServiceClient} boardsServiceClient={this.boardsServiceClient}
boardService={this.boardsService} />, boardService={this.boardsService} />,
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left' isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left'
@ -255,7 +263,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
id: ArduinoCommands.TOGGLE_ADVANCED_MODE.id, id: ArduinoCommands.TOGGLE_ADVANCED_MODE.id,
command: ArduinoCommands.TOGGLE_ADVANCED_MODE.id, command: ArduinoCommands.TOGGLE_ADVANCED_MODE.id,
tooltip: 'Toggle Advanced Mode', tooltip: 'Toggle Advanced Mode',
text: (ArduinoAdvancedMode.TOGGLED ? '$(toggle-on)' : '$(toggle-off)'), text: (EditorMode.IN_PRO_MODE ? '$(toggle-on)' : '$(toggle-off)'),
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right' isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right'
}); });
} }
@ -338,7 +346,7 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
}); });
} }
} else { } else {
this.commands.executeCommand(ArduinoCommands.OPEN_FILE_NAVIGATOR.id); this.commandRegistry.executeCommand(ArduinoCommands.OPEN_FILE_NAVIGATOR.id);
} }
} }
}); });
@ -385,9 +393,9 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
}) })
registry.registerCommand(ArduinoCommands.TOGGLE_ADVANCED_MODE, { registry.registerCommand(ArduinoCommands.TOGGLE_ADVANCED_MODE, {
execute: async () => { execute: async () => {
const oldState = ArduinoAdvancedMode.TOGGLED; const oldState = EditorMode.IN_PRO_MODE;
const inAdvancedMode = !oldState; const inAdvancedMode = !oldState;
window.localStorage.setItem(ArduinoAdvancedMode.LS_ID, String(inAdvancedMode)); window.localStorage.setItem(EditorMode.PRO_MODE_KEY, String(inAdvancedMode));
if (!inAdvancedMode) { if (!inAdvancedMode) {
// Close all widget that is neither editor nor `Output`. // Close all widget that is neither editor nor `Output`.
for (const area of ['left', 'right', 'bottom', 'main'] as Array<ApplicationShell.Area>) { for (const area of ['left', 'right', 'bottom', 'main'] as Array<ApplicationShell.Area>) {
@ -401,12 +409,12 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
window.location.reload(true); window.location.reload(true);
}, },
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right', isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'right',
isToggled: () => ArduinoAdvancedMode.TOGGLED isToggled: () => EditorMode.IN_PRO_MODE
}) })
} }
registerMenus(registry: MenuModelRegistry) { registerMenus(registry: MenuModelRegistry) {
if (!ArduinoAdvancedMode.TOGGLED) { if (!EditorMode.IN_PRO_MODE) {
// If are not in pro-mode, we have to disable the context menu for the tabs. // If are not in pro-mode, we have to disable the context menu for the tabs.
// Such as `Close`, `Close All`, etc. // Such as `Close`, `Close All`, etc.
for (const command of [ for (const command of [
@ -415,7 +423,9 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
CommonCommands.CLOSE_RIGHT_TABS, CommonCommands.CLOSE_RIGHT_TABS,
CommonCommands.CLOSE_ALL_TABS, CommonCommands.CLOSE_ALL_TABS,
CommonCommands.COLLAPSE_PANEL, CommonCommands.COLLAPSE_PANEL,
CommonCommands.TOGGLE_MAXIMIZED CommonCommands.TOGGLE_MAXIMIZED,
FileNavigatorCommands.REVEAL_IN_NAVIGATOR
]) { ]) {
registry.unregisterMenuAction(command); registry.unregisterMenuAction(command);
} }
@ -478,8 +488,8 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
const command: Command = { const command: Command = {
id: 'openSketch' + sketch.name id: 'openSketch' + sketch.name
} }
this.commands.registerCommand(command, { this.commandRegistry.registerCommand(command, {
execute: () => this.commands.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch) execute: () => this.commandRegistry.executeCommand(ArduinoCommands.OPEN_SKETCH.id, sketch)
}); });
registry.registerMenuAction(ArduinoToolbarContextMenu.WS_SKETCHES_GROUP, { registry.registerMenuAction(ArduinoToolbarContextMenu.WS_SKETCHES_GROUP, {

View File

@ -10,7 +10,7 @@ import { LanguageGrammarDefinitionContribution } from '@theia/monaco/lib/browser
import { LanguageClientContribution } from '@theia/languages/lib/browser'; import { LanguageClientContribution } from '@theia/languages/lib/browser';
import { ArduinoLanguageClientContribution } from './language/arduino-language-client-contribution'; import { ArduinoLanguageClientContribution } from './language/arduino-language-client-contribution';
import { LibraryListWidget } from './library/library-list-widget'; import { LibraryListWidget } from './library/library-list-widget';
import { ArduinoFrontendContribution, ArduinoAdvancedMode } from './arduino-frontend-contribution'; import { ArduinoFrontendContribution, EditorMode } from './arduino-frontend-contribution';
import { ArduinoLanguageGrammarContribution } from './language/arduino-language-grammar-contribution'; import { ArduinoLanguageGrammarContribution } from './language/arduino-language-grammar-contribution';
import { LibraryService, LibraryServicePath } from '../common/protocol/library-service'; import { LibraryService, LibraryServicePath } from '../common/protocol/library-service';
import { BoardsService, BoardsServicePath, BoardsServiceClient } from '../common/protocol/boards-service'; import { BoardsService, BoardsServicePath, BoardsServiceClient } from '../common/protocol/boards-service';
@ -199,7 +199,7 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
themeService.register(...ArduinoTheme.themes); themeService.register(...ArduinoTheme.themes);
// Customizing default Theia layout // Customizing default Theia layout
if (!ArduinoAdvancedMode.TOGGLED) { if (!EditorMode.IN_PRO_MODE) {
unbind(OutlineViewContribution); unbind(OutlineViewContribution);
bind(OutlineViewContribution).to(SilentOutlineViewContribution).inSingletonScope(); bind(OutlineViewContribution).to(SilentOutlineViewContribution).inSingletonScope();
unbind(ProblemContribution); unbind(ProblemContribution);
@ -220,7 +220,7 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
bind(SearchInWorkspaceFrontendContribution).to(SilentSearchInWorkspaceContribution).inSingletonScope(); bind(SearchInWorkspaceFrontendContribution).to(SilentSearchInWorkspaceContribution).inSingletonScope();
} else { } else {
// We use this CSS class on the body to modify the visibility of the close button for the editors and views. // We use this CSS class on the body to modify the visibility of the close button for the editors and views.
document.body.classList.add(ArduinoAdvancedMode.LS_ID); document.body.classList.add(EditorMode.PRO_MODE_KEY);
} }
unbind(FrontendApplication); unbind(FrontendApplication);
bind(FrontendApplication).to(ArduinoFrontendApplication).inSingletonScope(); bind(FrontendApplication).to(ArduinoFrontendApplication).inSingletonScope();

View File

@ -4,7 +4,7 @@ import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service
import { ConfigService } from '../common/protocol/config-service'; import { ConfigService } from '../common/protocol/config-service';
import { SketchesService } from '../common/protocol/sketches-service'; import { SketchesService } from '../common/protocol/sketches-service';
import { ArduinoWorkspaceRootResolver } from './arduino-workspace-resolver'; import { ArduinoWorkspaceRootResolver } from './arduino-workspace-resolver';
import { ArduinoAdvancedMode } from './arduino-frontend-contribution'; import { EditorMode as EditorMode } from './arduino-frontend-contribution';
@injectable() @injectable()
export class ArduinoWorkspaceService extends WorkspaceService { export class ArduinoWorkspaceService extends WorkspaceService {
@ -18,7 +18,7 @@ export class ArduinoWorkspaceService extends WorkspaceService {
@inject(LabelProvider) @inject(LabelProvider)
protected readonly labelProvider: LabelProvider; protected readonly labelProvider: LabelProvider;
async getDefaultWorkspacePath(): Promise<string | undefined> { async getDefaultWorkspaceUri(): Promise<string | undefined> {
const [hash, recentWorkspaces, recentSketches] = await Promise.all([ const [hash, recentWorkspaces, recentSketches] = await Promise.all([
window.location.hash, window.location.hash,
this.sketchService.getSketches().then(sketches => sketches.map(({ uri }) => uri)), this.sketchService.getSketches().then(sketches => sketches.map(({ uri }) => uri)),
@ -36,7 +36,8 @@ export class ArduinoWorkspaceService extends WorkspaceService {
await this.server.setMostRecentlyUsedWorkspace(uri); await this.server.setMostRecentlyUsedWorkspace(uri);
return toOpen.uri; return toOpen.uri;
} }
return (await this.sketchService.createNewSketch()).uri; const { sketchDirUri } = (await this.configService.getConfiguration());
return (await this.sketchService.createNewSketch(sketchDirUri)).uri;
} }
private async isValid(uri: string): Promise<boolean> { private async isValid(uri: string): Promise<boolean> {
@ -46,7 +47,7 @@ export class ArduinoWorkspaceService extends WorkspaceService {
} }
// The workspace root location must exist. However, when opening a workspace root in pro-mode, // The workspace root location must exist. However, when opening a workspace root in pro-mode,
// the workspace root must not be a sketch folder. It can be the default sketch directory, or any other directories, for instance. // the workspace root must not be a sketch folder. It can be the default sketch directory, or any other directories, for instance.
if (!ArduinoAdvancedMode.TOGGLED) { if (EditorMode.IN_PRO_MODE) {
return true; return true;
} }
const sketchFolder = await this.sketchService.isSketchFolder(uri); const sketchFolder = await this.sketchService.isSketchFolder(uri);

View File

@ -2,7 +2,7 @@ import { injectable, inject } from 'inversify';
import { FileSystem } from '@theia/filesystem/lib/common/filesystem'; import { FileSystem } from '@theia/filesystem/lib/common/filesystem';
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service'; import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application'; import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
import { ArduinoFrontendContribution, ArduinoAdvancedMode } from '../arduino-frontend-contribution'; import { ArduinoFrontendContribution, EditorMode } from '../arduino-frontend-contribution';
@injectable() @injectable()
export class ArduinoFrontendApplication extends FrontendApplication { export class ArduinoFrontendApplication extends FrontendApplication {
@ -21,7 +21,7 @@ export class ArduinoFrontendApplication extends FrontendApplication {
// If not in PRO mode, we open the sketch file with all the related files. // If not in PRO mode, we open the sketch file with all the related files.
// Otherwise, we reuse the workbench's restore functionality and we do not open anything at all. // Otherwise, we reuse the workbench's restore functionality and we do not open anything at all.
// TODO: check `otherwise`. Also, what if we check for opened editors, instead of blindly opening them? // TODO: check `otherwise`. Also, what if we check for opened editors, instead of blindly opening them?
if (!ArduinoAdvancedMode.TOGGLED) { if (!EditorMode.IN_PRO_MODE) {
this.workspaceService.roots.then(roots => { this.workspaceService.roots.then(roots => {
for (const root of roots) { for (const root of roots) {
this.fileSystem.exists(root.uri).then(exists => { this.fileSystem.exists(root.uri).then(exists => {

View File

@ -1,10 +1,17 @@
import { injectable } from 'inversify'; import { injectable, postConstruct } from 'inversify';
import { FileNavigatorContribution } from '@theia/navigator/lib/browser/navigator-contribution'; import { FileNavigatorContribution } from '@theia/navigator/lib/browser/navigator-contribution';
import { FrontendApplication } from '@theia/core/lib/browser'; import { FrontendApplication } from '@theia/core/lib/browser';
@injectable() @injectable()
export class SilentNavigatorContribution extends FileNavigatorContribution { export class SilentNavigatorContribution extends FileNavigatorContribution {
@postConstruct()
protected async init(): Promise<void> {
// @ts-ignore
delete this.toggleCommand; // The `Explorer` should not be accessible via command or keybinding.
return super.init();
}
async initializeLayout(app: FrontendApplication): Promise<void> { async initializeLayout(app: FrontendApplication): Promise<void> {
} }

View File

@ -8,10 +8,11 @@ export interface SketchesService {
getSketches(uri?: string): Promise<Sketch[]> getSketches(uri?: string): Promise<Sketch[]>
getSketchFiles(uri: string): Promise<string[]> getSketchFiles(uri: string): Promise<string[]>
/** /**
* Creates a new sketch folder in the `parentUri` location. If `parentUri` is not specified, * Creates a new sketch folder in the `parentUri` location.
* it falls back to the default `sketchDirUri` from the CLI. * Normally, `parentUri` is the client's workspace root, or the default `sketchDirUri` from the CLI.
* Note, `parentUri` and `sketchDirUri` can be the same.
*/ */
createNewSketch(parentUri?: string): Promise<Sketch> createNewSketch(parentUri: string): Promise<Sketch>
isSketchFolder(uri: string): Promise<boolean> isSketchFolder(uri: string): Promise<boolean>
} }