mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-26 20:56:35 +00:00
PROEDITOR-50: Customized the editor for built-ins
- From now on, sources from the `dataDir` opened in a read-only editor. - Disabled the tab-bar decoration for built-ins. - No problem markers for the built-ins. Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
ac4e877a10
commit
daedae1ba7
@ -63,6 +63,12 @@ import { MonitorWidget } from './monitor/monitor-widget';
|
|||||||
import { MonitorViewContribution } from './monitor/monitor-view-contribution';
|
import { MonitorViewContribution } from './monitor/monitor-view-contribution';
|
||||||
import { MonitorConnection } from './monitor/monitor-connection';
|
import { MonitorConnection } from './monitor/monitor-connection';
|
||||||
import { MonitorModel } from './monitor/monitor-model';
|
import { MonitorModel } from './monitor/monitor-model';
|
||||||
|
import { MonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider';
|
||||||
|
import { ArduinoMonacoEditorProvider } from './editor/arduino-monaco-editor-provider';
|
||||||
|
import { TabBarDecoratorService } from '@theia/core/lib/browser/shell/tab-bar-decorator';
|
||||||
|
import { ArduinoTabBarDecoratorService } from './shell/arduino-tab-bar-decorator';
|
||||||
|
import { ProblemManager } from '@theia/markers/lib/browser';
|
||||||
|
import { ArduinoProblemManager } from './markers/arduino-problem-manager';
|
||||||
const ElementQueries = require('css-element-queries/src/ElementQueries');
|
const ElementQueries = require('css-element-queries/src/ElementQueries');
|
||||||
|
|
||||||
export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => {
|
export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Unbind, isBound: interfaces.IsBound, rebind: interfaces.Rebind) => {
|
||||||
@ -213,4 +219,19 @@ export default new ContainerModule((bind: interfaces.Bind, unbind: interfaces.Un
|
|||||||
}
|
}
|
||||||
unbind(FrontendApplication);
|
unbind(FrontendApplication);
|
||||||
bind(FrontendApplication).to(CustomFrontendApplication).inSingletonScope();
|
bind(FrontendApplication).to(CustomFrontendApplication).inSingletonScope();
|
||||||
|
|
||||||
|
// monaco customizations
|
||||||
|
unbind(MonacoEditorProvider);
|
||||||
|
bind(ArduinoMonacoEditorProvider).toSelf().inSingletonScope();
|
||||||
|
bind(MonacoEditorProvider).toService(ArduinoMonacoEditorProvider);
|
||||||
|
|
||||||
|
// decorator customizations
|
||||||
|
unbind(TabBarDecoratorService);
|
||||||
|
bind(ArduinoTabBarDecoratorService).toSelf().inSingletonScope();
|
||||||
|
bind(TabBarDecoratorService).toService(ArduinoTabBarDecoratorService);
|
||||||
|
|
||||||
|
// problem markers
|
||||||
|
unbind(ProblemManager);
|
||||||
|
bind(ArduinoProblemManager).toSelf().inSingletonScope();
|
||||||
|
bind(ProblemManager).toService(ArduinoProblemManager);
|
||||||
});
|
});
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
import { inject, injectable } from 'inversify';
|
||||||
|
import URI from '@theia/core/lib/common/uri';
|
||||||
|
import { DisposableCollection } from '@theia/core/lib/common/disposable';
|
||||||
|
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
|
||||||
|
import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model';
|
||||||
|
import { MonacoEditorProvider } from '@theia/monaco/lib/browser/monaco-editor-provider';
|
||||||
|
import { ConfigService } from '../../common/protocol/config-service';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class ArduinoMonacoEditorProvider extends MonacoEditorProvider {
|
||||||
|
|
||||||
|
@inject(ConfigService)
|
||||||
|
protected readonly configService: ConfigService;
|
||||||
|
protected dataDirUri: string | undefined;
|
||||||
|
|
||||||
|
protected async getModel(uri: URI, toDispose: DisposableCollection): Promise<MonacoEditorModel> {
|
||||||
|
// `createMonacoEditorOptions` is not `async` so we ask the `dataDirUri` here.
|
||||||
|
// https://github.com/eclipse-theia/theia/issues/6234
|
||||||
|
const { dataDirUri } = await this.configService.getConfiguration()
|
||||||
|
this.dataDirUri = dataDirUri;
|
||||||
|
return super.getModel(uri, toDispose);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected createMonacoEditorOptions(model: MonacoEditorModel): MonacoEditor.IOptions {
|
||||||
|
const options = this.createOptions(this.preferencePrefixes, model.uri, model.languageId);
|
||||||
|
options.model = model.textEditorModel;
|
||||||
|
options.readOnly = model.readOnly;
|
||||||
|
if (this.dataDirUri) {
|
||||||
|
options.readOnly = new URI(this.dataDirUri).isEqualOrParent(new URI(model.uri));
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
import { inject, injectable, postConstruct } from 'inversify';
|
||||||
|
import { Diagnostic } from 'vscode-languageserver-types';
|
||||||
|
import URI from '@theia/core/lib/common/uri';
|
||||||
|
import { Marker } from '@theia/markers/lib/common/marker';
|
||||||
|
import { ProblemManager } from '@theia/markers/lib/browser/problem/problem-manager';
|
||||||
|
import { ConfigService } from '../../common/protocol/config-service';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class ArduinoProblemManager extends ProblemManager {
|
||||||
|
|
||||||
|
@inject(ConfigService)
|
||||||
|
protected readonly configService: ConfigService;
|
||||||
|
protected dataDirUri: URI | undefined;
|
||||||
|
|
||||||
|
@postConstruct()
|
||||||
|
protected init(): void {
|
||||||
|
super.init();
|
||||||
|
this.configService.getConfiguration().then(({ dataDirUri }) => this.dataDirUri = new URI(dataDirUri));
|
||||||
|
}
|
||||||
|
|
||||||
|
setMarkers(uri: URI, owner: string, data: Diagnostic[]): Marker<Diagnostic>[] {
|
||||||
|
if (this.dataDirUri && this.dataDirUri.isEqualOrParent(uri)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return super.setMarkers(uri, owner, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
import { inject, injectable, postConstruct } from 'inversify';
|
||||||
|
import URI from '@theia/core/lib/common/uri';
|
||||||
|
import { Title, Widget } from '@phosphor/widgets';
|
||||||
|
import { WidgetDecoration } from '@theia/core/lib/browser/widget-decoration';
|
||||||
|
import { TabBarDecoratorService } from '@theia/core/lib/browser/shell/tab-bar-decorator';
|
||||||
|
import { ConfigService } from '../../common/protocol/config-service';
|
||||||
|
import { EditorWidget } from '@theia/editor/lib/browser';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class ArduinoTabBarDecoratorService extends TabBarDecoratorService {
|
||||||
|
|
||||||
|
@inject(ConfigService)
|
||||||
|
protected readonly configService: ConfigService;
|
||||||
|
protected dataDirUri: URI | undefined;
|
||||||
|
|
||||||
|
@postConstruct()
|
||||||
|
protected init(): void {
|
||||||
|
super.init();
|
||||||
|
this.configService.getConfiguration().then(({ dataDirUri }) => this.dataDirUri = new URI(dataDirUri));
|
||||||
|
}
|
||||||
|
|
||||||
|
getDecorations(title: Title<Widget>): WidgetDecoration.Data[] {
|
||||||
|
if (title.owner instanceof EditorWidget) {
|
||||||
|
const editor = title.owner.editor;
|
||||||
|
if (this.dataDirUri && this.dataDirUri.isEqualOrParent(editor.uri)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.getDecorations(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user