-
-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
Akos Kitta
committed
Sep 20, 2019
1 parent
ac4e877
commit daedae1
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
arduino-ide-extension/src/browser/editor/arduino-monaco-editor-provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
arduino-ide-extension/src/browser/markers/arduino-problem-manager.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
arduino-ide-extension/src/browser/shell/arduino-tab-bar-decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |